:root {
  --bg: #111214;
  --panel: #1b1d21;
  --line: #2c2f35;
  --text: #e8e6e3;
  --muted: #8d9199;
  --accent: #76af4e;
  --light: #f0d9b5;
  --dark: #b58863;
  --last: rgba(205, 210, 106, 0.55);
  --selected: rgba(20, 85, 30, 0.5);
  --board: min(92vw, calc(100vh - 150px));
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main { padding: 16px; }

button, select, input {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
}

button { cursor: pointer; }
button:hover { border-color: var(--accent); }

/* Lobby */

.lobby { max-width: 420px; margin: 8vh auto; }
.lobby h1 { display: flex; align-items: center; gap: 10px; margin: 0 0 4px; font-size: 28px; }
.lobby h1 img { width: 36px; height: 36px; }
.tagline { color: var(--muted); margin: 0 0 24px; }
.lobby form { display: grid; gap: 14px; }
.lobby label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.lobby button[type=submit] { background: var(--accent); color: #0b0c0d; font-weight: 600; border: 0; padding: 12px; }
.error { color: #e07070; }

/* Game layout */

.game { display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; align-items: flex-start; }
.board-col { width: var(--board); }
.info {
  width: min(92vw, 300px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 12px;
}

.player {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "who reserve clock" "mana mana clock";
  align-items: center;
  column-gap: 12px;
  min-height: 56px;
  padding: 6px 2px;
}
.player .who { grid-area: who; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.player .dot { width: 8px; height: 8px; border-radius: 50%; background: #555; }
.player .dot.on { background: var(--accent); }
.player .reserve { grid-area: reserve; display: flex; flex-wrap: wrap; gap: 2px 8px; color: var(--muted); font-size: 13px; }
.player .res { display: inline-flex; align-items: center; }
.player .res img { width: 20px; height: 20px; }
.player .mana { grid-area: mana; display: flex; gap: 2px; min-height: 22px; }
.player .mana img { width: 20px; height: 20px; }
.player .mana img[src*=full] { filter: drop-shadow(0 0 3px rgba(118, 175, 78, 0.6)); }
.player .clock {
  grid-area: clock;
  font: 600 26px/1 ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  min-width: 96px;
  text-align: right;
  opacity: 0.6;
}
.player .clock.running { opacity: 1; border-color: var(--accent); }
.player .clock.low.running { color: #ff8a80; }

/* Board */

.board {
  position: relative;
  width: var(--board);
  height: var(--board);
  user-select: none;
  touch-action: none;
  border-radius: 4px;
  overflow: hidden;
}
.sq { position: absolute; width: 12.5%; height: 12.5%; }
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq.last { box-shadow: inset 0 0 0 999px var(--last); }
.sq.selected { box-shadow: inset 0 0 0 999px var(--selected); }
.sq.check { background-image: radial-gradient(circle, #ff0000 0%, rgba(231, 0, 0, 0.9) 25%, rgba(169, 0, 0, 0) 90%); }
.sq.target::after {
  content: "";
  position: absolute;
  inset: 37%;
  border-radius: 50%;
  background: rgba(20, 85, 30, 0.45);
}
.sq.over { box-shadow: inset 0 0 0 999px rgba(255, 255, 255, 0.45); }
.sq.target.over::after, .sq.capture.over::after { display: none; }
.sq.capture::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 6px rgba(20, 85, 30, 0.45);
}
.coords { position: absolute; inset: 0; pointer-events: none; }
.coord { position: absolute; font-size: 11px; font-weight: 600; opacity: 0.8; color: var(--light); line-height: 1; }
.coord.on-light { color: var(--dark); }
.coord.file { bottom: 1px; width: 12.5%; text-align: right; padding-right: 3px; box-sizing: border-box; }
.coord.rank { left: 3px; height: 12.5%; padding-top: 1px; }

.ghosts, .pieces, .promo, .fx { position: absolute; inset: 0; pointer-events: none; }
.coords { z-index: 6; }
.resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 22px;
  height: 22px;
  z-index: 15;
  cursor: nwse-resize;
  touch-action: none;
  opacity: 0.55;
  background:
    radial-gradient(circle, #fff 1.3px, transparent 1.6px) 15px 15px / 6px 6px no-repeat,
    radial-gradient(circle, #fff 1.3px, transparent 1.6px) 9px 15px / 6px 6px no-repeat,
    radial-gradient(circle, #fff 1.3px, transparent 1.6px) 15px 9px / 6px 6px no-repeat,
    radial-gradient(circle, #fff 1.3px, transparent 1.6px) 3px 15px / 6px 6px no-repeat,
    radial-gradient(circle, #fff 1.3px, transparent 1.6px) 9px 9px / 6px 6px no-repeat,
    radial-gradient(circle, #fff 1.3px, transparent 1.6px) 15px 3px / 6px 6px no-repeat;
  filter: drop-shadow(0 0 1px #000);
}
.resize-handle:hover, .board:has(.resize-handle:active) .resize-handle { opacity: 1; }
.fx { width: 100%; height: 100%; z-index: 5; }
.ghost { position: absolute; width: 12.5%; height: 12.5%; animation: ghost-in var(--ghost-in, 120ms) ease-out; }
.ghost.out { animation: ghost-out var(--ghost-out, 120ms) ease-in forwards; pointer-events: none; }
.ghost img { position: absolute; inset: 0; width: 100%; height: 100%; opacity: var(--ghost-opacity, 0.45); }
@keyframes ghost-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes ghost-out { from { opacity: 1; } to { opacity: 0; } }
.ghost .cost {
  position: absolute;
  right: 4%;
  top: 4%;
  width: 34%;
  height: 34%;
  display: grid;
  place-items: center;
  background: url(/img/mana-full.png) center / contain no-repeat;
  color: #fff;
  font-weight: 700;
  font-size: calc(var(--board) / 42);
  text-shadow: 0 0 2px #000, 0 0 2px #000;
}

.piece {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  transition: transform 150ms ease;
  will-change: transform;
}
.piece.dragging { transition: none; z-index: 10; pointer-events: none; }
.piece.arriving { visibility: hidden; } /* drawn by the summon effect meanwhile */
.piece.appear { animation: summon-pop 200ms ease-out; } /* fallback without WebGL */
@keyframes summon-pop {
  0% { scale: 0; opacity: 0; }
  60% { scale: 1.15; opacity: 1; }
  100% { scale: 1; }
}

.promo.open { pointer-events: auto; background: rgba(0, 0, 0, 0.35); z-index: 20; }
.promo .choice {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  background: #f5f5f5;
  border-radius: 50%;
  cursor: pointer;
}
.promo .choice img { width: 100%; height: 100%; }

/* Side panel */

.status { font-weight: 600; }
.status.over { color: var(--accent); }
.share { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.share input { width: 100%; }
.controls { display: flex; gap: 10px; align-items: center; }
.controls a { color: var(--muted); }
.turns {
  margin: 0;
  padding-left: 28px;
  max-height: 40vh;
  overflow-y: auto;
  font: 13px/1.6 ui-monospace, Menlo, monospace;
  color: var(--muted);
}

/* Sandbox */

.sandbox .side { display: grid; gap: 16px; align-content: start; }
.sandbox .info { width: min(92vw, 320px); }

.sandbox .info h2 { margin: 4px 0 0; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.sandbox .row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.sandbox .sliders .row { grid-template-columns: 96px 1fr 64px; }
.sandbox .sliders .num { width: 64px; padding: 3px 4px; font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.sandbox input[type=range] { width: 100%; padding: 0; accent-color: var(--accent); }
.sandbox input[type=color] { width: 44px; height: 28px; padding: 2px; }
.sandbox .swatches { display: flex; gap: 6px; }
.sandbox .swatches button { flex: 1; padding: 6px 4px; font-size: 12px; border-left: 6px solid var(--swatch); }
.sandbox .swatches button.on { border-color: var(--accent); }
.sandbox .presets { display: grid; gap: 8px; }
.sandbox .preset-status, .sandbox .geo-status, .sandbox .ghost-status { font-size: 12px; color: var(--muted); min-height: 1.4em; }
.sandbox .controls button { padding: 6px 10px; }
.sandbox .controls label { color: var(--muted); font-size: 13px; }
.sandbox button:disabled { opacity: 0.4; cursor: default; }

/* Sandbox sound library, below the board. */
.sandbox .sound-panel { margin-top: 14px; padding: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.sound-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.sound-heading h2 { margin: 0; font-size: 18px; }
.sound-count, .sound-intro, .sound-status { color: var(--muted); font-size: 12px; }
.sound-intro { margin: 6px 0 14px; }
.sound-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 10px 0; }
.sound-toolbar label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.sandbox .sound-volume { width: 100px; }
.sound-panel button { padding: 5px 9px; font-size: 12px; }
.sound-slots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.sound-slot { display: grid; grid-template-columns: 1fr 26px; gap: 4px; min-width: 0; }
.sound-slot strong { grid-column: 1 / -1; text-transform: capitalize; font-size: 12px; }
.sound-slot button { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.sound-filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-top: 14px; }
.sound-filters input[type=search], .sound-filters select { width: 100%; min-width: 0; font-size: 12px; padding: 7px; }
.sound-filters label { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.sound-status { min-height: 2.8em; margin: 8px 0; overflow-wrap: anywhere; }
.sound-list { max-height: 440px; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
.sound-list h3 { position: sticky; top: 0; z-index: 1; margin: 0; padding: 8px 0; background: var(--panel); font-size: 12px; color: var(--muted); }
.sound-clip { display: grid; grid-template-columns: 30px minmax(0, 1fr) 30px 94px; gap: 6px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--line); }
.sound-name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sound-clip select { width: 100%; min-width: 0; font-size: 11px; padding: 5px 3px; }
.sound-panel .playing, .sound-star[aria-pressed=true] { color: var(--accent); border-color: var(--accent); }
.sound-credits { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 12px; }
.sound-credits a { font-size: 10px; color: var(--muted); }
@media (max-width: 420px) {
  .sandbox .sound-panel { padding: 10px; }
  .sound-filters { grid-template-columns: minmax(0, 1fr); }
  .sound-clip { grid-template-columns: 27px minmax(0, 1fr) 27px 82px; gap: 4px; }
}

.sound-slot .sound-edit{grid-column:1/-1;text-align:center;color:var(--accent)}
