:root {
  --hull: #07080f;
  --plate: #10121c;
  --ink: #e7f6ff;
  --muted: #7d8aa3;
  --red: #ff2e63;
  --green: #39ff14;
  --blue: #00f5ff;
  --yellow: #ffe600;
  --grey: #5a6273;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 20% 0%, rgba(0, 245, 255, 0.12), transparent 40%),
    radial-gradient(circle at 80% 100%, rgba(255, 46, 99, 0.14), transparent 45%),
    var(--hull);
  color: var(--ink);
  font-family: "Zen Dots", sans-serif;
}
button {
  font-family: inherit;
  cursor: pointer;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--blue);
  border-radius: 8px;
  padding: 8px 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
button:not(.tile):not(.plug) { min-height: 44px; }
button:disabled { opacity: 0.35; cursor: default; }
button:not(:disabled):hover { box-shadow: 0 0 12px var(--blue); }

.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(0, 245, 255, 0.25);
}
.topbar-brand { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
#game-title {
  font-family: "Tilt Neon", sans-serif;
  font-size: clamp(16px, 6vw, 28px);
  margin: 0;
  color: var(--yellow);
  text-shadow: 0 0 18px var(--yellow);
}
.game-version { color: var(--muted); font-size: 12px; }
.seed { font-size: 11px; color: var(--muted); }
.topbar-coins { color: var(--yellow); font-weight: 700; font-size: 15px; }

.menu-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 10px 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(0, 245, 255, 0.2);
}

.menu { margin-left: auto; position: relative; }
.menu summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 6px 16px;
  border: 1px solid var(--blue);
  border-radius: 8px;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary::marker { content: ""; }
.menu[open] summary { box-shadow: 0 0 12px var(--blue); }
.top-nav {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 170px;
  padding: 10px;
  background: var(--plate);
  border: 1px solid var(--blue);
  border-radius: 10px;
}
.top-nav button { width: 100%; }

.screen { display: none; padding: 16px; }
body[data-screen="title"] #title-screen,
body[data-screen="board"] #board-screen,
body[data-screen="summary"] #summary-screen,
body[data-screen="shop"] #shop-screen,
body[data-screen="win"] #win-screen,
body[data-screen="lost"] #lost-screen { display: block; }

body[data-screen="title"] #open-bag,
body[data-screen="title"] #open-connectors,
body[data-screen="title"] #seed-readout { display: none; }

.tagline, .seed-line { text-align: center; }
.cta {
  display: block;
  margin: 28px auto 0;
  font-size: 18px;
  padding: 14px 28px;
  border-color: var(--yellow);
  color: var(--yellow);
}

