:root {
  --bg: #f3f1f8;
  --surface: #ffffff;
  --ink: #1b1824;
  --muted: #6b6578;
  --line: #e1dceb;
  --accent: #6c3cff;
  --accent-ink: #ffffff;
  --danger: #e5484d;
  --t1: #8b8697;
  --t2: #22a05a;
  --t3: #2f7be0;
  --t4: #9a4ee6;
  --t5: #e0a100;
  --pixel: 'Press Start 2P', ui-monospace, monospace;
  --body: 'Rubik', system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12101a;
    --surface: #1d1a28;
    --ink: #f2eff9;
    --muted: #a39cb3;
    --line: #2e2a3d;
    --accent: #8b63ff;
    --t1: #a09aad;
    --t2: #3ccb78;
    --t3: #4f9bf5;
    --t4: #b67cf6;
    --t5: #f7bd2a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  max-width: 560px; margin: 0 auto; padding: 14px 16px;
}
.brand { background: none; border: 0; font-family: var(--pixel); font-size: 12px; letter-spacing: .04em; padding: 6px 0; }
.iconbtn {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1.5px solid var(--line); background: var(--surface); font-weight: 700;
}

.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px 48px; }
.screen { display: flex; flex-direction: column; gap: 16px; animation: in .25s ease-out; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }

.kicker { margin: 8px 0 0; color: var(--muted); font-size: 14px; font-weight: 500; }
.logo { font-family: var(--pixel); font-size: clamp(36px, 12vw, 56px); line-height: 1.15; margin: 0; letter-spacing: .02em; }
.hero { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hero-art { width: clamp(96px, 30vw, 150px); flex-shrink: 0; animation: heroBob 2.2s ease-in-out infinite alternate; filter: drop-shadow(0 6px 14px rgba(139, 99, 255, .45)); }
.hero-art svg { display: block; width: 100%; height: auto; }
@keyframes heroBob { from { transform: translateY(-4px) rotate(-4deg); } to { transform: translateY(4px) rotate(4deg); } }
.press { margin: -4px 0 0; font-family: var(--pixel); font-size: 12px; color: var(--accent); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.lede, .muted { color: var(--muted); margin: 0; }
.center { text-align: center; }
.h2 { margin: 8px 0 0; font-size: 26px; font-weight: 800; }

.today {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 16px; padding: 18px 20px;
}
.eyebrow { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.game-title { font-size: 30px; font-weight: 800; line-height: 1.15; }
.today .sub { color: var(--muted); font-size: 14px; }

.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; font-size: 16px;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 60%, #000); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); }
.btn.big { padding: 16px 20px; font-size: 18px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

.ladder { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ladder li {
  display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 10px;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 15px;
}
.ladder .dot { width: 12px; height: 12px; border-radius: 3px; background: var(--tc); }
.ladder li span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }

.t1 { --tc: var(--t1); } .t2 { --tc: var(--t2); } .t3 { --tc: var(--t3); } .t4 { --tc: var(--t4); } .t5 { --tc: var(--t5); }
.miss { --tc: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stats div { background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 4px; }
.stats b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }

/* round */
.meta { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; color: var(--muted); margin-top: 8px; }
.meta .xp { color: var(--ink); font-variant-numeric: tabular-nums; }
.timer { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.timer .bar { height: 100%; background: var(--accent); transform-origin: left; transition: background .2s; }
.timer .bar.low { background: var(--danger); }
.secs { font-family: var(--pixel); font-size: 28px; text-align: center; font-variant-numeric: tabular-nums; }
.secs.low { color: var(--danger); }
.prompt { font-size: clamp(24px, 6.5vw, 32px); font-weight: 800; line-height: 1.2; margin: 0; text-wrap: balance; }
.prompt.sm { font-size: 16px; font-weight: 500; color: var(--muted); margin-top: 4px; }
form#f { display: flex; gap: 8px; }
#g {
  flex: 1; min-width: 0; font: inherit; font-size: 18px; padding: 14px 14px;
  border-radius: 12px; border: 2px solid var(--line); background: var(--surface); color: var(--ink);
}
#g:focus { outline: none; border-color: var(--accent); }
.shake { animation: shake .3s; border-color: var(--danger) !important; }
@keyframes shake { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-3px); } }
.dym {
  margin: -4px 0 0; padding: 10px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--t5) 14%, var(--surface)); border: 1.5px solid color-mix(in srgb, var(--t5) 60%, transparent);
  font-weight: 500;
}
.dym.pop { animation: pop .3s cubic-bezier(.2, 1.4, .4, 1); }
.dym-pick {
  background: none; border: 0; padding: 0; font-weight: 800; color: var(--ink);
  text-decoration: underline; text-decoration-color: var(--t5); text-decoration-thickness: 2px; text-underline-offset: 3px;
}
.dym span { display: block; font-size: 13px; color: var(--muted); }
.fb { min-height: 1.5em; margin: -4px 0 0; color: var(--danger); font-weight: 500; }
.misses { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.misses li { font-size: 14px; padding: 3px 10px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); text-decoration: line-through; }

