/* ============================================================
   NeuroBack — Dual N-Back
   Dark premium theme. Mobile-first, no dependencies.
   ============================================================ */

:root {
  --bg: #0b0e1a;
  --bg-soft: #121628;
  --card: #171c33;
  --card-2: #1d2340;
  --line: rgba(255, 255, 255, 0.08);
  --txt: #eef0fa;
  --txt-dim: #9aa1c0;
  --accent: #6c5ce7;
  --accent-2: #00cec9;
  --grad: linear-gradient(135deg, #6c5ce7 0%, #00cec9 100%);
  --good: #2ecc71;
  --bad: #ff5e57;
  --radius: 18px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(108, 92, 231, 0.18), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(0, 206, 201, 0.12), transparent 60%),
    var(--bg);
  color: var(--txt);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

/* ---------------- Top bar ---------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px clamp(16px, 4vw, 32px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 34px; height: 34px; border-radius: 9px; }
.brand-name {
  font-weight: 800; font-size: 19px; letter-spacing: 0.2px;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lang-select {
  background: var(--card); color: var(--txt);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 10px; font-size: 14px; outline: none;
}

/* ---------------- Screens ---------------- */
#app { flex: 1; width: 100%; max-width: 560px; margin: 0 auto; padding: 0 16px 24px; }
.screen { display: none; animation: fadeIn 0.25s ease; }
.screen.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.screen-head { display: flex; align-items: center; gap: 12px; margin: 6px 0 18px; }
.screen-title { font-size: 22px; font-weight: 800; }
#screen-results .screen-title { text-align: center; margin: 10px 0 6px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; flex: 0 0 auto;
  background: var(--card); border: 1px solid var(--line);
  color: var(--txt-dim); font-size: 16px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: 0.15s;
}
.icon-btn:hover { color: var(--txt); border-color: rgba(255, 255, 255, 0.2); }

/* ---------------- Home ---------------- */
.hero { text-align: center; margin: 4vh 0 22px; }
.hero-title {
  font-size: clamp(26px, 6vw, 34px); font-weight: 800; line-height: 1.15;
}
.hero-sub { color: var(--txt-dim); margin-top: 8px; font-size: 15px; }

.home-card {
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px; text-align: center;
}
/* Grupos de configuração pré-jogo: etiqueta em cima, botões a toda a largura. */
.cfg-group { margin-bottom: 16px; text-align: left; }
.cfg-group.cfg-inline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cfg-label { display: block; color: var(--txt-dim); font-size: 13.5px; font-weight: 600; margin-bottom: 8px; }
.cfg-inline .cfg-label { margin-bottom: 0; }
.cfg-hint { display: block; color: var(--txt-dim); font-size: 12px; margin-top: 7px; opacity: 0.85; }
.seg.wide { display: flex; width: 100%; }
.seg.wide button { flex: 1; padding: 10px 6px; text-align: center; }
.home-level-value { font-size: 20px; font-weight: 800; }
.home-level-value span { color: var(--accent-2); }
.home-stepper b { min-width: 88px; text-align: center; }

.btn-play {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--grad); color: #fff; font-weight: 800; font-size: 19px;
  padding: 16px; border-radius: 14px; margin-top: 4px;
  box-shadow: 0 8px 24px rgba(108, 92, 231, 0.4);
  transition: transform 0.12s, box-shadow 0.12s;
}
.btn-play:active { transform: scale(0.97); }
.btn-play svg { width: 22px; height: 22px; }

.seg { display: inline-flex; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  padding: 8px 14px; border-radius: 9px; font-size: 13.5px; font-weight: 600;
  color: var(--txt-dim); transition: 0.15s; white-space: nowrap;
}
.seg button.on { background: var(--card-2); color: var(--txt); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12); }
.seg.small button { padding: 6px 11px; font-size: 12.5px; }

.home-streak { margin-top: 14px; font-size: 13.5px; color: var(--txt-dim); min-height: 18px; }
.home-streak b { color: #f6b93b; }

.home-nav { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.nav-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 8px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--txt-dim); transition: 0.15s;
}
.nav-card:hover { color: var(--txt); border-color: rgba(255, 255, 255, 0.18); transform: translateY(-1px); }
.nav-emoji { font-size: 20px; }

/* ---------------- Game ---------------- */
.game-top { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 10px; }
.game-n { font-weight: 800; font-size: 18px; }
.game-n span { color: var(--accent-2); }

.progress { height: 6px; border-radius: 99px; background: var(--bg-soft); overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--grad); border-radius: 99px; transition: width 0.3s ease; }
.game-counter { text-align: center; color: var(--txt-dim); font-size: 13px; margin: 8px 0 4px; }

