/* ── RESET ───────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── DESIGN TOKENS — GSSS Jethantri brand ───────────────────────────────────── */
:root {
  /* Brand */
  --blue:        #1e40af;
  --blue-dark:   #1e3a8a;
  --blue-mid:    #2563eb;
  --blue-light:  #dbeafe;
  --blue-50:     #eff6ff;
  --gold:        #f59e0b;
  --gold-dark:   #d97706;
  --gold-light:  #fef3c7;
  --gold-50:     #fffbeb;

  /* Semantic */
  --green:       #059669;
  --green-light: #d1fae5;
  --orange:      #ea580c;
  --orange-light:#ffedd5;
  --red:         #dc2626;
  --red-light:   #fee2e2;
  --purple:      #7c3aed;
  --purple-light:#ede9fe;

  /* Neutrals */
  --gray-50:  #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Gradients */
  --grad-hero:   linear-gradient(135deg, #1e3a8a 0%, #1e40af 55%, #2563eb 100%);
  --grad-gold:   linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%);
  --grad-green:  linear-gradient(135deg, #059669 0%, #10b981 100%);

  /* Layout */
  --radius-sm:  8px;
  --radius:     14px;
  --radius-lg:  20px;
  --shadow-sm:  0 1px 4px rgba(0,0,0,.08);
  --shadow:     0 2px 14px rgba(0,0,0,.10);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.14);
  --max-w:      680px;
  --gap:        .75rem;
  --font:       'Inter', system-ui, sans-serif;
}

/* ── BASE ────────────────────────────────────────────────────────────────────── */
html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100vh;
  padding-bottom: 3rem;
}
button { cursor: pointer; font-family: inherit; border: none; background: none; }
img    { max-width: 100%; display: block; }

/* ── HEADER ──────────────────────────────────────────────────────────────────── */
.app-header {
  background: var(--grad-hero);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 16px rgba(30,58,138,.3);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: .65rem 1rem;
  gap: .5rem;
}

.header-brand { display: flex; align-items: center; gap: .65rem; }

.brand-logo-img {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4);
  object-fit: cover;
  flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; }
.brand-name { font-size: 1rem; font-weight: 800; line-height: 1.2; letter-spacing: -.01em; }
.brand-tagline { font-size: .68rem; opacity: .8; letter-spacing: .02em; }

.header-actions { display: flex; align-items: center; gap: .4rem; }

.btn-settings, .btn-history {
  position: relative;
  background: rgba(255,255,255,.15);
  border-radius: var(--radius-sm);
  padding: .45rem .55rem;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.btn-settings:hover, .btn-history:hover { background: rgba(255,255,255,.28); }

.history-badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--gold);
  color: #000;
  font-size: .65rem;
  font-weight: 800;
  width: 16px; height: 16px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}

