:root {
  --ink: #f7f2ff;
  --muted: #bda9e6;
  --accent: #b7ff3e;
  --accent-deep: #7ecc00;
  --danger: #ff6b9d;
  --panel-top: #2a1650;
  --panel-bottom: #120a26;
  font-family: ui-rounded, "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0a0618;
  color: var(--ink);
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

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

.hidden { display: none !important; }

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
  transition: opacity .25s ease;
}

#hud.hidden { display: flex !important; opacity: 0; visibility: hidden; }

.hud-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 2px solid rgba(255, 255, 255, .14);
  border-radius: 999px;
  background: rgba(20, 9, 40, .78);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
  backdrop-filter: blur(8px);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.hud-pill > span:first-child { color: #a894d6; }
.hud-pill strong {
  font-size: 1.25rem;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.hud-grow {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
  max-width: 260px;
  flex: 1;
  padding: 5px 12px;
  border: 2px solid rgba(255, 255, 255, .14);
  border-radius: 16px;
  background: rgba(20, 9, 40, .78);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
  backdrop-filter: blur(8px);
}
.hud-grow > span {
  color: #cdbdf2;
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grow-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, .14);
}
#growth-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #a855f7, #ff6bd6);
  transition: width .18s ease;
}
#growth-fill.ready {
  background: linear-gradient(90deg, #b7ff3e, #35ffb0);
  animation: readyPulse .5s ease-in-out infinite alternate;
}

.hud-actions { margin-left: auto; }

.hud-button {
  pointer-events: auto;
  padding: 8px 12px;
  border: 2px solid rgba(255, 255, 255, .16);
  border-radius: 999px;
  background: rgba(20, 9, 40, .78);
  color: var(--muted);
  font: inherit;
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .04em;
  white-space: nowrap;
  cursor: pointer;
  backdrop-filter: blur(8px);
  margin-left: auto;
}
.hud-button:active { transform: translateY(1px); }

#overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: max(16px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: radial-gradient(circle at 50% 18%, rgba(94, 42, 160, .48), rgba(5, 2, 14, .86) 76%);
  backdrop-filter: blur(5px);
}

.panel {
  width: min(560px, 100%);
  margin: auto;
  padding: clamp(18px, 4vw, 34px);
  border: 2px solid rgba(255, 255, 255, .14);
  border-radius: 28px;
  background: linear-gradient(165deg, var(--panel-top), var(--panel-bottom));
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .14);
  text-align: center;
}

.eyebrow {
  margin: 0 0 6px;
  color: #a98ce0;
  font-size: .74rem;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: clamp(2rem, 7vw, 3.2rem);
  line-height: 1.02;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .28);
}

.tagline {
  margin: 0 auto 18px;
  max-width: 42ch;
  color: var(--muted);
  font-size: clamp(.95rem, 2.4vw, 1.05rem);
  line-height: 1.45;
}

.how-to {
  margin: 0 auto 22px;
  padding: 0 0 0 1.1em;
  max-width: 48ch;
  color: #e3daf7;
  font-size: .92rem;
  line-height: 1.55;
  text-align: left;
}
.how-to li { margin: 6px 0; }
.how-to li::marker { color: var(--accent); }
.how-to b { color: #fff; }

.big-button,
#win-form button {
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.big-button {
  padding: 15px 52px;
  background: linear-gradient(180deg, #d4ff70, var(--accent-deep));
  color: #223300;
  font-size: 1.35rem;
  letter-spacing: .01em;
  box-shadow: 0 6px 0 #4f8000, 0 14px 28px rgba(0, 0, 0, .42);
  transition: transform .1s ease, box-shadow .1s ease, filter .15s ease;
}
.big-button:hover { filter: brightness(1.06); }
.big-button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #4f8000, 0 8px 18px rgba(0, 0, 0, .36);
}

.big-button:focus-visible,
.hud-button:focus-visible,
input:focus-visible,
#win-form button:focus-visible {
  outline: 3px solid #8ce7ff;
  outline-offset: 3px;
}

.qualify {
  min-height: 1.4em;
  margin: 0 0 10px;
  color: var(--accent);
  font-weight: 800;
}

