/* ROOT — calm, dark, one thing at a time. No motion that is not necessary. */

:root {
  --bg: #0A0C0D;
  --panel: #101416;
  --panel-2: #151A1D;
  --line: #1F272B;
  --line-bright: #2E393E;
  --text: #DCE4E7;
  --dim: #7A8A91;
  --dimmer: #4E5C62;
  --accent: #6EE7A8;
  --accent-dim: #2E6B4E;
  --amber: #E8B054;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --radius: 4px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body { padding-bottom: 6rem; }

.wrap { max-width: 720px; margin: 0 auto; padding: 0 1.25rem; }

/* ── type ─────────────────────────────────────────── */
h1, h2, h3 { font-weight: 600; line-height: 1.25; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1rem; }
a { color: var(--accent); }

.mono { font-family: var(--mono); }
.label {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
}
.dim { color: var(--dim); }

/* ── masthead ─────────────────────────────────────── */
.masthead {
  border-bottom: 1px solid var(--line);
  padding: 1.5rem 0 1.25rem;
  margin-bottom: 2rem;
}
.masthead-inner { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.brand {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.35em;
  color: var(--accent);
}
.brand-sub { font-family: var(--mono); font-size: 0.7rem; color: var(--dimmer); letter-spacing: 0.1em; }

/* ── gate ─────────────────────────────────────────── */
.gate {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1.25rem;
}
.gate .brand { font-size: 2rem; margin-bottom: 0.75rem; }
.gate p { color: var(--dim); max-width: 30rem; }
.gate form { display: flex; gap: 0.5rem; margin-top: 1.5rem; }

input[type="text"], input[type="password"], textarea {
  background: var(--panel);
  border: 1px solid var(--line-bright);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.95rem;
  padding: 0.7rem 0.85rem;
  width: 100%;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent-dim); }
textarea { min-height: 7rem; resize: vertical; line-height: 1.5; }

button {
  background: var(--accent);
  color: #06120C;
  border: 0;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 0.7rem 1.2rem;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.4; cursor: default; }
button.ghost {
  background: transparent;
  color: var(--dim);
  border: 1px solid var(--line-bright);
}
button.ghost:hover { color: var(--text); border-color: var(--dim); }

/* ── the map ──────────────────────────────────────── */
.map { position: relative; }
.map::before {
  content: '';
  position: absolute;
  left: 27px; top: 20px; bottom: 20px;
  width: 1px;
  background: var(--line);
}

.world {
  position: relative;
  display: flex;
  gap: 1.1rem;
  padding: 0.9rem 0;
  text-decoration: none;
  color: inherit;
}

.node {
  flex: 0 0 auto;
  width: 55px;
  display: flex;
  justify-content: center;
  padding-top: 2px;
}
.node span {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--line-bright);
  display: grid; place-items: center;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--dimmer);
  position: relative;
  z-index: 1;
}
.world.done .node span { border-color: var(--accent-dim); color: var(--accent); }
.world.current .node span {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 3px rgba(110, 231, 168, 0.09);
}

.world-body { flex: 1; min-width: 0; }
.world-title { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.world-title strong { font-family: var(--mono); font-size: 0.95rem; letter-spacing: 0.08em; }
.world.locked .world-title strong { color: var(--dimmer); }
.world-blurb { color: var(--dim); font-size: 0.9rem; margin-top: 0.2rem; }
.world.locked .world-blurb { color: var(--dimmer); }

.tag {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 2px;
  border: 1px solid var(--line-bright);
  color: var(--dim);
}
.tag.open { border-color: var(--accent-dim); color: var(--accent); }
.tag.hw { border-color: #4A3A1E; color: var(--amber); }

.progress-strip {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--dimmer);
  margin-top: 0.35rem;
  letter-spacing: 0.12em;
}

/* ── panels ───────────────────────────────────────── */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  margin: 0 0 1.25rem;
}
.panel-head {
  display: flex; align-items: center; gap: 0.6rem;
  margin-bottom: 0.9rem;
}

/* briefing: the world talking. prose, generous. */
.briefing { white-space: pre-wrap; font-size: 1.02rem; line-height: 1.72; }
.briefing::first-line { color: var(--text); }

