:root {
  --bg: #FBF6EE;
  --surface: #FFFFFF;
  --surface-2: #F3ECE0;
  --ink: #1F2A4D;
  --ink-2: #5B6380;
  --line: #E6DDCD;
  --accent: #E4572E;
  --accent-ink: #FFFFFF;
  --sun: #F2B544;
  --good: #2E9E6A;
  --good-bg: #E3F4EA;
  --bad: #D2433B;
  --bad-bg: #FBE6E3;
  --almost-bg: #FFF3D6;
  --navy: #1F2A4D;
  --radius: 18px;
  --shadow: 0 1px 0 rgba(31, 42, 77, .06), 0 6px 20px rgba(31, 42, 77, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14182A;
    --surface: #1D2338;
    --surface-2: #252C45;
    --ink: #F3EEE6;
    --ink-2: #A9AFC6;
    --line: #313957;
    --good-bg: #173A2B;
    --bad-bg: #432023;
    --almost-bg: #3C3219;
    --navy: #2A3560;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 "DM Sans", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
h1, h2, h3, .big-fr { font-family: "Source Serif 4", Georgia, serif; font-weight: 700; letter-spacing: -.01em; margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 96px); }
.loading { display: grid; place-items: center; height: 80dvh; font-size: 48px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: scale(.9); opacity: .6; } }

/* ---------- buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 54px; padding: 14px 20px; border-radius: 16px;
  font-weight: 700; font-size: 17px; transition: transform .08s, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 0 #B8431F; }
.btn.good { background: var(--good); color: #fff; box-shadow: 0 4px 0 #1F7550; }
.btn.bad { background: var(--bad); color: #fff; box-shadow: 0 4px 0 #A12E28; }
.btn.light { background: #FBF6EE; color: #1F2A4D; width: auto; min-height: 44px; display: inline-flex; margin-top: 14px; }
.btn.ghost { background: var(--surface); border: 1.5px solid var(--line); }
.btn:disabled { opacity: .4; box-shadow: none; }
.link { color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; font-size: 14px; padding: 8px; }

/* ---------- tab bar ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 4px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(var(--safe-b) + 6px);
}
#tabbar a { flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; font-weight: 500; color: var(--ink-2); padding: 6px 0; border-radius: 12px; }
#tabbar a span { font-size: 22px; filter: grayscale(1); opacity: .7; }
#tabbar a.on { color: var(--ink); }
#tabbar a.on span { filter: none; opacity: 1; }

/* ---------- login ---------- */
.login { text-align: center; padding-top: 12dvh; }
.login .logo { font-size: 64px; }
.login h1 { font-size: 40px; margin-top: 8px; }
.login p { color: var(--ink-2); }
.login form { display: grid; gap: 12px; margin-top: 28px; }
.login input, .text-in, select {
  width: 100%; font: inherit; font-size: 18px; padding: 14px 16px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
}
.err { color: var(--bad); }

