:root {
  --bg: #fbf6ef;
  --ink: #2a2440;
  --muted: #6f6886;
  --faint: #a39cb8;
  --card: rgba(255, 255, 255, 0.72);
  --card-solid: #ffffff;
  --line: rgba(42, 36, 64, 0.09);
  --chip: rgba(42, 36, 64, 0.05);
  --accent: #ff7c9c;
  --mint: #5cc28a;
  --sky: #5bb8f0;
  --sun: #ffc94d;
  --lilac: #a98bf0;
  --blob1: #ffd6e2;
  --blob2: #d4f0ff;
  --blob3: #dff5e3;
  --shadow: 0 1px 2px rgba(42, 36, 64, 0.05), 0 18px 50px -20px rgba(42, 36, 64, 0.25);
  --shadow-lg: 0 2px 4px rgba(42, 36, 64, 0.04), 0 40px 80px -30px rgba(60, 40, 110, 0.35);
  --radius: 26px;
  --display: "Fraunces", Georgia, serif;
  --sans: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15132a;
    --ink: #f3effc;
    --muted: #aaa3c6;
    --faint: #6f6891;
    --card: rgba(36, 32, 66, 0.66);
    --card-solid: #221f40;
    --line: rgba(255, 255, 255, 0.08);
    --chip: rgba(255, 255, 255, 0.06);
    --blob1: #4a2753;
    --blob2: #1d3a5c;
    --blob3: #1f4640;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 18px 50px -20px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 2px 4px rgba(0, 0, 0, 0.2), 0 40px 80px -30px rgba(0, 0, 0, 0.7);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button, input { font: inherit; color: inherit; }

kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 0.1em 0.5em;
  border-radius: 7px;
  background: var(--card-solid);
  border: 1px solid var(--line);
  box-shadow: 0 2px 0 var(--line);
  font-family: var(--sans);
  font-size: 0.8em;
  font-weight: 700;
  text-align: center;
  color: var(--ink);
}

/* ---------- ambient background ---------- */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.8;
  animation: drift 26s ease-in-out infinite alternate;
}
.b1 { width: 46vmax; height: 46vmax; left: -14vmax; top: -16vmax; background: var(--blob1); }
.b2 { width: 40vmax; height: 40vmax; right: -12vmax; top: 10vmax; background: var(--blob2); animation-delay: -8s; }
.b3 { width: 38vmax; height: 38vmax; left: 20vmax; bottom: -20vmax; background: var(--blob3); animation-delay: -16s; }
@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(4vmax, 3vmax, 0) scale(1.08); }
}

/* ---------- top bar ---------- */
.topbar {
  max-width: 1140px;
  margin: 0 auto;
  padding: 22px 24px 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
}
.nav { display: flex; gap: 4px; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.93rem;
  padding: 8px 14px;
  border-radius: 999px;
  transition: background 0.2s, color 0.2s;
}
.nav a:hover { background: var(--chip); color: var(--ink); }

/* ---------- hero ---------- */
main { max-width: 1140px; margin: 0 auto; padding: 0 24px; }

.hero { text-align: center; padding: 56px 0 34px; }
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 10px;
  font-family: var(--display);
  font-style: italic;
  font-size: clamp(1.1rem, 2.4vw, 1.4rem);
  color: var(--muted);
}
.eyebrow::before, .eyebrow::after {
  content: "";
  width: 28px;
  height: 1.5px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.45;
}
h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(3.2rem, 11vw, 7.2rem);
  line-height: 0.95;
  letter-spacing: -0.045em;
}
h1 em {
  font-style: italic;
  font-weight: 700;
  padding-right: 0.06em;
  background: linear-gradient(100deg, var(--mint) 0%, var(--sky) 45%, var(--lilac) 75%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.lede {
  max-width: 560px;
  margin: 20px auto 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.8vw, 1.12rem);
  text-wrap: pretty;
}

/* ---------- stage ---------- */
.game-wrap { scroll-margin-top: 20px; }

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 2;
  border-radius: var(--radius);
  overflow: hidden;
  background: #bfe6ff;
  box-shadow: var(--shadow-lg);
  outline: 1px solid var(--line);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: pointer; }

