:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #18212f;
    --muted: #667085;
    --line: #e5e7eb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #15803d;
    --success-bg: #f0fdf4;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --warning: #b45309;
    --warning-bg: #fffbeb;
    --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  }

  * { box-sizing: border-box; }

  body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
  }

  button, input, select, textarea { font: inherit; }

  .app {
    width: min(1040px, calc(100% - 28px));
    margin: 28px auto 48px;
  }

  .hero {
    margin-bottom: 18px;
  }

  .hero h1 {
    margin: 0 0 6px;
    font-size: clamp(26px, 4vw, 38px);
    letter-spacing: -0.03em;
  }

  .hero p {
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
  }

  .panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
  }

  .setup-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    align-items: stretch;
  }

  .field-card {
    height: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px;
    background: #fbfcfe;
  }

  .field-card label,
  .field-label {
    display: block;
    font-weight: 700;
    margin-bottom: 9px;
  }

  .field-card small {
    display: block;
    color: var(--muted);
    margin-top: 7px;
    line-height: 1.4;
  }

  input[type="file"], select {
    width: 100%;
  }

  select,
  textarea,
  .cloze-input {
    border: 1px solid #cfd5df;
    border-radius: 10px;
    background: #fff;
    color: var(--text);
  }

  select {
    padding: 10px 12px;
  }

  .range-row {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .range-row input { flex: 1; }

  .hidden { display: none !important; }

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

  .lesson-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
  }

  .counter {
    font-weight: 800;
  }

  .file-name {
    color: var(--muted);
    max-width: 500px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .progress-track {
    width: 100%;
    height: 7px;
    border-radius: 999px;
    background: #edf0f5;
    overflow: hidden;
    margin-bottom: 18px;
  }

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

  .audio-buttons,
  .action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  button {
    border: 0;
    border-radius: 10px;
    padding: 10px 14px;
    font-weight: 700;
    cursor: pointer;
    transition: transform .05s ease, background .15s ease, opacity .15s ease;
  }

  button:active { transform: translateY(1px); }
  button:disabled { opacity: .45; cursor: not-allowed; }

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

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

  .btn-secondary {
    background: #eef2f7;
    color: #263244;
  }

  .btn-ghost {
    background: transparent;
    border: 1px solid var(--line);
    color: #344054;
  }

  .practice-shell {
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 20px;
    min-height: 330px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .instruction {
    text-align: center;
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 12px;
  }

  .sentence-mask {
    min-height: 42px;
    margin: 4px auto 16px;
    max-width: 820px;
    text-align: center;
    font-size: clamp(20px, 3vw, 28px);
    line-height: 1.65;
    letter-spacing: .01em;
  }

  .mask-word {
    display: inline-block;
    height: 1.05em;
    min-width: 30px;
    border-bottom: 2px solid #cbd5e1;
    margin: 0 3px;
    vertical-align: middle;
  }

  .dictation-input {
    display: block;
    width: min(820px, 100%);
    min-height: 104px;
    resize: vertical;
    margin: 0 auto;
    padding: 14px 16px;
    font-size: 18px;
    line-height: 1.5;
    outline: none;
  }

  .dictation-input:focus,
  .cloze-input:focus,
  select:focus {
    border-color: #7aa2f7;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
  }

  .feedback {
    width: min(820px, 100%);
    margin: 14px auto 0;
    border-radius: 12px;
    padding: 12px 14px;
    line-height: 1.55;
  }

  .feedback:empty { display: none; }

  .feedback.info { background: #eff6ff; color: #1e40af; }
  .feedback.success { background: var(--success-bg); color: var(--success); }
  .feedback.error { background: var(--danger-bg); color: #991b1b; }
  .feedback.warning { background: var(--warning-bg); color: #92400e; }

  .word-feedback {
    width: min(820px, 100%);
    margin: 12px auto 0;
    font-size: 18px;
    line-height: 1.8;
    text-align: center;
  }

  .word-feedback:empty { display: none; }

  .wf-correct {
    color: var(--success);
    font-weight: 700;
  }

  .wf-wrong {
    color: var(--danger);
    background: var(--danger-bg);
    border-radius: 6px;
    padding: 1px 4px;
    text-decoration: underline wavy;
    text-underline-offset: 3px;
  }

  .wf-extra {
    color: var(--danger);
    opacity: .72;
    text-decoration: line-through;
  }

  .wf-missing {
    color: var(--warning);
    background: var(--warning-bg);
    border: 1px dashed #f59e0b;
    border-radius: 6px;
    padding: 1px 7px;
    font-weight: 800;
  }

  .hint-box {
    width: min(820px, 100%);
    margin: 10px auto 0;
    text-align: center;
    color: #475467;
    font-size: 14px;
  }

  .actions-center {
    width: min(820px, 100%);
    margin: 16px auto 0;
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
  }

  .cloze-line {
    width: min(860px, 100%);
    margin: 0 auto;
    font-size: 21px;
    line-height: 2.1;
    text-align: center;
  }

  .cloze-input {
    width: 120px;
    padding: 5px 8px;
    margin: 0 3px;
    font-size: 18px;
    text-align: center;
    outline: none;
  }

  .cloze-input.correct {
    border-color: #22c55e;
    background: #f0fdf4;
    color: #166534;
  }

  .cloze-input.wrong {
    border-color: #ef4444;
    background: #fef2f2;
    color: #991b1b;
  }

  .media-stage {
    width: min(820px, 100%);
    margin: 0 auto 16px;
    border-radius: 14px;
    overflow: hidden;
    background: #0f172a;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .10);
  }

  .media-stage video {
    display: block;
    width: 100%;
    max-height: 460px;
    background: #000;
  }

  .media-note {
    width: min(820px, 100%);
    margin: -6px auto 14px;
    color: var(--muted);
    text-align: center;
    font-size: 12px;
  }

  .shortcut-strip {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 16px;
    color: var(--muted);
    font-size: 13px;
  }

  kbd {
    display: inline-block;
    padding: 2px 6px;
    border: 1px solid #cfd5df;
    border-bottom-width: 2px;
    border-radius: 6px;
    background: #fff;
    color: #344054;
    font-size: 12px;
    font-weight: 800;
  }

  .empty-state {
    color: var(--muted);
    text-align: center;
    line-height: 1.6;
    padding: 34px 12px;
  }

  .full-answer {
    width: min(820px, 100%);
    margin: 10px auto 0;
    text-align: center;
    color: #344054;
    font-size: 18px;
    line-height: 1.65;
  }

  .completed-review {
    width: min(820px, 100%);
    margin: 16px auto 0;
    padding: 14px 16px;
    border: 1px solid #dbe4f0;
    border-radius: 12px;
    background: #f8fafc;
  }

  .completed-review-title {
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 800;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
  }

  .completed-review-accuracy {
    margin: 4px 0 12px;
    font-size: 18px;
    line-height: 1.4;
    font-weight: 850;
    color: var(--text);
  }

  .completed-review-script {
    font-size: 19px;
    line-height: 1.75;
    color: #344054;
  }

  .review-mistake {
    display: inline;
    color: #b42318;
    background: #fff1f0;
    border-bottom: 2px solid #f04438;
    border-radius: 4px;
    padding: 1px 3px;
    font-weight: 800;
  }

  button.review-mistake {
    border-top: 0;
    border-left: 0;
    border-right: 0;
    font: inherit;
    line-height: inherit;
    cursor: pointer;
  }
  button.review-mistake:hover { background: #ffe4e1; }
  .review-save-plus { font-size: .72em; margin-left: 2px; opacity: .78; }
  button.review-mistake.saved { color:#027a48; background:#ecfdf3; border-bottom-color:#12b76a; }

  .lesson-review-item {
    display: grid;
    grid-template-columns: 38px 1fr;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid #e7edf5;
  }

  .lesson-review-item:last-child {
    border-bottom: 0;
  }

  .lesson-review-number {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    padding-top: 4px;
  }

  .lesson-review-sentence {
    min-width: 0;
  }

  .completed-review-note {
    margin-top: 8px;
    color: var(--muted);
    font-size: 13px;
  }

  @media (max-width: 980px) {
    .setup-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }

  @media (max-width: 780px) {
    .setup-grid { grid-template-columns: 1fr; }
    .panel { padding: 15px; border-radius: 14px; }
    .practice-shell { padding: 15px 10px; }
    .app { width: min(100% - 18px, 1040px); margin-top: 14px; }
  }

  /* ===== Site navigation ===== */
  .site-nav {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
  }
  .site-nav-inner {
    width: min(100% - 28px, 1040px);
    min-height: 64px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
  }
  .brand {
    color: var(--text);
    text-decoration: none;
    font-weight: 900;
    letter-spacing: -.02em;
    white-space: nowrap;
  }
  .brand span { color: var(--primary); }
  .nav-links {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
  }
  .nav-links a {
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 750;
    padding: 9px 11px;
    border-radius: 10px;
  }
  .nav-links a:hover,
  .nav-links a.active {
    color: var(--primary);
    background: #eff6ff;
  }
  .menu-toggle {
    display: none;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 10px;
    padding: 8px 10px;
    font: inherit;
    cursor: pointer;
  }
  @media (max-width: 760px) {
    .site-nav-inner { min-height: 58px; flex-wrap: wrap; padding: 8px 0; }
    .menu-toggle { display: inline-flex; }
    .nav-links { display: none; width: 100%; padding-bottom: 6px; }
    .nav-links.open { display: grid; grid-template-columns: 1fr 1fr; }
    .nav-links a { text-align: center; }
  }

  .library-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-color: #bfdbfe;
    background: #eff6ff;
  }
  .library-banner strong { display:block; margin-bottom:4px; }
  .library-banner .library-sub { color:#475467; font-size:14px; }
  .library-banner-actions { display:flex; gap:8px; flex-wrap:wrap; }
  .hero-actions { margin-top:12px; display:flex; gap:8px; flex-wrap:wrap; }
  .hero-link { display:inline-flex; align-items:center; gap:7px; text-decoration:none; border:1px solid var(--line); background:#fff; color:#344054; border-radius:10px; padding:9px 12px; font-weight:750; font-size:14px; }
  .hero-link:hover { color:var(--primary); border-color:#bfdbfe; }
  @media (max-width:760px) { .library-banner { align-items:flex-start; flex-direction:column; } }

  /* Shadowing mode */
  .shadowing-view { display:grid; gap:18px; }
  .shadowing-current {
    border:1px solid #dbe4f0;
    background:#f8fbff;
    border-radius:16px;
    padding:24px 22px;
    text-align:center;
  }
  .shadowing-kicker { color:var(--muted); font-size:12px; font-weight:850; text-transform:uppercase; letter-spacing:.08em; margin-bottom:8px; }
  .shadowing-subtitle { font-size:clamp(22px,3.2vw,34px); line-height:1.42; font-weight:800; color:var(--text); min-height:48px; }
  .shadowing-ipa { margin:10px auto 0; max-width:900px; color:#526173; font-size:clamp(16px,2vw,20px); line-height:1.55; font-family:"Noto Sans","Segoe UI",Arial,sans-serif; font-weight:600; letter-spacing:.01em; overflow-wrap:anywhere; }
  .shadowing-ipa.loading { color:#98a2b3; font-style:italic; font-weight:600; }
  .shadowing-ipa.error { color:#b54708; font-size:14px; font-style:normal; font-weight:650; }
  .shadowing-time { margin-top:9px; color:var(--muted); font-size:13px; font-variant-numeric:tabular-nums; }
  .shadow-controls { display:flex; justify-content:center; align-items:center; gap:9px; flex-wrap:wrap; }
  .shadow-play { min-width:120px; }
  .ipa-switch { display:inline-flex; align-items:center; gap:7px; min-height:40px; padding:0 10px; border:1px solid var(--line); border-radius:10px; background:#fff; color:#475467; font-size:13px; font-weight:800; cursor:pointer; user-select:none; }
  .ipa-switch:hover { border-color:#bfdbfe; background:#f8fbff; color:var(--primary); }
  .ipa-switch input { position:absolute; opacity:0; pointer-events:none; }
  .ipa-switch-track { width:34px; height:20px; padding:2px; border-radius:999px; background:#d0d5dd; display:inline-flex; align-items:center; transition:background .18s ease; box-sizing:border-box; }
  .ipa-switch-knob { width:16px; height:16px; border-radius:50%; background:#fff; box-shadow:0 1px 2px rgba(16,24,40,.18); transform:translateX(0); transition:transform .18s ease; }
  .ipa-switch input:checked + .ipa-switch-track { background:var(--primary); }
  .ipa-switch input:checked + .ipa-switch-track .ipa-switch-knob { transform:translateX(14px); }
  .ipa-switch input:focus-visible + .ipa-switch-track { outline:3px solid rgba(37,99,235,.2); outline-offset:2px; }
  .shadow-options { display:flex; justify-content:center; align-items:center; gap:14px; flex-wrap:wrap; color:#475467; font-size:14px; }
  .shadow-options label { display:inline-flex; align-items:center; gap:7px; font-weight:750; }
  .shadow-options select { border:1px solid var(--line); border-radius:9px; padding:7px 9px; background:#fff; color:var(--text); font:inherit; }
  .shadow-transcript { border:1px solid var(--line); border-radius:14px; overflow:hidden; background:#fff; }
  .shadow-transcript-head { padding:12px 14px; border-bottom:1px solid var(--line); font-weight:850; display:flex; justify-content:space-between; gap:10px; align-items:center; }
  .shadow-transcript-list { max-height:360px; overflow:auto; scroll-behavior:smooth; }
  .shadow-cue { width:100%; border:0; border-bottom:1px solid #eef1f5; background:#fff; display:grid; grid-template-columns:44px 78px minmax(0,1fr); gap:10px; align-items:start; padding:11px 14px; text-align:left; cursor:pointer; color:var(--text); }
  .shadow-cue:last-child { border-bottom:0; }
  .shadow-cue:hover { background:#f7f9fc; }
  .shadow-cue.active { background:#eff6ff; box-shadow:inset 3px 0 0 var(--primary); }
  .shadow-cue.visited .shadow-num { color:var(--success); }
  .shadow-num { color:#667085; font-weight:850; }
  .shadow-cue-time { color:#98a2b3; font-size:12px; font-variant-numeric:tabular-nums; padding-top:2px; }
  .shadow-cue-text { line-height:1.5; }
  @media (max-width:620px) {
    .shadow-cue { grid-template-columns:32px minmax(0,1fr); }
    .shadow-cue-time { display:none; }
    .shadowing-current { padding:20px 15px; }
  }

.privacy-note { margin-top:8px !important; font-size:14px; color:#475467 !important; }
.empty-state a { color:var(--primary); font-weight:700; }


/* ===== Vocabulary capture during dictation ===== */
.dictation-vocab-helper {
  width: min(820px, 100%);
  margin: 10px auto 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 14px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid #cfe0ff;
  border-radius: 12px;
  background: #f7faff;
}
.dictation-vocab-helper-copy { min-width: 0; }
.dictation-vocab-helper-copy strong { display:block; color:#1d4ed8; font-size:14px; margin-bottom:2px; }
.dictation-vocab-helper-copy span { display:block; color:#53627a; font-size:13px; line-height:1.45; }
.btn-vocab-save {
  background:#e8f1ff;
  color:#174ea6;
  border:1px solid #b8d2ff;
  white-space:nowrap;
}
.btn-vocab-save:hover:not(:disabled) { background:#dceaff; }
.selected-word-status {
  grid-column:1 / -1;
  min-height:18px;
  font-size:12px;
  font-weight:700;
  color:#475467;
}
.selected-word-status.ready { color:#1d4ed8; }
.selected-word-status.saved { color:#15803d; }

.completed-review-vocab-callout {
  display:flex;
  gap:13px;
  align-items:flex-start;
  margin:14px 0 16px;
  padding:15px 16px;
  border:1px solid #93c5fd;
  border-left:5px solid var(--primary);
  border-radius:13px;
  background:linear-gradient(135deg,#eff6ff 0%,#f8fbff 100%);
  box-shadow:0 7px 18px rgba(37,99,235,.08);
}
.completed-review-vocab-icon {
  flex:0 0 auto;
  width:34px;
  height:34px;
  display:grid;
  place-items:center;
  border-radius:10px;
  background:var(--primary);
  color:#fff;
  font-size:23px;
  line-height:1;
  font-weight:900;
}
.completed-review-vocab-callout strong {
  display:block;
  margin:0 0 4px;
  color:#173f84;
  font-size:17px;
  line-height:1.35;
}
.completed-review-vocab-callout span {
  display:block;
  color:#334e78;
  font-size:15px;
  line-height:1.55;
}

/* ===== Save vocabulary dialog ===== */
.vocab-save-modal {
  position:fixed;
  inset:0;
  z-index:2200;
  display:grid;
  place-items:center;
  padding:20px;
}
.vocab-save-backdrop { position:absolute; inset:0; background:rgba(15,23,42,.55); backdrop-filter:blur(2px); }
.vocab-save-card {
  position:relative;
  width:min(520px,100%);
  max-height:calc(100vh - 40px);
  overflow:auto;
  border-radius:18px;
  border:1px solid #d8e1ed;
  background:#fff;
  box-shadow:0 24px 70px rgba(15,23,42,.24);
  padding:20px;
}
.vocab-save-head { display:flex; justify-content:space-between; gap:16px; align-items:flex-start; margin-bottom:16px; }
.vocab-save-head h2 { margin:2px 0 0; font-size:24px; }
.vocab-save-eyebrow { color:var(--primary); text-transform:uppercase; letter-spacing:.08em; font-size:11px; font-weight:900; }
.vocab-close-btn { width:36px; height:36px; padding:0; border-radius:10px; background:#f2f4f7; color:#475467; font-size:24px; line-height:1; }
.vocab-save-field { display:block; margin-top:13px; }
.vocab-save-field > span,.vocab-save-context > span { display:block; margin-bottom:6px; font-size:13px; font-weight:800; color:#344054; }
.vocab-save-field input {
  width:100%;
  border:1px solid #cfd5df;
  border-radius:10px;
  padding:11px 12px;
  background:#fff;
  color:var(--text);
  outline:none;
}
.vocab-save-field input:focus { border-color:#7aa2f7; box-shadow:0 0 0 3px rgba(37,99,235,.12); }
.vocab-save-context { margin-top:14px; padding:12px 13px; border-radius:11px; background:#f8fafc; border:1px solid #e5e7eb; }
.vocab-save-context div { color:#475467; font-size:14px; line-height:1.55; }
.vocab-save-warning { margin-top:12px; padding:10px 12px; border-radius:10px; background:#fffbeb; border:1px solid #fde68a; color:#92400e; font-size:13px; line-height:1.45; }
.vocab-save-actions { display:flex; justify-content:flex-end; gap:8px; margin-top:18px; flex-wrap:wrap; }
body.vocab-modal-open { overflow:hidden; }

@media (max-width:620px) {
  .dictation-vocab-helper { grid-template-columns:1fr; }
  .btn-vocab-save { width:100%; }
  .selected-word-status { grid-column:1; }
  .completed-review-vocab-callout strong { font-size:16px; }
  .completed-review-vocab-callout span { font-size:14px; }
  .vocab-save-card { padding:17px; }
  .vocab-save-actions > button { flex:1 1 180px; }
}
