:root {
  --bg: #0f0f14;
  --card: #1a1a22;
  --line: #2a2a35;
  --text: #f2f2f5;
  --muted: #9a9aab;
  --accent: #ffb020;
  --good: #3ddc84;
  --bad: #ff5d5d;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { 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; }

.hero { text-align: center; padding: 16px 0 4px; }
.hero h1 {
  margin: 8px 0 4px;
  font-size: clamp(2rem, 9vw, 2.8rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #ff6b6b, #ffb020, #3ddc84, #4dabff, #b06bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { margin: 0; color: var(--muted); }
.logo { display: inline-grid; grid-template-columns: repeat(2, 22px); gap: 5px; }
.logo span { width: 22px; height: 22px; border-radius: 6px; }
.logo span:nth-child(1) { background: #ff6b6b; }
.logo span:nth-child(2) { background: #ffb020; }
.logo span:nth-child(3) { background: #4dabff; }
.logo span:nth-child(4) { background: #3ddc84; }

.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); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.challenge {
  margin: 0; padding: 12px 16px; border-radius: var(--radius);
  background: #2b2210; border: 1px solid #5a4417; color: #ffd27a; 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: #101016; 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: 600; color: var(--text); text-decoration: none;
  background: #262632; 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.primary { background: var(--accent); border-color: var(--accent); color: #1a1200; }
.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: right; 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; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard .s { font-weight: 700; font-variant-numeric: tabular-nums; }
.leaderboard li.me { background: #2b2210; border-radius: 8px; }

/* Memorize: whole screen becomes the color */
.memorize {
  position: fixed; inset: 0; z-index: 10; justify-content: center; align-items: center; gap: 8px;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  color: #fff; background: #000;
  transition: background-color var(--fade, .45s) ease;
}
.memorize > * { transition: opacity .3s ease; }
/* End of memorize: color fades smoothly to black, texts fade out */
.memorize.to-black { background-color: #000 !important; }
.memorize.to-black > * { opacity: 0; }
.memorize.light { color: #111; }
.round-label { position: absolute; top: calc(20px + var(--safe-top)); font-weight: 600; opacity: .85; }
/* Hint + timer in the bottom-right corner, above the progress bar */
.mem-corner {
  position: absolute; right: 24px; bottom: calc(48px + var(--safe-bottom));
  text-align: right; line-height: 1.1;
}
.mem-hint { font-weight: 600; opacity: .85; font-size: .95rem; }
.timer {
  font-size: clamp(2.4rem, 11vw, 3.4rem); font-weight: 800; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* Other screens fade in when shown */
.screen:not(.memorize) { animation: fade-in .35s ease both; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.progress {
  position: absolute; bottom: calc(28px + var(--safe-bottom)); left: 24px; right: 24px;
  height: 6px; border-radius: 3px; background: color-mix(in srgb, currentColor 25%, transparent); overflow: hidden;
}
.progress-bar { height: 100%; width: 100%; background: currentColor; transform-origin: left; }
.progress-bar.run { animation: shrink var(--dur, 5s) linear forwards; }
@keyframes shrink { to { transform: scaleX(0); } }

/* Choose */
.topbar { display: flex; justify-content: space-between; color: var(--muted); font-weight: 600; }
.choose-title { margin: 0; text-align: center; font-size: 1.4rem; }
.speed { margin: -8px 0 0; text-align: center; color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.grid {
  --cols: 3; --gap: 10px;
  display: flex; flex-wrap: wrap; justify-content: center; gap: var(--gap);
}
.tile {
  flex: 0 0 calc((100% - var(--gap) * (var(--cols) - 1)) / var(--cols));
  aspect-ratio: 1; border-radius: 14px; border: 0; cursor: pointer; position: relative;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
  transition: transform .1s, opacity .25s, box-shadow .2s;
  font: inherit; font-weight: 700; padding: 0;
}
.tile:active { transform: scale(.95); }
.tile:focus-visible { outline: 3px solid var(--text); outline-offset: 2px; }
.grid.done .tile { cursor: default; }
.grid.done .tile:not(.target):not(.picked) { opacity: .35; }
.tile.target { box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--good); }
.tile.picked:not(.target) { box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--bad); }
.tile .tag {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%);
  font-size: .78rem; padding: 2px 8px; border-radius: 999px; background: rgba(0,0,0,.55); color: #fff; white-space: nowrap;
}

.feedback { text-align: center; display: flex; flex-direction: column; gap: 12px; }
.feedback p { margin: 0; font-size: 1.1rem; font-weight: 600; }

/* Result */
.result { text-align: center; display: flex; flex-direction: column; gap: 6px; }
.result p { margin: 0; }
.total { font-size: 4.5rem; font-weight: 800; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.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: left; }
.round-summary .sw { display: flex; gap: 3px; }
.round-summary .sw i { width: 26px; height: 26px; border-radius: 6px; display: block; }
.round-summary .lbl { flex: 1; color: var(--muted); font-size: .9rem; }
.round-summary .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.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;
}
.footer { text-align: center; font-size: .85rem; }
.footer { display: flex; flex-direction: column; gap: 8px; }
.footer a { color: var(--text); }
.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 (min-width: 600px) {
  .grid { --gap: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
