:root {
  --bg: #0b0e13;
  --panel: #141922;
  --panel-2: #1c2330;
  --line: #262e3d;
  --text: #dbe3ef;
  --dim: #7d8899;
  --accent: #58d68d;
  --accent-ink: #06240f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  flex-wrap: wrap;
}

header.bar { justify-content: space-between; }

h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: .02em;
}

.stats {
  display: flex;
  gap: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
  font-size: 12px;
}
.stats b { color: var(--text); font-weight: 600; }
.dim { color: var(--dim); }

.group { display: flex; gap: 6px; }

button {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}
button:hover { border-color: #3a465c; }
button:active { transform: translateY(1px); }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  min-width: 92px;
}

.slider {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--dim);
}
.slider input { width: 108px; accent-color: var(--accent); }
.slider output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 46px;
}

.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--dim);
  cursor: pointer;
}
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.presets { gap: 8px; flex-wrap: nowrap; }
.presets-label {
  font-size: 12px;
  color: var(--dim);
  flex: 0 0 auto;
}
.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  font-size: 12px;
  padding: 6px 11px;
  border-radius: 999px;
  background: transparent;
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

#stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #05070a;
  overflow: hidden;
}

canvas {
  display: block;
  touch-action: none;
  cursor: crosshair;
  image-rendering: pixelated;
}

.hint {
  font-size: 12px;
  color: var(--dim);
  justify-content: space-between;
  border-bottom: none;
  border-top: 1px solid var(--line);
}
.hint .keys { font-size: 11px; }

@media (max-width: 720px) {
  .stats span:nth-child(4) { display: none; }
  .slider input { width: 84px; }
  .hint .keys { display: none; }
  button { padding: 8px 12px; }
}

/* ---------------------------------------------------------------- mode switch */
.modes {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  flex: 0 0 auto;
}
.mode {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  color: var(--dim);
  text-decoration: none;
  white-space: nowrap;
}
.mode:hover { color: var(--text); }
.mode.active {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

/* ----------------------------------------------------------------- scoreboard */
.scoreboard {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.side {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  transition: border-color .15s, background .15s;
}
.side b { color: var(--text); font-weight: 600; }
.side .who { color: var(--text); font-weight: 600; }
.side .swatch {
  width: 10px; height: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
}
#side-1 .swatch { background: #4d9ef0; }
#side-2 .swatch { background: #f0953d; }
#side-1.acting { border-color: #4d9ef0; background: rgba(77, 158, 240, .12); }
#side-2.acting { border-color: #f0953d; background: rgba(240, 149, 61, .12); }

/* ------------------------------------------------------------------- turn bar */
.turnbar { gap: 12px; }
.turn-label { font-size: 14px; font-weight: 600; }
.turn-sub { font-size: 12px; }
.spacer { flex: 1 1 auto; }
button:disabled { opacity: .45; cursor: default; }
button.ghost { background: transparent; color: var(--dim); }
.chip .cost {
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  margin-left: 2px;
}
.chip.active .cost { color: inherit; opacity: .7; }
.presets.disabled { opacity: .4; pointer-events: none; }

/* -------------------------------------------------------------------- overlay */
#stage { position: relative; }
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 7, 10, .78);
  padding: 20px;
  z-index: 10;
}
.overlay.hidden { display: none; }
/* Result cards cover only the board, so the header, the mode switcher and the
   level chips stay reachable while one is up. Help panels stay properly modal. */
.overlay.inline { position: absolute; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  max-width: 380px;
  text-align: center;
}
.card.wide { max-width: 560px; text-align: left; max-height: 80vh; overflow-y: auto; }
.card h2 { margin: 0 0 10px; font-size: 19px; }
.card p { margin: 0 0 18px; color: var(--dim); font-size: 13px; }
.card ul { margin: 0 0 18px; padding-left: 18px; color: var(--dim); font-size: 13px; }
.card li { margin-bottom: 9px; }
.card li b { color: var(--text); font-weight: 600; }

@media (max-width: 720px) {
  header.bar h1 { display: none; }
  .bar { padding: 6px 10px; gap: 8px; }
  .scoreboard { gap: 6px; }
  .side { padding: 4px 8px; gap: 5px; }
  .side .who { display: none; }
  /* keep the label, Done and Restart on one row; the round line drops below */
  .turnbar .spacer { display: none; }
  .turn-label {
    font-size: 13px;
    flex: 1 1 0;          /* zero basis, so the buttons never get wrapped off the row */
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .turn-sub { width: 100%; order: 3; }
  /* one scrollable row rather than two stacked ones */
  .controls {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .controls::-webkit-scrollbar { display: none; }
  .controls > * { flex: 0 0 auto; }
}

/* --------------------------------------------------------------------- puzzle */
.levels { gap: 8px; flex-wrap: nowrap; }
.levels .chip { min-width: 38px; text-align: center; }
.stats .over b { color: #f0953d; }
.stats .goal { color: #6f7a8c; }
.stats .goal b { color: #9aa6b8; }
.card-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}
/* the arena is bounded, unlike the other modes — the frame says so */
#stage canvas {
  border-radius: 4px;
  box-shadow: 0 0 0 1px #2f3949, 0 8px 30px rgba(0, 0, 0, .45);
}

/* --------------------------------------------------------- puzzle action bar */
.actions { gap: 8px; }
.actions .spacer { flex: 1 1 auto; }
@media (max-width: 720px) {
  .actions { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .actions::-webkit-scrollbar { display: none; }
  .actions > * { flex: 0 0 auto; }
  .actions .spacer { display: none; }
}
