/* Repspace — one stylesheet, dark like the board it frames.
   Laid out for a phone first: the board keeps the top, the program and the
   palette sit under the thumb. A classroom tablet in landscape gets the same
   thing, wider. */

:root {
  --bg: #0d1320;
  --panel: #151d2e;
  --panel-soft: #1b2437;
  --line: #27334b;
  --ink: #e6ecf8;
  --ink-soft: #94a3c0;
  --accent: #3a6df0;
  --accent-ink: #ffffff;
  --good: #35c08a;
  --bad: #ef6a63;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  color: var(--ink);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor: pointer;
  /* A child taps fast and twice; nothing here should select text. */
  user-select: none;
  touch-action: manipulation;
}
button:hover { border-color: #3b4a69; }
button:active { transform: translateY(1px); }

/* ── Language strip ─────────────────────────────────────────────── */
#languages {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  padding: 8px 12px 0;
}
#languages button {
  padding: 4px 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  background: none;
  border-color: transparent;
}
#languages button.on { color: var(--ink); border-color: var(--line); background: var(--panel); }

#app { max-width: 1000px; margin: 0 auto; padding: 8px 12px 32px; }

/* ── Bars ───────────────────────────────────────────────────────── */
.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
  padding: 8px 0 14px;
}
.bar h1 { margin: 0; font-size: 22px; }
.bar .sub { color: var(--ink-soft); font-size: 14px; }
.bar .goal { font-size: 18px; font-weight: 600; }
.bar .limit { color: var(--ink-soft); font-size: 14px; }
button.ghost { background: none; border-color: var(--line); color: var(--ink-soft); }

/* ── The level map ──────────────────────────────────────────────── */
.chapter { margin: 0 0 26px; }
.chapter h2 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* One rung, one notion. The prerequisite is written here and not on every
   card: inside a rung the levels are variations, between rungs there is
   something new, so this is the only line where "first do…" belongs. */
.rung { margin: 0 0 16px; }
.rung-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  padding: 0 2px 7px;
}
.rung-id {
  font-weight: 700;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}
.rung-notion { font-size: 15px; color: var(--ink); }
.rung-grade {
  font-size: 12px;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
}
/* A rung that is not open yet is dimmed and explained — never hidden, and
   never disabled: the system forbids nothing, it records. */
.rung-need { font-size: 13px; color: var(--ink-soft); }
.rung-need::before { content: "↳ "; opacity: 0.7; }
.rung-mark { font-size: 12px; color: var(--good); }
.rung.shut .rung-id,
.rung.shut .rung-notion { color: var(--ink-soft); }
.rung.shut .cards { opacity: 0.62; }
.rung.shut:hover .cards, .rung.shut:focus-within .cards { opacity: 1; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  padding: 12px 14px;
  background: var(--panel);
}
.card-id { font-weight: 700; letter-spacing: 0.04em; }
.card-done { margin-top: 4px; font-size: 12px; color: var(--good); }
.card-next { margin-top: 4px; font-size: 12px; color: var(--accent-ink); }
.card.solved { border-color: color-mix(in srgb, var(--good) 45%, var(--line)); }
/* Exactly one card on the whole map carries this: where to carry on. */
.card.next {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, var(--panel));
}
.card.next .card-title { color: var(--ink); }

/* ── The placement, offered from the map ────────────────────────── */
.placement-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 0 0 22px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.placement-strip .sub, .placement-strip .placed { font-size: 15px; color: var(--ink-soft); }
.placement-strip button { padding: 8px 12px; font-size: 15px; }
.ask { margin: 12px 0 10px; font-size: 18px; font-weight: 600; }
.form input#probe-answer { width: 10ch; font-size: 20px; text-align: center; }
.result { margin: 8px 0 14px; font-size: 17px; }
/* What a level builds on, said to whoever opened it out of order. */
.after {
  margin: -4px 0 12px;
  font-size: 14px;
  color: var(--ink-soft);
  border-left: 2px solid var(--accent);
  padding-left: 10px;
}