/* Step bar */
.step-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .5rem 1rem .65rem;
  gap: 0;
  max-width: var(--max-w);
  margin: 0 auto;
}
.step-item {
  display: flex; flex-direction: column; align-items: center;
  gap: .2rem; color: rgba(255,255,255,.45); font-size: .68rem; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase;
  transition: color .3s;
}
.step-item.active  { color: #fff; }
.step-item.done    { color: rgba(255,255,255,.7); }

.step-dot {
  width: 26px; height: 26px; border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700;
  border: 2px solid rgba(255,255,255,.3);
  transition: all .3s;
}
.step-item.active .step-dot {
  background: var(--gold);
  border-color: var(--gold);
  color: #000;
  box-shadow: 0 0 0 4px rgba(245,158,11,.3);
}
.step-item.done .step-dot {
  background: rgba(255,255,255,.35);
  border-color: rgba(255,255,255,.5);
}
.step-line {
  flex: 1; height: 2px;
  background: rgba(255,255,255,.2);
  margin: 0 .4rem;
  margin-bottom: 1rem;
  max-width: 60px;
}

/* ── API WARNING ─────────────────────────────────────────────────────────────── */
.api-warning {
  background: var(--gold-light);
  border-bottom: 2px solid var(--gold);
  padding: .6rem 1rem;
  display: flex; align-items: center; justify-content: space-between;
  font-size: .85rem; font-weight: 600; gap: .5rem;
  flex-wrap: wrap;
}
.api-warning button {
  background: var(--gold); color: #000;
  border-radius: 6px; padding: .3rem .9rem;
  font-size: .82rem; font-weight: 700;
}

/* ── PAGE WRAPPER ────────────────────────────────────────────────────────────── */
.page {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: .85rem .9rem 2rem;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ── HERO SECTION ────────────────────────────────────────────────────────────── */
.hero {
  background: #fff;
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
}
.hero h1 { font-size: 1.15rem; font-weight: 800; color: var(--blue-dark); margin-bottom: .18rem; }
.hero p   { font-size: .85rem; color: var(--gray-600); line-height: 1.5; }
.hero p strong { color: var(--blue); }

.hero-stats { display: flex; gap: .4rem; flex-wrap: wrap; flex-shrink: 0; }
.stat-pill {
  background: var(--blue-50);
  color: var(--blue);
  font-size: .75rem; font-weight: 700;
  padding: .3rem .65rem; border-radius: 50px;
  white-space: nowrap;
}

/* ── FILTER BAR ──────────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex; gap: .4rem;
  overflow-x: auto; padding-bottom: .15rem;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-btn {
  flex-shrink: 0;
  background: #fff;
  border: 2px solid var(--gray-200);
  border-radius: 50px;
  padding: .4rem .9rem;
  font-size: .82rem; font-weight: 600;
  color: var(--gray-600);
  transition: all .15s;
}
.filter-btn:hover  { border-color: var(--blue); color: var(--blue); }
.filter-btn.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

/* ── PASSAGE GRID ────────────────────────────────────────────────────────────── */
.passage-grid { display: flex; flex-direction: column; gap: .85rem; }

.level-group-title {
  font-size: .72rem; font-weight: 800;
  letter-spacing: .08em; text-transform: uppercase;
  margin-bottom: .5rem; padding-left: .2rem;
  display: flex; align-items: center; gap: .4rem;
}
.level-group-title.l1 { color: var(--green); }
.level-group-title.l2 { color: var(--blue); }
.level-group-title.l3 { color: var(--orange); }

.level-desc {
  font-size: .75rem; color: var(--gray-400); font-weight: 500;
}

.passage-cards-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }

@media (max-width: 480px) { .passage-cards-row { grid-template-columns: 1fr; } }

.passage-card {
  background: #fff;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  text-align: left;
  transition: all .18s;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: .35rem;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  width: 100%;
}
.passage-card::before {
  content: '';
  position: absolute; top: 0; left: 0;
  width: 3px; height: 100%;
  border-radius: 3px 0 0 3px;
}
.passage-card.l1::before { background: var(--green); }
.passage-card.l2::before { background: var(--blue); }
.passage-card.l3::before { background: var(--orange); }

.passage-card:hover, .passage-card:focus-visible {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  outline: none;
}
.passage-card.l1:hover { border-color: var(--green); }
.passage-card.l2:hover { border-color: var(--blue); }
.passage-card.l3:hover { border-color: var(--orange); }

.pc-emoji  { font-size: 1.4rem; line-height: 1; }
.pc-title  { font-size: .95rem; font-weight: 700; color: var(--gray-800); }
.pc-topic  { font-size: .72rem; color: var(--gray-400); font-weight: 500; }
.pc-pills  { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .1rem; }
.pc-pill   {
  font-size: .68rem; font-weight: 600;
  padding: .15rem .45rem; border-radius: 50px;
  background: var(--gray-100); color: var(--gray-500);
}

/* ── BACK BUTTON ─────────────────────────────────────────────────────────────── */
.btn-back {
  display: inline-flex; align-items: center; gap: .3rem;
  color: var(--blue); font-size: .88rem; font-weight: 600;
  padding: .3rem 0; margin-bottom: .75rem;
  transition: gap .15s;
}
.btn-back:hover { gap: .5rem; }

/* ── PASSAGE DISPLAY CARD ────────────────────────────────────────────────────── */
.passage-card-display {
  background: #fff;
  border-radius: var(--radius);
  border: 2px solid var(--blue-light);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.pcd-header {
  display: flex; align-items: flex-start; gap: .75rem;
  margin-bottom: .9rem;
}
.pcd-emoji  { font-size: 2rem; line-height: 1; flex-shrink: 0; }
.pcd-title  { font-size: 1.05rem; font-weight: 800; color: var(--blue-dark); display: block; margin-bottom: .3rem; }
.pcd-meta   { flex: 1; }
.pcd-pills  { display: flex; gap: .35rem; flex-wrap: wrap; }

.level-pill {
  font-size: .7rem; font-weight: 700; padding: .2rem .55rem; border-radius: 50px;
}
.level-pill.l1 { background: var(--green-light); color: var(--green); }
.level-pill.l2 { background: var(--blue-light);  color: var(--blue); }
.level-pill.l3 { background: var(--orange-light); color: var(--orange); }

.words-pill, .time-pill {
  font-size: .7rem; font-weight: 600; padding: .2rem .55rem; border-radius: 50px;
  background: var(--gray-100); color: var(--gray-500);
}

/* Passage text with word spans for live highlighting */
.passage-text {
  font-size: 1.22rem;
  line-height: 2;
  color: var(--gray-800);
  letter-spacing: .01em;
  word-spacing: .12em;
}

/* Reading mode — subtle highlight on passage card while recording */
.passage-text.reading-mode {
  background: var(--gold-50);
  border-radius: var(--radius-sm);
  padding: .4rem .5rem;
  margin: -.4rem -.5rem;
}

/* Each word wrapped in a span for karaoke highlight */
.passage-text .word-span {
  display: inline;
  border-radius: 5px;
  padding: .05rem .1rem;
  transition: background .15s, color .15s;
  cursor: default;
}
.passage-text .word-span.word-active {
  background: var(--gold);
  color: #000;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(245,158,11,.4);
}
.passage-text .word-span.word-done {
  color: var(--gray-400);
}

.passage-hint {
  display: flex; align-items: flex-start; gap: .4rem;
  margin-top: .9rem; padding-top: .75rem;
  border-top: 1px solid var(--gray-200);
  font-size: .82rem; color: var(--gray-500); line-height: 1.5;
}
.passage-hint svg { flex-shrink: 0; margin-top: .1rem; color: var(--blue); }

/* ── WAVEFORM ────────────────────────────────────────────────────────────────── */
.waveform-wrap {
  background: var(--gray-900);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: .85rem;
  height: 60px;
}
#waveform-canvas { width: 100%; height: 60px; display: block; }

/* ── RECORD CARD ─────────────────────────────────────────────────────────────── */
.record-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.25rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.rec-state { margin-bottom: .6rem; }

.rec-icon-wrap {
  font-size: 2.5rem; line-height: 1;
  margin-bottom: .5rem;
  animation: none;
}
.rec-icon-wrap.recording { animation: micPulse 1s ease-in-out infinite; }

@keyframes micPulse {
  0%,100% { transform: scale(1); }
  50%      { transform: scale(1.12); }
}

.rec-instruction p {
  font-size: .92rem; color: var(--gray-600); line-height: 1.6;
}
.rec-instruction strong { color: var(--gray-800); }

.rec-live {
  display: flex; align-items: center; justify-content: center;
  gap: .55rem; margin-bottom: .4rem;
}
.rec-dot-anim {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--red);
  animation: pulse .9s infinite;
  flex-shrink: 0;
}
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.35;transform:scale(.8)} }