.grid-wrap { position: relative; margin: 10px auto; width: min(86vw, 380px); }
.grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  aspect-ratio: 1; width: 100%;
}
.grid i {
  display: block; position: relative; border-radius: 16px;
  background: var(--card); border: 1px solid var(--line);
  transition: background 0.1s, transform 0.1s, box-shadow 0.25s;
}
.grid i.lit {
  background: var(--grad);
  box-shadow: 0 0 26px rgba(108, 92, 231, 0.65), 0 0 60px rgba(0, 206, 201, 0.3);
  transform: scale(1.04);
  border-color: transparent;
}
.grid i.pulse { box-shadow: 0 0 18px rgba(0, 206, 201, 0.35); }

/* Feedback na grelha: célula pisca verde/vermelho ao carregar em POSIÇÃO
   (overlay ::after, para funcionar também por cima da célula acesa). */
.grid i::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit;
  opacity: 0; pointer-events: none;
}
.grid i.fb-good::after { background: var(--good); animation: fbFlash 0.5s ease; }
.grid i.fb-bad::after { background: var(--bad); animation: fbFlash 0.5s ease; }
.grid i.fb-good { box-shadow: 0 0 26px rgba(46, 204, 113, 0.55); }
.grid i.fb-bad { box-shadow: 0 0 26px rgba(255, 94, 87, 0.5); }
@keyframes fbFlash { 0% { opacity: 0.9; } 100% { opacity: 0; } }
.grid.mini { width: 130px; gap: 5px; margin: 0 auto; }
.grid.mini i { border-radius: 8px; }

.countdown {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  font-size: 76px; font-weight: 800; color: var(--txt);
  text-shadow: 0 0 40px rgba(108, 92, 231, 0.8);
  background: rgba(11, 14, 26, 0.55); border-radius: 20px; backdrop-filter: blur(2px);
}
.countdown.show { display: flex; }

.letter-flash {
  position: absolute; right: -6px; top: -6px;
  min-width: 44px; padding: 8px 12px; border-radius: 12px;
  background: var(--card-2); border: 1px solid var(--line);
  font-size: 22px; font-weight: 800; text-align: center;
  opacity: 0; transform: scale(0.8); transition: 0.15s;
  pointer-events: none;
}
.letter-flash.show { opacity: 1; transform: scale(1); }

.paused-overlay {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(11, 14, 26, 0.75); border-radius: 20px; backdrop-filter: blur(3px);
  z-index: 5;
}
.paused-overlay.show { display: flex; }
.paused-box { text-align: center; }
.paused-box p { font-size: 20px; font-weight: 700; margin-bottom: 14px; }

.match-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.match-btns.single { grid-template-columns: 1fr; }
.match-btn {
  position: relative;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 18px 10px 16px; font-weight: 700; font-size: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: transform 0.08s, background 0.15s, border-color 0.15s, box-shadow 0.15s;
  user-select: none; touch-action: manipulation;
}
.match-btn:active { transform: scale(0.96); }
.match-btn:disabled { opacity: 0.45; cursor: default; }
.match-btn .match-key {
  position: absolute; top: 8px; right: 10px;
  font-size: 11px; font-weight: 700; color: var(--txt-dim);
  border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px;
}
.match-btn .match-ico { font-size: 20px; }
.match-btn.pressed { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.35); }
.match-btn.good { border-color: var(--good); background: rgba(46, 204, 113, 0.14); box-shadow: 0 0 0 2px rgba(46, 204, 113, 0.35); }
.match-btn.bad { border-color: var(--bad); background: rgba(255, 94, 87, 0.12); box-shadow: 0 0 0 2px rgba(255, 94, 87, 0.35); }
.match-btn.hidden { display: none; }

.kbd-hint { text-align: center; color: var(--txt-dim); font-size: 12px; margin-top: 10px; }
@media (pointer: coarse) { .kbd-hint, .match-btn .match-key { display: none; } }

