:root {
  --bg: #090b10;
  --ink: #eef1f7;
  --muted: #8a93a8;
  --amber: #ffb547;
  --cyan: #5ad1ff;
  --pink: #ff6fae;
  --red: #ff5c5c;
  --green: #8ef0a0;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: radial-gradient(1200px 800px at 50% 45%, #151b28 0%, var(--bg) 62%) var(--bg);
}

/* faint dot grid, fading out towards the edges */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(255, 255, 255, 0.07) 1px, transparent 1.2px);
  background-size: 28px 28px;
  -webkit-mask-image: radial-gradient(circle at 50% 45%, #000 15%, transparent 72%);
  mask-image: radial-gradient(circle at 50% 45%, #000 15%, transparent 72%);
}

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.top {
  position: fixed;
  top: calc(20px + env(safe-area-inset-top));
  left: 26px;
  pointer-events: none;
}

h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(90deg, var(--amber) 0 50%, var(--cyan) 50% 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tag {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.hud {
  position: fixed;
  top: calc(22px + env(safe-area-inset-top));
  right: 26px;
  text-align: right;
  pointer-events: none;
}

.level { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.pass { margin: 2px 0 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.shape-name { margin: 6px 0 0; font-size: 14px; font-weight: 600; min-height: 1.2em; }

.result {
  position: fixed;
  left: 50%;
  bottom: calc(66px + env(safe-area-inset-bottom));
  transform: translate(-50%, 14px);
  opacity: 0;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.5s cubic-bezier(0.2, 1.4, 0.4, 1);
  white-space: nowrap;
}
.result.show { opacity: 1; transform: translate(-50%, 0); }

.score {
  font-size: clamp(46px, 9vw, 76px);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.meter {
  position: relative;
  width: 220px;
  height: 6px;
  margin: 20px auto 0;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
}
.meter-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 3px; }
.meter-mark {
  position: absolute;
  top: -5px;
  bottom: -5px;
  width: 2px;
  margin-left: -1px;
  background: var(--ink);
  border-radius: 1px;
}
.meter-mark::after {
  content: "pass";
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.split {
  margin-top: 6px;
  font-size: 15px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.split b { font-weight: 700; }
.split .a { color: var(--amber); }
.split .b { color: var(--cyan); }

.verdict {
  margin-top: 8px;
  font-size: 17px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.result.reveal .verdict { opacity: 1; transform: none; }
.result.pass .verdict { color: #8ef0a0; }
.result.fail .verdict { color: #ff7a7a; }
.result.fail .score { animation: thud 0.5s ease; }

@keyframes thud {
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
}

.hint {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(22px + env(safe-area-inset-bottom));
  margin: 0;
  padding: 0 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.hint.fade { opacity: 0; }

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(9, 11, 16, 0.55);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  animation: fade 0.4s ease;
}
.overlay[hidden] { display: none; }

.card {
  width: min(400px, 100%);
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  padding: 28px 28px 22px;
  border-radius: 20px;
  background: rgba(22, 27, 38, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: pop 0.55s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.eyebrow { margin: 0; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.12em; }
.avg { font-size: 56px; font-weight: 800; letter-spacing: -0.04em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.avg-label { margin: 0; color: var(--muted); font-size: 14px; }
.stats { margin: 6px 0 0; font-size: 14px; color: var(--ink); font-variant-numeric: tabular-nums; }
.best { margin: 10px 0 0; font-size: 14px; color: var(--ink); min-height: 1.2em; }

.submit { margin: 18px 0 0; text-align: left; }
.submit[hidden] { display: none; }
.submit label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.submit .row { display: flex; gap: 8px; }
.submit input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 15px;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  -webkit-user-select: text;
  user-select: text;
}
.submit input:focus { outline: 2px solid var(--cyan); outline-offset: 1px; }
.submit button { flex: 0 0 auto; }
.msg { margin: 6px 0 0; font-size: 13px; color: var(--muted); min-height: 1.2em; }
.msg.ok { color: #8ef0a0; }
.msg.err { color: #ff7a7a; }

.board { margin-top: 18px; text-align: left; }
.board .eyebrow { margin-bottom: 6px; }
.board-list { list-style: none; margin: 0; padding: 0; }
.board-list li {
  display: grid;
  grid-template-columns: 26px 1fr auto 40px;
  gap: 8px;
  align-items: baseline;
  padding: 6px 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  animation: rise 0.35s ease forwards;
}
.board-list li:nth-child(n+2) { animation-delay: 0.04s; }
.board-list li:nth-child(n+4) { animation-delay: 0.08s; }
.board-list li:nth-child(n+6) { animation-delay: 0.12s; }
.board-list li:nth-child(n+8) { animation-delay: 0.16s; }
.board-list .rank { color: var(--muted); }
.board-list .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list .acc { color: var(--muted); text-align: right; }
.board-list li.me { background: rgba(90, 209, 255, 0.12); border-radius: 8px; }
.board-list li:nth-child(1) .rank { color: var(--amber); font-weight: 700; }
.board-empty { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.board-empty[hidden] { display: none; }

.actions { display: flex; gap: 10px; margin-top: 22px; }

button {
  flex: 1;
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 0;
  cursor: pointer;
  color: #10131a;
  background: linear-gradient(90deg, var(--amber), var(--cyan));
  transition: transform 0.15s ease, filter 0.15s ease;
}
button:hover { filter: brightness(1.08); transform: translateY(-1px); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
button.ghost { background: rgba(255, 255, 255, 0.07); color: var(--ink); }

.small { margin: 16px 0 0; font-size: 12px; color: var(--muted); }

/* 404 page */
.notfound {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  -webkit-user-select: text;
  user-select: text;
}
.notfound h1 { font-size: 64px; }
.notfound p { color: var(--muted); }
.notfound a { color: var(--ink); font-weight: 700; }

@keyframes pop {
  from { opacity: 0; transform: scale(0.9) translateY(12px); }
  to { opacity: 1; transform: none; }
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------- Halve+ */
h1 .plus {
  margin-left: 2px;
  color: var(--pink);
  -webkit-text-fill-color: var(--pink);
}
h2 { margin: 6px 0 0; font-size: 24px; letter-spacing: -0.02em; }

.points { margin: 4px 0 0; font-size: 15px; font-variant-numeric: tabular-nums; }
.points b { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.points .unit { color: var(--muted); }
.mult {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  color: #10131a;
  background: var(--amber);
  transition: transform 0.2s ease;
}
.mult:empty { display: none; }
.mult.bump { animation: bump 0.45s ease; }
.points.bump b { animation: bump 0.45s ease; display: inline-block; }

.perks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; max-width: 46vw; pointer-events: auto; }
.perk {
  flex: 0 0 auto;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 9px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.perk .n { color: var(--muted); font-weight: 600; }
.perk.on { background: rgba(255, 111, 174, 0.2); border-color: var(--pink); }
.perk.auto { cursor: default; opacity: 0.85; }
.perk.auto:hover { transform: none; filter: none; }
.perk:disabled { opacity: 0.4; cursor: default; transform: none; filter: none; }
.perk.new { animation: pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1); }

.lives { margin: 6px 0 0; font-size: 18px; letter-spacing: 2px; min-height: 1.2em; }
.lives .heart { display: inline-block; color: var(--red); }
.lives .heart.empty { color: rgba(255, 255, 255, 0.16); }
.lives .heart.lost { animation: lost 0.8s ease; }
.lives .heart.gain { animation: bump 0.6s ease; }

.toast {
  position: fixed;
  left: 50%;
  top: calc(96px + env(safe-area-inset-top));
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  background: rgba(22, 27, 38, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  transform: translate(-50%, -8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.gain { margin-top: 6px; font-size: 15px; font-weight: 700; color: var(--amber); min-height: 1.2em; opacity: 0; transition: opacity 0.4s ease; }
.result.reveal .gain { opacity: 1; }

.draft-options { display: grid; gap: 10px; margin-top: 18px; }
.draft-options button {
  display: grid;
  grid-template-columns: 40px 1fr;
  align-items: center;
  gap: 4px 10px;
  text-align: left;
  padding: 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  opacity: 0;
  animation: rise 0.4s ease forwards;
}
.draft-options button:nth-child(2) { animation-delay: 0.08s; }
.draft-options button:nth-child(3) { animation-delay: 0.16s; }
.draft-options button:hover { border-color: var(--pink); background: rgba(255, 111, 174, 0.12); }
.draft-options .icon { grid-row: span 2; font-size: 26px; text-align: center; }
.draft-options .name { font-size: 16px; font-weight: 800; }
.draft-options .desc { font-size: 13px; font-weight: 500; color: var(--muted); }

.rules { margin: 16px 0 0; padding: 0 0 0 18px; text-align: left; font-size: 14px; line-height: 1.45; }
.rules li { margin: 0 0 8px; }
.small a { color: var(--ink); }

@keyframes bump { 40% { transform: scale(1.35); } }
@keyframes lost {
  0% { transform: scale(1); color: var(--red); }
  30% { transform: scale(1.6) rotate(-12deg); color: #fff; }
  100% { transform: scale(1); }
}

@media (max-width: 560px) {
  .perks { max-width: 52vw; }
  .perk { padding: 5px 7px; font-size: 12px; }
  .toast { top: calc(150px + env(safe-area-inset-top)); }
}

@media (max-width: 560px) {
  .top { left: 18px; }
  .hud { right: 18px; }
  h1 { font-size: 24px; }
  .tag { font-size: 12px; }
}

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