/* ── The board ──────────────────────────────────────────────────── */
.board-box {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
#board { display: block; width: 100%; height: min(52vh, 420px); }

/* ── Feedback ───────────────────────────────────────────────────── */
.feedback {
  margin: 10px 0;
  min-height: 1.45em;
  font-size: 16px;
  color: var(--ink-soft);
  opacity: 0;
  transition: opacity 120ms;
}
.feedback.on { opacity: 1; }
.feedback.bad { color: var(--bad); }
.feedback.on:not(.bad) { color: var(--good); }

/* ── The program ────────────────────────────────────────────────── */
.program {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 52px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.program .hint { color: var(--ink-soft); font-size: 14px; }
.chip {
  padding: 2px 10px;
  font-size: 20px;
  line-height: 1.3;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
}
/* The instruction that walked into the wall stays lit, and stays in place:
   nothing is reset, so the learner can read their own program back. */
.chip.wrong { border-color: var(--bad); color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, var(--panel-soft)); }

/* ── The palette ────────────────────────────────────────────────── */
.palette { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 0; }
.key { min-width: 56px; font-size: 24px; line-height: 1.1; padding: 10px 12px; }
.form {
  /* A form never shrinks and never breaks across lines: its label, its
     fields and its button are one control, not three flex items. */
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  padding: 6px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.form label { font-size: 14px; color: var(--ink-soft); }
.form input {
  font: inherit;
  width: 5.5ch;
  padding: 6px 8px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.form input#goto-place { width: 11ch; }
.form .add { padding: 6px 12px; font-size: 14px; }

/* A shortcut nobody is told about is a shortcut nobody uses — but only where
   there is a keyboard to press it on. */
.keys-line { display: none; }
@media (hover: hover) and (pointer: fine) {
  .keys-line {
    display: block;
    margin: 12px 0 0;
    font-size: 13px;
    color: var(--ink-soft);
  }
}

/* ── Controls ───────────────────────────────────────────────────── */
.controls { display: flex; flex-wrap: wrap; gap: 8px; }
.controls .go { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

@media (max-width: 480px) {
  .key { min-width: 48px; font-size: 21px; }
  .controls button { flex: 1 1 auto; }
}

/* ── A level's own words ────────────────────────────────────────── */
.brief { margin: 0 0 12px; color: var(--ink-soft); font-size: 15px; }
.brief strong { color: var(--ink); }
.card-title { font-size: 14px; color: var(--ink-soft); }
/* The hint waits for a first failure: handed out before anyone has tried,
   it answers a question nobody has asked yet. */
.hint-line {
  margin: -4px 0 10px;
  font-size: 15px;
  color: var(--ink-soft);
  border-left: 2px solid var(--line);
  padding-left: 10px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: opacity 160ms, max-height 160ms;
}
.hint-line.on { max-height: 6em; opacity: 1; }

/* ── The workshop ───────────────────────────────────────────────────
   A form and a grid, on the same dark board as everything else. The grid
   IS the map: what is drawn here is what blocks a piece there, which is the
   whole reason version 3 has an editor at all. */
.fields {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin: 0 0 14px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--ink-soft);
}
.field input, .field select {
  font: inherit;
  font-size: 15px;
  padding: 7px 9px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.field input[type="text"] { min-width: 22ch; }
.field input[type="number"] { width: 8ch; }

/* The four tools. Exactly one is held, and it is the one that looks held. */
.tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.tool { padding: 8px 12px; font-size: 15px; }
.tool.on {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 22%, var(--panel));
  color: var(--ink);
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 8), minmax(0, 1fr));
  gap: 2px;
  max-width: min(100%, 560px);
  margin: 0 0 14px;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.grid .cell {
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  border-radius: 4px;
  border: 1px solid transparent;
}
.grid .cell.free { background: var(--panel-soft); }
.grid .cell.wall { background: #0a0f19; border-color: #1d2739; }
.grid .cell.start { color: var(--good); border-color: var(--good); }
.grid .cell.goal { color: var(--accent); border-color: var(--accent); }

/* A level of one's own, in the list: the same card, with its own row of
   gestures — and publishing is the only one that leaves the browser. */
.card.draft { gap: 4px; }
.card.draft .row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.card.draft .row button { padding: 6px 10px; font-size: 14px; }

.server-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 12px;
  margin: 0 0 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.server-row select {
  font: inherit;
  font-size: 14px;
  padding: 5px 8px;
  color: var(--ink);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.server-row button { padding: 6px 10px; font-size: 14px; }