/* steps: literal, unambiguous, never metaphor. */
.steps { background: var(--panel-2); border-color: var(--line-bright); }
.steps ol { margin: 0; padding-left: 1.35rem; }
.steps li { margin-bottom: 0.65rem; font-size: 0.95rem; }
.steps li:last-child { margin-bottom: 0; }
.steps code, .cmd {
  font-family: var(--mono);
  font-size: 0.88em;
  background: #0B0E10;
  border: 1px solid var(--line-bright);
  border-radius: 3px;
  padding: 0.1rem 0.35rem;
  color: var(--accent);
}
.steps .blank { list-style: none; height: 0.35rem; }
.steps .code-line {
  list-style: none;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent);
  white-space: pre;
  overflow-x: auto;
  margin-left: -0.6rem;
  padding: 0.05rem 0;
}

.note {
  border-left: 2px solid var(--amber);
  padding: 0.15rem 0 0.15rem 0.9rem;
  color: var(--dim);
  font-size: 0.9rem;
  margin: 1.25rem 0;
}
.note strong { color: var(--amber); font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.12em; display: block; margin-bottom: 0.25rem; }

.hint {
  border-left: 2px solid var(--accent-dim);
  padding: 0.15rem 0 0.15rem 0.9rem;
  color: var(--text);
  font-size: 0.92rem;
  margin: 1rem 0 0;
}

/* ── badges ───────────────────────────────────────── */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.75rem; }
.badge {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 0.5rem;
  text-align: center;
  background: var(--panel);
}
.badge .glyph { font-size: 1.6rem; color: var(--dimmer); line-height: 1; }
.badge .name { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.1em; color: var(--dimmer); margin-top: 0.5rem; }
.badge.earned { border-color: var(--accent-dim); }
.badge.earned .glyph { color: var(--accent); }
.badge.earned .name { color: var(--accent); }

/* ── letters ──────────────────────────────────────── */
.letter {
  white-space: pre-wrap;
  font-size: 1.02rem;
  line-height: 1.75;
  border: 1px solid var(--line);
  border-left: 2px solid var(--amber);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 1.5rem 1.6rem;
}

/* ── nav ──────────────────────────────────────────── */
.tabs {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(10, 12, 13, 0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.6rem 0.5rem calc(0.6rem + env(safe-area-inset-bottom));
  z-index: 20;
}
.tabs button {
  background: transparent;
  color: var(--dimmer);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  padding: 0.45rem 0.9rem;
}
.tabs button.on { color: var(--accent); }

.back {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--dim);
  background: none;
  border: 0;
  padding: 0 0 1rem;
  cursor: pointer;
}
.back:hover { color: var(--text); }

/* ── mission list ─────────────────────────────────── */
.mission-row {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.mission-row:last-child { border-bottom: 0; }
.mission-row .tick {
  font-family: var(--mono); font-size: 0.8rem;
  width: 1.5rem; color: var(--dimmer); flex: 0 0 auto;
}
.mission-row.done .tick { color: var(--accent); }
.mission-row .m-title { flex: 1; font-size: 0.97rem; }
.mission-row.done .m-title { color: var(--dim); }
.mission-row .chev { color: var(--dimmer); font-family: var(--mono); }

.photo-thumb {
  width: 100%; border-radius: var(--radius);
  border: 1px solid var(--line-bright); display: block; margin-top: 0.75rem;
}

.toast {
  position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--accent-dim);
  color: var(--text); border-radius: var(--radius);
  padding: 0.75rem 1.1rem; font-family: var(--mono); font-size: 0.82rem;
  z-index: 40; opacity: 0; transition: opacity 0.25s; pointer-events: none;
  max-width: calc(100vw - 2.5rem); text-align: center;
}
.toast.show { opacity: 1; }

.hr { height: 1px; background: var(--line); margin: 2rem 0; border: 0; }

@media (max-width: 480px) {
  h1 { font-size: 1.45rem; }
  .panel { padding: 1.1rem; }
  .briefing, .letter { font-size: 0.98rem; }
}

/* Respect anyone who does not want movement. */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ═══ LESSON VIEW (teach-then-build missions) ═══════════════════ */

.briefing-panel { background: var(--panel-2); }

