/* Seedling — 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: #e8ebf0;
  --tile-line: #ccd3db;

  --alive: #3f9e6a;
  --ok: #3f9e6a;
  --extra: #c2564a;
  --missing: #4d7fc4;

  --on-colour: #ffffff;
  --focus: #4d7fc4;

  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d;
    --surface: #1a212a;
    --ink: #e9edf2;
    --ink-soft: #9aa5b3;
    --line: #2c3542;
    --tile: #222c38;
    --tile-line: #333e4c;

    --alive: #3f9e6a;
    --ok: #3f9e6a;
    --extra: #b8503f;
    --missing: #4a76b8;
  }
}

* {
  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,
.cell:focus-visible,
.button: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.5rem;
  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.solved {
  color: var(--ok);
  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;
}

.help-link:hover {
  color: var(--ink);
}

/* ---------------------------------------------------------------- boards */

.panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.panel-title {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.verdict {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}

.verdict.wrong {
  color: var(--extra);
}

.verdict.right {
  color: var(--ok);
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--cells, 6), 1fr);
  gap: 3px;
  aspect-ratio: 1;
  padding: 3px;
  border-radius: 10px;
  background: var(--tile-line);
  touch-action: manipulation;
}

/* The seed is where all the interaction happens, so it gets the room. */
.board.seed {
  width: min(100%, 19rem);
}

/* The result is read-only, so it can be smaller without costing anything. */
.board.result {
  width: min(78%, 15rem);
}

.cell {
  position: relative;
  border: none;
  border-radius: var(--radius);
  background: var(--tile);
  padding: 0;
  cursor: pointer;
}

.board.result .cell {
  cursor: default;
}

.cell.alive {
  background: var(--alive);
}

.cell.ok {
  background: var(--ok);
}

.cell.extra {
  background: var(--extra);
}

/* Wanted but not yet produced: an outline, so the target is always readable
   as "everything green plus everything ringed". */
.cell.missing {
  background: var(--tile);
  box-shadow: inset 0 0 0 2.5px var(--missing);
}

.cell.pulse {
  animation: pulse 180ms ease-out;
}

@keyframes pulse {
  50% {
    transform: scale(1.12);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cell.pulse {
    animation: none;
  }
}

.arrow-row {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* --------------------------------------------------------------- legend */

.legend-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.15rem 0.9rem;
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.legend-row span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.swatch {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 3px;
  background: var(--tile);
}

.swatch.ok {
  background: var(--ok);
}
.swatch.extra {
  background: var(--extra);
}
.swatch.missing {
  box-shadow: inset 0 0 0 2.5px var(--missing);
}

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

.controls {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  max-width: 19rem;
  margin-top: auto;
}

.button {
  flex: 1;
  padding: 0.7rem;
  border: none;
  border-radius: 8px;
  background: var(--ok);
  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;
}

.legend {
  list-style: none;
  margin: 0 0 0.6rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.legend li {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-size: 0.9rem;
}

.legend .swatch,
.legend .chip {
  flex: 0 0 auto;
  margin-top: 0.15rem;
}

.chip {
  display: grid;
  place-items: center;
  min-width: 1.6rem;
  height: 1.3rem;
  padding: 0 0.3rem;
  border-radius: 4px;
  background: var(--tile);
  font-size: 0.75rem;
  font-weight: 700;
}

/* Stats + result --------------------------------------------------------- */

.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.seed {
    width: min(100%, 15rem);
  }
  .board.result {
    width: min(70%, 12rem);
  }
}
