:root {
  color-scheme: light dark;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-subtle: #eef2f8;
  --text: #0f172a;
  --text-muted: #475569;
  --border: #dbe3ef;
  --primary: #1e40af;
  --primary-hover: #1e3a8a;
  --primary-fg: #ffffff;
  --primary-soft: #dbeafe;
  --primary-soft-fg: #1e3a8a;
  --accent-amber: #d97706;
  --accent-amber-bg: #fef3c7;
  --accent-amber-fg: #92400e;
  --correct-bg: #dcfce7;
  --correct-border: #22c55e;
  --correct-fg: #15803d;
  --wrong-bg: #fee2e2;
  --wrong-border: #ef4444;
  --wrong-fg: #b91c1c;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 9px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120;
    --surface: #151f32;
    --surface-subtle: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #283548;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-fg: #ffffff;
    --primary-soft: #1e3a8a;
    --primary-soft-fg: #dbeafe;
    --accent-amber: #f59e0b;
    --accent-amber-bg: #3b2a10;
    --accent-amber-fg: #fde68a;
    --correct-bg: #123123;
    --correct-border: #22c55e;
    --correct-fg: #86efac;
    --wrong-bg: #37181d;
    --wrong-border: #f87171;
    --wrong-fg: #fca5a5;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #151f32;
  --surface-subtle: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #283548;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-fg: #ffffff;
  --primary-soft: #1e3a8a;
  --primary-soft-fg: #dbeafe;
  --accent-amber: #f59e0b;
  --accent-amber-bg: #3b2a10;
  --accent-amber-fg: #fde68a;
  --correct-bg: #123123;
  --correct-border: #22c55e;
  --correct-fg: #86efac;
  --wrong-bg: #37181d;
  --wrong-border: #f87171;
  --wrong-fg: #fca5a5;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
    "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 600px;
  margin: 0 auto;
}

/* 상단 바 */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px);
}

.top-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 14px;
  gap: 8px;
}

.app-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-height: 40px;
  min-width: 40px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.icon-btn:active {
  background: var(--surface-subtle);
}

.back-label {
  font-size: 0.92rem;
}

.progress-track {
  height: 4px;
  background: var(--surface-subtle);
  width: 100%;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.25s ease;
}

/* 메인 컨텐츠 */
.main-content {
  flex: 1;
  padding: 16px 16px calc(28px + env(safe-area-inset-bottom, 0px));
}

.hidden {
  display: none !important;
}

/* 홈 요약 카드 */
.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
  margin-bottom: 22px;
}

.hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.hero-eyebrow {
  margin: 0 0 2px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary);
}

.hero-heading {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.hero-ring {
  min-width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-soft-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.98rem;
}

.hero-bar-bg {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-subtle);
  overflow: hidden;
  margin-bottom: 16px;
}

.hero-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #60a5fa);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.hero-quick-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

@media (max-width: 400px) {
  .hero-quick-row {
    grid-template-columns: 1fr;
  }
}

/* 공통 버튼 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 11px 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.985);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-fg);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-subtle);
  color: var(--text);
  border-color: var(--border);
}

.btn-wrong {
  background: var(--wrong-bg);
  color: var(--wrong-fg);
  border-color: var(--wrong-border);
}

.btn-danger {
  background: #dc2626;
  color: #ffffff;
}

.btn-outline-sm {
  min-height: 40px;
  padding: 8px 12px;
  font-size: 0.85rem;
  background: var(--surface);
  color: var(--text-muted);
  border-color: var(--border);
}

/* 섹션 헤더 & 단원 카드 */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 2px 12px;
}

.section-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 800;
}

.text-link-btn {
  border: none;
  background: none;
  color: var(--primary);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 6px 4px;
  cursor: pointer;
}

.unit-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.unit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.unit-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.unit-meta {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 3px;
}

.unit-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.38;
}

.unit-count-badge {
  flex-shrink: 0;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-subtle);
  color: var(--text-muted);
}

.unit-mini-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-subtle);
  overflow: hidden;
  margin: 10px 0 12px;
}

.unit-mini-fill {
  height: 100%;
  background: #22c55e;
  border-radius: 999px;
}

.unit-btn-row {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 8px;
}

.unit-btn-row .btn {
  min-height: 42px;
  padding: 8px 10px;
  font-size: 0.88rem;
}

.footer-actions {
  margin-top: 26px;
  text-align: center;
}

.subtle-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.82rem;
  text-decoration: underline;
  padding: 8px 12px;
  cursor: pointer;
}

/* 퀴즈 화면 */
.quiz-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.unit-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-soft-fg);
  font-size: 0.8rem;
  font-weight: 700;
}

