:root {
  color-scheme: dark;
  --bg: #080907;
  --panel: #11170f;
  --panel-soft: #192012;
  --ink: #f6f1e4;
  --muted: #aaa792;
  --line: #33402b;
  --acid: #b6f44f;
  --hot: #ff7042;
  --cool: #7ec7d8;
  --warn: #ffd15c;
  --bad: #ff5268;
  --tile-prompt: #b6f44f;
  --tile-token: #ffd15c;
  --tile-model: #7ec7d8;
  --tile-cache: #b08cff;
  --tile-spam: #ff7042;
  --tile-bug: #ff5268;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(8, 9, 7, 0.72), var(--bg)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 70px),
    repeating-linear-gradient(0deg, rgba(182, 244, 79, 0.028) 0 1px, transparent 1px 70px),
    radial-gradient(circle at 14% 11%, rgba(126, 199, 216, 0.17), transparent 28%),
    radial-gradient(circle at 86% 8%, rgba(255, 112, 66, 0.16), transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family:
    "Trebuchet MS", "Gill Sans", Avenir, ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--acid);
}

button:disabled {
  cursor: default;
  opacity: 0.52;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  margin-bottom: 24px;
}

.studio-link {
  color: var(--muted);
  font-size: 14px;
  font-weight: 900;
  text-decoration: none;
}

.studio-link:hover {
  color: var(--ink);
}

.game-title {
  text-align: center;
}

.game-title p,
.stats span {
  margin: 0 0 6px;
  color: var(--acid);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(44px, 8vw, 94px);
  line-height: 0.84;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-self: end;
  justify-content: flex-end;
  gap: 8px;
}

.audio-button,
.settings-button,
.new-button {
  min-width: 72px;
  min-height: 42px;
  padding: 0 14px;
  font-weight: 900;
}

.audio-button.on {
  border-color: rgba(126, 199, 216, 0.74);
  background: rgba(126, 199, 216, 0.18);
  color: #d9f8fb;
}

.game-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.side-panel {
  position: sticky;
  top: 18px;
  border: 1px solid var(--line);
  background: rgba(17, 23, 15, 0.94);
  padding: 18px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stats div {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #10150d;
}

.stats strong {
  font-size: 24px;
}

.mode-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 14px;
  border: 1px solid var(--line);
}

.segment {
  min-height: 42px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  font-size: 13px;
  font-weight: 900;
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  background: var(--acid);
  color: #101608;
}

.brief-panel {
  min-height: 112px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid rgba(255, 112, 66, 0.45);
  background:
    linear-gradient(135deg, rgba(255, 112, 66, 0.16), transparent 54%),
    #10150d;
  color: #f8d8c7;
  line-height: 1.4;
}

.legend {
  display: grid;
  gap: 8px;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 32px;
  color: var(--muted);
  font-weight: 850;
}

.swatch {
  width: 18px;
  height: 18px;
  border: 1px solid rgba(246, 241, 228, 0.34);
}

.swatch-prompt { background: var(--tile-prompt); }
.swatch-token { background: var(--tile-token); }
.swatch-model { background: var(--tile-model); }
.swatch-cache { background: var(--tile-cache); }
.swatch-spam { background: var(--tile-spam); }
.swatch-bug { background: var(--tile-bug); }

.board-wrap {
  display: grid;
  justify-items: center;
  gap: 16px;
}

.board-shell {
  width: min(100%, 700px);
  padding: clamp(8px, 1.8vw, 16px);
  border: 3px solid var(--ink);
  background:
    linear-gradient(135deg, rgba(182, 244, 79, 0.16), transparent 35%),
    linear-gradient(315deg, rgba(126, 199, 216, 0.14), transparent 32%),
    #0d120b;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: clamp(5px, 1vw, 9px);
  aspect-ratio: 1;
  touch-action: none;
}

.tile {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  border: 1px solid rgba(246, 241, 228, 0.2);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.26), transparent 42%),
    var(--tile-color);
  color: #080907;
  font-size: clamp(18px, 4.7vw, 34px);
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 1px rgba(255, 255, 255, 0.24);
  touch-action: none;
  user-select: none;
  transition:
    transform 150ms ease,
    filter 150ms ease,
    opacity 150ms ease,
    outline-color 150ms ease;
}