.stage:fullscreen { aspect-ratio: auto; width: 100vw; height: 100vh; border-radius: 0; }
.stage:-webkit-full-screen { aspect-ratio: auto; width: 100vw; height: 100vh; border-radius: 0; }

@media (max-width: 760px) { .stage { aspect-ratio: 16 / 10; } }
@media (max-width: 480px) { .stage { aspect-ratio: 4 / 3.3; border-radius: 20px; } }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}
.overlay[hidden] { display: none; }

/* start */
.overlay.start { pointer-events: none; align-items: flex-start; padding-top: 7%; }
.start-card {
  text-align: center;
  padding: 16px 26px 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(10px) saturate(1.4);
  -webkit-backdrop-filter: blur(10px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, 0.7);
  color: #2a2440;
  box-shadow: 0 10px 30px -14px rgba(42, 36, 64, 0.35);
  animation: floaty 3.2s ease-in-out infinite;
}
.press { display: flex; justify-content: center; }
.big-key {
  font-size: 1rem;
  padding: 0.35em 1.6em;
  border-radius: 10px;
  background: #fff;
  color: #2a2440;
  border-color: rgba(42, 36, 64, 0.12);
  box-shadow: 0 3px 0 rgba(42, 36, 64, 0.16);
  animation: keypress 1.6s ease-in-out infinite;
}
.touch-label { display: none; font-weight: 700; }
.start-title { margin: 8px 0 0; font-weight: 700; font-size: 0.98rem; }
.start-sub { margin: 2px 0 0; font-size: 0.84rem; color: #6f6886; }
.start-sub:empty { display: none; }
@keyframes floaty { 50% { transform: translateY(-5px); } }
@keyframes keypress {
  0%, 60%, 100% { transform: translateY(0); box-shadow: 0 3px 0 rgba(42, 36, 64, 0.16); }
  70% { transform: translateY(2px); box-shadow: 0 1px 0 rgba(42, 36, 64, 0.16); }
}

/* pause */
.overlay.pause { background: rgba(28, 24, 58, 0.35); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); cursor: pointer; }
.pause-card { text-align: center; color: #fff; }
.pause-title { margin: 0; font-family: var(--display); font-weight: 800; font-size: clamp(2rem, 6vw, 3.4rem); letter-spacing: -0.03em; }
.pause-sub { margin: 4px 0 0; opacity: 0.9; }
.pause-sub kbd { color: #2a2440; background: #fff; }

/* game over */
.overlay.over { background: rgba(28, 24, 58, 0.18); }
.panel {
  width: min(360px, 100%);
  max-height: 100%;
  overflow: auto;
  text-align: center;
  padding: 18px 22px 14px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(14px) saturate(1.5);
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
  border: 1px solid rgba(255, 255, 255, 0.85);
  color: #2a2440;
  box-shadow: 0 24px 60px -24px rgba(28, 24, 58, 0.55);
  animation: pop 0.42s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.94); } }