.rec-live-label {
  font-size: .72rem; font-weight: 800;
  letter-spacing: .1em; color: var(--red);
}
.rec-timer {
  font-size: 1.3rem; font-weight: 800;
  color: var(--gray-800); font-variant-numeric: tabular-nums;
}
.rec-active-hint { font-size: .82rem; color: var(--gray-500); line-height: 1.5; margin-bottom: .65rem; }

.rec-btn-row {
  display: flex; gap: .75rem; justify-content: center;
  flex-wrap: wrap;
}

.btn-record {
  display: inline-flex; align-items: center; gap: .5rem;
  background: var(--grad-hero);
  color: #fff; font-size: 1rem; font-weight: 700;
  padding: .9rem 2rem; border-radius: 50px;
  box-shadow: 0 4px 18px rgba(30,64,175,.35);
  transition: opacity .15s, transform .1s;
  min-width: 180px; justify-content: center;
}
.btn-record:hover  { opacity: .92; }
.btn-record:active { transform: scale(.97); }

.btn-stop {
  display: inline-flex; align-items: center; gap: .5rem;
  background: var(--red);
  color: #fff; font-size: 1rem; font-weight: 700;
  padding: .9rem 1.75rem; border-radius: 50px;
  box-shadow: 0 4px 14px rgba(220,38,38,.3);
  transition: opacity .15s;
  min-width: 130px; justify-content: center;
}
.btn-stop:hover    { opacity: .9; }
.btn-stop:disabled { opacity: .5; cursor: not-allowed; }