.play {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: start;
}
.board-wrap {
  position: relative;
  width: min(92vw, calc(100dvh - 14rem));
  aspect-ratio: 1;
  margin: 0 auto;
}
.board {
  display: grid;
  width: 100%;
  height: 100%;
  gap: 4px;
  touch-action: none;
}
.tile {
  position: relative;
  border: 1px solid rgba(231, 246, 255, 0.18);
  border-radius: 8px;
  background: var(--plate);
  color: var(--ink);
  font-family: "Roboto", sans-serif;
  font-weight: 700;
  font-size: clamp(16px, 3vw, 28px);
  padding: 0;
  display: grid;
  place-items: center;
}
.tile .letter { line-height: 1; }
.tile .stats {
  position: absolute;
  right: 4px;
  bottom: 3px;
  font-size: 10px;
  color: var(--muted);
  font-weight: 500;
}
.tile[data-color="red"] { background: rgba(255, 46, 99, 0.22); border-color: var(--red); }
.tile[data-color="green"] { background: rgba(57, 255, 20, 0.18); border-color: var(--green); }
.tile[data-color="blue"] { background: rgba(0, 245, 255, 0.18); border-color: var(--blue); }
.tile[data-color="yellow"] { background: rgba(255, 230, 0, 0.18); border-color: var(--yellow); color: #111; }
.tile.is-dead {
  background: #0a0b10;
  border-style: dashed;
  opacity: 0.45;
}
.tile.is-neon { box-shadow: inset 0 0 10px var(--yellow); }
.tile.is-chrome { box-shadow: inset 0 0 10px #c0c8d8; }
.tile.is-draft { box-shadow: inset 0 0 0 2px var(--blue); }
.tile.is-scoring { animation: score-pulse 220ms ease-out; }
@keyframes score-pulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.14); box-shadow: 0 0 18px var(--yellow); }
  100% { transform: scale(1); }
}
.tile.is-flipped .letter, .tile.is-flipped .stats { visibility: hidden; }
.wires {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
.wire {
  fill: none;
  stroke-width: 14;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 6px currentColor);
}
.rail {
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: var(--hull);
  padding: 8px 0 4px;
}
.connector-picker { display: flex; flex-direction: column; gap: 8px; }
.connector-picker[hidden] { display: none; }
.inventory { display: flex; flex-wrap: wrap; gap: 10px; }
.plug {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid #fff;
  font-family: "Roboto", sans-serif;
  font-size: 20px;
  font-weight: 700;
}
.plug[data-color="red"] { background: var(--red); }
.plug[data-color="green"] { background: var(--green); color: #111; }
.plug[data-color="blue"] { background: var(--blue); color: #111; }
.plug[data-color="yellow"] { background: var(--yellow); color: #111; }
.plug.is-selected { box-shadow: 0 0 16px #fff; }
.plug:disabled { opacity: 0.3; }
.connector-info {
  background: var(--hull);
  border: 1px solid rgba(0, 245, 255, 0.2);
  border-left: 3px solid var(--grey);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  min-height: 72px;
  visibility: hidden;
}
.connector-info:not([hidden]) { visibility: visible; }
.connector-info[data-color="red"] { border-left-color: var(--red); }
.connector-info[data-color="green"] { border-left-color: var(--green); }
.connector-info[data-color="blue"] { border-left-color: var(--blue); }
.connector-info[data-color="yellow"] { border-left-color: var(--yellow); }
.connector-info-title {
  margin: 0 0 2px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
}
.connector-info-base { margin: 0; color: var(--muted); }
.connector-info-upgrade { margin: 0; color: var(--blue); }
.score-panel {
  position: relative;
  z-index: 0;
  background: var(--plate);
  border: 1px solid rgba(0, 245, 255, 0.25);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 10px;
  font-size: 12px;
}
@property --mega-angle {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
.score-panel.is-mega::before {
  content: "";
  position: absolute;
  inset: -4px;
  z-index: -1;
  border-radius: 13px;
  background: conic-gradient(from var(--mega-angle), var(--red), var(--yellow), var(--green), var(--blue), var(--red));
  filter: blur(7px);
  animation: mega-spin 1.6s linear infinite, mega-pulse 0.8s ease-in-out infinite;
}
@keyframes mega-spin {
  to { --mega-angle: 360deg; }
}
@keyframes mega-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}
.score-panel.is-word { animation: word-pop 360ms ease-out; }
.score-panel.is-land { animation: score-land 480ms ease-out; }
@keyframes word-pop {
  40% { box-shadow: 0 0 22px var(--blue); }
}
@keyframes score-land {
  30% { transform: scale(1.06); box-shadow: 0 0 24px var(--yellow); }
}
#pool-points, #pool-amp { display: inline-block; }
#pool-points.is-tick, #pool-amp.is-tick { animation: tick-pop 180ms ease-out; }
@keyframes tick-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.3); color: var(--yellow); }
  100% { transform: scale(1); }
}
.scoring-badge {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: var(--plate);
  border-radius: 10px;
  text-align: center;
  color: var(--yellow);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  animation: badge-blink 1s ease-in-out infinite;
}
body[data-scoring="true"] .scoring-badge { display: flex; }
@keyframes badge-blink {
  50% { opacity: 0.35; }
}
body[data-scoring="true"] .inventory .plug,
body[data-scoring="true"] .board .tile {
  opacity: 0.5;
  pointer-events: none;
}
.send { width: 100%; border-color: var(--green); color: var(--green); }
.send.is-ready {
  animation: rainbow 1.2s linear infinite;
  border-width: 3px;
}
@keyframes rainbow {
  from { filter: hue-rotate(0deg); }
  to { filter: hue-rotate(360deg); }
}
.challenge {
  text-align: center;
  color: var(--red);
  text-shadow: 0 0 10px var(--red);
}
.panel {
  background: var(--plate);
  border: 1px solid rgba(0, 245, 255, 0.25);
  border-radius: 12px;
  padding: 18px;
  max-width: 560px;
  margin: 0 auto 18px;
  line-height: 1.6;
}
.summary-hero {
  text-align: center;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(0, 245, 255, 0.2);
}
.summary-label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}
.summary-score {
  display: block;
  font-family: "Tilt Neon", sans-serif;
  font-size: clamp(32px, 11vw, 44px);
  color: var(--yellow);
  text-shadow: 0 0 18px var(--yellow);
  line-height: 1.2;
}
.summary-gate {
  display: block;
  font-size: 12px;
  color: var(--muted);
}
.summary-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.summary-stat {
  background: var(--hull);
  border: 1px solid rgba(0, 245, 255, 0.18);
  border-radius: 8px;
  padding: 8px 10px;
  text-align: center;
}
.summary-stat-label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.summary-stat-value {
  display: block;
  font-family: "Roboto", sans-serif;
  font-weight: 700;
  font-size: 20px;
  margin-top: 2px;
}
.summary-words {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.summary-word {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  background: var(--hull);
  border-left: 3px solid var(--grey);
  border-radius: 4px;
  font-family: "Roboto", sans-serif;
  font-size: 13px;
}
.summary-word[data-color="red"] { border-left-color: var(--red); }
.summary-word[data-color="green"] { border-left-color: var(--green); }
.summary-word[data-color="blue"] { border-left-color: var(--blue); }
.summary-word[data-color="yellow"] { border-left-color: var(--yellow); }
.summary-word-name { font-weight: 700; letter-spacing: 0.06em; }
.summary-word-score { color: var(--blue); font-weight: 700; }
.summary-coins {
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px dashed rgba(255, 230, 0, 0.35);
}
.summary-coin-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.summary-coins-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.summary-coins-value { color: var(--yellow); font-weight: 700; font-size: 18px; }
.row { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.leftover-group {
  max-width: 560px;
  margin: 0 auto 16px;
  padding: 12px 0 16px;
  text-align: center;
  border-bottom: 1px solid rgba(0, 245, 255, 0.15);
}
.leftover-hint {
  margin: 0 0 10px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.summary-actions { margin-top: 4px; }
.ghost { border-color: var(--grey); color: var(--muted); }
.ghost:not(:disabled):hover { box-shadow: 0 0 10px var(--grey); }
.primary { border-color: var(--green); color: var(--green); font-weight: 700; }
.primary:not(:disabled):hover { box-shadow: 0 0 16px var(--green); }
.slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 12px; margin: 16px 0; }
.slot {
  min-height: 88px;
  border: 1px solid var(--yellow);
  border-radius: 10px;
  padding: 12px;
  background: #14182a;
}
.slot.is-spin { animation: spin 0.4s linear; }
@keyframes spin {
  from { transform: translateY(-8px); opacity: 0.4; }
  to { transform: none; opacity: 1; }
}
.paint { margin: 18px 0 24px; }
.paint-draw { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.swatches { display: flex; gap: 8px; margin: 8px 0; }
.swatch { width: 44px; height: 44px; border-radius: 4px; border: 2px solid #fff; padding: 0; }
.swatch[data-color="red"] { background: var(--red); }
.swatch[data-color="green"] { background: var(--green); }
.swatch[data-color="blue"] { background: var(--blue); }
.swatch[data-color="yellow"] { background: var(--yellow); }
.shop-coins { font-size: 18px; color: var(--yellow); }
.shop-section {
  background: var(--plate);
  border: 1px solid rgba(0, 245, 255, 0.25);
  border-radius: 12px;
  padding: 16px 18px;
  margin: 16px 0;
}
.shop-section h3 { margin: 0 0 4px; }
.shop-section-hint { margin: 0 0 12px; font-size: 12px; color: var(--muted); }
#leave-shop {
  margin-top: 8px;
  min-height: 44px;
  position: sticky;
  bottom: 0;
  z-index: 2;
  width: 100%;
  background: var(--hull);
}
.slot[data-rarity="common"] { border-color: var(--grey); }
.slot[data-rarity="uncommon"] { border-color: var(--blue); }
.slot[data-rarity="rare"] { border-color: var(--red); box-shadow: inset 0 0 10px rgba(255, 46, 99, 0.25); }
.bag-count { color: var(--muted); font-size: 12px; margin: -4px 0 12px; }
.bag-grid { display: flex; flex-wrap: wrap; gap: 6px; max-width: 520px; }
.bag-grid .tile { width: 40px; height: 40px; font-size: 16px; padding: 0; }
dialog {
  background: var(--plate);
  color: var(--ink);
  border: 1px solid var(--blue);
  border-radius: 12px;
  padding: 20px;
  max-width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.65); }

@media (min-width: 1024px) {
  .screen { padding: 24px; }
  .play { grid-template-columns: minmax(0, 1fr) 220px; }
  .board-wrap { width: min(72vw, 72vh, 640px); }
  .rail { position: static; padding: 0; gap: 14px; }
  .connector-info { min-height: 0; }
  .connector-info[hidden] { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .tile.is-scoring, .score-panel.is-word, .score-panel.is-land,
  #pool-points.is-tick, #pool-amp.is-tick, .scoring-badge,
  .score-panel.is-mega::before { animation: none; }
}
