* {
  box-sizing: border-box;
}

:root {
  --color-bg: #f0f4f8;
  --color-card: #ffffff;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-admin: #059669;
  --color-admin-dark: #047857;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --max-width: 480px;
}

body {
  margin: 0;
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--color-bg);
  min-height: 100vh;
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: var(--max-width);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--color-bg);
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 20px 20px 16px;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: white;
  box-shadow: var(--shadow-md);
}

.header h1 {
  margin: 0 0 4px;
  font-size: 1.35rem;
  font-weight: 700;
}

.subtitle {
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.9;
}

/* Main */
.main {
  padding: 20px 20px 40px;
}

/* Admin: 주제 입력 */
.admin-section {
  background: var(--color-card);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
  border: 2px dashed var(--color-admin);
}

.admin-title {
  margin: 0 0 14px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-admin-dark);
}

.admin-section input[type="text"],
.admin-section input[type="password"] {
  width: 100%;
  padding: 12px 16px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  margin-bottom: 10px;
  transition: border-color 0.2s;
}

.admin-section input[type="text"]:focus,
.admin-section input[type="password"]:focus {
  outline: none;
  border-color: var(--color-admin);
}

.admin-section input[type="text"]::placeholder,
.admin-section input[type="password"]::placeholder {
  color: var(--color-text-muted);
  opacity: 0.8;
}

.btn-add-topic {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--color-admin) 0%, var(--color-admin-dark) 100%);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

.btn-add-topic:hover,
.btn-add-topic:focus {
  opacity: 0.95;
}

.btn-add-topic:active {
  transform: scale(0.98);
}

/* Topic List */
.topic-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.topic-list-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

/* Topic Block */
.topic-block {
  background: var(--color-card);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
}

.topic-link-block {
  cursor: pointer;
  transition: box-shadow 0.2s;
}

.topic-link-block:hover {
  box-shadow: var(--shadow-md);
}

.topic-meta-inline {
  margin: 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.topic-block-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-border);
}

.topic-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.4;
  flex: 1;
}

.btn-delete-topic {
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-delete-topic:hover {
  color: #dc2626;
  border-color: rgba(220, 38, 38, 0.4);
}

.topic-desc {
  margin: 0 0 16px;
  font-size: 0.88rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* 의견 입력 폼 (주제 바로 밑) */
.opinion-form {
  margin-bottom: 16px;
}

.opinion-form input[type="text"],
.opinion-form textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  margin-bottom: 10px;
  resize: none;
  transition: border-color 0.2s;
}

.opinion-form input[type="text"]:focus,
.opinion-form textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.opinion-form input::placeholder,
.opinion-form textarea::placeholder {
  color: var(--color-text-muted);
  opacity: 0.8;
}

.btn-submit-opinion {
  width: 100%;
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

.btn-submit-opinion:hover,
.btn-submit-opinion:focus {
  opacity: 0.95;
}

.btn-submit-opinion:active {
  transform: scale(0.98);
}

/* 의견 목록 */
.opinion-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.opinion-item {
  padding: 12px 14px;
  background: var(--color-bg);
  border-radius: 10px;
  margin-bottom: 8px;
  border-left: 4px solid var(--color-primary);
}

.opinion-item:last-child {
  margin-bottom: 0;
}

.opinion-item-wrapper {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.opinion-item-content {
  flex: 1;
  min-width: 0;
}

.btn-delete-opinion {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-delete-opinion:hover {
  color: #dc2626;
  border-color: rgba(220, 38, 38, 0.4);
}

.opinion-author {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: 4px;
}

.opinion-author.anonymous {
  color: var(--color-text-muted);
  font-weight: 500;
}

.opinion-text {
  font-size: 0.92rem;
  color: var(--color-text);
  line-height: 1.5;
  margin: 0;
}

.opinion-empty {
  text-align: center;
  padding: 16px;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  background: var(--color-bg);
  border-radius: 10px;
}

/* Topic 페이지 (새 창) */
.header-topic {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topic-page-title {
  margin: 0;
  font-size: 1.2rem;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-close-page {
  flex-shrink: 0;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  color: white;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  text-decoration: none;
  transition: background 0.2s;
}

.btn-close-page:hover {
  background: rgba(255, 255, 255, 0.35);
}

.topic-main .opinion-section h3 {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
}

/* Safe area */
@supports (padding: max(0px)) {
  .header {
    padding-left: max(20px, calc(20px + env(safe-area-inset-left)));
    padding-right: max(20px, calc(20px + env(safe-area-inset-right)));
  }
  .main {
    padding-left: max(20px, calc(20px + env(safe-area-inset-left)));
    padding-right: max(20px, calc(20px + env(safe-area-inset-right)));
  }
}