/* ---------------- Results ---------------- */
.res-title {
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
  font-size: 28px;
}
.score-sub { text-align: center; color: var(--txt-dim); font-size: 13px; margin-top: 8px; }
.score-wrap { position: relative; width: 156px; margin: 10px auto 2px; }
.score-ring { width: 100%; height: auto; display: block; transform: rotate(-90deg); }
.score-ring circle { fill: none; stroke-width: 10; stroke-linecap: round; }
.score-ring .ring-bg { stroke: var(--bg-soft); }
.score-ring .ring-val {
  stroke: url(#ring-grad);
  stroke-dasharray: 351.86;
  stroke-dashoffset: 351.86;
  transition: stroke-dashoffset 0.9s cubic-bezier(0.22, 0.8, 0.3, 1);
}
.score-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.score-center b { font-size: 40px; font-weight: 800; line-height: 1; }
.score-center span { font-size: 11px; color: var(--txt-dim); letter-spacing: 0.12em; text-transform: uppercase; }

.res-level-msg {
  text-align: center; font-size: 17px; font-weight: 700;
  border-radius: 14px; padding: 14px; margin: 14px 0;
  background: var(--card); border: 1px solid var(--line);
}
.res-level-msg.up { border-color: rgba(46, 204, 113, 0.5); color: var(--good); background: rgba(46, 204, 113, 0.08); }
.res-level-msg.down { border-color: rgba(246, 185, 59, 0.5); color: #f6b93b; background: rgba(246, 185, 59, 0.07); }

.res-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.res-card {
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px;
}
.res-card h3 { font-size: 14px; color: var(--txt-dim); font-weight: 600; margin-bottom: 6px; }
.res-pct { font-size: 30px; font-weight: 800; margin-bottom: 10px; }
.res-bar { height: 7px; border-radius: 99px; background: var(--bg-soft); overflow: hidden; margin-bottom: 12px; }
.res-bar i { display: block; height: 100%; background: var(--grad); border-radius: 99px; }
.res-rows { display: grid; gap: 7px; }
.res-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--txt-dim); }
.res-row b { font-weight: 700; }
.c-good { color: var(--good); }
.c-warn { color: #f6b93b; }
.c-bad { color: var(--bad); }

.res-actions { display: grid; gap: 10px; margin-top: 18px; }

.btn-primary {
  background: var(--grad); color: #fff; font-weight: 800; font-size: 16px;
  padding: 14px 22px; border-radius: 13px;
  box-shadow: 0 6px 20px rgba(108, 92, 231, 0.35);
  transition: transform 0.12s;
}
.btn-primary:active { transform: scale(0.97); }
.btn-primary.wide { width: 100%; margin-top: 16px; }
.btn-ghost {
  background: var(--card); border: 1px solid var(--line); color: var(--txt-dim);
  font-weight: 700; padding: 13px 22px; border-radius: 13px; transition: 0.15s;
}
.btn-ghost:hover { color: var(--txt); }
.btn-danger {
  background: rgba(255, 94, 87, 0.12); border: 1px solid rgba(255, 94, 87, 0.45);
  color: var(--bad); font-weight: 700; padding: 9px 16px; border-radius: 11px;
}

/* ---------------- Stats ---------------- */
.stat-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat-tile {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 8px; text-align: center; display: flex; flex-direction: column; gap: 4px;
}
.stat-tile b { font-size: 24px; }
.stat-tile span { font-size: 12px; color: var(--txt-dim); }

.chart-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px;
}
.chart-card h3 { font-size: 14px; color: var(--txt-dim); font-weight: 600; margin-bottom: 12px; }
.chart-card canvas { width: 100%; height: auto; display: block; }
.chart-empty { color: var(--txt-dim); font-size: 14px; text-align: center; padding: 20px 0; display: none; }

/* ---------------- Settings ---------------- */
.set-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.set-row:last-child { border-bottom: none; }
.set-row b { display: block; font-size: 15px; }
.set-row small { display: block; color: var(--txt-dim); font-size: 12.5px; margin-top: 3px; line-height: 1.35; }
.danger-row b { color: var(--bad); }

.stepper { display: flex; align-items: center; gap: 4px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.stepper button { width: 34px; height: 34px; border-radius: 9px; font-size: 18px; font-weight: 700; color: var(--txt-dim); transition: 0.15s; }
.stepper button:hover { color: var(--txt); background: var(--card-2); }
.stepper b { min-width: 26px; text-align: center; font-size: 17px; }

.switch { position: relative; display: inline-block; width: 48px; height: 28px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 99px; cursor: pointer;
  background: var(--bg-soft); border: 1px solid var(--line); transition: 0.2s;
}
.switch span::before {
  content: ''; position: absolute; width: 20px; height: 20px; border-radius: 50%;
  left: 3px; top: 3px; background: var(--txt-dim); transition: 0.2s;
}
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::before { transform: translateX(20px); background: #fff; }

/* ---------------- Help ---------------- */
.help-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.help-demo { display: flex; align-items: center; justify-content: center; gap: 18px; margin-bottom: 18px; }
.help-demo-sound { font-size: 18px; font-weight: 700; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.help-list { padding-left: 20px; display: grid; gap: 10px; color: var(--txt-dim); font-size: 14.5px; line-height: 1.5; }
.help-list li::marker { color: var(--accent-2); font-weight: 700; }

/* ---------------- Footer ---------------- */
.foot { text-align: center; color: var(--txt-dim); font-size: 12px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); }

/* ---------------- Desktop tweaks ---------------- */
@media (min-width: 720px) {
  .hero { margin-top: 6vh; }
  .grid-wrap { width: 400px; }
}