/* ---------- home ---------- */
.hello { font-size: 30px; margin: 8px 0 16px; }
.offline { background: var(--almost-bg); padding: 8px 12px; border-radius: 10px; font-size: 14px; }
.hide { display: none; }
.streak-card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.streak-num { display: flex; align-items: baseline; gap: 8px; }
.streak-num b { font: 700 34px "Source Serif 4", serif; }
.streak-num small { color: var(--ink-2); }
.flame { font-size: 28px; }
.flame.dim { filter: grayscale(1); opacity: .4; }
.week { display: flex; justify-content: space-between; margin: 14px 0 12px; }
.day { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--ink-2); }
.day i { width: 30px; height: 30px; border-radius: 50%; background: var(--surface-2); display: block; }
.day.on i { background: var(--sun); }
.day.today span { color: var(--ink); font-weight: 700; }
.day.today i { outline: 2px solid var(--accent); outline-offset: 2px; }
.stats { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; color: var(--ink-2); border-top: 1px solid var(--line); padding-top: 10px; }
.stats b { color: var(--ink); }
.hero {
  display: block; margin: 16px 0 12px; padding: 20px; border-radius: var(--radius);
  background: var(--navy); color: #FBF6EE; position: relative; overflow: hidden;
}
.hero::after { content: ""; position: absolute; right: -50px; top: -50px; width: 130px; height: 130px; border-radius: 50%; background: var(--accent); opacity: .9; }
.hero::before { content: ""; position: absolute; right: 62px; top: 22px; width: 38px; height: 38px; border-radius: 50%; background: var(--sun); opacity: .9; z-index: 1; }
.hero > * { position: relative; z-index: 2; }
.hero small { text-transform: uppercase; letter-spacing: .08em; font-size: 12px; opacity: .8; }
.hero h2 { font-size: 30px; margin: 4px 0 6px; max-width: 75%; }
.hero p { margin: 0; opacity: .85; }
.tile-card { display: flex; align-items: center; gap: 14px; padding: 16px; margin-bottom: 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); position: relative; }
.tile-card .ic { font-size: 28px; width: 48px; height: 48px; display: grid; place-items: center; background: var(--surface-2); border-radius: 14px; flex: none; }
.tile-card h3 { font-size: 19px; }
.tile-card p { margin: 2px 0 0; color: var(--ink-2); font-size: 14px; }
.tile-card.muted { opacity: .75; }
.badge { position: absolute; right: 16px; background: var(--accent); color: #fff; font-weight: 700; border-radius: 99px; padding: 2px 10px; }

/* ---------- course ---------- */
.unit-head { margin: 8px 0 18px; }
.unit-head small { background: var(--sun); color: #1F2A4D; font-weight: 700; padding: 2px 8px; border-radius: 6px; font-size: 12px; }
.unit-head h2 { font-size: 30px; margin-top: 8px; }
.unit-head p { margin: 2px 0 0; color: var(--ink-2); }
.path { list-style: none; padding: 0; margin: 0; position: relative; }
.path::before { content: ""; position: absolute; left: 27px; top: 20px; bottom: 20px; width: 3px; background: var(--line); border-radius: 2px; }
.path li a { display: flex; align-items: center; gap: 14px; padding: 8px 0; position: relative; }
.path .dot { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 18px; background: var(--surface-2); color: var(--ink-2); border: 3px solid var(--bg); flex: none; }
.path li.open .dot { background: var(--accent); color: #fff; box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 25%, transparent); }
.path li.done .dot { background: var(--good); color: #fff; }
.path li.locked { opacity: .5; }
.path .txt b { display: block; font-family: "Source Serif 4", serif; font-size: 19px; }
.path .txt small { color: var(--ink-2); }
.more { text-align: center; color: var(--ink-2); margin-top: 28px; font-style: italic; }

/* ---------- session ---------- */
.session { display: flex; flex-direction: column; min-height: calc(100dvh - var(--safe-t) - 16px); margin-bottom: -96px; }
.session header { display: flex; align-items: center; gap: 14px; padding-bottom: 12px; }
.close { font-size: 22px; color: var(--ink-2); width: 36px; height: 36px; display: grid; place-items: center; }
.bar { flex: 1; height: 14px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--good); border-radius: 99px; transition: width .35s ease; }
.stage { flex: 1; padding: 8px 0 20px; }
.session footer {
  position: sticky; bottom: 0; margin: 0 -16px; padding: 12px 16px calc(var(--safe-b) + 14px);
  background: var(--bg); border-top: 1px solid var(--line);
}
.feedback { margin: -12px -16px 12px; padding: 14px 16px 6px; border-radius: 0; }
.feedback.good { background: var(--good-bg); }
.feedback.bad { background: var(--bad-bg); }
.feedback.almost { background: var(--almost-bg); }
.fb-title { font-weight: 700; font-size: 19px; }
.feedback.good .fb-title { color: var(--good); }
.feedback.bad .fb-title { color: var(--bad); }
.fb-answer { font: 700 20px "Source Serif 4", serif; margin-top: 4px; display: flex; align-items: center; gap: 8px; }
.fb-tr, .fb-heard { color: var(--ink-2); font-size: 15px; }
.feedback .report { font-size: 12px; padding: 6px 0; }

.ex-title { font-size: 24px; margin-bottom: 16px; }
.ex-sub { color: var(--ink-2); margin: -10px 0 14px; font-size: 14px; }
.pill { display: inline-block; background: var(--accent); color: #fff; font-weight: 700; font-size: 12px; padding: 3px 10px; border-radius: 99px; text-transform: uppercase; letter-spacing: .06em; }
.pill.tip { background: var(--sun); color: #1F2A4D; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-top: 12px; box-shadow: var(--shadow); }
.card.intro { text-align: center; display: grid; gap: 12px; justify-items: center; }
.big-fr { font-size: 34px; line-height: 1.15; }
.big-tr { font-size: 19px; color: var(--ink-2); }
.row { display: flex; gap: 10px; align-items: center; justify-content: center; }
.tipcard h2 { font-size: 24px; margin-bottom: 10px; }
.tipcard p { font-size: 17px; margin: 0; }

.speaker { width: 48px; height: 48px; border-radius: 14px; background: var(--navy); color: #fff; font-size: 22px; display: inline-grid; place-items: center; flex: none; box-shadow: 0 3px 0 rgba(0,0,0,.25); }
.speaker.small { width: 36px; height: 36px; font-size: 16px; border-radius: 10px; background: var(--surface-2); color: var(--ink); box-shadow: none; }
.speaker.huge { width: 96px; height: 96px; border-radius: 28px; font-size: 42px; }
.prompt { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.prompt.center { justify-content: center; margin: 12px 0 28px; }
.prompt .big-fr { font-size: 30px; }
.prompt .big-tr { font-size: 22px; color: var(--ink); font-weight: 500; }

.options { display: grid; gap: 10px; }
.opt {
  text-align: left; padding: 15px 16px; border-radius: 14px; font-size: 17px; font-weight: 500;
  background: var(--surface); border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line);
  transition: transform .08s;
}
.opt:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.opt.sel { border-color: #3D6FB6; background: color-mix(in srgb, #3D6FB6 10%, var(--surface)); box-shadow: 0 3px 0 #3D6FB6; }
.opt.good { border-color: var(--good); background: var(--good-bg); box-shadow: 0 3px 0 var(--good); }
.opt.bad { border-color: var(--bad); background: var(--bad-bg); box-shadow: 0 3px 0 var(--bad); animation: shake .3s; }
.opt:disabled { cursor: default; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.answer-line { min-height: 64px; border-bottom: 2px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 0; margin-bottom: 24px; align-content: flex-start; }
.bank { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.tile { padding: 10px 14px; border-radius: 12px; background: var(--surface); border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line); font-size: 17px; font-weight: 500; }
.tile.used { visibility: hidden; }
.text-in { margin-top: 8px; font-size: 20px; }

.mic { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 28px auto 8px; width: 120px; height: 120px; justify-content: center; border-radius: 50%; background: var(--accent); color: #fff; font-size: 40px; box-shadow: 0 6px 0 #B8431F; }
.mic span { font-size: 12px; font-weight: 700; }
.mic.on { animation: pulse 1s infinite; background: var(--bad); }
.mic:disabled { opacity: .3; }
.heard { text-align: center; min-height: 26px; color: var(--ink-2); }
.ex-speak .skip { display: block; margin: 6px auto 0; }

.match { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match .col { display: grid; gap: 10px; align-content: start; }
.match .opt { text-align: center; padding: 14px 8px; font-size: 16px; }
.match .opt.good { opacity: .45; }

.dialogue { display: grid; gap: 10px; }
.bubble { text-align: left; max-width: 85%; padding: 10px 14px; border-radius: 18px 18px 18px 4px; background: var(--surface); border: 1px solid var(--line); opacity: .25; transition: opacity .3s; display: grid; gap: 2px; }
.bubble.shown { opacity: 1; }
.bubble.me { justify-self: end; border-radius: 18px 18px 4px 18px; background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); }
.bubble .who { font-size: 12px; color: var(--ink-2); font-weight: 700; }
.bubble .fr { font-size: 18px; font-weight: 500; }
.bubble .tr { font-size: 14px; color: var(--ink-2); display: none; }
.bubble.open .tr { display: block; }

/* ---------- finish ---------- */
.finish { text-align: center; padding-top: 10dvh; display: grid; gap: 14px; }
.confetti { font-size: 72px; animation: pop .6s ease; }
@keyframes pop { 0% { transform: scale(0); } 70% { transform: scale(1.2); } }
.finish h1 { font-size: 34px; }
.lesson-name { margin: -8px 0 0; color: var(--ink-2); }
.finish-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
.finish-stats div { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 6px; display: grid; gap: 4px; }
.finish-stats b { font: 700 22px "Source Serif 4", serif; }
.finish-stats small { font-size: 12px; color: var(--ink-2); }

/* ---------- talk ---------- */
.talk-pick h1, .settings h1 { font-size: 32px; margin: 8px 0 4px; }
.sub { color: var(--ink-2); margin: 0 0 20px; }
.talk-pick h3 { font-size: 18px; margin-bottom: 12px; }
.scenarios { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.scenario { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; font-weight: 700; display: grid; gap: 6px; box-shadow: var(--shadow); }
.scenario span { font-size: 30px; }

.chat { display: flex; flex-direction: column; height: calc(100dvh - var(--safe-t) - 16px); margin-bottom: -96px; }
.chat header { display: flex; align-items: center; gap: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.chat header b { flex: 1; text-align: center; }
.chat header .close { font-size: 30px; }
.restart { font-size: 22px; width: 36px; height: 36px; color: var(--ink-2); }
.msgs { flex: 1; overflow-y: auto; padding: 14px 0; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; flex-direction: column; }
.msg .b { max-width: 85%; padding: 10px 14px; border-radius: 18px; }
.msg.bot .b { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; align-self: flex-start; }
.msg.me { align-items: flex-end; }
.msg.me .b { background: var(--navy); color: #FBF6EE; border-bottom-right-radius: 4px; }
.msg .fr { font-size: 18px; }
.tools { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.tools .link { padding: 4px; font-size: 13px; }
.msg .tr { color: var(--ink-2); font-size: 14px; margin-top: 4px; }
.corr { max-width: 85%; margin-top: 6px; background: var(--almost-bg); border-radius: 12px; padding: 8px 12px; font-size: 15px; }
.corr p { margin: 4px 0 0; color: var(--ink-2); font-size: 14px; }
.sys { text-align: center; color: var(--ink-2); font-size: 14px; padding: 8px; }
.typing { display: flex; gap: 5px; padding: 14px 16px !important; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-2); animation: blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: .2; } }
.hints { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; align-items: center; }
.hints small { color: var(--ink-2); font-size: 12px; flex: none; max-width: 70px; line-height: 1.2; }
.hint { flex: none; text-align: left; background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 6px 10px; display: grid; max-width: 230px; }
.hint b { font-weight: 500; }
.hint span { font-size: 12px; color: var(--ink-2); }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 0 calc(var(--safe-b) + 8px); }
.composer textarea { flex: 1; resize: none; font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 22px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); max-height: 120px; }
.composer .send, .mic-sm { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 18px; flex: none; }
.mic-sm { background: var(--navy); }
.mic-sm.on { background: var(--bad); animation: pulse 1s infinite; }
.composer.busy .send { opacity: .4; }

/* ---------- settings ---------- */
.settings { display: grid; gap: 18px; }
.field { display: grid; gap: 8px; }
.field > span { font-weight: 700; }
.seg { display: flex; background: var(--surface-2); padding: 4px; border-radius: 14px; }
.seg button { flex: 1; padding: 10px; border-radius: 10px; font-weight: 500; }
.seg button.on { background: var(--surface); box-shadow: var(--shadow); font-weight: 700; }
.warn { background: var(--almost-bg); padding: 10px 12px; border-radius: 12px; font-size: 14px; margin: 0; }
.ver { text-align: center; color: var(--ink-2); font-size: 12px; }

#tabbar[hidden] { display: none; }