.tile::after {
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(8, 9, 7, 0.22);
  content: "";
  pointer-events: none;
}

.tile:hover {
  filter: brightness(1.08);
  transform: translateY(-2px);
}

.tile.selected {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
  transform: translateY(-3px) scale(1.03);
  z-index: 2;
}

.tile.clearing {
  opacity: 0.2;
  transform: scale(0.72) rotate(7deg);
  animation: clear-pop 160ms ease-in forwards;
}

.tile.dropping {
  animation: tile-drop 280ms cubic-bezier(0.14, 0.88, 0.28, 1.22);
}

.tile.dragging {
  z-index: 5;
  filter: brightness(1.16);
  transform: translate(var(--drag-x, 0), var(--drag-y, 0)) scale(1.08);
  transition: none;
}

.tile.boost::before {
  position: absolute;
  inset: 9px;
  border: 2px solid rgba(8, 9, 7, 0.38);
  content: "";
  transform: rotate(45deg);
}

.tile[data-kind="prompt"] { --tile-color: var(--tile-prompt); }
.tile[data-kind="token"] { --tile-color: var(--tile-token); }
.tile[data-kind="model"] { --tile-color: var(--tile-model); }
.tile[data-kind="cache"] { --tile-color: var(--tile-cache); }
.tile[data-kind="spam"] { --tile-color: var(--tile-spam); }
.tile[data-kind="bug"] { --tile-color: var(--tile-bug); }

@keyframes tile-drop {
  0% {
    opacity: 0.35;
    transform: translateY(calc(var(--drop-distance, 1) * -118%)) scale(0.92);
  }

  72% {
    opacity: 1;
    transform: translateY(5%) scale(1.02);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes clear-pop {
  0% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }

  100% {
    opacity: 0.16;
    transform: scale(0.55) rotate(9deg);
  }
}

.hint-strip {
  width: min(100%, 700px);
  min-height: 46px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(17, 23, 15, 0.9);
  color: var(--muted);
  font-weight: 850;
  line-height: 1.3;
}

.result-dialog,
.settings-dialog {
  width: min(430px, calc(100% - 28px));
  border: 1px solid var(--acid);
  background: var(--panel);
  color: var(--ink);
  padding: 24px;
}

.settings-dialog {
  width: min(520px, calc(100% - 28px));
}

.result-dialog:not([open]),
.settings-dialog:not([open]) {
  display: none;
}

.result-dialog[open],
.settings-dialog[open] {
  display: block;
  position: fixed;
  inset: 50% auto auto 50%;
  max-height: calc(100vh - 28px);
  overflow: auto;
  transform: translate(-50%, -50%);
  z-index: 40;
}

.result-dialog::backdrop,
.settings-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.result-dialog h2,
.settings-dialog h2 {
  margin-bottom: 10px;
  font-size: 32px;
}

.result-dialog p,
.settings-dialog p {
  color: var(--muted);
  line-height: 1.5;
}

.setting-row {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr) 58px;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #10150d;
}

.setting-row label,
.setting-row strong {
  font-weight: 900;
}

.setting-row input {
  width: 100%;
  accent-color: var(--acid);
}

.result-dialog button,
.settings-dialog button {
  width: 100%;
  min-height: 46px;
  background: var(--acid);
  color: #101608;
  font-weight: 900;
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .game-title {
    grid-column: 1 / -1;
    grid-row: 1;
    text-align: left;
  }

  .studio-link,
  .top-actions {
    grid-row: 2;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
    order: 2;
  }

  .board-wrap {
    order: 1;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 16px, 1180px);
    padding-top: 12px;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .stats div {
    min-height: 58px;
    padding: 8px;
  }

  .stats span {
    font-size: 10px;
  }

  .stats strong {
    font-size: 17px;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button {
    flex: 1 1 92px;
    min-width: 0;
    padding: 0 10px;
  }

  .legend {
    grid-template-columns: repeat(2, 1fr);
  }
}
