:root {
  --bg: #050918; --card: #0c1330; --text: #f5f2ea; --muted: #8fb8e8; --line: #1d2a55;
  --brand: #4cc3ff; --brand-2: #43ffab; --ok: #22c55e; --warn: #f59e0b; --bad: #e2402c;
  --bubble-me: #4cc3ff; --bubble-me-text: #050918; --bubble-bot: #121c42; --on-brand: #050918;
  --radius: 18px; color-scheme: dark;
}
* { 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, #0f2a66, #0b4d6e); color: #fff; border: 1px solid #1e4a8a; }
.hero .muted { color: #cfe6ff; }
.progress > div { background: var(--brand-2) !important; }
.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: 700; cursor: pointer; background: var(--brand); color: var(--on-brand); }
.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); color: #fff; } .btn.warn { background: var(--warn); color: #1a1200; } .btn.bad { background: var(--bad); color: #fff; }
.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: var(--on-brand); }
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: var(--on-brand); 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%; }

/* keep everything inside the phone width */
html, body { overflow-x: hidden; max-width: 100%; }
main, .card, .scenario, .msg, .fix { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.grid > * { min-width: 0; }
.topbar .stats { flex-shrink: 0; }

/* NETXO Speak */
#splash { position: fixed; inset: 0; background: #050918; display: grid; place-items: center; z-index: 50; transition: opacity .45s; }
#splash img { width: min(46vw, 220px); animation: pop .6s ease-out; }
#splash.hide { opacity: 0; pointer-events: none; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.brand { width: 28px; height: 29px; }
.flag-btn { border: 0; background: none; font-size: 20px; padding: 0; cursor: pointer; line-height: 1; }
.tabbar a b { display: block; font-weight: 600; }
body.bare .tabbar, body.bare .stats { display: none; }
.onboard { padding: 22px 18px; }
.hero-logo { display: block; width: 120px; margin: 4px auto 8px; }
.dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 14px; }
.dots span { width: 22px; height: 5px; border-radius: 9px; background: var(--line); }
.dots span.on { background: var(--brand-2); }
.lang-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.lang-grid.small { grid-template-columns: repeat(3, 1fr); }
.lang { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 6px; border-radius: 16px; border: 1.5px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; min-width: 0; }
.lang .flag { font-size: 30px; }
.lang-grid.small .lang { padding: 8px 4px; font-size: 13px; }
.lang-grid.small .flag { font-size: 22px; }
.lang.active { border-color: var(--brand-2); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand-2) 35%, transparent); }
.scenario.wide { width: 100%; }
.romaji { font-size: 13px; color: var(--muted); margin-top: 4px; font-style: italic; }
.tipline { margin-top: 6px; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.btn:disabled { opacity: .4; cursor: default; }