#win-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0 8px;
  text-align: left;
}
#win-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
#win-form input {
  width: 100%;
  padding: 11px 13px;
  border: 2px solid rgba(255, 255, 255, .16);
  border-radius: 13px;
  background: rgba(6, 3, 18, .62);
  color: #fff;
  font: inherit;
  font-size: 1rem;
  letter-spacing: 0;
  text-transform: none;
}
#win-form[hidden] { display: none; }
#win-form button {
  grid-column: 1 / -1;
  padding: 12px 20px;
  background: #4cd964;
  color: #09360f;
  font-size: 1.02rem;
  box-shadow: 0 4px 0 #24802f;
}
#win-form button:active { transform: translateY(2px); box-shadow: 0 2px 0 #24802f; }
#win-form button:disabled { opacity: .55; cursor: wait; }

.form-status {
  min-height: 1.3em;
  margin: 6px 0 14px;
  color: var(--muted);
  font-size: .88rem;
}

.scores-box {
  margin-top: 20px;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(4, 2, 14, .4);
  text-align: left;
}
.scores-box h2 {
  margin: 0 0 8px;
  color: #a892d8;
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.scores-status {
  margin: 0;
  color: var(--muted);
  font-size: .85rem;
}
.scores-board {
  display: grid;
  gap: 2px;
  max-height: 210px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}
.scores-board:empty { display: none; }
.scores-board li {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 8px;
  align-items: baseline;
  padding: 5px 3px;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
  font-size: .9rem;
}
.scores-board li:last-child { border-bottom: 0; }
.scores-board .rank { color: var(--accent); font-weight: 900; }
.scores-board .score-value { color: #d4ff70; font-variant-numeric: tabular-nums; font-weight: 800; }

.big-score {
  margin: 4px 0 12px;
  color: var(--accent);
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .24);
}

#cutscene-ui {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 16px calc(9vh + env(safe-area-inset-bottom));
  pointer-events: none;
}
#cutscene-ui.hidden { display: none !important; }
#skip-cutscene {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  margin-left: 0;
  pointer-events: auto;
}
#cutscene-caption {
  max-width: min(660px, 92vw);
  margin: 0;
  padding: 14px 24px;
  border: 2px solid rgba(255, 255, 255, .2);
  border-radius: 20px;
  background: rgba(20, 9, 40, .88);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .5);
  backdrop-filter: blur(8px);
  color: #f3eaff;
  font-size: clamp(1rem, 3vw, 1.3rem);
  font-weight: 800;
  line-height: 1.4;
  text-align: center;
  animation: captionIn .35s ease;
}

@keyframes captionIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border: 2px solid rgba(255, 255, 255, .16);
  border-radius: 999px;
  background: rgba(20, 9, 40, .94);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color: #fff;
  font-size: .9rem;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 16px);
  transition: opacity .2s ease, transform .2s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes readyPulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.5); }
}

@media (max-width: 560px) {
  #hud { gap: 5px; }
  .hud-pill { gap: 5px; padding: 5px 9px; font-size: .62rem; }
  .hud-pill strong { font-size: 1.08rem; }
  .hud-grow { min-width: 84px; padding: 4px 9px; }
  .hud-grow > span { font-size: .56rem; }
  .hud-button { padding: 7px 9px; font-size: .62rem; }
  .panel { border-radius: 22px; }
  .how-to { font-size: .86rem; }
  #win-form { grid-template-columns: 1fr; }
}

@media (max-width: 400px) {
  #hud { gap: 4px; padding-left: 8px; padding-right: 8px; }
  .hud-pill { gap: 4px; padding: 4px 7px; font-size: .56rem; }
  .hud-pill strong { font-size: 1rem; }
  .hud-grow { min-width: 70px; }
  .hud-button { padding: 6px 8px; }
}

@media (max-height: 560px) and (orientation: landscape) {
  #overlay { align-items: start; }
  .panel { padding: 16px 22px; }
  h1 { font-size: 1.8rem; }
  .how-to { font-size: .82rem; margin-bottom: 12px; }
  .tagline { margin-bottom: 10px; }
  .scores-board { max-height: 120px; }
}

@media (prefers-reduced-motion: reduce) {
  #growth-fill.ready { animation: none; }
  * { scroll-behavior: auto; }
}
