:root {
  --bg: #0b0d10;
  --card: #15181d;
  --line: #262a32;
  --text: #eef1f5;
  --muted: #8f97a5;
  --accent: #36c9ff;
  --accent-ink: #04121a;
  --warn: #ffc53d;
  --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 { width: 132px; height: 66px; overflow: visible; fill: #8f97a5; }
.logo path, .logo use { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.logo .flat { stroke: #3a414d; stroke-width: 2.5; stroke-dasharray: 4 7; }
.logo .echo { stroke: url(#logo-fade); stroke-width: 2.4; }
.logo .bend { stroke: url(#logo-grad); stroke-width: 5.5; filter: drop-shadow(0 0 6px rgba(54, 201, 255, .55)); }
.logo .core { stroke: #eafaff; stroke-width: 1.4; opacity: .8; }

.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: #0d2330; border: 1px solid #1d4a60; color: #9fe3ff; 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:disabled { opacity: .4; cursor: default; transform: none; filter: none; }
.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: #0d2330; 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; }
.meter-bar.memo { background: var(--muted); }
[dir="rtl"] .meter-bar { transform-origin: right; }
.phase {
  margin: 0; text-align: center; font-weight: 800; min-height: 1.5em;
  font-size: clamp(1.15rem, 5vw, 1.45rem); letter-spacing: -0.01em;
}
.phase.go { color: var(--accent); }

.board {
  position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: calc(100dvh - 370px); min-height: 220px;
  margin: 0 auto; border-radius: var(--radius); background: #0f1216; border: 1px solid var(--line);
  overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; cursor: default;
}
.board.live { cursor: ew-resize; border-color: #2c4a59; }
.board:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.board canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.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;
  background: #0f1216; animation: pop .75s ease both;
}
@keyframes pop { 0% { opacity: 0; transform: scale(.85); } 25%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* Where the curve is: left/right = bends (a), up/down = arch (b); center = flat. */
.pad {
  position: relative; width: 132px; height: 60px; margin: 0 auto; direction: ltr;
  border: 1px solid var(--line); border-radius: 12px; background: #0f1216;
  background-image: linear-gradient(var(--line), var(--line)), linear-gradient(var(--line), var(--line));
  background-size: 100% 1px, 1px 100%; background-position: center; background-repeat: no-repeat;
}
.pad-x, .pad-y { position: absolute; font-size: 11px; line-height: 1; color: #4a5260; }
.pad-x { right: 6px; top: 4px; }
.pad-y { left: 7px; bottom: 4px; }
.pad-knob {
  position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 4px rgba(54, 201, 255, .18), 0 0 12px rgba(54, 201, 255, .5);
  opacity: .35; transition: opacity .2s;
}
.board.live ~ .pad .pad-knob { opacity: 1; }

.feedback { margin: 0; min-height: 1.6em; text-align: center; font-weight: 700; font-size: 1.1rem; }
.feedback.hit { color: var(--good); }
.feedback.mid { color: var(--warn); }
.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 canvas { width: 84px; height: 34px; flex: none; border-radius: 6px; background: #0f1216; border: 1px solid var(--line); }
.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; }
}