.over-kicker {
  margin: 0;
  font-family: var(--display);
  font-style: italic;
  font-size: 1.05rem;
  color: #6f6886;
}
.over-kicker.record {
  font-style: normal;
  font-weight: 800;
  background: linear-gradient(90deg, #ff7c9c, #ffab5c, #f2b92a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.over-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  line-height: 1;
  margin: 4px 0 6px;
}
.over-score span { font-family: var(--display); font-weight: 800; font-size: clamp(2.4rem, 6vw, 3.4rem); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.over-score small { font-weight: 500; color: #6f6886; }
.over-meta { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 0.9rem; color: #6f6886; }
.over-meta b { color: #2a2440; font-variant-numeric: tabular-nums; }
.over-meta .dot { width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: 0.4; }
.star-ico {
  display: inline-block;
  width: 13px;
  height: 13px;
  vertical-align: -1px;
  background: #f5b82e;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.name-row { margin-top: 12px; display: grid; gap: 6px; }
.name-row label { font-size: 0.8rem; font-weight: 700; color: #ff5f86; }
.name-row input {
  width: 100%;
  padding: 9px 14px;
  border-radius: 12px;
  border: 1.5px solid rgba(42, 36, 64, 0.12);
  background: #fff;
  color: #2a2440;
  text-align: center;
  font-weight: 700;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.name-row input:focus { border-color: #ff9fb6; box-shadow: 0 0 0 4px rgba(255, 124, 156, 0.18); }
.over-actions { display: flex; gap: 8px; justify-content: center; margin-top: 14px; }
.hint { margin: 8px 0 0; font-size: 0.75rem; color: #8b84a3; }
.hint kbd { font-size: 0.72rem; color: #2a2440; background: #fff; border-color: rgba(42, 36, 64, 0.12); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 0;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s;
}
.btn svg { width: 18px; height: 18px; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: #2a2440; color: #fff; box-shadow: 0 8px 20px -8px rgba(42, 36, 64, 0.7); }
.btn.primary:hover { transform: translateY(-1px); box-shadow: 0 12px 24px -8px rgba(42, 36, 64, 0.7); }
.btn.ghost { background: rgba(42, 36, 64, 0.07); color: #2a2440; }
.btn.ghost:hover { background: rgba(42, 36, 64, 0.12); }

/* toasts */
.toasts {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  justify-items: center;
  pointer-events: none;
  z-index: 5;
  width: max-content;
  max-width: calc(100% - 24px);
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px 7px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #2a2440;
  font-size: 0.86rem;
  box-shadow: 0 10px 28px -12px rgba(28, 24, 58, 0.5);
  animation: toast-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.toast.out { animation: toast-out 0.35s ease forwards; }
.toast .t-ico { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(135deg, #fff3c4, #ffd6e2); font-size: 0.95rem; }
.toast b { font-weight: 700; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(0.9); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px); } }

/* controls bar */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 14px;
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.86rem;
}
.keys { display: flex; flex-wrap: wrap; gap: 6px 20px; }
.keys kbd { margin-right: 3px; }
.keys em { color: var(--faint); font-style: normal; }
.k-touch { display: none; }
.toggles { display: flex; gap: 6px; flex: none; }
.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.15s, background 0.2s;
}
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn .off { display: none; }
.icon-btn.muted .on { display: none; }
.icon-btn.muted .off { display: block; }
.icon-btn[hidden] { display: none; }

@media (hover: none) and (pointer: coarse) {
  .k-desk { display: none; }
  .k-touch { display: inline; }
  .big-key { display: none; }
  .touch-label { display: inline; }
  .hint { display: none; }
}

/* ---------- cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin: 48px 0 20px;
}
.card {
  padding: 22px 22px 20px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  scroll-margin-top: 20px;
}
.card.wide { grid-column: span 2; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.card-ico { display: grid; place-items: center; width: 42px; height: 42px; flex: none; border-radius: 14px; background: var(--chip); font-size: 1.25rem; }
.card h2 { margin: 0; font-family: var(--display); font-weight: 700; font-size: 1.28rem; letter-spacing: -0.02em; line-height: 1.2; }
.card-sub { margin: 1px 0 0; color: var(--muted); font-size: 0.85rem; }
.card-sub::first-letter { text-transform: uppercase; }

/* daily */
.objectives { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.obj { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 4px 10px; }
.check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  transition: all 0.3s;
}
.check svg { width: 12px; height: 12px; opacity: 0; }
.obj.done .check { background: var(--mint); border-color: var(--mint); }
.obj.done .check svg { opacity: 1; }
.obj-label { font-size: 0.93rem; }
.obj-label b { font-variant-numeric: tabular-nums; }
.obj-prog { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { grid-column: 2 / 4; height: 7px; border-radius: 99px; background: var(--chip); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--sun), var(--accent)); transition: width 0.6s cubic-bezier(0.2, 0.9, 0.3, 1); }
.obj.done .bar i { background: linear-gradient(90deg, #8fe0b1, var(--mint)); }
.streak { margin: 16px 0 0; padding: 10px 14px; border-radius: 14px; background: var(--chip); font-size: 0.86rem; color: var(--muted); }
.streak b { color: var(--ink); }

/* board */
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.board li { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px; padding: 7px 10px 7px 7px; border-radius: 13px; transition: background 0.3s; }
.board li:nth-child(odd):not(.empty) { background: var(--chip); }
.board li.me { background: rgba(255, 124, 156, 0.14) !important; box-shadow: inset 0 0 0 1.5px rgba(255, 124, 156, 0.35); }
.rank { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 9px; font-size: 0.8rem; font-weight: 700; background: var(--card-solid); color: var(--muted); }
.rank.r1 { background: linear-gradient(135deg, #ffe38a, #f5b82e); color: #6b4a00; }
.rank.r2 { background: linear-gradient(135deg, #eef1f6, #c3c9d6); color: #4a5060; }
.rank.r3 { background: linear-gradient(135deg, #ffd2b0, #e39a64); color: #6b3510; }
.who { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.board .empty { display: block; text-align: center; padding: 22px 10px; color: var(--muted); font-size: 0.9rem; border: 1.5px dashed var(--line); border-radius: 16px; }

/* stats */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { padding: 12px 14px; border-radius: 16px; background: var(--chip); }
.stat b { display: block; font-family: var(--display); font-weight: 700; font-size: 1.45rem; letter-spacing: -0.02em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.8rem; color: var(--muted); }

/* badges */
.badge-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.badge {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 14px 6px 12px;
  border-radius: 18px;
  background: var(--chip);
  text-align: center;
  transition: transform 0.2s;
}
.badge:hover { transform: translateY(-2px); }
.badge .medal {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  font-size: 1.5rem;
  background: var(--card-solid);
  box-shadow: inset 0 0 0 1px var(--line);
  filter: grayscale(1);
  opacity: 0.45;
}
.badge.on .medal {
  filter: none;
  opacity: 1;
  background: radial-gradient(circle at 30% 25%, #fff9dc, #ffe08a 60%, #f5b82e);
  box-shadow: 0 6px 16px -6px rgba(245, 184, 46, 0.8), inset 0 -2px 0 rgba(160, 100, 0, 0.18);
}
.badge .b-name { font-size: 0.78rem; font-weight: 700; line-height: 1.2; }
.badge .b-desc { font-size: 0.7rem; color: var(--muted); line-height: 1.25; }
.badge:not(.on) .b-name { color: var(--muted); }

/* skins */
.skin-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.skin {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 8px 4px 9px;
  border-radius: 16px;
  border: 1.5px solid transparent;
  background: var(--chip);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, background 0.2s;
}
.skin:hover:not(:disabled) { transform: translateY(-2px); }
.skin canvas { width: 80px; height: 68px; }
.skin .s-name { font-size: 0.76rem; font-weight: 700; }
.skin .s-need { font-size: 0.68rem; color: var(--muted); }
.skin.sel { border-color: var(--accent); background: rgba(255, 124, 156, 0.1); }
.skin:disabled { cursor: not-allowed; }
.skin:disabled canvas { filter: grayscale(1) brightness(1.1); opacity: 0.35; }
.skin .lock { position: absolute; top: 34px; left: 50%; transform: translateX(-50%); font-size: 1rem; }

/* footer */
.footer {
  max-width: 1140px;
  margin: 0 auto;
  padding: 26px 24px 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 0.86rem;
}
.footer p { margin: 0; }
.footer strong { color: var(--ink); font-weight: 700; }
.link-btn { flex: none; background: none; border: 0; padding: 6px 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: 0.84rem; }
.link-btn:hover { color: var(--accent); }

#confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 50; }

:focus-visible { outline: 2.5px solid var(--sky); outline-offset: 2px; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card.wide { grid-column: 1 / -1; }
  .badge-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .topbar { padding: 16px 16px 0; }
  .nav { display: none; }
  main { padding: 0 12px; }
  .hero { padding: 34px 4px 24px; }
  .eyebrow::before, .eyebrow::after { width: 16px; }
  .cards { grid-template-columns: 1fr; gap: 14px; margin-top: 34px; }
  .badge-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .controls-bar { font-size: 0.8rem; }
  .panel { padding: 12px 14px 10px; border-radius: 18px; }
  .over-score { margin: 2px 0 4px; }
  .over-actions { margin-top: 10px; }
  .btn { padding: 8px 14px; font-size: 0.88rem; }
  .name-row { margin-top: 8px; }
  .name-row input { padding: 6px 12px; }
  .start-card { padding: 12px 18px 10px; }
  .footer { flex-direction: column; text-align: center; padding: 20px 16px 36px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  html { scroll-behavior: auto; }
}