/* loot card */
.loot {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  background: var(--surface); border: 2px solid var(--tc); border-radius: 18px; padding: 22px 16px;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--tc) 18%, transparent);
}
.loot.big { padding: 30px 16px; animation: pop .45s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.loot .tier { font-family: var(--pixel); font-size: 12px; color: var(--tc); text-transform: uppercase; letter-spacing: .06em; }
.loot .name { font-size: 28px; font-weight: 800; line-height: 1.15; }
.loot .xpv { font-weight: 700; color: var(--tc); font-variant-numeric: tabular-nums; }
.loot.t5 { background: linear-gradient(160deg, color-mix(in srgb, var(--t5) 16%, var(--surface)), var(--surface) 60%); }
.loot.t5.big::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.45) 50%, transparent 70%);
  transform: translateX(-100%); animation: shine 1.4s .3s ease-out;
}
@keyframes shine { to { transform: translateX(100%); } }

.others h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 4px 0 8px; }
.chips { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { padding: 5px 12px; border-radius: 99px; font-size: 14px; font-weight: 600; border: 1.5px solid var(--tc); color: var(--ink); background: var(--surface); }

/* end */
.total { font-family: var(--pixel); font-size: clamp(36px, 11vw, 52px); margin: 0; line-height: 1.1; }
.total small { font-size: .4em; color: var(--muted); }
.rating { font-size: 20px; font-weight: 700; margin: -6px 0 0; }
.meter { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.meter span { display: block; height: 100%; background: linear-gradient(90deg, var(--t2), var(--t3), var(--t4), var(--t5)); }
.rank { background: var(--surface); border: 1.5px solid var(--line); border-radius: 16px; padding: 14px 16px 12px; }
.rank-head { display: flex; justify-content: space-between; align-items: baseline; }
.rank h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.rank .pct { font-family: var(--pixel); font-size: 14px; color: var(--accent); }
.curve { display: block; width: 100%; height: auto; margin: 8px 0 4px; overflow: visible; }
.c-all { fill: color-mix(in srgb, var(--muted) 18%, transparent); }
.c-you { fill: color-mix(in srgb, var(--accent) 55%, transparent); }
.c-line { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.c-mark { stroke: var(--ink); stroke-width: 2; stroke-dasharray: 3 3; }
.c-dot { fill: var(--accent); }
.c-label { fill: var(--ink); font: 700 12px var(--body); }
.c-reveal { animation: reveal 1.1s .2s cubic-bezier(.3, .8, .3, 1) backwards; }
@keyframes reveal { from { width: 0; } }
.small { font-size: 13px; }

/* leaderboard */
.lb { background: var(--surface); border: 1.5px solid var(--line); border-radius: 16px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.lb h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.lb-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.lb-list li { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 10px; background: color-mix(in srgb, var(--line) 45%, transparent); font-variant-numeric: tabular-nums; }
.lb-list li.you { background: color-mix(in srgb, var(--accent) 22%, var(--surface)); outline: 1.5px solid var(--accent); }
.lb-list .pos { font-weight: 800; text-align: center; }
.lb-list .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-list .nm em { font-style: normal; font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; margin-left: 4px; }
.lb-list .sc { font-weight: 800; }
.lb-gap { text-align: center; color: var(--muted); line-height: 1; }
.linkbtn { align-self: flex-start; background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; font-size: 14px; }
.lb-join { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border: 1.5px solid var(--accent); border-radius: 16px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; animation: pop .35s cubic-bezier(.2, 1.4, .4, 1); }
.lb-join label { font-weight: 800; font-size: 17px; }
.lb-row { display: flex; gap: 8px; }
.lb-row input { flex: 1; min-width: 0; font: inherit; font-size: 17px; padding: 12px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); color: var(--ink); }
.lb-row input:focus { outline: none; border-color: var(--accent); }
.lb-join .fb { margin: 0; min-height: 0; }
.recap { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.recap li {
  display: grid; grid-template-columns: 1fr auto 44px; grid-template-areas: "lbl tag pts" "name tag pts";
  align-items: center; column-gap: 10px;
  background: var(--surface); border: 1.5px solid var(--line); border-left: 6px solid var(--tc); border-radius: 12px; padding: 8px 12px;
}
.recap .lbl { grid-area: lbl; font-size: 12px; color: var(--muted); }
.recap b { grid-area: name; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recap .tag { grid-area: tag; font-size: 12px; font-weight: 700; color: var(--tc); }
.recap .pts { grid-area: pts; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* free play */
.gamelist { display: grid; gap: 8px; }
.gamecard {
  display: flex; justify-content: space-between; align-items: center;
  text-align: left; font-size: 18px; font-weight: 700;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px; padding: 16px 18px;
}
.gamecard:hover { border-color: var(--accent); }
.gamecard span { display: flex; flex-direction: column; }
.gamecard small { font-size: 12px; font-weight: 500; color: var(--muted); }
.gamecard.locked { color: var(--muted); cursor: not-allowed; }
.gamecard.locked:hover { border-color: var(--line); }
.gamecard.locked i { display: flex; color: var(--muted); }
.gamecard.nope { animation: shake .3s; }
.empty { margin: 0; padding: 18px; text-align: center; color: var(--muted); border: 1.5px dashed var(--line); border-radius: 14px; }
.gamecard em { font-style: normal; font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: .08em; }

/* animations: side sprites + reward burst */
.fx { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.topbar, .wrap { position: relative; z-index: 1; }
.sprite {
  position: absolute; bottom: -60px; opacity: .55;
  animation: floatUp var(--dur) linear var(--delay) infinite;
  filter: drop-shadow(0 0 6px rgba(139, 99, 255, .35));
}
.sprite svg { display: block; width: 100%; height: 100%; animation: bob var(--bob) ease-in-out infinite alternate; }
@keyframes floatUp { to { transform: translateY(calc(-100vh - 140px)) rotate(var(--rot)); } }
@keyframes bob { from { transform: translateX(-10px); } to { transform: translateX(10px); } }
@media (max-width: 640px) { .sprite { opacity: .3; } }
@media (prefers-color-scheme: light) { .sprite { opacity: .7; filter: none; } }

.loot-wrap { position: relative; }
.spark {
  position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; pointer-events: none; z-index: 2;
  animation: spark .9s cubic-bezier(.15, .7, .3, 1) both;
}
@keyframes spark {
  from { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.3); opacity: 0; }
}
.timer .bar {
  background-image: repeating-linear-gradient(90deg, rgba(255,255,255,.18) 0 8px, transparent 8px 16px);
  background-size: 32px 100%; animation: march .6s linear infinite;
}
@keyframes march { to { background-position: 32px 0; } }

/* dialog + toast */
dialog {
  border: 0; border-radius: 18px; padding: 0; max-width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgba(10, 8, 20, .55); }
dialog form { padding: 22px; display: flex; flex-direction: column; gap: 10px; }
dialog h2 { margin: 0; font-family: var(--pixel); font-size: 16px; }
dialog p { margin: 0; }
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600;
  transition: .2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

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