:root {
  --bg: #F3EEE8;
  --paper: #FFFFFF;
  --ink: #1F1D22;
  --muted: #77707A;
  --line: #E6DED5;
  --accent: #E2626F;
  --accent-ink: #B83946;
  --mine: #FFE7A6;
  --mine-ink: #2A2420;
  --teal: #2C7A74;
  --teal-soft: #E1F1EF;
  --warn: #9A5A12;
  --warn-soft: #FFF2DE;
  --tip: #EEF0FF;
  --tip-ink: #3B3F8F;
  --wall: #C9D6E3;
  --ko: 'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --tabs-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17151A; --paper: #222026; --ink: #F1ECE8; --muted: #A49CA6; --line: #35313B;
    --accent: #F07A86; --accent-ink: #F59AA4; --mine: #5A4A1E; --mine-ink: #FFF3D6;
    --teal: #67C2B9; --teal-soft: #1C3331; --warn: #F2B266; --warn-soft: #3A2B19;
    --tip: #262A4A; --tip-ink: #C4C8FF; --wall: #1E2630; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17151A; --paper: #222026; --ink: #F1ECE8; --muted: #A49CA6; --line: #35313B;
  --accent: #F07A86; --accent-ink: #F59AA4; --mine: #5A4A1E; --mine-ink: #FFF3D6;
  --teal: #67C2B9; --teal-soft: #1C3331; --warn: #F2B266; --warn-soft: #3A2B19;
  --tip: #262A4A; --tip-ink: #C4C8FF; --wall: #1E2630; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 'Be Vietnam Pro', system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[lang="ko"], .ko { font-family: var(--ko); }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .35em; }
p { margin: 0 0 .5em; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.pron { font-family: var(--ko); color: var(--teal); font-size: .9rem; }

/* ---------- Khung chung ---------- */
.view { max-width: 720px; margin: 0 auto; }
.page { padding: 0 16px calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom)); }
.page-head { padding: 22px 0 10px; }
.page-head h1 { font-size: 1.5rem; }
.page-head p { color: var(--muted); }