.counter-pill {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text-muted);
}

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 18px;
  box-shadow: var(--shadow-md);
  margin-bottom: 14px;
}

.question-instruction {
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
}

.question-body {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 700;
  line-height: 1.58;
  word-break: keep-all;
}

.hint-banner {
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--accent-amber-bg);
  color: var(--accent-amber-fg);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.hint-tag {
  font-size: 0.76rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.08);
}

.chosung-value {
  font-size: 1.12rem;
  letter-spacing: 0.08em;
}

.length-badge {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 600;
}

/* 단답형 입력 (iOS 자동 줌 방지를 위해 16px 이상 필수) */
.answer-form {
  margin-bottom: 12px;
}

.input-group {
  display: flex;
  gap: 8px;
}

.answer-input {
  flex: 1;
  min-width: 0;
  height: 52px;
  padding: 0 15px;
  font-family: inherit;
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.15s ease;
}

.answer-input:focus {
  border-color: var(--primary);
}

.answer-input:disabled {
  background: var(--surface-subtle);
  opacity: 0.85;
}

.btn-submit {
  height: 52px;
  min-width: 78px;
  background: var(--primary);
  color: var(--primary-fg);
  font-size: 1rem;
}

.input-tip {
  margin: 6px 4px 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* 피드백 카드 */
.feedback-card {
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 14px;
  border: 2px solid var(--border);
}

.feedback-card.is-correct {
  background: var(--correct-bg);
  border-color: var(--correct-border);
}

.feedback-card.is-wrong {
  background: var(--wrong-bg);
  border-color: var(--wrong-border);
}

.feedback-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.feedback-badge {
  font-size: 0.98rem;
  font-weight: 800;
}

.is-correct .feedback-badge {
  color: var(--correct-fg);
}

.is-wrong .feedback-badge {
  color: var(--wrong-fg);
}

.feedback-user-ans {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.feedback-answer-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin-bottom: 12px;
}

.feedback-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

.feedback-correct-ans {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text);
}

.feedback-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.btn-next {
  flex: 1;
}

/* 힌트 툴바 & 단어 보기 */
.hint-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 40px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
}

.chip-btn[aria-pressed="true"] {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: var(--primary);
}

.chip-btn-muted {
  color: var(--text-muted);
}

.wordbank-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.wordbank-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.wordbank-summary::-webkit-details-marker {
  display: none;
}

.wordbank-chevron {
  transition: transform 0.2s ease;
}

.wordbank-panel[open] .wordbank-chevron {
  transform: rotate(180deg);
}

.wordbank-helper {
  padding: 0 16px 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.wordbank-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 14px 16px;
}

.word-chip {
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.word-chip:active {
  background: var(--primary-soft);
}

.word-chip.is-solved {
  opacity: 0.45;
  text-decoration: line-through;
}

/* 결과 화면 */
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 20px;
  text-align: center;
  box-shadow: var(--shadow-md);
  margin-bottom: 20px;
}

.result-eyebrow {
  margin: 0 0 6px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--primary);
}

.result-score {
  font-size: 2.35rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}

.result-message {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.missed-section {
  margin-top: 8px;
}

.missed-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.missed-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--wrong-border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
}

.missed-term {
  font-weight: 800;
  font-size: 1rem;
  margin-bottom: 4px;
  color: var(--wrong-fg);
}

.missed-desc {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text);
}

/* 전체 개념표 (암기장) */
.study-controls {
  position: sticky;
  top: 57px;
  z-index: 10;
  background: var(--bg);
  padding-bottom: 12px;
}

.search-input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  margin-bottom: 8px;
}

.study-filter-row {
  display: flex;
  gap: 8px;
}

.unit-select {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
}

.study-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.study-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.study-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}

.study-term-btn {
  border: none;
  padding: 3px 9px;
  border-radius: 7px;
  background: var(--primary-soft);
  color: var(--primary-soft-fg);
  font-family: inherit;
  font-size: 0.96rem;
  font-weight: 800;
  cursor: pointer;
}

.study-term-btn.is-blind {
  background: var(--surface-subtle);
  color: transparent;
  user-select: none;
  position: relative;
  min-width: 96px;
}

.study-term-btn.is-blind::after {
  content: "터치하여 확인";
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.study-num {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-muted);
}

.study-desc {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.48;
}

/* 모달 다이얼로그 */
.modal-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  max-width: 360px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow-md);
}

.modal-dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.modal-body {
  padding: 22px 20px 18px;
}

.modal-title {
  margin: 0 0 8px;
  font-size: 1.08rem;
  font-weight: 800;
}

.modal-desc {
  margin: 0 0 18px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
