:root {
  --bg: #0b0d10;
  --card: #15181d;
  --line: #262a32;
  --text: #eef1f5;
  --muted: #8f97a5;
  --accent: #ff3d5a;
  --accent-ink: #fff;
  --good: #3ddc84;
  --bad: #ff3d5a;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

#app { max-width: 560px; margin: 0 auto; padding: calc(16px + var(--safe-top)) 16px calc(24px + var(--safe-bottom)); }
.screen { display: flex; flex-direction: column; gap: 16px; animation: fade-in .3s ease both; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Home ---------- */
.hero { text-align: center; padding: 16px 0 4px; }
.hero h1 {
  margin: 10px 0 4px;
  font-size: clamp(2.1rem, 10vw, 3rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-weight: 850;
}
.tagline { margin: 0; color: var(--muted); }
.logo { position: relative; display: inline-grid; grid-template-columns: repeat(3, 18px); gap: 4px; padding: 6px; }
.logo span { width: 18px; height: 18px; border-radius: 4px; background: #3f7be0; }
.logo span.odd { background: #4f8bf0; }
.logo .scope { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); fill: none; stroke: var(--accent); stroke-width: 4; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card h2 { margin: 0 0 12px; font-size: 1.1rem; }
.card h3 { margin: 16px 0 6px; font-size: 1rem; }
.info p { margin: 0; color: var(--muted); }
.steps { margin: 0; padding-inline-start: 22px; color: var(--muted); }
.steps li::marker { color: var(--accent); font-weight: 700; }
.muted { color: var(--muted); }

.challenge {
  margin: 0; padding: 12px 16px; border-radius: var(--radius);
  background: #2a1218; border: 1px solid #5c1f2b; color: #ff9aaa; text-align: center; font-weight: 600;
}

.start { display: flex; flex-direction: column; gap: 10px; }
.start label { font-weight: 600; font-size: .95rem; }
input {
  font: inherit; font-size: 1.05rem; color: var(--text);
  background: #0d0f13; border: 1px solid var(--line); border-radius: 12px; padding: 14px;
  width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 650; color: var(--text); text-decoration: none;
  background: #222730; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 16px; min-height: 48px; cursor: pointer; transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn:hover { filter: brightness(1.12); }
.btn:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.big { width: 100%; font-size: 1.1rem; min-height: 54px; }
.btn.whatsapp { background: #1f8f4e; border-color: #1f8f4e; }

.leaderboard { list-style: none; margin: 0; padding: 0; counter-reset: lb; }
.leaderboard li {
  counter-increment: lb; display: flex; align-items: center; gap: 10px;
  padding: 9px 4px; border-top: 1px solid var(--line);
}
.leaderboard li:first-child { border-top: 0; }
.leaderboard li::before { content: counter(lb); width: 28px; text-align: end; color: var(--muted); font-variant-numeric: tabular-nums; }
.leaderboard li:nth-child(1)::before { content: "🥇"; }
.leaderboard li:nth-child(2)::before { content: "🥈"; }
.leaderboard li:nth-child(3)::before { content: "🥉"; }
.leaderboard li.muted::before { content: none; }
.leaderboard .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard .s { font-weight: 700; font-family: var(--mono); font-size: .92rem; }
.leaderboard li.me { background: #2a1218; border-radius: 8px; }

/* ---------- Play ---------- */
.play { gap: 10px; }
.topbar { display: flex; justify-content: space-between; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.meter { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.meter-bar { height: 100%; background: var(--accent); transform-origin: left; }
[dir="rtl"] .meter-bar { transform-origin: right; }
.live {
  margin: 0; text-align: center; font-family: var(--mono); font-weight: 800;
  font-size: clamp(2rem, 10vw, 2.8rem); line-height: 1.1; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.live.hit { color: var(--good); }
.live.zero { color: var(--bad); }

.board { position: relative; width: min(100%, max(260px, calc(100dvh - 270px))); margin: 4px auto 0; aspect-ratio: 1; }
.grid {
  --n: 3; --gap: clamp(3px, calc(18px / var(--n)), 8px);
  display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: var(--gap);
  width: 100%; height: 100%;
}
.grid.waiting { visibility: hidden; }
.tile {
  border: 0; padding: 0; margin: 0; cursor: crosshair; position: relative;
  border-radius: clamp(4px, calc(36px / var(--n)), 12px);
  transition: opacity .2s, box-shadow .15s, transform .08s;
  touch-action: manipulation;
}
.tile:active { transform: scale(.94); }
.tile:focus-visible { outline: 3px solid var(--text); outline-offset: 1px; }
.grid.done .tile { cursor: default; }
.grid.done .tile:not(.odd):not(.miss) { opacity: .25; }
.tile.odd { box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--good); z-index: 1; }
.tile.miss { box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--bad); z-index: 1; }

.intro {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: clamp(1.6rem, 8vw, 2.4rem); font-weight: 800; letter-spacing: -0.02em;
  animation: pop .75s ease both;
}
@keyframes pop { 0% { opacity: 0; transform: scale(.85); } 25%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

.feedback { margin: 4px 0 0; min-height: 1.6em; text-align: center; font-weight: 700; font-size: 1.1rem; }
.feedback.hit { color: var(--good); }
.feedback.zero { color: var(--bad); }

/* ---------- Result ---------- */
.result { text-align: center; display: flex; flex-direction: column; gap: 6px; }
.result p { margin: 0; }
.total {
  font-family: var(--mono); font-size: clamp(2.4rem, 12vw, 3.6rem); font-weight: 800; line-height: 1.1;
  color: var(--accent); font-variant-numeric: tabular-nums; letter-spacing: -0.03em;
}
.rank { margin: 8px 0 !important; font-weight: 600; min-height: 1.5em; }
.round-summary { list-style: none; padding: 0; margin: 8px 0 14px; display: flex; flex-direction: column; gap: 6px; }
.round-summary li { display: flex; align-items: center; gap: 10px; text-align: start; }
.round-summary .sw { display: flex; gap: 2px; }
.round-summary .sw i { width: 22px; height: 26px; display: block; }
.round-summary .sw i:first-child { border-radius: 6px 0 0 6px; }
.round-summary .sw i:last-child { border-radius: 0 6px 6px 0; }
.round-summary .lbl { flex: 1; min-width: 0; color: var(--muted); font-size: .88rem; }
.round-summary .pts { font-weight: 700; font-family: var(--mono); font-size: .92rem; }
.round-summary .pts.zero { color: var(--muted); }
.share { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.share-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.share-row .btn { padding: 10px 6px; font-size: .9rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; z-index: 50;
  max-width: calc(100% - 32px); text-align: center;
}
.footer { text-align: center; font-size: .85rem; display: flex; flex-direction: column; gap: 8px; }
.langs { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; }
.langs a { color: var(--muted); text-decoration: none; }
.langs a:hover { color: var(--text); text-decoration: underline; }
.langs [aria-current] { color: var(--text); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
