:root {
  --bg: #f6f7fb; --card: #ffffff; --text: #151827; --muted: #646b80; --line: #e4e6ef;
  --brand: #4f46e5; --brand-2: #7c3aed; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --bubble-me: #4f46e5; --bubble-me-text: #fff; --bubble-bot: #ffffff;
  --radius: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1120; --card: #191c2f; --text: #eceefe; --muted: #9aa0b8; --line: #2a2e47;
    --bubble-bot: #22263d;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); display: flex; flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
.topbar {
  display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats { display: flex; gap: 10px; font-weight: 600; font-size: 14px; }
.icon-btn { border: 0; background: none; font-size: 28px; line-height: 1; color: var(--brand); padding: 0 6px; cursor: pointer; }
main { flex: 1; overflow-y: auto; padding: 16px; padding-bottom: 90px; max-width: 720px; width: 100%; margin: 0 auto; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
.tabbar a { flex: 1; text-align: center; padding: 8px 0 10px; color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600; }
.tabbar a span { display: block; font-size: 22px; }
.tabbar a.active { color: var(--brand); }
body.in-chat .tabbar { display: none; }
body.in-chat main { padding-bottom: 16px; display: flex; flex-direction: column; }

h2 { font-size: 20px; margin: 8px 0 12px; }
p.muted, .muted { color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.hero { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border: 0; }
.hero .muted { color: #e0e7ff; }
.progress { height: 10px; background: rgba(255,255,255,.3); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: #fff; border-radius: 99px; transition: width .4s; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.scenario { text-align: left; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: var(--radius); padding: 14px; cursor: pointer; font: inherit; }
.scenario .emoji { font-size: 28px; }
.scenario b { display: block; margin-top: 6px; }
.scenario small { color: var(--muted); }
.scenario:active { transform: scale(.98); }

.btn { border: 0; border-radius: 14px; padding: 12px 16px; font: inherit; font-weight: 600; cursor: pointer; background: var(--brand); color: #fff; }
.btn.secondary { background: transparent; color: var(--brand); border: 1.5px solid var(--brand); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ok { background: var(--ok); } .btn.warn { background: var(--warn); } .btn.bad { background: var(--bad); }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.stretch > * { flex: 1; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1.5px solid var(--line); background: var(--card); color: var(--text); padding: 8px 12px; border-radius: 99px; font: inherit; font-size: 14px; cursor: pointer; }
.chip.active { border-color: var(--brand); background: var(--brand); color: #fff; }
label { display: block; font-weight: 600; margin: 12px 0 6px; }
input[type=text], input[type=password] { width: 100%; padding: 12px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
input[type=range] { width: 100%; }

/* chat */
.chat { flex: 1; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; padding-bottom: 8px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 18px; line-height: 1.4; }
.msg.bot { align-self: flex-start; background: var(--bubble-bot); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.me { align-self: flex-end; background: var(--bubble-me); color: var(--bubble-me-text); border-bottom-right-radius: 6px; }
.msg .tools { display: flex; gap: 6px; margin-top: 6px; }
.msg .tools button { border: 0; background: none; cursor: pointer; font-size: 18px; padding: 2px; }
.msg .es { font-size: 14px; color: var(--muted); margin-top: 4px; }
.fix { align-self: stretch; background: color-mix(in srgb, var(--warn) 12%, var(--card)); border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line)); border-radius: 14px; padding: 10px 12px; font-size: 15px; }
.fix s { color: var(--bad); }
.fix b { color: var(--ok); }
.hint { align-self: stretch; font-size: 14px; color: var(--muted); }
.typing { align-self: flex-start; color: var(--muted); font-style: italic; }
.composer { border-top: 1px solid var(--line); padding-top: 10px; }
.interim { min-height: 22px; color: var(--muted); font-style: italic; text-align: center; margin-bottom: 8px; }
.mic {
  width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; font-size: 32px; cursor: pointer;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--brand) 45%, transparent); display: block; margin: 0 auto;
}
.mic.listening { background: var(--bad); animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--bad) 60%, transparent); } 100% { box-shadow: 0 0 0 22px transparent; } }
.textrow { display: flex; gap: 8px; margin-top: 10px; }
.textrow input { flex: 1; }

/* practice */
.big { font-size: 22px; font-weight: 700; text-align: center; margin: 10px 0; }
.word-ok { color: var(--ok); } .word-miss { color: var(--bad); text-decoration: underline; }
.score { text-align: center; font-size: 40px; font-weight: 800; }
.center { text-align: center; }
.blur { filter: blur(7px); user-select: none; }
.toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 20; max-width: 90%; }
