:root {
  color-scheme: dark;
  --background: #130b26;
  --surface: rgba(29, 20, 51, 0.9);
  --surface-strong: #24173d;
  --surface-soft: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.14);
  --text: #f8f7ff;
  --muted: #b9b1cc;
  --accent: #f0d85b;
  --success: #65e5a5;
  --danger: #ff7b91;
  --shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.35);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
   text-shadow:-1px -1px 0 rgba(0,0,0,0.3);
}

html {
  min-width: 18rem;
  min-height: 100%;
  background: var(--background);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 5%, rgba(121, 77, 255, 0.22), transparent 30rem),
    radial-gradient(circle at 90% 15%, rgba(232, 62, 140, 0.17), transparent 32rem),
    linear-gradient(145deg, #10091f, #1c0e35 55%, #0d182b);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  border: 1px solid var(--border);
  border-radius: 0.75rem;
}

button {
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.hero {
  display: flex;
  width: min(94vw, 90rem);
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 3.5rem) 0 clamp(1rem, 3vw, 2rem);
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.3rem;
  font-size: clamp(2.7rem, 8vw, 6.4rem);
  line-height: 0.9;
  letter-spacing: -0.065em;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 2vw, 1.65rem);
  letter-spacing: -0.025em;
}

h3 {
  margin-bottom: 0.65rem;
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.lead {
  max-width: 42rem;
  margin-bottom: 0;
  color: var(--muted);
  font-size: clamp(0.95rem, 1.8vw, 1.12rem);
}

.scoreboard {
  display: grid;
  min-width: min(100%, 25rem);
  margin: 0;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(1rem);
}

.scoreboard div {
  padding: 0.85rem 1rem;
  text-align: center;
}

.scoreboard div + div {
  border-left: 1px solid var(--border);
}

.scoreboard dt {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.scoreboard dd {
  margin: 0.2rem 0 0;
  font-size: clamp(1.1rem, 3vw, 1.65rem);
  font-weight: 800;
}

.app-shell {
  display: grid;
  width: min(94vw, 90rem);
  margin: 0 auto;
  grid-template-columns: minmax(17rem, 22rem) minmax(0, 1fr);
  gap: clamp(1rem, 2.5vw, 2rem);
  align-items: start;
}

.control-panel,
.game-panel {
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(1rem);
}

.control-panel {
  position: sticky;
  top: 1rem;
  padding: 1.15rem;
}

.panel-heading,
.game-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.settings-grid {
  display: grid;
  margin: 1.2rem 0;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.settings-grid label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.settings-grid select,
.settings-grid input {
  width: 100%;
  min-height: 2.65rem;
  padding: 0.55rem 0.7rem;
  color: var(--text);
  background: rgba(8, 5, 18, 0.6);
}

.settings-grid option {
  color: #181224;
  background: white;
}

.seed-field {
  grid-column: 1 / -1;
}

.input-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.45rem;
}

.icon-button {
  width: 2.65rem;
  padding: 0;
  color: var(--accent);
  background: var(--surface-soft);
  font-size: 1.2rem;
}

.primary-button {
  display: flex;
  width: 100%;
  min-height: 3.15rem;
  padding: 0.75rem 1rem;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  border-color: transparent;
  color: #221a04;
  background: linear-gradient(135deg, #f8e879, #eebd35);
  font-weight: 850;
  box-shadow: 0 0.8rem 2rem rgba(240, 205, 73, 0.18);
}

.primary-button:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.actions {
  display: grid;
  margin-top: 0.75rem;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.actions button {
  display: grid;
  min-height: 3.4rem;
  padding: 0.55rem 0.65rem;
  grid-template-columns: auto 1fr auto;
  gap: 0.45rem;
  align-items: center;
  background: var(--surface-soft);
  font-size: 0.82rem;
  font-weight: 750;
}

kbd {
  min-width: 1.45em;
  padding: 0.12rem 0.3rem;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-bottom-width: 2px;
  border-radius: 0.35rem;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.25);
  font: 700 0.7rem/1.2 ui-monospace, SFMono-Regular, Consolas, monospace;
  text-align: center;
}

.switch {
  display: grid;
  margin-top: 0.85rem;
  padding: 0.85rem;
  grid-template-columns: auto 1fr;
  gap: 0.75rem;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  cursor: pointer;
}

.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch-control {
  position: relative;
  width: 2.7rem;
  height: 1.5rem;
  border-radius: 2rem;
  background: rgba(255, 255, 255, 0.18);
  transition: background 180ms ease;
}

.switch-control::after {
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: white;
  content: "";
  transition: transform 180ms ease;
}

.switch input:checked + .switch-control {
  background: #7a5cff;
}

.switch input:checked + .switch-control::after {
  transform: translateX(1.2rem);
}

.switch input:focus-visible + .switch-control {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.switch strong,
.switch small {
  display: block;
}

.switch strong {
  font-size: 0.82rem;
}

.switch small {
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.7rem;
}

.game-panel {
  position: relative;
  min-width: 0;
  overflow: hidden;
  padding: clamp(1rem, 2.5vw, 1.6rem);
}

.status-message {
  max-width: 24rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.82rem;
  text-align: right;
}

.game-panel[data-status="won"] .status-message {
  border-color: rgba(101, 229, 165, 0.5);
  color: var(--success);
  background: rgba(101, 229, 165, 0.09);
}

.game-panel[data-status="lost"] .status-message {
  border-color: rgba(255, 123, 145, 0.5);
  color: var(--danger);
  background: rgba(255, 123, 145, 0.09);
}

.progress-track {
  margin: 1rem 0;
}

progress {
  display: block;
  width: 100%;
  height: 0.6rem;
  overflow: hidden;
  border: 0;
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.08);
}

progress::-webkit-progress-bar {
  background: rgba(255, 255, 255, 0.08);
}

progress::-webkit-progress-value {
  border-radius: 1rem;
  background: linear-gradient(90deg, #7a5cff, #e83e8c, #f0d85b);
  transition: width 240ms ease;
}

progress::-moz-progress-bar {
  border-radius: 1rem;
  background: linear-gradient(90deg, #7a5cff, #e83e8c, #f0d85b);
}

.board-frame {
  display: grid;
  min-height: 18rem;
  padding: clamp(0.55rem, 1.5vw, 1rem);
  place-items: center;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 1rem;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%) 0 0 / 1rem 1rem,
    linear-gradient(-45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%) 0 0 / 1rem 1rem,
    rgba(4, 3, 10, 0.32);
}

.board {
  --columns: 10;
  --rows: 7;
  --board-max-width: 32.5rem;
  --board-padding: clamp(0.25rem, 0.7vw, 0.5rem);
  position: relative;
  isolation: isolate;
  display: grid;
  width: min(100%, var(--board-max-width));
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  gap: 0;
  padding: var(--board-padding);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 0.85rem;
  background: rgba(0, 0, 0, 0.3);
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.3);
}

.cell {
  position: relative;
  z-index: 1;
  display: grid;
  min-width: 0;
  padding: 0;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
  border: 0;
  border-radius: clamp(0.12rem, 0.4vw, 0.35rem);
  color: var(--cell-ink);
  background-color: var(--cell-color);
  box-shadow:
    inset 0 0 0 clamp(1px, 0.18vw, 2px) rgba(4, 3, 10, 0.38),
    inset 0 1px rgba(255, 255, 255, 0.18),
    inset 0 -1px rgba(0, 0, 0, 0.12);
}

.cell.is-player-area {
  border-radius: 0;
  color: transparent;
  background-color: transparent;
  background-image: none;
  box-shadow: none;
}

.player-area-layer {
  position: absolute;
  z-index: 2;
  inset: var(--board-padding);
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  pointer-events: none;
  filter: drop-shadow(0 0.35rem 0.42rem rgba(0, 0, 0, 0.62));
}

.player-area-tile {
  --edge-size: clamp(1px, 0.2vw, 2px);
  --edge-top: 0px;
  --edge-right: 0px;
  --edge-bottom: 0px;
  --edge-left: 0px;
  --corner-top-left: 0;
  --corner-top-right: 0;
  --corner-bottom-right: 0;
  --corner-bottom-left: 0;
  --blob-radius: clamp(0.18rem, 0.55vw, 0.48rem);
  display: grid;
  min-width: 0;
  place-items: center;
  overflow: hidden;
  box-sizing: border-box;
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.42) rgba(3, 2, 10, 0.5) rgba(3, 2, 10, 0.56) rgba(255, 255, 255, 0.28);
  border-width: var(--edge-top) var(--edge-right) var(--edge-bottom) var(--edge-left);
  border-radius:
    var(--corner-top-left)
    var(--corner-top-right)
    var(--corner-bottom-right)
    var(--corner-bottom-left);
  color: var(--cell-ink);
  background-color: var(--cell-color);
}

.player-area-tile.edge-top {
  --edge-top: var(--edge-size);
}

.player-area-tile.edge-right {
  --edge-right: var(--edge-size);
}

.player-area-tile.edge-bottom {
  --edge-bottom: var(--edge-size);
}

.player-area-tile.edge-left {
  --edge-left: var(--edge-size);
}

.player-area-tile.corner-top-left {
  --corner-top-left: var(--blob-radius);
}

.player-area-tile.corner-top-right {
  --corner-top-right: var(--blob-radius);
}

.player-area-tile.corner-bottom-right {
  --corner-bottom-right: var(--blob-radius);
}

.player-area-tile.corner-bottom-left {
  --corner-bottom-left: var(--blob-radius);
}

.cell[data-index="0"] {
  z-index: 3;
}

.cell[data-index="0"]::after {
  position: absolute;
  top: clamp(2px, 0.35vw, 4px);
  left: clamp(2px, 0.35vw, 4px);
  width: clamp(4px, 0.65vw, 8px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
  content: '';
}

.cell-symbol {
  opacity: 0;
  font-size: clamp(0.5rem, 2.1vw, 1.25rem);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

body.colorblind .cell:not(.is-player-area),
body.colorblind .player-area-tile {
  background-image: var(--cell-pattern);
  background-size: 0.7rem 0.7rem;
}

body.colorblind .cell-symbol {
  opacity: 0.9;
}

.player-area-tile.is-captured {
  animation: capture 420ms cubic-bezier(0.2, 0.85, 0.25, 1.25) both;
  animation-delay: var(--capture-delay, 0ms);
}

@keyframes capture {
  0% {
    filter: brightness(1.8);
  }
  55% {
    filter: brightness(1.25);
  }
  100% {
    filter: brightness(1);
  }
}

.result-overlay {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  padding: clamp(1.2rem, 4vw, 3rem);
  place-items: center;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(122, 92, 255, 0.13), rgba(232, 62, 140, 0.08));
  animation: resultReveal 360ms ease-out both;
}

.result-overlay[hidden] {
  display: none;
}

.result-card {
  width: min(100%, 34rem);
  padding: clamp(1.5rem, 5vw, 3rem);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 1.5rem;
  background: linear-gradient(145deg, rgba(72, 55, 132, 0.66), rgba(43, 33, 87, 0.58));
  box-shadow: 0 1.5rem 4rem rgba(66, 45, 145, 0.3);
  backdrop-filter: blur(0.18rem);
  text-align: center;
}

.result-icon {
  display: grid;
  width: clamp(4.5rem, 12vw, 7rem);
  margin: 0 auto 1.2rem;
  place-items: center;
  aspect-ratio: 1;
  border: 2px solid currentColor;
  border-radius: 50%;
  color: var(--success);
  background: rgba(101, 229, 165, 0.12);
  box-shadow: 0 0 2.5rem rgba(101, 229, 165, 0.3);
  font-size: clamp(2rem, 7vw, 3.8rem);
}

.result-overlay[data-result="won"] {
  background: linear-gradient(135deg, rgba(101, 229, 165, 0.12), rgba(122, 92, 255, 0.08));
}

.result-overlay[data-result="lost"] {
  background: linear-gradient(135deg, rgba(255, 123, 145, 0.12), rgba(122, 92, 255, 0.07));
}

.result-overlay[data-result="lost"] .result-card {
  background: linear-gradient(145deg, rgba(121, 55, 86, 0.62), rgba(60, 38, 88, 0.56));
  box-shadow: 0 1.5rem 4rem rgba(145, 45, 91, 0.25);
}

.result-overlay[data-result="lost"] .result-icon {
  color: var(--danger);
  background: rgba(255, 123, 145, 0.12);
  box-shadow: 0 0 2.5rem rgba(255, 123, 145, 0.25);
}

.result-card h2 {
  margin-top: 0.35rem;
  font-size: clamp(2.1rem, 7vw, 4rem);
}

.result-card > p:not(.eyebrow) {
  max-width: 29rem;
  margin: 1rem auto 0;
  color: var(--text);
  font-size: clamp(0.9rem, 2vw, 1.05rem);
}

.result-card .result-time {
  width: fit-content;
  padding: 0.5rem 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  color: white;
  background: rgba(255, 255, 255, 0.09);
  font-size: clamp(1rem, 3vw, 1.35rem);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.result-actions {
  display: flex;
  margin-top: 1.6rem;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.result-actions button,
.result-actions .primary-button {
  width: auto;
  min-width: 10rem;
}

@keyframes resultReveal {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
.palette-section {
  margin-top: 1rem;
}

.palette {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(3.8rem, 1fr));
  gap: 0.55rem;
}

.palette-button {
  position: relative;
  display: grid;
  min-height: 3.65rem;
  padding: 0.35rem;
  place-items: center;
  border: 2px solid transparent;
  color: var(--cell-ink);
  background-color: var(--cell-color);
  background-image: var(--cell-pattern);
  background-size: 0.8rem 0.8rem;
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.28),
    0 0.4rem 1rem rgba(0, 0, 0, 0.2);
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    opacity 150ms ease;
}

.palette-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.28),
    0 0.7rem 1.4rem rgba(0, 0, 0, 0.3);
}

.palette-button.is-current {
  border-color: white;
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.2),
    inset 0 1px rgba(255, 255, 255, 0.3);
}

.palette-button.is-hint {
  animation: hintPulse 800ms ease-in-out infinite alternate;
}

.palette-symbol {
  font-size: 1.25rem;
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.palette-button kbd {
  position: absolute;
  right: 0.25rem;
  bottom: 0.25rem;
  color: inherit;
  background: rgba(0, 0, 0, 0.28);
}

@keyframes hintPulse {
  to {
    box-shadow:
      0 0 0 4px var(--accent),
      0 0 1.4rem var(--accent);
    transform: translateY(-2px);
  }
}

.keyboard-help {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.7;
  text-align: center;
}

footer {
  width: min(94vw, 90rem);
  margin: 0 auto;
  padding: 1.4rem 0 2rem;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

[data-color="0"] {
  --cell-color: #e83e8c;
  --cell-ink: #fff;
  --cell-pattern: repeating-linear-gradient(45deg, transparent 0 5px, rgba(0, 0, 0, 0.22) 5px 7px);
}

[data-color="1"] {
  --cell-color: #3b82f6;
  --cell-ink: #fff;
  --cell-pattern: repeating-linear-gradient(-45deg, transparent 0 5px, rgba(255, 255, 255, 0.24) 5px 7px);
}

[data-color="2"] {
  --cell-color: #f97316;
  --cell-ink: #1f1205;
  --cell-pattern: radial-gradient(circle, rgba(0, 0, 0, 0.28) 0 2px, transparent 2.5px);
}

[data-color="3"] {
  --cell-color: #14b8a6;
  --cell-ink: #062b27;
  --cell-pattern: linear-gradient(90deg, transparent 45%, rgba(0, 0, 0, 0.23) 45% 55%, transparent 55%);
}

[data-color="4"] {
  --cell-color: #eab308;
  --cell-ink: #291e02;
  --cell-pattern: linear-gradient(0deg, transparent 42%, rgba(0, 0, 0, 0.24) 42% 58%, transparent 58%);
}

[data-color="5"] {
  --cell-color: #8b5cf6;
  --cell-ink: #fff;
  --cell-pattern: repeating-linear-gradient(0deg, transparent 0 4px, rgba(255, 255, 255, 0.2) 4px 5px);
}

[data-color="6"] {
  --cell-color: #22c55e;
  --cell-ink: #062d14;
  --cell-pattern: repeating-linear-gradient(90deg, transparent 0 4px, rgba(0, 0, 0, 0.2) 4px 5px);
}

[data-color="7"] {
  --cell-color: #ef4444;
  --cell-ink: #fff;
  --cell-pattern: conic-gradient(from 45deg, rgba(0, 0, 0, 0.22) 0 25%, transparent 0 75%, rgba(0, 0, 0, 0.22) 0);
}

[data-color="8"] {
  --cell-color: #06b6d4;
  --cell-ink: #05282e;
  --cell-pattern: repeating-radial-gradient(circle, transparent 0 3px, rgba(0, 0, 0, 0.2) 3px 4px);
}

[data-color="9"] {
  --cell-color: #64748b;
  --cell-ink: #fff;
  --cell-pattern: repeating-linear-gradient(135deg, transparent 0 3px, rgba(255, 255, 255, 0.22) 3px 4px);
}

@media (max-width: 62rem) {
  .hero {
    align-items: stretch;
    flex-direction: column;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }

  .settings-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .seed-field {
    grid-column: span 2;
  }
}

@media (max-width: 42rem) {
  .hero {
    gap: 1rem;
  }

  .scoreboard {
    min-width: 0;
  }

  .scoreboard div {
    padding: 0.7rem 0.4rem;
  }

  .settings-grid {
    grid-template-columns: 1fr 1fr;
  }

  .seed-field {
    grid-column: 1 / -1;
  }

  .game-heading {
    display: grid;
  }

  .status-message {
    max-width: none;
    text-align: left;
  }

  .board-frame {
    min-height: 12rem;
  }
}

@media (max-width: 27rem) {
  .settings-grid,
  .actions {
    grid-template-columns: 1fr;
  }

  .seed-field {
    grid-column: auto;
  }

  .palette {
    grid-template-columns: repeat(5, 1fr);
  }
}

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