/* Audio playback */
.audio-playback {
  margin-top: 1rem;
  padding-top: .9rem;
  border-top: 1px solid var(--gray-200);
  display: flex; align-items: center; gap: .6rem;
  flex-wrap: wrap;
}
.playback-label { font-size: .8rem; font-weight: 600; color: var(--gray-500); white-space: nowrap; }
.audio-playback audio { flex: 1; min-width: 180px; height: 36px; }

/* ── RESULTS ─────────────────────────────────────────────────────────────────── */
.result-hero {
  background: var(--grad-hero);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .5rem;
}
.result-fluency-badge {
  font-size: 1rem; font-weight: 800;
  padding: .4rem 1rem; border-radius: 50px;
  border: 2px solid rgba(255,255,255,.5);
  color: #fff;
}
.result-passage-name { font-size: .82rem; color: rgba(255,255,255,.75); font-weight: 500; }

/* Score grid */
.score-grid {
  display: flex; gap: var(--gap);
  flex-wrap: wrap;
}
.score-main {
  display: flex; align-items: center; justify-content: center;
  padding: 1.1rem;
}
.score-side {
  flex: 1; display: flex; flex-direction: column;
  gap: .55rem; min-width: 140px;
}
.score-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  padding: .85rem 1rem;
}
.score-mini {
  display: flex; align-items: center; gap: .65rem;
  padding: .7rem .9rem;
}
.score-mini-icon { font-size: 1.35rem; line-height: 1; flex-shrink: 0; }
.score-mini-val  { font-size: 1.2rem; font-weight: 800; color: var(--gray-800); line-height: 1.1; }
.score-mini-label{ font-size: .7rem; color: var(--gray-400); font-weight: 500; }

