/* Skitter — one stylesheet, no build step, no external requests. */

:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #18202a;
  --ink-soft: #5b6673;
  --line: #d8dde4;
  --tile: #eceff3;
  --tile-line: #dbe0e7;
  --wall: #55606d;

  --runner: #3f9e6a;
  --blocker: #6b7889;
  --goal: #cba32f;
  --focus: #4d7fc4;

  --on-colour: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d;
    --surface: #1a212a;
    --ink: #e9edf2;
    --ink-soft: #9aa5b3;
    --line: #2c3542;
    --tile: #1e2732;
    --tile-line: #263141;
    --wall: #46525f;

    --runner: #3f9e6a;
    --blocker: #6b7889;
    --goal: #c8a53a;
  }
}

* {
  box-sizing: border-box;
}

/*
 * The UA rule for [hidden] is `display: none` at element specificity, so any
 * class that sets `display` silently beats it. Keep this above every display
 * rule or hidden dialogs stay painted on screen.
 */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem max(0.75rem, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.wordmark {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid transparent;
  border-radius: 50%;
  background: none;
  color: var(--ink-soft);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.icon-button:hover {
  background: var(--tile);
  color: var(--ink);
}

.icon-button:focus-visible,
.button:focus-visible,
.pad-key:focus-visible,
.pad-centre:focus-visible,
.help-link:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------- app */

.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  max-width: 26rem;
  margin: 0 auto;
  padding: 0.75rem 0.75rem max(1rem, env(safe-area-inset-bottom));
}

.loading {
  margin: 3rem auto;
  color: var(--ink-soft);
}

.puzzle-line {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.puzzle-line .dot {
  margin: 0 0.35rem;
  opacity: 0.5;
}

#score-line.over {
  color: var(--goal);
  font-weight: 600;
}

#score-line.solved {
  color: var(--runner);
  font-weight: 600;
}

.help-link {
  padding: 0;
  border: none;
  background: none;
  color: var(--focus);
  font: inherit;
  font-size: 0.85rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.prompt {
  min-height: 1.4rem;
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.prompt.win {
  color: var(--runner);
  font-weight: 600;
}

/* ----------------------------------------------------------------- board */

.board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

/*
 * Cells are laid out on a grid with no gaps, and pieces are absolutely
 * positioned on top at percentage offsets. That keeps the arithmetic exact —
 * one cell is always 10% — and lets a piece animate between squares by
 * transitioning left/top rather than being re-parented.
 */
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cells, 10), 1fr);
  width: min(100%, 22rem);
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--tile);
  touch-action: none;
  user-select: none;
}

.square {
  box-shadow: inset 0 0 0 1px var(--tile-line);
}

.square.wall {
  background: var(--wall);
  box-shadow: none;
}

/* The target sits under the pieces, so it stays visible until one lands. */
.square.goal::after {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  border: 3px solid var(--goal);
}

.square.goal {
  position: relative;
}

/*
 * No percentage padding here. Percentage padding resolves against the
 * *containing block's* width, not the element's, so `padding: 8%` on a piece
 * meant 8% of the whole board — which swallowed the piece's own 10% box and
 * collapsed every piece to nothing. Size the inner shape instead, where a
 * percentage means what it looks like it means.
 */
.piece {
  position: absolute;
  display: grid;
  place-items: center;
  width: 10%;
  height: 10%;
  transition: left 170ms cubic-bezier(0.2, 0.8, 0.3, 1),
    top 170ms cubic-bezier(0.2, 0.8, 0.3, 1);
  cursor: pointer;
}

.piece::after {
  content: "";
  display: block;
  width: 76%;
  height: 76%;
  border-radius: 50%;
  background: var(--blocker);
}

.piece.runner::after {
  background: var(--runner);
}

/* A square blocker reads as furniture; a round runner reads as the thing that
   moves. Shape carries the distinction as well as colour. */
.piece:not(.runner)::after {
  border-radius: 22%;
}

.piece.selected::after {
  box-shadow: 0 0 0 2px var(--tile), 0 0 0 4px var(--focus);
}

@media (prefers-reduced-motion: reduce) {
  .piece {
    transition: none;
  }
}

/* ------------------------------------------------------------------- pad */

.pad {
  display: grid;
  grid-template-columns: repeat(3, 3.2rem);
  grid-template-rows: repeat(3, 3.2rem);
  gap: 0.3rem;
  margin-top: auto;
}

.pad-key,
.pad-centre {
  border: none;
  border-radius: 8px;
  background: var(--tile);
  color: var(--ink);
  font-size: 1.2rem;
  cursor: pointer;
}

.pad-centre {
  font-size: 1rem;
  color: var(--ink-soft);
}

.pad-key:active,
.pad-centre:active {
  background: var(--tile-line);
}

.pad-key.up { grid-area: 1 / 2; }
.pad-key.left { grid-area: 2 / 1; }
.pad-centre { grid-area: 2 / 2; }
.pad-key.right { grid-area: 2 / 3; }
.pad-key.down { grid-area: 3 / 2; }

/* -------------------------------------------------------------- controls */

.controls {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  max-width: 22rem;
}

.button {
  flex: 1;
  padding: 0.7rem;
  border: none;
  border-radius: 8px;
  background: var(--runner);
  color: var(--on-colour);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.button.secondary {
  background: var(--tile);
  color: var(--ink);
}

.button:disabled {
  opacity: 0.45;
  cursor: default;
}

/* -------------------------------------------------------------- overlay */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgb(0 0 0 / 0.55);
  z-index: 10;
}

.sheet {
  position: relative;
  width: min(100%, 30rem);
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.25rem;
  border-radius: 12px;
  background: var(--surface);
}

.sheet h2 {
  margin: 0 0 0.75rem;
  font-size: 1.2rem;
}

.sheet h3 {
  margin: 1.25rem 0 0.4rem;
  font-size: 0.95rem;
}

.sheet p {
  margin: 0 0 0.6rem;
  font-size: 0.92rem;
}

.sheet-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 1.4rem;
}

kbd {
  padding: 0.05rem 0.3rem;
  border: 1px solid var(--tile-line);
  border-radius: 4px;
  background: var(--tile);
  font-size: 0.85em;
}

.stats {
  display: flex;
  justify-content: space-around;
  margin: 0.5rem 0 1rem;
  text-align: center;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.sheet .button {
  width: 100%;
  margin-top: 0.6rem;
}

.countdown {
  margin-top: 0.75rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

@media (max-height: 720px) {
  .board {
    width: min(100%, 17rem);
  }
  .pad {
    grid-template-columns: repeat(3, 2.7rem);
    grid-template-rows: repeat(3, 2.7rem);
  }
}
