:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #111111;
  --muted: #5b6168;
  --line: #e3e3df;
  --accent: #f5c842;
  --accent-text: #111111;
  --mastered: #2f9e6b;
  --learning: #f5c842;
  --fresh: #d9dad6;
  --danger: #c0392b;
  --up: #2f9e6b;
  --down: #c0392b;
  --heat-0: #e8e8e4;
  --heat-1: #fbe9a8;
  --heat-2: #f5c842;
  --heat-3: #d9a514;
  --heat-4: #8a6a06;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1c1c1c;
    --text: #f2f2f2;
    --muted: #a3a8ae;
    --line: #2e2e2e;
    --fresh: #3a3a3a;
    --heat-0: #262626;
    --heat-1: #4d4115;
    --heat-2: #8a6f17;
    --heat-3: #c9a227;
    --heat-4: #f5c842;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

main { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }

[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }

/* ---------- Topo ---------- */

.topbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.tabs { display: flex; gap: 4px; margin-left: auto; background: var(--bg); padding: 3px; border-radius: 10px; }
.tabs button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  padding: 6px 14px; border-radius: 8px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.logout { margin: 0; }
.link { border: 0; background: none; color: var(--muted); font: inherit; cursor: pointer; padding: 6px; }

/* ---------- Botões ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 12px 20px;
  font: inherit; font-weight: 600; cursor: pointer;
  touch-action: manipulation;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--muted); padding: 8px 12px; }
.btn-big { width: 100%; padding: 16px; font-size: 1.05rem; }
.btn:active { transform: scale(0.98); }
.pts { font-size: 0.85rem; background: rgba(0, 0, 0, 0.1); padding: 2px 8px; border-radius: 999px; }

/* ---------- Estudo ---------- */

.study-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
select {
  font: inherit; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  max-width: 100%;
}

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px; margin-bottom: 12px; }
.panel h2 { font-size: 0.95rem; margin: 0 0 12px; }

.card { text-align: center; min-height: 360px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.card-meta { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 0.85rem; align-self: stretch; justify-content: space-between; }
.badge { background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; }

.play {
  width: 104px; height: 104px; margin-top: 12px; border-radius: 50%;
  border: 0; background: var(--text); color: var(--accent);
  display: grid; place-items: center; cursor: pointer;
}
.play:active { transform: scale(0.96); }
.audio-actions { display: flex; gap: 4px; }

.text-en { font-size: 1.35rem; font-weight: 600; margin: 8px 0 0; }
.text-pt { font-size: 1.05rem; color: var(--muted); margin: 0; }

.actions { display: grid; gap: 8px; margin-bottom: 12px; }

kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; font-size: 0.8em; }
@media (hover: none) { .keys-hint { display: none; } }

.flash {
  position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%);
  font-size: 2.4rem; font-weight: 800; color: var(--accent);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  pointer-events: none; animation: flash 0.7s ease-out forwards;
}
@keyframes flash { to { opacity: 0; transform: translate(-50%, -110%); } }

.form-error { color: var(--danger); }

/* ---------- Painel ---------- */

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi-main { grid-column: 1 / -1; border-color: var(--accent); }
.kpi-label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.kpi-value small { font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.kpi-sub { font-size: 0.8rem; color: var(--muted); }
.up { color: var(--up); font-weight: 700; }
.down { color: var(--down); font-weight: 700; }

.stack-bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--fresh); }
.stack-bar.thin { height: 8px; }
.seg.mastered { background: var(--mastered); }
.seg.learning { background: var(--learning); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 0.9rem; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.dot.mastered { background: var(--mastered); }
.dot.learning { background: var(--learning); }
.dot.fresh { background: var(--fresh); }
.queue { margin: 12px 0 0; }

.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; }
.cell { display: inline-block; aspect-ratio: 1; border-radius: 3px; background: var(--heat-0); }
.heatmap .cell { width: 100%; }
.heat-legend { display: flex; align-items: center; gap: 3px; justify-content: flex-end; margin-top: 8px; }
.heat-legend .cell { width: 11px; }
.l1 { background: var(--heat-1); }
.l2 { background: var(--heat-2); }
.l3 { background: var(--heat-3); }
.l4 { background: var(--heat-4); }

.bars { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; height: 160px; align-items: end; }
.bar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bar { width: 100%; max-width: 32px; background: var(--accent); border-radius: 6px 6px 0 0; }
.bar-val, .bar-label { font-size: 0.7rem; color: var(--muted); }

.islands { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.island-row { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }

/* ---------- Login ---------- */

body.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-box h1 { font-size: 1.4rem; margin: 8px 0 24px; }
.login-box form { display: grid; gap: 10px; text-align: left; }
.login-box input {
  font: inherit; padding: 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}

@media (prefers-color-scheme: dark) {
  .play { background: var(--accent); color: #111111; }
}