/* ---------- MINJI: man hinh nhan tin ---------- */
.chat-view {
  display: flex; flex-direction: column;
  height: calc(100dvh - var(--tabs-h) - env(safe-area-inset-bottom));
  background: var(--wall);
}
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--paper); border-bottom: 1px solid var(--line); position: relative;
}
.avatar { width: 44px; height: 44px; border-radius: 16px; flex: none; }
.who-box { min-width: 0; flex: 1; }
.name { font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.name small { font-weight: 400; color: var(--muted); font-size: .76rem; }
.status { font-family: 'Gowun Dodum', var(--ko); color: var(--muted); font-size: .84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clock { font-size: .78rem; color: var(--muted); text-align: right; line-height: 1.25; white-space: nowrap; }
.clock b { display: block; color: var(--ink); font-size: .95rem; }
.head-btn { border: 0; background: transparent; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; }
.head-btn svg { width: 22px; height: 22px; fill: var(--muted); }
.head-btn:hover { background: var(--bg); }

.menu { background: var(--paper); border-bottom: 1px solid var(--line); padding: 10px 14px 14px; }
.menu-title { font-size: .82rem; font-weight: 600; color: var(--muted); margin: 8px 0 6px; }
.seg { display: flex; background: var(--bg); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 6px; border-radius: 9px; font-size: .86rem; }
.seg button.on { background: var(--paper); font-weight: 600; color: var(--accent-ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
select, input[type="text"] {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: .92rem; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.thread { flex: 1; overflow-y: auto; padding: 12px 12px 6px; display: flex; flex-direction: column; gap: 4px; overscroll-behavior: contain; }
.day { align-self: center; background: rgba(0,0,0,.12); color: #fff; font-size: .76rem; padding: 3px 12px; border-radius: 99px; margin: 10px 0 6px; }
.divider { align-self: center; background: var(--paper); color: var(--muted); font-size: .8rem; padding: 5px 12px; border-radius: 99px; margin: 10px 0 6px; text-align: center; max-width: 90%; }

.row { display: flex; gap: 8px; align-items: flex-start; margin-top: 6px; }
.row.me { justify-content: flex-end; }
.row .mini { width: 34px; height: 34px; border-radius: 12px; flex: none; margin-top: 2px; }
.stack { display: flex; flex-direction: column; gap: 4px; max-width: 80%; min-width: 0; }
.row.me .stack { align-items: flex-end; }
.sender { font-size: .78rem; color: var(--ink); opacity: .75; margin-left: 2px; }
.bubble {
  background: var(--paper); color: var(--ink); padding: 8px 12px; border-radius: 4px 16px 16px 16px;
  font: 400 1.04rem/1.5 var(--ko); word-break: keep-all; overflow-wrap: anywhere; width: fit-content; max-width: 100%;
}
.bubble + .bubble { border-radius: 16px; }
.row.me .bubble { background: var(--mine); color: var(--mine-ink); border-radius: 16px 4px 16px 16px; }
.bubble .pron { display: block; margin-top: 2px; }
.bubble .vi { display: block; font: .9rem/1.45 'Be Vietnam Pro', sans-serif; color: var(--muted); margin-top: 4px; }
.hide-ko .row:not(.me) .bubble .t, .hide-ko .row:not(.me) .bubble .pron { filter: blur(6px); transition: filter .2s; }
.hide-ko .row:not(.me) .stack.peek .bubble .t, .hide-ko .row:not(.me) .stack.peek .bubble .pron { filter: none; }
.meta { font-size: .7rem; color: var(--ink); opacity: .55; }
.tools { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  border: 0; background: rgba(255,255,255,.75); color: var(--ink); border-radius: 99px; padding: 4px 10px;
  font-size: .78rem; display: inline-flex; align-items: center; gap: 4px; min-height: 30px;
}
.chip svg { width: 14px; height: 14px; fill: currentColor; }
.chip.on { background: var(--ink); color: var(--paper); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip { background: rgba(255,255,255,.1); } }

.fix { background: var(--paper); border-radius: 14px; padding: 10px 12px; font-size: .9rem; max-width: 100%; border-left: 4px solid var(--warn); }
.fix.sach { border-left-color: var(--teal); }
.fix .lb { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--warn); }
.fix.sach .lb { color: var(--teal); }
.fix .wrong { text-decoration: line-through; color: var(--muted); font-family: var(--ko); }
.fix .right { font: 600 1.04rem/1.5 var(--ko); }
.fix .tools { margin-top: 6px; }
.fix .chip { background: var(--bg); }
.tip { align-self: center; background: var(--tip); color: var(--tip-ink); border-radius: 14px; padding: 9px 12px; font-size: .88rem; max-width: 92%; margin: 4px 0; }
.tip b { display: block; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; }
.typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: none; opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

.hint-bar { background: var(--paper); border-top: 1px solid var(--line); padding: 8px 12px; font-size: .9rem; }
.hint-bar .ko { font-weight: 600; cursor: pointer; }
.composer { display: flex; gap: 8px; align-items: center; padding: 8px 10px; background: var(--paper); border-top: 1px solid var(--line); }
.composer input { min-height: 46px; border-radius: 23px; padding: 10px 16px; }
.mic, .send { flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; display: grid; place-items: center; }
.mic { background: var(--accent); color: #fff; }
.mic svg, .send svg { width: 24px; height: 24px; fill: currentColor; }
.mic.recording { animation: pulse 1s infinite; background: #A92D3A; }
.send { background: var(--bg); color: var(--ink); }
.send:disabled { opacity: .4; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(226,98,111,.25); } }
.mic-status { margin: 0; font-size: .82rem; text-align: center; color: var(--muted); background: var(--paper); min-height: 0; }
.mic-status:empty { display: none; }

/* ---------- CANH DOI THAT ---------- */
.timeline { position: relative; padding-left: 58px; }
.timeline::before { content: ''; position: absolute; left: 44px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.scene-item {
  position: relative; display: block; width: 100%; text-align: left; border: 0; background: var(--paper);
  border-radius: 16px; padding: 12px 14px; margin-bottom: 10px;
}
.scene-item::before { content: ''; position: absolute; left: -19px; top: 18px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--bg); }
.scene-item .time { position: absolute; left: -60px; top: 13px; font-size: .78rem; color: var(--muted); width: 36px; text-align: right; font-variant-numeric: tabular-nums; }
.scene-item .ko { color: var(--accent-ink); font-size: .85rem; }
.scene-item b { display: block; font-size: 1.02rem; }
.scene-item .done { font-size: .78rem; color: var(--teal); }

.back { border: 0; background: transparent; color: var(--accent-ink); padding: 6px 0; font-weight: 600; margin-bottom: 4px; }
.scene-top { background: var(--paper); border-radius: 18px; padding: 16px; margin-bottom: 12px; }
.scene-top .ko { color: var(--accent-ink); }
.scene-top .bc { color: var(--muted); }
.scene-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.script { background: var(--paper); border-radius: 18px; padding: 6px 14px; margin-bottom: 12px; }
.line { display: grid; grid-template-columns: 62px 1fr; gap: 8px; padding: 12px 0; border-top: 1px solid var(--line); }
.line:first-child { border-top: 0; }
.line.playing { background: linear-gradient(90deg, var(--warn-soft), transparent); margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
.spk { font: 700 .86rem var(--ko); padding-top: 3px; }
.line .k { font: 500 1.12rem/1.5 var(--ko); }
.line .v { color: var(--muted); font-size: .92rem; }
.hide-vi .line .v { display: none; }
.line .tools { margin-top: 6px; }
.line .chip { background: var(--bg); }
.line .result { margin-top: 6px; }
.stage { grid-column: 1 / -1; text-align: center; font-size: .84rem; color: var(--muted); font-style: italic; padding: 8px 0; border-top: 1px solid var(--line); }

.compare { display: grid; gap: 10px; margin-bottom: 12px; }
.cmp { background: var(--paper); border-radius: 16px; padding: 12px 14px; }
.cmp .sach { font-family: var(--ko); color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(0,0,0,.3); }
.cmp .doi { font: 600 1.1rem var(--ko); color: var(--ink); }
.cmp .lbl { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-right: 6px; }
.cmp .lbl.real { color: var(--teal); }
.cmp p { margin: 4px 0 0; font-size: .9rem; color: var(--muted); }
.culture { background: var(--tip); color: var(--tip-ink); border-radius: 16px; padding: 12px 14px; margin-bottom: 12px; }
.culture b { display: block; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
h2.sec { font-size: 1.05rem; margin: 18px 0 8px; }

/* ---------- ON TAP ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stats div { background: var(--paper); border-radius: 14px; padding: 10px; text-align: center; }
.stats b { display: block; font-size: 1.35rem; }
.stats span { font-size: .76rem; color: var(--muted); }
.review { background: var(--paper); border-radius: 18px; padding: 18px 16px; text-align: center; }
.review .from { font-size: .78rem; color: var(--muted); }
.review .ask { color: var(--muted); font-size: .9rem; margin-top: 8px; }
.review .vi-big { font-size: 1.2rem; font-weight: 600; margin: 4px 0 12px; }
.review .ko-big { font: 600 1.55rem/1.4 var(--ko); margin: 14px 0 2px; }
.review .actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.empty { color: var(--muted); padding: 6px 0; }

/* ---------- GHI CHU ---------- */
.block { background: var(--paper); border-radius: 18px; padding: 16px; margin-bottom: 12px; }
.block h2 { font-size: 1.08rem; }
.memory { list-style: none; padding: 0; margin: 0; }
.memory li { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); font-family: var(--ko); }
.memory li:first-child { border-top: 0; }
.memory button { border: 0; background: var(--bg); width: 30px; height: 30px; border-radius: 50%; flex: none; }
.word { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.word:first-child { border-top: 0; }
.word .w { font: 700 1.05rem var(--ko); border: 0; background: transparent; padding: 0; text-align: left; color: var(--accent-ink); }
.word .ex { grid-column: 1 / -1; font-family: var(--ko); font-size: .92rem; color: var(--muted); }
.rule { padding: 10px 0; border-top: 1px solid var(--line); }
.rule:first-child { border-top: 0; }
.rule .ex { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.rule .ex button { border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 6px 12px; text-align: left; font-family: var(--ko); }
.rule .ex button span { display: block; color: var(--teal); font-size: .88rem; }
.field { display: block; font-size: .9rem; font-weight: 500; margin: 10px 0; }
.field select, .field input { margin-top: 4px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

/* ---------- Nut, ket qua, thong bao ---------- */
.btn { border: 1px solid var(--line); background: var(--paper); border-radius: 12px; padding: 9px 14px; font-weight: 500; min-height: 42px; display: inline-flex; align-items: center; gap: 6px; }
.btn svg { width: 18px; height: 18px; fill: currentColor; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.teal { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.recording { background: var(--accent); color: #fff; border-color: var(--accent); animation: pulse 1s infinite; }
.chip.recording { background: var(--accent); color: #fff; animation: pulse 1s infinite; }
.result { margin-top: 8px; padding: 10px 12px; border-radius: 12px; background: var(--bg); font-size: .9rem; text-align: left; }
.result .heard { font-family: var(--ko); }
.result .miss { color: var(--accent-ink); text-decoration: underline; text-decoration-thickness: 2px; }
.score { font-weight: 700; }
.score.good { color: var(--teal); } .score.mid { color: var(--warn); } .score.low { color: var(--accent-ink); }
.voice-warn { background: var(--warn-soft); color: var(--ink); border-radius: 12px; padding: 10px 12px; font-size: .88rem; margin-bottom: 12px; }
.chat-view .voice-warn { margin: 0; border-radius: 0; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  display: flex; justify-content: center; background: var(--paper); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
.tabs button { flex: 1; max-width: 180px; border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .74rem; color: var(--muted); }
.tabs svg { width: 24px; height: 24px; fill: currentColor; }
.tabs button.on { color: var(--accent-ink); font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 80px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(16px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: .25s; max-width: calc(100% - 32px); text-align: center; z-index: 10;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 760px) {
  .chat-view { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
