:root {
  --bg: #13112b;
  --ink: #13112b;
  --card-text: #ffffff;
  --muted: #9a97c4;
  --green: #6fd9b0;
  --blue: #6ab4f5;
  --orange: #f2a55a;
  --purple: #a98bf5;
  --pink: #ec6a90;
  --yellow: #f6d55f;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--card-text);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; cursor: pointer; }

.screen { display: none; min-height: 100%; }
.screen.active { display: flex; flex-direction: column; }

/* ---------- Menu ---------- */
#menu { max-width: 1100px; margin: 0 auto; padding: 24px 16px 32px; }

.menu-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logo { display: flex; align-items: center; gap: 12px; }
.logo svg { width: 60px; height: 40px; }
.logo h1 { margin: 0; font-size: 28px; letter-spacing: .5px; }
.logo h1 span { display: block; font-size: 14px; font-weight: 400; color: var(--muted); letter-spacing: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 22px 0 18px; }
.chip {
  border: 2px solid #2b2852; background: transparent; color: var(--card-text);
  padding: 6px 14px; border-radius: 999px; font-weight: 700; font-size: 14px;
  transition: background .15s, border-color .15s;
}
.chip:hover { border-color: #4a4680; }
.chip.on { background: var(--card-text); color: var(--ink); border-color: var(--card-text); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 22px 18px;
}

.card {
  background: none; border: 0; padding: 0; text-align: left; color: inherit;
  display: flex; flex-direction: column; gap: 8px;
}
.card .thumb {
  aspect-ratio: 19 / 14; border-radius: var(--radius); overflow: hidden;
  transition: transform .18s cubic-bezier(.3,1.6,.6,1), box-shadow .18s;
}
.card .thumb svg { width: 100%; height: 100%; display: block; }
.card:hover .thumb, .card:focus-visible .thumb { transform: translateY(-4px) rotate(-1deg); box-shadow: 0 10px 0 rgba(0,0,0,.25); }
.card:focus-visible { outline: none; }
.card:focus-visible .thumb { outline: 3px solid var(--card-text); outline-offset: 3px; }
.card .name { font-weight: 800; font-size: 16px; padding-left: 4px; }
.card .meta { display: flex; justify-content: space-between; padding: 0 4px; font-size: 12px; font-weight: 700; margin-top: -6px; }
.card .best { color: var(--muted); font-weight: 400; }

.menu-foot { margin-top: 32px; color: var(--muted); font-size: 13px; text-align: center; }
kbd { background: #2b2852; border-radius: 4px; padding: 1px 6px; font-family: inherit; }

/* ---------- Game ---------- */
#game { height: 100%; }

.hud {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  flex-wrap: wrap;
}
.hud-title { font-weight: 800; font-size: 18px; flex: 1; min-width: 100px; }
.hud-stats { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hud-info { font-weight: 700; letter-spacing: 1px; }
.pill { background: #24214a; border-radius: 999px; padding: 5px 12px; font-size: 14px; }
.pill b { margin-left: 4px; }
.pill.dim { color: var(--muted); }

.btn {
  background: var(--card-text); color: var(--ink); border: 0;
  border-radius: 12px; padding: 10px 18px; font-weight: 800; font-size: 15px;
  box-shadow: 0 4px 0 rgba(0,0,0,.3); transition: transform .08s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.3); }
.btn.ghost { background: #24214a; color: var(--card-text); }

.icon-btn {
  background: #24214a; color: var(--card-text); border: 0; border-radius: 10px;
  width: 38px; height: 34px; font-size: 16px;
}

.stage { flex: 1; display: flex; align-items: center; justify-content: center; padding: 0 16px 16px; min-height: 0; }
.canvas-wrap {
  position: relative;
  width: min(100%, calc((100vh - 90px) * 4 / 3));
  aspect-ratio: 4 / 3;
  border-radius: 20px; overflow: hidden;
  box-shadow: 0 0 0 4px #24214a;
}
canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.overlay {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(19, 17, 43, .72); padding: 16px;
}
.overlay.show { display: flex; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }

.panel {
  background: var(--bg); border-radius: 20px; padding: 22px 24px; max-width: 380px; width: 100%;
  text-align: center; box-shadow: 0 0 0 3px #2b2852;
  animation: pop .25s cubic-bezier(.3,1.6,.6,1);
}
@keyframes pop { from { transform: scale(.85); } }
.ov-thumb { width: 140px; margin: 0 auto 8px; border-radius: 12px; overflow: hidden; aspect-ratio: 19/14; }
.ov-thumb:empty { display: none; }
.ov-thumb svg { width: 100%; height: 100%; display: block; }
.panel h2 { margin: 6px 0; font-size: 24px; }
.panel p { color: var(--muted); margin: 0 0 12px; line-height: 1.4; font-size: 15px; }
.ov-score { font-size: 18px; margin-bottom: 14px; }
.ov-score:empty { display: none; }
.ov-score .big { font-size: 44px; font-weight: 800; display: block; }
.ov-score .rec { color: var(--yellow); font-weight: 800; }
.ov-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 16px 12px; }
  .hud-title { font-size: 15px; }
  .pill { font-size: 12px; padding: 4px 9px; }
  .canvas-wrap { border-radius: 14px; }
  .overlay { padding: 8px; overflow: auto; }
  .panel { padding: 14px 16px; }
  .ov-thumb { display: none; }
  .panel h2 { font-size: 20px; }
  .panel p { font-size: 13px; margin-bottom: 8px; }
  .ov-score .big { font-size: 32px; }
}

/* ---------- Icons ---------- */
.ico { width: 18px; height: 18px; display: inline-block; vertical-align: middle; flex: none; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; }
.icon-btn .ico { width: 20px; height: 20px; }
.btn { display: inline-flex; align-items: center; gap: 6px; }
.btn .ico { width: 16px; height: 16px; }
.hud-info { display: inline-flex; align-items: center; gap: 4px; font-size: 16px; }
.hud-info:empty { display: none; }
.card .best { display: inline-flex; align-items: center; gap: 4px; }
.card .best .ico { width: 14px; height: 14px; }

/* ---------- Splash ---------- */
.splash {
  position: fixed; inset: 0; z-index: 100;
  background: #080818;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; user-select: none;
  transition: opacity .5s ease, transform .5s ease;
}
.splash.out { opacity: 0; transform: scale(1.06); pointer-events: none; }
.splash-inner { text-align: center; display: flex; flex-direction: column; align-items: center; }
.splash-logo {
  width: min(220px, 52vw); height: auto; display: block;
  animation: logoPop .8s cubic-bezier(.3, 1.5, .5, 1) both;
}
.splash-logo .wave { animation: wave 1.1s cubic-bezier(.2, .9, .3, 1) both; }
.splash-logo .w1 { --dx: 40px; --dy: -60px; animation-delay: .15s; }
.splash-logo .w2 { --dx: 60px; --dy: -60px; animation-delay: .25s; }
.splash-logo .w3 { --dx: -60px; --dy: 60px; animation-delay: .35s; }
.splash-logo .letter {
  transform-box: fill-box; transform-origin: 50% 100%;
  animation: letterIn .6s .5s cubic-bezier(.3, 1.7, .5, 1) both;
}
@keyframes logoPop { from { transform: scale(.3) rotate(-12deg); opacity: 0; } }
@keyframes wave { from { transform: translate(var(--dx), var(--dy)); } }
@keyframes letterIn { from { transform: scaleY(.2) translateY(60px); opacity: 0; } }
.splash-name {
  font-family: "Russo One", "Trebuchet MS", system-ui, sans-serif;
  font-size: clamp(38px, 9vw, 66px); letter-spacing: 1px; line-height: 1.1;
  margin-top: 26px; animation: rise .6s .85s ease-out both;
}
.splash-presents {
  font-family: Nunito, "Trebuchet MS", system-ui, sans-serif; font-weight: 600;
  font-size: clamp(15px, 3.6vw, 22px); letter-spacing: .5em; text-transform: uppercase;
  margin: 26px 0 0 .5em; animation: rise .6s 1.15s ease-out both;
}
.splash-skip {
  position: absolute; bottom: 24px; left: 0; right: 0; text-align: center;
  color: #3b3a66; font-size: 13px; animation: rise .6s 1.7s both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* menu cards pop in after the splash */
body.ready .card { animation: rise .45s both; }
body.ready .card:nth-child(2) { animation-delay: .04s; }
body.ready .card:nth-child(3) { animation-delay: .08s; }
body.ready .card:nth-child(4) { animation-delay: .12s; }
body.ready .card:nth-child(5) { animation-delay: .16s; }
body.ready .card:nth-child(6) { animation-delay: .20s; }
body.ready .card:nth-child(7) { animation-delay: .24s; }
body.ready .card:nth-child(8) { animation-delay: .28s; }

@media (prefers-reduced-motion: reduce) {
  .splash *, .splash-logo .wave, body.ready .card { animation: none !important; }
}