/* SVG accuracy ring */
.accuracy-ring-wrap {
  position: relative; width: 120px; height: 120px;
}
.accuracy-svg { width: 120px; height: 120px; transform: rotate(-90deg); }
.ring-bg   { fill: none; stroke: var(--gray-200); stroke-width: 10; }
.ring-fill {
  fill: none; stroke-width: 10; stroke-linecap: round;
  stroke: var(--green);
  transition: stroke-dasharray 1s cubic-bezier(.4,0,.2,1), stroke .4s;
}
.accuracy-text {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.accuracy-num   { font-size: 1.5rem; font-weight: 900; color: var(--gray-800); line-height: 1; }
.accuracy-label { font-size: .65rem; color: var(--gray-400); font-weight: 600; margin-top: .1rem; }

/* ── DETAILED RESULT SECTIONS ────────────────────────────────────────────────── */

/* Error breakdown bar */
.error-breakdown {
  background: #fff;
  border-radius: var(--radius);
  padding: .9rem 1rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
}
.section-title {
  font-size: .72rem; font-weight: 800;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--gray-400); margin-bottom: .75rem;
}
.error-bar-row {
  display: flex; flex-direction: column; gap: .5rem;
}
.error-bar-item { display: flex; align-items: center; gap: .6rem; }
.error-bar-label {
  font-size: .78rem; font-weight: 600;
  width: 70px; flex-shrink: 0; color: var(--gray-600);
}
.error-bar-track {
  flex: 1; height: 10px; background: var(--gray-100);
  border-radius: 50px; overflow: hidden;
}
.error-bar-fill {
  height: 100%; border-radius: 50px;
  transition: width 1s cubic-bezier(.4,0,.2,1);
  width: 0%;
}
.error-bar-fill.correct { background: var(--green); }
.error-bar-fill.missed  { background: var(--red); }
.error-bar-fill.wrong   { background: var(--orange); }
.error-bar-count {
  font-size: .78rem; font-weight: 700;
  width: 28px; text-align: right; flex-shrink: 0;
  color: var(--gray-600);
}

/* Fluency meter */
.fluency-meter {
  background: #fff;
  border-radius: var(--radius);
  padding: .9rem 1rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
}
.fluency-scale {
  display: flex; border-radius: 50px; overflow: hidden;
  height: 16px; margin: .6rem 0 .4rem;
}
.fluency-seg {
  flex: 1; transition: opacity .3s;
  opacity: .25;
}
.fluency-seg.active { opacity: 1; }
.fluency-seg.s1 { background: var(--red); }
.fluency-seg.s2 { background: var(--orange); }
.fluency-seg.s3 { background: var(--gold); }
.fluency-seg.s4 { background: var(--green); }

.fluency-labels {
  display: flex; justify-content: space-between;
  font-size: .68rem; color: var(--gray-400); font-weight: 600;
}

/* Phoneme tip */
.phoneme-tip {
  background: var(--gold-50);
  border: 2px solid var(--gold-light);
  border-radius: var(--radius);
  padding: .9rem 1rem;
}
.phoneme-tip-title {
  font-size: .82rem; font-weight: 800; color: var(--gold-dark);
  margin-bottom: .5rem;
}
.phoneme-tip-body {
  font-size: .82rem; color: var(--gray-700); line-height: 1.6;
}
.phoneme-word {
  display: inline-block;
  background: var(--gold-light); color: var(--gold-dark);
  font-weight: 700; border-radius: 5px;
  padding: .1rem .4rem; margin: .1rem;
}

/* Diff */
.diff-legend {
  display: flex; gap: .75rem; flex-wrap: wrap;
  margin-bottom: .5rem; font-size: .78rem; color: var(--gray-600); align-items: center;
}
.diff-legend-item { display: flex; align-items: center; gap: .3rem; }

.diff-card {
  background: #fff;
  border-radius: var(--radius);
  padding: .9rem 1rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
}
.diff-card-title {
  font-size: .72rem; font-weight: 800;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--gray-400); margin-bottom: .7rem;
}
.diff-output {
  font-size: 1.05rem; line-height: 2.1; word-spacing: .08em;
}

.word-correct {
  background: var(--green-light); color: var(--green);
  padding: .12rem .35rem; border-radius: 5px; font-weight: 600;
  display: inline-block; margin: .05rem;
}
.word-missed {
  background: var(--red-light); color: var(--red);
  padding: .12rem .35rem; border-radius: 5px; font-weight: 600;
  display: inline-block; margin: .05rem;
  text-decoration: line-through;
}
.word-wrong {
  background: var(--orange-light); color: var(--orange);
  padding: .12rem .35rem; border-radius: 5px; font-weight: 600;
  display: inline-block; margin: .05rem;
  cursor: help;
  position: relative;
}

