:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #efece5;
  --ink: #1a1c1e;
  --ink-2: #5d6166;
  --line: #e2ded5;
  --accent: #0f6b57;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe8;
  --hi: #fff1c9;
  --good: #1d8a4e;
  --bad: #c2412d;
  --warn: #b7791f;
  --shadow: 0 8px 30px rgba(20, 20, 20, .12);
  --radius: 16px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121416; --surface: #1b1e21; --surface-2: #24282c; --ink: #eceae6; --ink-2: #a3a7ab;
    --line: #2e3337; --accent: #3fb592; --accent-ink: #08241c; --accent-soft: #1d3a31;
    --hi: #3d3518; --good: #4cc27f; --bad: #ef7a64; --warn: #e0b057; --shadow: 0 8px 30px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121416; --surface: #1b1e21; --surface-2: #24282c; --ink: #eceae6; --ink-2: #a3a7ab;
  --line: #2e3337; --accent: #3fb592; --accent-ink: #08241c; --accent-soft: #1d3a31;
  --hi: #3d3518; --good: #4cc27f; --bad: #ef7a64; --warn: #e0b057; --shadow: 0 8px 30px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { 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 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: currentColor; flex: none; }
[hidden] { display: none !important; }

#app { max-width: 640px; margin: 0 auto; min-height: 100%; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }

.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg);
}
.top h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.streak {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-weight: 700;
}
.streak svg { width: 18px; height: 18px; color: var(--warn); }
.streak.done svg { color: #e2572b; }

.view { display: none; }
.view.active { display: block; }

/* ---------- Hoje ---------- */
.player-wrap {
  position: sticky; top: calc(54px + env(safe-area-inset-top)); z-index: 10; background: #000;
  aspect-ratio: 16 / 9; margin: 0 16px; border-radius: var(--radius); overflow: hidden;
}
.player-wrap iframe, #player { width: 100%; height: 100%; display: block; }
.vid-meta { padding: 12px 16px 4px; }
.vid-title { font-weight: 700; font-size: 17px; line-height: 1.3; }
.vid-sub { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.toolbar { display: flex; gap: 8px; padding: 8px 16px 4px; overflow-x: auto; scrollbar-width: none; }
.chip {
  white-space: nowrap; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: 14px; font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.lines { padding: 6px 12px 8px; }
.line {
  padding: 12px; border-radius: 14px; margin: 4px 0; border: 1px solid transparent;
  transition: background .15s;
}
.line.now { background: var(--surface); border-color: var(--line); box-shadow: 0 1px 0 var(--line); }
.line .en { font-size: 18px; line-height: 1.55; }
.line .en span { border-radius: 4px; padding: 1px 0; }
.line .en span.w:active { background: var(--hi); }
.line .pt { color: var(--ink-2); font-size: 15px; margin-top: 4px; display: none; }
.line.show-pt .pt, .lines.all-pt .pt { display: block; }
.line .pt.wait { font-style: italic; opacity: .7; }
.line .acts { display: none; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.line.now .acts { display: flex; }
.act {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 10px;
  background: var(--surface-2); font-size: 14px; font-weight: 600;
}
.act svg { width: 18px; height: 18px; }
.act.main { background: var(--accent); color: var(--accent-ink); }
.vid-end { padding: 8px 16px 24px; display: grid; gap: 10px; }
.vid-end .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: 50px; border-radius: 14px; font-weight: 700; font-size: 16px; padding: 0 16px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: var(--surface); border: 1px solid var(--line); }
.btn.bad { background: var(--bad); color: #fff; }
.btn:disabled { opacity: .5; }

/* ---------- sheet ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 640px; margin: 0 auto;
  background: var(--surface); border-radius: 22px 22px 0 0; box-shadow: var(--shadow);
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom)); max-height: 85vh; overflow-y: auto;
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.term { font-size: 26px; font-weight: 800; letter-spacing: -.01em; display: flex; align-items: center; gap: 10px; }
.pron { color: var(--ink-2); font-size: 15px; margin-top: 2px; }
.trad { font-size: 19px; font-weight: 600; margin: 12px 0 6px; color: var(--accent); }
.expl { font-size: 15px; color: var(--ink); margin: 8px 0; }
.ex { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin: 12px 0; font-size: 15px; }
.ex .ex-pt { color: var(--ink-2); margin-top: 2px; }
.sheet .btns { display: grid; gap: 10px; margin-top: 16px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; display: inline-flex; align-items: center;
  justify-content: center; background: var(--surface-2); flex: none;
}
.skeleton { height: 14px; border-radius: 7px; background: var(--surface-2); margin: 10px 0; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* falar */
.target { font-size: 21px; line-height: 1.5; font-weight: 600; margin: 4px 0 6px; }
.target .ok { color: var(--good); }
.target .miss { color: var(--bad); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.heard { color: var(--ink-2); font-size: 15px; min-height: 22px; }
.score { font-size: 44px; font-weight: 800; text-align: center; margin: 8px 0 0; }
.score small { display: block; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.bigmic {
  width: 84px; height: 84px; border-radius: 50%; margin: 18px auto 6px; display: flex; align-items: center;
  justify-content: center; background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow);
}
.bigmic svg { width: 38px; height: 38px; }
.bigmic.rec { background: var(--bad); color: #fff; animation: ring 1.2s infinite; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(194,65,45,.5); } 100% { box-shadow: 0 0 0 22px rgba(194,65,45,0); } }
.center { text-align: center; color: var(--ink-2); font-size: 14px; }

/* ---------- Revisar ---------- */
#review { padding: 8px 16px 24px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 26px 20px;
  min-height: 300px; display: flex; flex-direction: column; box-shadow: 0 2px 0 var(--line);
}
.card .count { color: var(--ink-2); font-size: 13px; font-weight: 600; }
.card .front { font-size: 30px; font-weight: 800; margin: 24px 0 8px; display: flex; gap: 10px; align-items: center; }
.card .ctx { color: var(--ink-2); font-size: 16px; }
.card .ctx mark { background: var(--hi); color: var(--ink); border-radius: 4px; padding: 0 2px; }
.card .back { margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--line); }
.card .back .trad { margin-top: 0; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.grades button { border-radius: 14px; padding: 12px 4px; background: var(--surface); border: 1px solid var(--line); font-weight: 700; font-size: 14px; }
.grades button small { display: block; font-weight: 500; color: var(--ink-2); font-size: 12px; }
.grades .g0 { color: var(--bad); }
.grades .g3 { color: var(--good); }
.empty { text-align: center; padding: 48px 16px; color: var(--ink-2); }
.empty h3 { color: var(--ink); margin: 12px 0 6px; font-size: 20px; }
.empty svg { width: 48px; height: 48px; color: var(--accent); }

/* ---------- Conversar ---------- */
#v-conversar.active { display: flex; flex-direction: column; height: calc(100dvh - var(--nav-h) - 62px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 16px 10px; gap: 12px; }
.chat-name { font-weight: 800; }
.chat-hint { color: var(--ink-2); font-size: 13px; }
.chat { flex: 1; overflow-y: auto; padding: 4px 16px 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 18px; font-size: 16px; }
.msg.ai { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.msg .mpt { color: var(--ink-2); font-size: 14px; margin-top: 6px; display: none; }
.msg.open .mpt { display: block; }
.msg .mtools { display: flex; gap: 12px; margin-top: 6px; font-size: 13px; font-weight: 600; color: var(--accent); }
.fix { align-self: flex-end; max-width: 86%; background: var(--hi); border-radius: 14px; padding: 8px 12px; font-size: 14px; }
.fix b { display: block; font-size: 15px; }
.typing { align-self: flex-start; color: var(--ink-2); font-size: 14px; padding: 4px 6px; }
.composer {
  display: flex; gap: 8px; align-items: center; padding: 8px 12px; background: var(--bg); border-top: 1px solid var(--line);
}
.composer input {
  flex: 1; min-width: 0; height: 46px; border-radius: 23px; border: 1px solid var(--line); background: var(--surface);
  padding: 0 16px; outline: none;
}
.composer .send { background: var(--accent); color: var(--accent-ink); }
.composer .mic.rec { background: var(--bad); color: #fff; }

/* ---------- Progresso ---------- */
#progress { padding: 4px 16px 24px; display: grid; gap: 14px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.big { display: flex; align-items: baseline; gap: 10px; }
.big b { font-size: 52px; line-height: 1; letter-spacing: -.03em; }
.big span { color: var(--ink-2); font-weight: 600; }
.muted { color: var(--ink-2); font-size: 14px; }
.heat { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 14px; }
.heat i { aspect-ratio: 1; border-radius: 6px; background: var(--surface-2); display: block; }
.heat i.l1 { background: color-mix(in srgb, var(--accent) 40%, var(--surface-2)); }
.heat i.l2 { background: color-mix(in srgb, var(--accent) 70%, var(--surface-2)); }
.heat i.l3 { background: var(--accent); }
.heat i.today { outline: 2px solid var(--ink); outline-offset: 1px; }
.nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.nums div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 10px; text-align: center; }
.nums b { display: block; font-size: 26px; }
.nums span { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.list h3 { margin: 0 0 8px; font-size: 16px; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { color: var(--ink-2); font-size: 13px; }
.item button { color: var(--ink-2); padding: 6px; }
.item svg { width: 18px; height: 18px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: var(--accent); }

/* ---------- nav ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line); max-width: 640px; margin: 0 auto;
}
.tabs button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--ink-2); font-size: 12px; font-weight: 600; position: relative; }
.tabs button.on { color: var(--accent); }
.badge {
  position: absolute; top: 8px; left: calc(50% + 6px); min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px;
  background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

/* ---------- login / toast ---------- */
.login { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; }
.login form { width: 100%; max-width: 340px; display: grid; gap: 12px; text-align: center; }
.login h2 { margin: 6px 0 0; }
.login p { margin: 0 0 10px; color: var(--ink-2); }
.login input { height: 52px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); padding: 0 16px; font-size: 17px; }
.logo { width: 72px; height: 72px; border-radius: 20px; margin: 0 auto; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 28px; display: flex; align-items: center; justify-content: center; }
.err { color: var(--bad); min-height: 20px; font-size: 14px; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 70;
  max-width: 600px; margin: 0 auto; background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px;
  font-size: 15px; box-shadow: var(--shadow);
}
