:root {
  color-scheme: dark;
  --bg: #070706;
  --panel: #111510;
  --panel-soft: #181f14;
  --cell: #10140e;
  --cell-open: #1c2418;
  --ink: #f6f0e4;
  --muted: #a9a696;
  --line: #354130;
  --acid: #b6f44f;
  --hot: #ff7042;
  --warn: #ffd15c;
  --bad: #ff5268;
  --cool: #7ec7d8;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(7, 7, 6, 0.72), var(--bg)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 68px),
    repeating-linear-gradient(0deg, rgba(182, 244, 79, 0.03) 0 1px, transparent 1px 68px),
    radial-gradient(circle at 20% 8%, rgba(255, 112, 66, 0.14), transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe 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.48;
}

.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: 850;
  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(42px, 7vw, 84px);
  line-height: 0.86;
}

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

.audio-button,
.settings-button,
.new-button {
  justify-self: end;
  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: 310px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.side-panel {
  position: sticky;
  top: 18px;
  border: 1px solid var(--line);
  background: rgba(17, 21, 16, 0.92);
  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: var(--cell);
}

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

.mode-group,
.tool-group {
  display: grid;
  margin-bottom: 14px;
  border: 1px solid var(--line);
}

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

.tool-group {
  grid-template-columns: 1fr;
}

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

.tool {
  border-right: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 0 12px;
}

.segment:last-child,
.tool:last-child {
  border: 0;
}

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

.threat-panel {
  min-height: 116px;
  padding: 12px;
  border: 1px solid rgba(255, 112, 66, 0.45);
  background:
    linear-gradient(135deg, rgba(255, 112, 66, 0.16), transparent 52%),
    var(--cell);
  color: #f8d8c7;
  line-height: 1.4;
}

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

.board {
  display: grid;
  width: min(100%, 690px);
  aspect-ratio: 1;
  border: 3px solid var(--ink);
  background: var(--line);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

.tile {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  border: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(182, 244, 79, 0.08), transparent 55%),
    var(--cell);
  color: var(--ink);
  font-size: clamp(16px, 3.4vw, 28px);
  font-weight: 950;
  line-height: 1;
}

.tile.closed:hover {
  background: #202a19;
}

.tile.open {
  background: var(--cell-open);
}

.tile.flagged {
  color: var(--warn);
}

.tile.cleaned {
  color: var(--cool);
}

.tile.slop-hit {
  background:
    repeating-linear-gradient(45deg, rgba(255, 82, 104, 0.18) 0 8px, transparent 8px 16px),
    #261014;
  color: var(--bad);
}

.tile.leaked::after {
  position: absolute;
  inset: 4px;
  border: 1px dashed rgba(255, 112, 66, 0.72);
  content: "";
  pointer-events: none;
}

.tile.n1 { color: #9ad4ff; }
.tile.n2 { color: #b6f44f; }
.tile.n3 { color: #ffd15c; }
.tile.n4 { color: #ff9c5c; }
.tile.n5,
.tile.n6,
.tile.n7,
.tile.n8 { color: #ff6677; }

.action-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 10px;
  width: min(100%, 690px);
}

.action-strip button {
  min-height: 44px;
  font-weight: 850;
}

.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: var(--cell);
}

.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: 880px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

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

  .studio-link {
    grid-row: 2;
  }

  .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(4, 1fr);
  }

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

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

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

  .action-strip {
    grid-template-columns: 1fr;
  }

  .top-actions {
    width: 100%;
  }

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