/* Transcript */
.transcript-details {
  background: #fff; border-radius: var(--radius);
  padding: .85rem 1rem; box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  font-size: .88rem;
}
.transcript-details summary {
  cursor: pointer; font-weight: 600; color: var(--gray-500);
  display: flex; align-items: center; gap: .4rem;
  user-select: none; list-style: none;
}
.transcript-details summary::-webkit-details-marker { display: none; }
.transcript-details[open] summary svg { transform: rotate(180deg); }
.transcript-details summary svg { transition: transform .2s; flex-shrink: 0; }
.transcript-raw {
  margin-top: .65rem; color: var(--gray-600);
  line-height: 1.6; font-style: italic;
  background: var(--gray-50); border-radius: 8px;
  padding: .65rem .8rem;
}

/* Result actions */
.result-actions {
  display: flex; gap: .6rem; flex-wrap: wrap;
}
.btn-action {
  flex: 1; min-width: 120px;
  padding: .85rem 1rem;
  border-radius: 50px; font-size: .92rem; font-weight: 700;
  text-align: center; transition: opacity .15s, transform .1s;
}
.btn-action:active { transform: scale(.97); }
.btn-primary   { background: var(--grad-hero); color: #fff; box-shadow: 0 3px 12px rgba(30,64,175,.3); }
.btn-secondary { background: var(--gray-100); color: var(--gray-800); border: 2px solid var(--gray-200); }
.btn-ghost     { background: transparent; color: var(--gray-500); border: 2px solid var(--gray-200); font-size: .85rem; flex: 0 1 auto; }
.btn-primary:hover, .btn-secondary:hover, .btn-ghost:hover { opacity: .85; }

/* ── HISTORY DRAWER ──────────────────────────────────────────────────────────── */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 150;
}
.history-drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(340px, 92vw);
  background: #fff; z-index: 200;
  display: flex; flex-direction: column;
  box-shadow: -4px 0 30px rgba(0,0,0,.15);
  animation: slideInRight .22s ease;
}
@keyframes slideInRight {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}
.drawer-title { font-size: 1rem; font-weight: 700; }
.drawer-close {
  color: var(--gray-400); font-size: 1.1rem; padding: .25rem .4rem;
  border-radius: 6px; transition: background .15s;
}
.drawer-close:hover { background: var(--gray-100); }

.history-list { flex: 1; overflow-y: auto; padding: .75rem; display: flex; flex-direction: column; gap: .5rem; }

.history-empty {
  text-align: center; color: var(--gray-400);
  font-size: .88rem; padding: 2rem 1rem; line-height: 1.6;
}

.history-item {
  background: var(--gray-50); border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm); padding: .75rem;
  display: flex; flex-direction: column; gap: .2rem;
}
.hi-top { display: flex; justify-content: space-between; align-items: baseline; }
.hi-passage { font-size: .88rem; font-weight: 700; color: var(--gray-800); }
.hi-date    { font-size: .7rem; color: var(--gray-400); }
.hi-scores  { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .25rem; }
.hi-score-pill {
  font-size: .7rem; font-weight: 700;
  padding: .15rem .5rem; border-radius: 50px;
  background: var(--blue-50); color: var(--blue);
}
.hi-score-pill.accuracy-high { background: var(--green-light); color: var(--green); }
.hi-score-pill.accuracy-mid  { background: var(--gold-50);  color: var(--gold-dark); }
.hi-score-pill.accuracy-low  { background: var(--red-light); color: var(--red); }

