:root {
  color-scheme: dark;
  --bg: #071517;
  --panel: #102125;
  --panel-2: #172e32;
  --text: #eef7ee;
  --muted: #9fb8ae;
  --line: #2e4c4f;
  --green: #23d2a7;
  --gold: #f6c646;
  --red: #ee5d6c;
  --blue: #4da3ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 20% 10%, #173236 0, transparent 26rem), var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
  align-items: stretch;
}

.game-panel,
.side-panel {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border-radius: 8px;
}

.game-panel {
  display: grid;
  grid-template-rows: auto minmax(300px, 1fr) auto;
  gap: 16px;
  padding: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 4.6rem);
  line-height: 0.95;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(78px, 1fr));
  gap: 8px;
  min-width: 280px;
}

.metrics span,
.economy span {
  display: grid;
  gap: 2px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b191c;
  color: var(--muted);
}

.metrics b,
.economy b {
  color: var(--text);
  font-size: 1.2rem;
}

.board {
  align-self: center;
  justify-self: center;
  width: min(72vh, 100%);
  max-width: 680px;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 5px;
  touch-action: none;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  border: 1px solid #28464a;
  border-radius: 6px;
  background: #0d2023;
  overflow: hidden;
}

.cell::before {
  content: "";
  width: 42%;
  aspect-ratio: 1;
  border-radius: 3px;
  transform: rotate(45deg);
  background: #31585b;
}

.cell.glyph::before {
  background: var(--green);
  box-shadow: 0 0 18px #23d2a766;
}

.cell.key::before {
  width: 28%;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 18px #f6c64677;
}

.cell.gate::before {
  width: 68%;
  border: 2px solid var(--blue);
  background: transparent;
}

.cell.hazard::before {
  width: 52%;
  border-radius: 50% 50% 50% 0;
  background: var(--red);
}

.cell.exit::before {
  width: 58%;
  border-radius: 50%;
  border: 3px solid var(--gold);
  background: transparent;
}

.cell.collected {
  opacity: 0.38;
}

.cell.player {
  outline: 3px solid var(--text);
  outline-offset: -4px;
}

.controls {
  display: grid;
  grid-template-columns: repeat(4, 54px);
  gap: 10px;
  justify-content: center;
}

button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  min-height: 44px;
  border-radius: 6px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--green);
}

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

.icon-button {
  width: 54px;
  font-size: 1.4rem;
}

.side-panel {
  padding: 16px;
  display: grid;
  grid-template-rows: auto auto auto auto auto minmax(0, 1fr);
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  min-height: 120px;
}

.brand-mark svg {
  width: min(120px, 48vw);
}

.mode-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.wallet-label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  background: #081416;
  color: var(--text);
  border-radius: 6px;
  min-height: 42px;
  padding: 0 10px;
}

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

.leaderboard {
  min-height: 0;
  overflow: auto;
  margin: 0;
  padding-left: 1.4rem;
}

.leaderboard li {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .topbar {
    display: grid;
  }

  .metrics {
    min-width: 0;
    grid-template-columns: repeat(3, 1fr);
  }

  .board {
    width: min(94vw, 72vh);
  }

  .side-panel {
    grid-template-rows: none;
  }
}
