: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;
}

.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;
}

.actions {
  display: grid;
  margin-bottom: 14px;
}

.actions button {
  min-height: 42px;
  background: rgba(126, 199, 216, 0.14);
  color: #d9f8fb;
  font-weight: 900;
}

.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 {
  position: relative;
  overflow: hidden;
  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-shell.hot {
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.38),
    0 0 28px rgba(255, 209, 92, 0.18);
}

.board-shell.overdrive {
  border-color: var(--warn);
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.38),
    0 0 42px rgba(255, 112, 66, 0.28);
}

.board-shell.pulse {
  animation: board-pulse 420ms ease;
}

.board-shell.checkpoint {
  animation: checkpoint-pulse 620ms ease;
}

.board-shell.shake {
  animation: board-shake 320ms ease;
}

.board-shell.shake-strong {
  animation: board-shake-strong 420ms ease;
}

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

.effect-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow: hidden;
  pointer-events: none;
}

.score-float {
  position: absolute;
  color: var(--ink);
  font-size: clamp(18px, 3.2vw, 30px);
  font-weight: 950;
  text-shadow:
    0 2px 0 #080907,
    0 0 18px rgba(182, 244, 79, 0.5);
  transform: translate(-50%, -50%);
  animation: score-float 900ms ease-out forwards;
  white-space: nowrap;
}

.score-float.hot {
  color: var(--warn);
  text-shadow:
    0 2px 0 #080907,
    0 0 22px rgba(255, 112, 66, 0.7);
}

.clear-particle {
  position: absolute;
  width: 9px;
  height: 9px;
  border: 1px solid rgba(246, 241, 228, 0.8);
  background: var(--acid);
  transform: translate(-50%, -50%);
  animation: clear-particle 650ms ease-out forwards;
}

.combo-banner {
  min-height: 38px;
  color: var(--warn);
  font-size: clamp(18px, 3vw, 30px);
  font-weight: 950;
  opacity: 0;
  text-align: center;
  text-shadow:
    0 2px 0 #080907,
    0 0 22px rgba(255, 112, 66, 0.6);
  transform: translateY(-6px) scale(0.96);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.combo-banner.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.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.special::before {
  position: absolute;
  inset: 9px;
  border: 2px solid rgba(8, 9, 7, 0.38);
  content: "";
  transform: rotate(45deg);
}

.tile.prism::before {
  inset: 11px;
  border-color: rgba(246, 241, 228, 0.88);
  border-radius: 50%;
  box-shadow:
    0 0 0 3px rgba(8, 9, 7, 0.28),
    0 0 16px rgba(246, 241, 228, 0.72);
}

.tile.prism::after {
  border-color: rgba(246, 241, 228, 0.54);
  transform: rotate(45deg) scale(0.74);
}

.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);
  }
}

@keyframes score-float {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.82);
  }

  16% {
    opacity: 1;
    transform: translate(-50%, -58%) scale(1.08);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -160%) scale(0.98);
  }
}

@keyframes clear-particle {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
  }

  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.2) rotate(180deg);
  }
}

@keyframes board-pulse {
  0%,
  100% {
    filter: none;
    transform: scale(1);
  }

  45% {
    filter: brightness(1.16) saturate(1.14);
    transform: scale(1.01);
  }
}

@keyframes checkpoint-pulse {
  0%,
  100% {
    filter: none;
    transform: scale(1);
  }

  38% {
    filter: brightness(1.24) saturate(1.28);
    transform: scale(1.018);
  }
}

@keyframes board-shake {
  0%,
  100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}

@keyframes board-shake-strong {
  0%,
  100% { transform: translateX(0) scale(1); }
  18% { transform: translateX(-7px) scale(1.006); }
  36% { transform: translateX(7px) scale(1.006); }
  54% { transform: translateX(-5px) scale(1.004); }
  72% { transform: translateX(4px) scale(1.002); }
}

.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;
}

@media (min-width: 1500px) {
  .app-shell {
    width: min(1760px, calc(100% - 64px));
  }

  .game-layout {
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 32px;
  }

  .board-shell,
  .hint-strip {
    width: min(100%, 1040px);
  }

  .tile {
    font-size: clamp(24px, 1.5vw, 44px);
  }

  .score-float,
  .combo-banner {
    font-size: clamp(24px, 1.6vw, 40px);
  }
}

@media (min-width: 2600px) and (min-height: 1400px) {
  .app-shell {
    width: min(2240px, calc(100% - 96px));
  }

  .game-layout {
    grid-template-columns: 380px minmax(0, 1fr);
    gap: 40px;
  }

  .board-shell,
  .hint-strip {
    width: min(100%, 1320px);
  }

  .tile {
    font-size: clamp(36px, 1.32vw, 56px);
  }

  .score-float,
  .combo-banner {
    font-size: clamp(34px, 1.18vw, 54px);
  }
}

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

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

.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;
}

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

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

.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);
}

.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;
    gap: 12px;
    margin-bottom: 16px;
  }

  .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;
    gap: 16px;
  }

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

  .board-wrap {
    order: 1;
  }
}

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

  h1 {
    font-size: clamp(38px, 14vw, 58px);
  }

  .game-title p {
    margin-bottom: 3px;
  }

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

  .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;
  }

  .side-panel {
    padding: 12px;
  }

  .brief-panel,
  .legend {
    margin-bottom: 10px;
  }

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