.drawer-footer {
  padding: .75rem; border-top: 1px solid var(--gray-200); flex-shrink: 0;
}
.btn-clear-history {
  width: 100%; padding: .65rem; border-radius: var(--radius-sm);
  background: var(--red-light); color: var(--red);
  font-size: .82rem; font-weight: 700;
}
.btn-clear-history:hover { background: #fecaca; }

/* ── SETTINGS MODAL ──────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 300;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal-card {
  background: #fff;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 1.5rem 1.25rem 2rem;
  width: 100%; max-width: var(--max-w);
  box-shadow: 0 -8px 40px rgba(0,0,0,.18);
  animation: slideUp .22s ease;
}
@keyframes slideUp {
  from { transform: translateY(50px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.1rem;
}
.modal-title { font-size: 1.1rem; font-weight: 800; }
.modal-close {
  color: var(--gray-400); font-size: 1.1rem;
  padding: .25rem .4rem; border-radius: 6px;
}
.modal-close:hover { background: var(--gray-100); }

.modal-label { display: block; font-size: .82rem; font-weight: 700; color: var(--gray-600); margin-bottom: .35rem; }
.modal-input-wrap { position: relative; }
.modal-input {
  width: 100%; padding: .75rem 2.5rem .75rem .9rem;
  border: 2px solid var(--gray-200); border-radius: var(--radius-sm);
  font-size: .95rem; font-family: monospace;
  outline: none; transition: border-color .15s;
}
.modal-input:focus { border-color: var(--blue); }
.btn-toggle-key {
  position: absolute; right: .6rem; top: 50%;
  transform: translateY(-50%);
  font-size: 1rem; color: var(--gray-400);
  padding: .2rem;
}
.modal-help {
  font-size: .76rem; color: var(--gray-400);
  margin-top: .45rem; line-height: 1.55; margin-bottom: .5rem;
}
.modal-label-tag {
  font-size: .65rem; font-weight: 700;
  background: var(--blue-light); color: var(--blue);
  padding: .1rem .4rem; border-radius: 50px; margin-left: .3rem;
  vertical-align: middle;
}
.modal-label-tag-alt {
  background: var(--gold-light); color: var(--gold-dark);
}
.modal-divider {
  text-align: center; font-size: .75rem; font-weight: 600;
  color: var(--gray-400); margin: .65rem 0;
  display: flex; align-items: center; gap: .5rem;
}
.modal-divider::before, .modal-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--gray-200);
}
.modal-model-badge {
  background: var(--blue-50); color: var(--blue);
  font-size: .78rem; font-weight: 600;
  padding: .5rem .8rem; border-radius: var(--radius-sm);
  border: 1px solid var(--blue-light);
  margin-top: .65rem;
}
.modal-actions { display: flex; gap: .65rem; margin-top: 1.25rem; }
.btn-modal-save {
  flex: 1; background: var(--grad-hero); color: #fff;
  padding: .85rem; border-radius: var(--radius-sm);
  font-size: .95rem; font-weight: 700;
}
.btn-modal-cancel {
  flex: 1; background: var(--gray-100); color: var(--gray-700);
  padding: .85rem; border-radius: var(--radius-sm);
  font-size: .95rem; font-weight: 600;
  border: 2px solid var(--gray-200);
}

/* ── LOADING OVERLAY ─────────────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6); z-index: 400;
  display: flex; align-items: center; justify-content: center;
}
.loading-card {
  background: #fff; border-radius: var(--radius-lg);
  padding: 2.25rem 2.5rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; align-items: center; gap: 1.25rem;
  max-width: 280px; width: 90%;
}
.loading-rings { position: relative; width: 56px; height: 56px; }
.loading-ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 3px solid transparent;
  animation: spin 1.2s linear infinite;
}
.r1 { border-top-color: var(--blue);   animation-duration: 1.0s; }
.r2 { border-top-color: var(--gold);   animation-duration: 1.4s; inset: 6px; }
.r3 { border-top-color: var(--green);  animation-duration: 1.8s; inset: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-size: .92rem; font-weight: 600; color: var(--gray-700); line-height: 1.6;
  display: flex; flex-direction: column; gap: .3rem; align-items: center;
}
.loading-text small { font-weight: 400; font-size: .78rem; color: var(--gray-400); text-align: center; }

/* ── TOAST ───────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--gray-900); color: #fff;
  padding: .7rem 1.25rem; border-radius: 50px;
  font-size: .88rem; font-weight: 600;
  z-index: 500; transition: transform .25s ease;
  pointer-events: none; white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
}
.toast.show          { transform: translateX(-50%) translateY(0); }
.toast.toast-error   { background: var(--red); }
.toast.toast-success { background: var(--green); }

/* ── PRINT ───────────────────────────────────────────────────────────────────── */
.print-only { display: none; }

@media print {
  body > *:not(#print-report) { display: none !important; }
  .print-only { display: block !important; font-family: var(--font); padding: 2rem; }
  .print-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; border-bottom: 2px solid #333; padding-bottom: .75rem; }
  .print-logo { font-size: 1.1rem; font-weight: 800; }
  .print-date { font-size: .85rem; color: #666; }
  #print-report h2 { font-size: 1.3rem; margin-bottom: 1rem; }
  .print-scores { display: flex; gap: 1.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
  .print-score-item { text-align: center; }
  .print-score-val { font-size: 1.8rem; font-weight: 900; }
  .print-score-label { font-size: .75rem; color: #666; }
  .print-diff { line-height: 2; font-size: 1rem; margin-bottom: 1.5rem; }
  .print-footer { font-size: .72rem; color: #999; border-top: 1px solid #ccc; padding-top: .5rem; margin-top: 1rem; }
  .word-correct { background: #d1fae5; color: #065f46; padding: .1rem .3rem; border-radius: 4px; }
  .word-missed  { background: #fee2e2; color: #991b1b; padding: .1rem .3rem; border-radius: 4px; text-decoration: line-through; }
  .word-wrong   { background: #ffedd5; color: #9a3412; padding: .1rem .3rem; border-radius: 4px; }
}

/* ── UTILITY ─────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── RESPONSIVE ──────────────────────────────────────────────────────────────── */

/* Tablet+ */
@media (min-width: 600px) {
  .passage-text { font-size: 1.3rem; }
  .hero h1      { font-size: 1.4rem; }
  .passage-cards-row { grid-template-columns: 1fr 1fr; }
}

/* Small phones (≤ 420px) */
@media (max-width: 420px) {
  .page         { padding: .65rem .75rem 2rem; }
  .passage-text { font-size: 1.05rem; line-height: 1.85; }
  .btn-record   { font-size: .95rem; padding: .85rem 1.25rem; min-width: 0; flex: 1; }
  .btn-stop     { font-size: .95rem; padding: .85rem 1.1rem; min-width: 0; }
  .rec-btn-row  { flex-direction: row; gap: .5rem; }
  .score-grid   { flex-direction: column; }
  .score-main   { width: 100%; }
  .result-actions { flex-direction: column; }
  .btn-action   { min-width: unset; flex: unset; width: 100%; }
  .loading-card { padding: 1.75rem 1.5rem; }
  .modal-card   { padding: 1.25rem 1rem 1.75rem; }
  .modal-input  { padding: .7rem 2.2rem .7rem .8rem; font-size: .88rem; }
  .history-drawer { width: 100%; }
  .brand-logo-img { width: 36px; height: 36px; }
  .brand-name   { font-size: .9rem; }
  .brand-tagline{ font-size: .62rem; }
}

/* Very small phones (≤ 360px) */
@media (max-width: 360px) {
  .passage-text { font-size: .95rem; line-height: 1.8; }
  .hero h1      { font-size: 1rem; }
  .pcd-title    { font-size: .95rem; }
  .score-mini-val { font-size: 1.05rem; }
  .diff-output  { font-size: .95rem; }
  .step-bar     { padding: .4rem .5rem .55rem; gap: 0; }
  .step-item span { font-size: .6rem; }
  .step-dot     { width: 22px; height: 22px; font-size: .72rem; }
  .pc-title     { font-size: .88rem; }
  .pc-topic     { font-size: .68rem; }
  .header-inner { padding: .55rem .75rem; }
  .loading-card { padding: 1.5rem 1.1rem; max-width: 90vw; }
}