/* section dividers: LEARN / CHALLENGE */
.sec { display: flex; align-items: center; gap: 0.7rem; margin: 2.4rem 0 1.1rem; }
.sec .tab {
  font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.2em;
  padding: 0.3rem 0.62rem; border-radius: 3px;
  border: 1px solid var(--accent-dim); color: var(--accent); background: rgba(110,231,168,0.06);
}
.sec .tab.chal { border-color: #7A5A22; color: var(--amber); background: rgba(232,176,84,0.06); }
.sec .line { flex: 1; height: 1px; background: var(--line); }
.sec h2 { font-size: 0.76rem; font-family: var(--mono); letter-spacing: 0.1em; color: var(--dim); font-weight: 400; text-transform: none; }

/* a taught idea */
.concept { margin: 0 0 1.6rem; padding-left: 1rem; border-left: 2px solid var(--line-bright); }
.concept .cn { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.14em; color: var(--accent); }
.concept h3 { font-size: 1.1rem; font-weight: 600; margin: 0.2rem 0 0.6rem; }
.concept p { font-size: 0.97rem; line-height: 1.72; margin: 0 0 0.8rem; }
.concept em { color: var(--text); font-style: italic; }

/* inline code inside prose */
.k {
  font-family: var(--mono); font-size: 0.86em; color: var(--accent);
  background: #0A100D; border: 1px solid var(--accent-dim); border-radius: 3px; padding: 0.03rem 0.32rem;
}

/* terminal "type this, watch what happens" block */
.term { background: #070C0A; border: 1px solid var(--accent-dim); border-radius: 6px; overflow: hidden; margin: 0.5rem 0 1rem; }
.term .th {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.42rem 0.78rem;
  border-bottom: 1px solid rgba(46,107,78,0.4);
  font-family: var(--mono); font-size: 0.58rem; letter-spacing: 0.16em; color: var(--accent-dim);
}
.term .th .d { width: 6px; height: 6px; border-radius: 50%; background: var(--accent-dim); }
.term pre { margin: 0; padding: 0.75rem 0.9rem; font-family: var(--mono); font-size: 0.85rem; line-height: 1.65; color: var(--accent); white-space: pre; overflow-x: auto; }
.term pre .o { color: var(--dim); }

/* checkpoint */
.checkpoint { display: flex; gap: 0.6rem; align-items: flex-start; margin: 0.7rem 0 0; padding: 0.65rem 0.85rem; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.checkpoint .i { color: var(--accent); font-family: var(--mono); }
.checkpoint p { margin: 0; font-size: 0.9rem; color: var(--dim); }
.checkpoint .k { font-size: 0.82em; }

/* the challenge */
.chal-box {
  background: var(--panel-2);
  border: 1px solid #4A3A1E; border-radius: var(--radius); padding: 1.3rem 1.4rem;
}
.chal-box > p { font-size: 0.98rem; line-height: 1.72; margin: 0 0 0.9rem; }
.chal-box .have { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.12em; color: var(--amber); margin: 0.4rem 0 0.5rem; text-transform: uppercase; }
.pieces { list-style: none; margin: 0 0 1.2rem; padding: 0; }
.pieces li { font-size: 0.92rem; padding: 0.32rem 0 0.32rem 1.5rem; position: relative; }
.pieces li::before { content: "▸"; position: absolute; left: 0.35rem; color: var(--amber); }
.shape { color: var(--dim); font-size: 0.86rem; margin: 0 0 0.5rem; }
.scaffold {
  background: #070C0A; border: 1px dashed var(--line-bright); border-radius: 6px;
  padding: 0.85rem 1rem; font-family: var(--mono); font-size: 0.83rem; line-height: 1.75;
  color: var(--dim); white-space: pre; overflow-x: auto;
}
.scaffold .blank { color: var(--amber); }

/* stuck? progressive help */
details.stuck { margin-top: 1rem; }
details.stuck summary {
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.1em; color: var(--accent);
  cursor: pointer; list-style: none; padding: 0.5rem 0.75rem; display: inline-block;
  border: 1px solid var(--accent-dim); border-radius: 5px; background: rgba(110,231,168,0.05);
}
details.stuck summary::-webkit-details-marker { display: none; }
details.stuck summary:hover { background: rgba(110,231,168,0.1); }
details.stuck[open] summary { margin-bottom: 0.7rem; }
details.stuck .help { font-size: 0.92rem; color: var(--dim); line-height: 1.72; padding-left: 0.2rem; }

/* classic-format code block (older worlds) */
.codeblock { margin: 0; overflow-x: auto; }
.codeblock code { font-family: var(--mono); font-size: 0.85rem; line-height: 1.55; color: var(--accent); background: none; border: 0; padding: 0; }

/* proof */
.proof { margin-top: 1.5rem; }
.proof .pl { font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.16em; color: var(--dimmer); }
.proof .pq { font-size: 0.98rem; margin: 0.4rem 0 0.75rem; }
.proof-done { background: var(--panel-2); border-color: var(--accent-dim); }
