:root {
  --red: #e63946;
  --red-dark: #c1121f;
  --gold: #f4a259;
  --ink: #1d1e2c;
  --ink-soft: #4a4b5c;
  --paper: #fff9f5;
  --card: #ffffff;
  --line: #eadfd6;
  --green: #2a9d8f;
  --shadow: 0 10px 30px rgba(29, 30, 44, 0.08);
  --shadow-lg: 0 20px 50px rgba(29, 30, 44, 0.14);
  --radius: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 100% -10%, #ffe8dd 0%, transparent 55%),
    radial-gradient(900px 500px at -10% 10%, #ffe0e3 0%, transparent 50%),
    var(--paper);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.han { font-family: "Noto Sans SC", "Nunito", sans-serif; }

/* ---------- Layout ---------- */
.layout {
  display: flex;
  align-items: flex-start;
  width: 100%;
  gap: 30px;
  padding: 0 32px 0 0;
}
.content { flex: 1; min-width: 0; padding-bottom: 40px; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  width: 250px;
  flex-shrink: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand-logo {
  font-family: "Noto Sans SC";
  font-weight: 900;
  font-size: 24px;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  border-radius: 14px;
  box-shadow: 0 6px 16px rgba(230, 57, 70, 0.35);
}
.brand-text { font-weight: 900; font-size: 22px; line-height: 1; }
.brand-text small { display: block; font-size: 11px; font-weight: 700; color: var(--ink-soft); letter-spacing: 1px; text-transform: uppercase; }

.side-block { display: flex; flex-direction: column; gap: 8px; }
.side-label {
  font-size: 11px; font-weight: 800; letter-spacing: 1.2px; text-transform: uppercase;
  color: #b3a79d; padding-left: 2px;
}

/* Lesson nav */
.lesson-nav { display: flex; flex-direction: column; gap: 6px; }
.lesson-link {
  font-size: 14px; font-weight: 800;
  padding: 10px 14px; border-radius: 12px;
  text-decoration: none; color: var(--ink-soft);
  border: 1px solid var(--line); background: #fff;
  transition: .2s;
}
.lesson-link.active,
.lesson-link:hover { background: var(--red); color: #fff; border-color: var(--red); }

/* Section nav — lồng ngay dưới bài đang mở */
.section-nav {
  display: flex; flex-direction: column; gap: 2px;
  margin: 4px 0 4px 10px; padding-left: 10px;
  border-left: 2px solid var(--line);
}
.section-nav a {
  display: flex; align-items: center; gap: 10px;
  font-size: 13.5px; font-weight: 700; color: var(--ink-soft);
  padding: 8px 12px; border-radius: 10px; text-decoration: none;
  border-left: 3px solid transparent; margin-left: -12px; transition: .15s;
}
.section-nav a .s-num { font-size: 11px; font-weight: 900; color: #c7bab0; }
.section-nav a:hover { background: #fff2ec; color: var(--ink); }
.section-nav a.active {
  background: #fff2ec; color: var(--red-dark); border-left-color: var(--red);
}
.section-nav a.active .s-num { color: var(--red); }

/* TTS block */
.tts-row { display: grid; gap: 6px; font-weight: 700; font-size: 13px; color: var(--ink-soft); }
.tts-row b { color: var(--red); }
.tts-row input[type="range"] { width: 100%; accent-color: var(--red); cursor: pointer; }
.tts-status {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 12px; font-weight: 700; color: var(--ink-soft);
  background: #faf5f0; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.tts-status b { color: var(--ink); }
.tts-status .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.tts-status .dot.ok { background: var(--green); box-shadow: 0 0 0 3px rgba(42,157,143,.18); }
.tts-status .dot.warn { background: var(--gold); box-shadow: 0 0 0 3px rgba(244,162,89,.2); }
.tts-test { justify-content: center; font-size: 13px; padding: 9px; width: 100%; }

/* Sidebar progress */
.side-progress { margin-top: auto; display: flex; align-items: center; gap: 10px; padding-top: 8px; }

/* Mobile nav toggle */
.nav-toggle {
  display: none;
  position: fixed; top: 14px; left: 14px; z-index: 80;
  width: 44px; height: 44px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; font-size: 20px;
  box-shadow: var(--shadow);
}
.nav-scrim {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(29,30,44,.45); backdrop-filter: blur(2px);
}

/* ---------- Hero ---------- */
.hero {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 24px;
  align-items: center;
  margin: 32px 0 8px;
  padding: 40px;
  background: linear-gradient(135deg, #fff, #fff5ef);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.badge {
  display: inline-block;
  font-size: 12px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase;
  color: var(--red-dark);
  background: #ffe3e6;
  padding: 6px 14px; border-radius: 999px;
}
.hero-title { font-family: "Noto Sans SC"; font-size: 84px; line-height: 1; margin: 14px 0 4px; color: var(--ink); }
.hero-pinyin { font-size: 24px; color: var(--red); font-weight: 800; }
.hero-subtitle { font-size: 22px; font-weight: 800; margin-top: 2px; }
.hero-intro { color: var(--ink-soft); margin-top: 12px; max-width: 46ch; }
.hero-actions { display: flex; gap: 12px; margin-top: 22px; flex-wrap: wrap; }
.hero-source { margin-top: 16px; font-size: 12px; color: var(--ink-soft); }

.hero-card { position: relative; height: 240px; }
.hanzi-float {
  position: absolute;
  font-family: "Noto Sans SC";
  font-weight: 900;
  color: #fff;
  display: grid; place-items: center;
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  animation: bob 5s ease-in-out infinite;
}
.hanzi-float.h1 { width: 120px; height: 120px; font-size: 64px; background: linear-gradient(135deg,#e63946,#c1121f); top: 10px; left: 20px; }
.hanzi-float.h2 { width: 96px; height: 96px; font-size: 52px; background: linear-gradient(135deg,#f4a259,#e76f51); top: 90px; right: 30px; animation-delay: .6s; }
.hanzi-float.h3 { width: 80px; height: 80px; font-size: 42px; background: linear-gradient(135deg,#2a9d8f,#1d7870); bottom: 0; left: 90px; animation-delay: 1.2s; }
.hanzi-float.h4 { width: 68px; height: 68px; font-size: 36px; background: linear-gradient(135deg,#4361ee,#3a0ca3); top: 0; right: 0; animation-delay: 1.8s; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-2deg);} 50% { transform: translateY(-14px) rotate(2deg);} }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit; font-weight: 800; font-size: 15px;
  padding: 12px 22px; border-radius: 999px; border: none; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 8px;
  transition: transform .15s, box-shadow .2s, background .2s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--red), var(--red-dark)); color: #fff; box-shadow: 0 8px 18px rgba(230,57,70,.35); }
.btn-primary:hover { box-shadow: 0 12px 24px rgba(230,57,70,.45); }
.btn-ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: var(--red); color: var(--red); }

/* ---------- Icon buttons ---------- */
.btn-icon {
  width: 48px; height: 48px; border-radius: 50%;
  display: inline-grid; place-items: center;
  border: none; cursor: pointer; text-decoration: none;
  transition: transform .15s, box-shadow .2s, background .2s;
}
.btn-icon svg { width: 22px; height: 22px; }
.btn-icon:active { transform: translateY(1px); }
.btn-icon-primary {
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  color: #fff; box-shadow: 0 8px 18px rgba(230,57,70,.35);
}
.btn-icon-primary:hover { box-shadow: 0 12px 24px rgba(230,57,70,.45); }
.btn-icon-ghost {
  background: #fff; color: var(--ink);
  border: 1px solid var(--line);
}
.btn-icon-ghost:hover { border-color: var(--red); color: var(--red); }
.btn-icon-record {
  background: linear-gradient(135deg, #7b2cbf, #5a189a);
  color: #fff; box-shadow: 0 8px 18px rgba(123,44,191,.35);
}
.btn-icon-record:hover { box-shadow: 0 12px 24px rgba(123,44,191,.45); }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: none; cursor: pointer;
  background: #fff2ec; color: var(--red);
  display: inline-grid; place-items: center;
  transition: .2s; flex-shrink: 0;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--red); color: #fff; transform: scale(1.06); }
.icon-btn.speaking { animation: pulse .8s infinite; background: var(--red); color: #fff; }
.icon-btn.recording { background: var(--red); color: #fff; animation: pulse .8s infinite; }
.icon-btn.saved { background: var(--green); color: #fff; }
.icon-btn.has-saved { box-shadow: inset 0 0 0 2px var(--green); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; transform: none; }
.icon-btn.rec-btn { width: 36px; height: 36px; }
.icon-btn.rec-btn svg { width: 18px; height: 18px; }
.icon-btn.rec-stop { background: #ffe9eb; color: var(--red-dark); }
.icon-btn.rec-stop:hover:not(:disabled) { background: var(--red); color: #fff; }
.icon-btn.rec-replay { background: #e8f4ff; color: #1f5fb0; }
.icon-btn.rec-replay:hover:not(:disabled) { background: #1f5fb0; color: #fff; }
.icon-btn.rec-save { background: #e8f7f4; color: var(--green); }
.icon-btn.rec-save:hover:not(:disabled) { background: var(--green); color: #fff; }

/* ---------- Progress ---------- */
.progress-wrap { display: flex; align-items: center; gap: 12px; margin: 26px 4px 10px; }
.progress-bar { flex: 1; height: 10px; background: #f0e6dd; border-radius: 999px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--red)); border-radius: 999px; transition: width .4s; }
.progress-label { font-weight: 800; font-size: 13px; color: var(--ink-soft); min-width: 38px; text-align: right; }

/* ---------- Section ---------- */
.section { margin-top: 46px; scroll-margin-top: 90px; }
.section-head h2 { font-size: 26px; display: flex; align-items: center; gap: 12px; }
.section-head p { color: var(--ink-soft); margin-top: 4px; }
.sec-num {
  font-size: 14px; font-weight: 900; color: #fff;
  background: var(--ink); width: 34px; height: 34px;
  border-radius: 10px; display: grid; place-items: center;
}

/* ---------- Patterns ---------- */
.pattern-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-top: 18px; }
.pattern {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); display: flex; justify-content: space-between; align-items: center; gap: 14px;
  transition: transform .15s, box-shadow .2s;
}
.pattern:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.pattern .han { font-size: 30px; font-weight: 700; }
.pattern .pinyin { color: var(--red); font-weight: 700; margin-top: 2px; }
.pattern .vi { color: var(--ink-soft); font-size: 15px; }

/* ---------- Speaker button ---------- */
.speak {
  flex-shrink: 0;
}
.speak svg { width: 20px; height: 20px; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(230,57,70,.4);} 50% { box-shadow: 0 0 0 10px rgba(230,57,70,0);} }

/* ---------- Dialogues ---------- */
.dialogue-list { display: grid; gap: 18px; margin-top: 18px; }
.dialogue {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow);
}
.dialogue-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dialogue h3 { font-size: 15px; text-transform: uppercase; letter-spacing: 1px; color: var(--red-dark); margin: 0; }
.play-all {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: inherit; font-size: 13px; font-weight: 800; cursor: pointer;
  color: #fff; background: linear-gradient(135deg, var(--green), #1d7870);
  border: none; padding: 8px 16px; border-radius: 999px;
  box-shadow: 0 6px 14px rgba(42,157,143,.3); transition: transform .15s, box-shadow .2s, background .2s;
}
.play-all:hover { box-shadow: 0 10px 20px rgba(42,157,143,.4); }
.play-all:active { transform: translateY(1px); }
.play-all .pa-icon { font-size: 11px; }
.play-all.playing { background: linear-gradient(135deg, var(--red), var(--red-dark)); box-shadow: 0 6px 14px rgba(230,57,70,.32); }
.d-line { display: flex; gap: 12px; align-items: flex-start; padding: 10px 8px; margin: 0 -8px; border-top: 1px dashed var(--line); border-radius: 10px; transition: background .2s; }
.d-line.active-line { background: #fff2ec; box-shadow: inset 3px 0 0 var(--red); }
.d-line:first-of-type { border-top: none; }
.d-speaker {
  font-family: "Noto Sans SC"; font-weight: 700; font-size: 15px;
  padding: 4px 10px; border-radius: 8px; white-space: nowrap;
}
.d-speaker.spk-f { background: #ffe6f0; color: #b5177e; }
.d-speaker.spk-m { background: #e2f0ff; color: #1f5fb0; }
.d-body { flex: 1; }
.d-body .han { font-size: 22px; font-weight: 500; }
.d-body .pinyin { color: var(--red); font-weight: 700; font-size: 14px; }
.d-body .vi { color: var(--ink-soft); font-size: 14px; }

/* ---------- Vocabulary ---------- */
.vocab-toolbar { display: flex; align-items: center; gap: 16px; margin: 16px 0; }
.chip { font-weight: 800; font-size: 13px; background: #fff; border: 1px solid var(--line); padding: 6px 14px; border-radius: 999px; }
.switch { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; cursor: pointer; color: var(--ink-soft); }
.switch input { width: 18px; height: 18px; accent-color: var(--red); cursor: pointer; }

.vocab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.card-flip { perspective: 1000px; height: 190px; transition: transform .2s; }
.card-flip.playing-card { transform: translateY(-4px); }
.card-flip.playing-card .card-face { box-shadow: 0 0 0 3px var(--red), var(--shadow-lg); }
.card-inner {
  position: relative; width: 100%; height: 100%;
  transition: transform .5s; transform-style: preserve-3d; cursor: pointer;
}
.card-flip.flipped .card-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--card); box-shadow: var(--shadow);
  padding: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.card-front .han { font-size: 46px; font-weight: 700; }
.card-front .pinyin { color: var(--red); font-weight: 800; margin-top: 6px; }
.card-front .type { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--ink-soft); margin-top: 8px; background: #f6efe9; padding: 3px 10px; border-radius: 999px; }
.card-back { transform: rotateY(180deg); background: linear-gradient(160deg,#fff,#fff2ec); justify-content: flex-start; }
.card-back .vi { font-weight: 800; font-size: 18px; margin-top: 6px; }
.card-back .ex { font-size: 13px; color: var(--ink-soft); margin-top: 10px; }
.card-back .ex .han { font-size: 16px; color: var(--ink); font-weight: 500; }
.card-back .ex .pinyin { color: var(--red); font-weight: 700; }
.card-face .speak { position: absolute; top: 10px; right: 10px; width: 38px; height: 38px; }
.card-face .speak svg { width: 18px; height: 18px; }
.card-hint { position: absolute; bottom: 8px; font-size: 10px; color: var(--ink-soft); letter-spacing: .5px; }
.pinyin-hidden .card-front .pinyin { visibility: hidden; }

/* ---------- Grammar ---------- */
.grammar-list { display: grid; gap: 12px; margin-top: 18px; }
.grammar {
  background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--gold);
  border-radius: 14px; padding: 18px 20px; box-shadow: var(--shadow);
}
.grammar h3 { font-size: 17px; margin-bottom: 6px; }
.grammar h3 .han { color: var(--red); }
.grammar p { color: var(--ink-soft); }

/* ---------- Quiz ---------- */
.quiz { display: grid; gap: 16px; margin-top: 18px; }
.q {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.q-title { font-weight: 800; margin-bottom: 12px; }
.q-title .num { color: var(--red); }
.options { display: grid; gap: 10px; }
.opt {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border: 1.5px solid var(--line); border-radius: 12px;
  cursor: pointer; font-weight: 600; transition: .15s; background: #fff;
}
.opt:hover { border-color: var(--red); }
.opt input { accent-color: var(--red); width: 18px; height: 18px; }
.opt.correct { border-color: var(--green); background: #e8f7f4; }
.opt.wrong { border-color: var(--red); background: #ffe9eb; }
.quiz-footer { display: flex; align-items: center; gap: 12px; margin-top: 20px; flex-wrap: wrap; }
.quiz-score { font-weight: 900; font-size: 18px; padding: 10px 20px; border-radius: 999px; background: var(--ink); color: #fff; }

/* ---------- Footer ---------- */
.footer { text-align: center; padding: 40px 20px; color: var(--ink-soft); border-top: 1px solid var(--line); margin-top: 40px; }
.footer strong { color: var(--ink); }
.footer-note { font-size: 12px; margin-top: 6px; }

/* ---------- Voice hint ---------- */
.voice-hint {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; border: none; padding: 12px 20px;
  border-radius: 999px; font-family: inherit; font-weight: 700; font-size: 13px;
  box-shadow: var(--shadow-lg); cursor: pointer; z-index: 60; max-width: 90vw;
}

/* ---------- Record page ---------- */
.record-page {
  max-width: 960px; margin: 0 auto;
  padding: 28px 24px 60px;
}
.record-header {
  display: flex; align-items: flex-start; gap: 16px;
  margin-bottom: 20px;
}
.record-header-text h1 {
  font-family: "Noto Sans SC"; font-size: 36px; margin: 8px 0 4px;
}
.record-header-text p { color: var(--red); font-weight: 700; }
.record-hint {
  color: var(--ink-soft); font-size: 14px; margin-bottom: 28px;
  padding: 12px 16px; background: #fff; border: 1px solid var(--line);
  border-radius: 12px;
}
.record-section { margin-bottom: 36px; }
.record-section-title {
  font-size: 15px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--red-dark); margin-bottom: 12px;
}
.record-table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow);
}
.record-table thead th {
  text-align: left; font-size: 12px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .8px;
  color: var(--ink-soft); background: #faf5f0;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.record-table tbody tr { border-top: 1px solid var(--line); }
.record-table tbody tr:first-child { border-top: none; }
.record-table td { padding: 14px 16px; vertical-align: middle; }
.col-speak { width: 72px; text-align: center; }
.col-rec { width: auto; min-width: 200px; }
.rec-han { font-size: 22px; font-weight: 500; }
.rec-pinyin { color: var(--red); font-weight: 700; font-size: 15px; margin-top: 2px; }
.rec-vi { color: var(--ink-soft); font-size: 13px; margin-top: 2px; }
.rec-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.record-empty {
  text-align: center; padding: 60px 20px; color: var(--ink-soft);
}

@media (max-width: 640px) {
  .record-table thead { display: none; }
  .record-table tbody tr {
    display: grid; grid-template-columns: auto 1fr;
    grid-template-areas:
      "speak text"
      "rec rec";
    gap: 8px 12px; padding: 14px; border-top: 1px solid var(--line);
  }
  .record-table td { padding: 0; }
  .col-speak { grid-area: speak; width: auto; }
  .col-text { grid-area: text; }
  .col-rec { grid-area: rec; }
}

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .layout { padding: 0 16px; gap: 0; }
  .nav-toggle { display: grid; place-items: center; }
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 75;
    height: 100vh; width: 270px; max-width: 82vw;
    background: var(--paper); box-shadow: var(--shadow-lg);
    transform: translateX(-100%); transition: transform .28s ease;
    border-right: 1px solid var(--line);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .content { padding-top: 64px; }
}
@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; padding: 28px; }
  .hero-card { display: none; }
  .hero-title { font-size: 64px; }
  .pattern-grid { grid-template-columns: 1fr; }
}
