/* ============================================================
   CodeCraft — Minecraft-ish, mobile-first theme.
   Zero external assets: colours + blocky borders + emoji only.
   ============================================================ */

:root {
  --grass:   #5aa734;
  --grass-d: #3b8526;
  --dirt:    #8b5a2b;
  --stone:   #7a7a7a;
  --stone-d: #565656;
  --sky:     #7ec0ee;
  --night:   #23262e;
  --panel:   #2f333d;
  --panel-2: #3a3f4b;
  --text:    #f4f4f4;
  --muted:   #b9c0cc;
  --gold:    #f2c94c;
  --emerald: #43d17a;
  --redstone:#e0483d;
  --diamond: #4fd6e6;
  --ok:      #57c04a;
  --bad:     #e0483d;

  --edge-light: rgba(255,255,255,0.35);
  --edge-dark:  rgba(0,0,0,0.45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--night);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.screen { max-width: 720px; margin: 0 auto; padding: 16px; }
.hidden { display: none !important; }

/* ---------- Blocky button base ---------- */
.btn {
  display: inline-block;
  font: inherit;
  font-weight: 700;
  color: var(--text);
  background: var(--stone);
  border: none;
  border-radius: 0;
  padding: 14px 18px;
  min-height: 48px;
  cursor: pointer;
  box-shadow:
    inset 3px 3px 0 var(--edge-light),
    inset -3px -3px 0 var(--edge-dark);
  transition: transform .04s ease, filter .1s ease;
}
.btn:active { transform: translateY(2px); filter: brightness(1.05); }
.btn--grass { background: var(--grass); }
.btn--grass:hover { background: var(--grass-d); }
.btn--full { display: block; width: 100%; }
.btn--big { font-size: 1.1rem; padding: 16px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ============================================================
   Lock / PIN screen
   ============================================================ */
#screen-lock {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(180deg, var(--sky) 0%, #a9d8f5 45%, var(--grass) 45%, var(--grass-d) 100%);
}
.lock-box {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  padding: 22px;
  text-align: center;
  box-shadow: inset 4px 4px 0 var(--edge-light), inset -4px -4px 0 var(--edge-dark);
}
.logo { font-size: 1.8rem; font-weight: 800; letter-spacing: 1px; }
.lock-hello { font-size: 1.3rem; font-weight: 800; margin: 14px 0 2px; }
.lock-sub { color: var(--muted); margin: 0 0 14px; font-size: .95rem; }

.pin-display {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 14px;
  letter-spacing: 6px;
  font-size: 2rem;
}
.pin-dot { width: 14px; height: 14px; background: var(--diamond); display: inline-block; }
.pin-dot--empty { background: var(--stone-d); }

.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pin-key {
  font: inherit; font-size: 1.4rem; font-weight: 700;
  color: var(--text); background: var(--panel-2); border: none;
  padding: 16px 0; cursor: pointer;
  box-shadow: inset 3px 3px 0 var(--edge-light), inset -3px -3px 0 var(--edge-dark);
}
.pin-key:active { transform: translateY(2px); }
.pin-key--ok { background: var(--grass); }
.pin-key--wide { background: var(--stone-d); }
.pin-error { color: var(--redstone); min-height: 1.2em; margin: 12px 0 0; font-weight: 700; }

/* Profile picker ("Who's coding?") */
.profile-list { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 4px; }
.profile-btn {
  display: flex; align-items: center; gap: 12px;
  font: inherit; font-size: 1.15rem; font-weight: 800; text-align: left;
  color: var(--text); background: var(--panel-2); border: none;
  padding: 14px 16px; cursor: pointer;
  box-shadow: inset 3px 3px 0 var(--edge-light), inset -3px -3px 0 var(--edge-dark);
}
.profile-btn:active { transform: translateY(2px); }
.profile-btn--last { box-shadow: inset 0 0 0 3px var(--grass); }
.profile-last { margin-left: auto; font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.profile-ico { font-size: 1.6rem; }
.lock-switch {
  margin-top: 16px; font: inherit; font-weight: 700; color: var(--muted);
  background: none; border: none; cursor: pointer;
}
.lock-switch:active { transform: translateY(1px); }

/* ============================================================
   Top bar
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--grass-d);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.3);
}
.topbar-home {
  font-size: 1.4rem; background: none; border: none; cursor: pointer; padding: 4px;
}
.topbar-name { font-weight: 800; flex: 1; }
.topbar-stats { display: flex; gap: 8px; }
.stat {
  font-weight: 700; font-size: .9rem; padding: 6px 10px; background: rgba(0,0,0,.25);
  box-shadow: inset 2px 2px 0 var(--edge-light), inset -2px -2px 0 var(--edge-dark);
}
.stat--xp { color: var(--emerald); }
.stat--level { color: var(--gold); }

/* XP progress bar under the top area */
.xpbar-wrap { margin: 14px 0 20px; }
.xpbar-label { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.xpbar {
  height: 18px; background: var(--stone-d);
  box-shadow: inset 2px 2px 0 var(--edge-dark);
}
.xpbar-fill { height: 100%; background: var(--emerald); transition: width .4s ease; }

/* ============================================================
   Map screen
   ============================================================ */
.world-title { font-size: 1.3rem; font-weight: 800; margin: 18px 0 4px; }
.world-sub { color: var(--muted); margin: 0 0 12px; font-size: .95rem; }
.world-locked { color: var(--gold); font-weight: 700; margin: 0 0 12px; font-size: .95rem; }
.world-lang {
  display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--night); background: var(--gold);
  padding: 3px 8px; margin-left: 8px; vertical-align: middle;
}

/* The Nether — the (hidden) Rust track gets its own dimension look */
.track-divider {
  font-size: 1.05rem; font-weight: 800; letter-spacing: 3px;
  margin: 30px 0 6px; padding: 10px 14px; text-align: center;
}
.track-divider--rust {
  color: #ffb08a; background: #3a1512;
  box-shadow: inset 3px 3px 0 #5c2a1f, inset -3px -3px 0 #1f0a08;
}
.world-title--rust { color: #ff8a5c; }
.world-lang--rust { background: #c2410c; color: #fff; }

.practice-mixed { margin: 4px 0 12px; }
.topic-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 22px; }
.topic-chip {
  font: inherit; font-weight: 700; font-size: .9rem;
  color: var(--text); background: var(--panel-2); border: none; padding: 10px 14px; cursor: pointer;
  box-shadow: inset 2px 2px 0 var(--edge-light), inset -2px -2px 0 var(--edge-dark);
}
.topic-chip:active { transform: translateY(1px); }

.lesson-list { display: grid; gap: 12px; }
.lesson-card {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  background: var(--panel); color: var(--text);
  border: none; padding: 16px; cursor: pointer;
  box-shadow: inset 3px 3px 0 var(--edge-light), inset -3px -3px 0 var(--edge-dark);
}
.lesson-card:active { transform: translateY(2px); }
.lesson-card--locked { opacity: .55; cursor: not-allowed; }
.lesson-card--done { box-shadow: inset 3px 3px 0 var(--edge-light), inset -3px -3px 0 var(--edge-dark), inset 0 0 0 3px var(--emerald); }
.lesson-ico { font-size: 1.9rem; width: 44px; text-align: center; flex: none; }
.lesson-meta { flex: 1; min-width: 0; }
.lesson-name { font-weight: 800; }
.lesson-note { color: var(--muted); font-size: .85rem; }
.lesson-badge { font-size: 1.3rem; flex: none; }

/* map footer: active profile + reset */
.map-footer {
  margin: 28px 0 8px; padding-top: 16px;
  border-top: 2px solid var(--stone-d);
  color: var(--muted); font-size: .9rem;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-start;
}
.map-footer strong { color: var(--text); }
.footer-reset {
  font: inherit; font-size: .85rem; font-weight: 700;
  color: var(--text); background: var(--panel-2); border: none; padding: 10px 14px; cursor: pointer;
  box-shadow: inset 2px 2px 0 var(--edge-light), inset -2px -2px 0 var(--edge-dark);
}
.footer-reset:active { transform: translateY(1px); }
.footer-row { display: flex; gap: 10px; flex-wrap: wrap; }
.footer-hint { font-size: .8rem; opacity: .8; }

/* ============================================================
   Lesson screen
   ============================================================ */
.lesson-head { display: flex; align-items: center; gap: 12px; margin: 8px 0 16px; }
.lesson-head .lesson-ico { font-size: 2.2rem; }
.lesson-head h1 { font-size: 1.4rem; margin: 0; }

.block { margin: 0 0 16px; }
.block-text { font-size: 1.05rem; }
.block-text strong { color: var(--gold); }
.block-tip {
  background: var(--panel-2); padding: 14px;
  box-shadow: inset 3px 3px 0 var(--edge-light), inset -3px -3px 0 var(--edge-dark);
}
.block-tip::before { content: "💡 "; }

/* Optional slow-lane walkthrough — collapsed <details>, enchantment purple */
.block-deep {
  background: #2c2440;
  box-shadow: inset 3px 3px 0 var(--edge-light), inset -3px -3px 0 var(--edge-dark);
}
.block-deep summary {
  cursor: pointer; padding: 13px 14px; font-weight: 700; color: #cdb4ff;
  list-style: none; -webkit-tap-highlight-color: transparent;
}
.block-deep summary::-webkit-details-marker { display: none; }
.block-deep summary::after { content: "  ▸"; color: #8f7cc0; }
.block-deep[open] summary::after { content: "  ▾"; }
.block-deep > :not(summary) { margin: 0 12px 14px; }
.block-deep .block-text { font-size: 1rem; }

pre.code {
  background: #1b1e24; color: #e8e8e8; margin: 0 0 16px;
  padding: 14px; overflow-x: auto;
  box-shadow: inset 3px 3px 0 var(--edge-dark);
  font-size: .98rem; line-height: 1.55;
}
pre.code .cmt, .wk-code .cmt { color: #7f8a99; }
pre.code .str, .wk-code .str { color: #9fe08b; }
pre.code .num, .wk-code .num { color: #f2c94c; }
pre.code .kw,  .wk-code .kw  { color: #6fc3ff; }

/* progress dots for exercises within a lesson */
.ex-progress { display: flex; gap: 6px; margin: 4px 0 18px; }
.ex-dot { width: 100%; height: 8px; background: var(--stone-d); }
.ex-dot--done { background: var(--emerald); }
.ex-dot--cur  { background: var(--gold); }

.ex-q { font-size: 1.1rem; font-weight: 700; margin: 6px 0 14px; }
.ex-tag {
  display:inline-block; font-size:.7rem; font-weight:700; letter-spacing:1px;
  text-transform:uppercase; color:var(--night); background:var(--diamond);
  padding:3px 8px; margin-bottom:10px;
}
.ex-tag--challenge { background: var(--gold); }

/* choice options */
.choice-list { display: grid; gap: 10px; }
.choice {
  width: 100%; text-align: left; font: inherit;
  background: var(--panel); color: var(--text); border: none; padding: 14px; cursor: pointer;
  box-shadow: inset 3px 3px 0 var(--edge-light), inset -3px -3px 0 var(--edge-dark);
  white-space: pre-line; /* options may contain real \n — program output is shown honestly */
}
.choice:active { transform: translateY(2px); }
.choice.is-correct { box-shadow: inset 0 0 0 3px var(--ok); background: #274d24; }
.choice.is-wrong   { box-shadow: inset 0 0 0 3px var(--bad); background: #4d2622; }
.choice.is-locked  { pointer-events: none; }

/* parsons / reorder */
.reorder-list { display: grid; gap: 8px; margin-bottom: 8px; }
.reorder-row { display: flex; align-items: stretch; gap: 8px; }
.reorder-code {
  flex: 1; background: #1b1e24; color: #e8e8e8; padding: 12px 14px;
  font-family: ui-monospace, Menlo, Consolas, monospace; white-space: pre;
  overflow-x: auto; box-shadow: inset 2px 2px 0 var(--edge-dark);
}
.reorder-btns { display: flex; flex-direction: column; gap: 4px; }
.reorder-move {
  font: inherit; font-size: 1.1rem; line-height: 1; width: 40px; flex: 1;
  background: var(--panel-2); color: var(--text); border: none; cursor: pointer;
  box-shadow: inset 2px 2px 0 var(--edge-light), inset -2px -2px 0 var(--edge-dark);
}
.reorder-move:active { transform: translateY(1px); }
.reorder-list.is-correct .reorder-code { box-shadow: inset 0 0 0 3px var(--ok); }
.reorder-list.is-wrong   .reorder-code { box-shadow: inset 0 0 0 3px var(--bad); }

/* feedback + actions */
.ex-feedback { margin: 14px 0; padding: 14px; font-weight: 600; }
.ex-feedback--ok  { background: #274d24; box-shadow: inset 3px 3px 0 var(--edge-light), inset -3px -3px 0 var(--edge-dark); }
.ex-feedback--bad { background: #4d2622; box-shadow: inset 3px 3px 0 var(--edge-light), inset -3px -3px 0 var(--edge-dark); }
.ex-feedback .why { display:block; margin-top:6px; font-weight: 400; color: var(--text); }
.ex-actions { display: flex; gap: 10px; margin-top: 14px; }
.ex-actions .btn { flex: 1; }

/* lesson complete */
.complete-box { text-align: center; padding: 24px 12px; }
.complete-box .big { font-size: 3rem; }
.complete-box h2 { margin: 8px 0; }
.complete-reward { color: var(--emerald); font-weight: 800; font-size: 1.2rem; margin: 8px 0 20px; }

/* ============================================================
   Code Playground (sandbox)
   ============================================================ */
.playground-btn { margin: 6px 0 22px; background: var(--diamond); color: var(--night); }
.playground-btn:active { transform: translateY(2px); }

.sandbox-head { display: flex; align-items: center; gap: 12px; margin: 6px 0 6px; }
.sandbox-head h1 { font-size: 1.4rem; margin: 0; }
.sandbox-back {
  font: inherit; font-weight: 700; color: var(--text); background: var(--panel-2);
  border: none; padding: 8px 12px; cursor: pointer;
  box-shadow: inset 2px 2px 0 var(--edge-light), inset -2px -2px 0 var(--edge-dark);
}
.sandbox-hint { color: var(--muted); font-size: .9rem; margin: 0 0 12px; }
.sandbox-brief {
  background: var(--panel-2); padding: 12px 14px; margin: 0 0 12px;
  box-shadow: inset 3px 3px 0 var(--edge-light), inset -3px -3px 0 var(--edge-dark);
}
.sandbox-brief-title { font-weight: 800; color: var(--gold); margin-bottom: 4px; }
.sandbox-brief ul { margin: 4px 0 0; padding-left: 20px; }
.sandbox-brief li { margin: 4px 0; }
.sandbox-editor {
  width: 100%; min-height: 220px; resize: vertical;
  background: #1b1e24; color: #e8e8e8; border: none; padding: 14px;
  font-size: 1rem; line-height: 1.55;
  box-shadow: inset 3px 3px 0 var(--edge-dark);
}
.sandbox-actions { display: flex; gap: 10px; margin: 12px 0; }
.sandbox-actions .btn { flex: 1; }
.sandbox-status { color: var(--gold); font-weight: 700; min-height: 1.2em; margin: 6px 0; }

/* "code" exercises: small in-lesson editor + graded output boxes */
.ex-editor {
  width: 100%; min-height: 150px; resize: vertical;
  background: #1b1e24; color: #e8e8e8; border: none; padding: 14px;
  font-size: 1rem; line-height: 1.55;
  box-shadow: inset 3px 3px 0 var(--edge-dark);
  margin-bottom: 10px;
}
.ex-editor[readonly] { opacity: .7; }
.ex-outbox { margin: 10px 0; }
.ex-outlabel { font-weight: 700; font-size: .9rem; margin-bottom: 4px; color: var(--gold); }
.ex-output {
  background: #12141a; color: #b8f0c0; margin: 0; padding: 12px;
  white-space: pre-wrap; word-break: break-word;
  box-shadow: inset 3px 3px 0 var(--edge-dark);
}
.sandbox-output {
  background: #12141a; color: #b8f0c0; margin: 8px 0 24px; padding: 14px;
  min-height: 60px; white-space: pre-wrap; word-break: break-word;
  box-shadow: inset 3px 3px 0 var(--edge-dark);
}

/* ============================================================
   Werkstatt — project workshop (desktop-first editor)
   The gutter, overlay <pre> and <textarea> MUST share font family/size,
   line-height and vertical padding — that alignment is load-bearing.
   ============================================================ */
.wk-head { margin-bottom: 12px; }
.wk-name {
  flex: 1; min-width: 0; text-align: left;
  font: inherit; font-size: 1.15rem; font-weight: 800;
  color: var(--text); background: none; border: none; cursor: pointer; padding: 4px 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wk-saveind { flex: none; font-size: .85rem; font-weight: 700; color: var(--muted); }
.wk-saveind--ok  { color: var(--emerald); }
.wk-saveind--bad { color: var(--gold); }

.wk-notice { color: var(--gold); font-weight: 700; margin: 0 0 12px; }

.wk-projlist { margin: 16px 0 8px; }
.wk-projrow { display: flex; gap: 8px; align-items: stretch; }
.wk-projrow .lesson-card { flex: 1; min-width: 0; }
.wk-del {
  flex: none; width: 50px; font: inherit; font-size: 1.1rem;
  color: var(--text); background: var(--panel-2); border: none; cursor: pointer;
  box-shadow: inset 2px 2px 0 var(--edge-light), inset -2px -2px 0 var(--edge-dark);
}
.wk-del:active { transform: translateY(1px); }
.wk-del--armed { background: #4d2622; }

.wk-tier { font-size: 1.05rem; font-weight: 800; margin: 18px 0 8px; }
.wk-tier-blurb { display: block; font-size: .85rem; font-weight: 400; color: var(--muted); }

.wk-hints summary { cursor: pointer; font-weight: 700; color: var(--gold); margin-top: 8px; }
.wk-questfold > summary {
  cursor: pointer; font-weight: 800; color: var(--gold);
  list-style: none; -webkit-tap-highlight-color: transparent;
}
.wk-questfold > summary::-webkit-details-marker { display: none; }
.wk-questfold > summary::after { content: "  ▸"; color: var(--muted); }
.wk-questfold[open] > summary::after { content: "  ▾"; }
.wk-questfold > :not(summary) { margin-top: 8px; }

.wk-editwrap {
  display: flex; align-items: stretch;
  background: #1b1e24;
  box-shadow: inset 3px 3px 0 var(--edge-dark);
}
.wk-gutter {
  flex: none; width: 46px; margin: 0; padding: 14px 8px 14px 0;
  text-align: right; color: #5b6472; background: #171a20;
  overflow: hidden; user-select: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1rem; line-height: 1.55; white-space: pre;
}
.wk-editbox { position: relative; flex: 1; min-width: 0; }
.wk-code {
  position: absolute; inset: 0; margin: 0; padding: 14px;
  overflow: hidden; pointer-events: none;
  background: transparent; color: #e8e8e8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1rem; line-height: 1.55; white-space: pre;
}
.wk-input {
  position: relative; display: block; width: 100%; min-height: 340px;
  resize: vertical; border: none; margin: 0; padding: 14px; outline: none;
  background: transparent; color: transparent; caret-color: #e8e8e8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1rem; line-height: 1.55; white-space: pre; overflow: auto;
}
.wk-input::selection { background: rgba(79, 214, 230, .35); }

.wk-runhint { color: var(--muted); font-size: .85rem; margin: 0 0 8px; }
.wk-warn { color: var(--gold); font-weight: 700; margin: 6px 0; }
.wk-questdone { margin: 4px 0 24px; background: var(--gold); color: var(--night); }
.wk-questdone:disabled { opacity: .75; }

/* Desktop editor view (≥1100px): use the space a laptop has. The screen goes
   wide, the editor grows tall, and the Run/output panel sits BESIDE the code
   (sticky, so Run + output stay in view while scrolling long programs).
   Keyed on .wk-editing (set only while an editor is open) so the hub, quest
   intros and every phone/tablet keep the stacked 720px layout untouched. */
@media (min-width: 1100px) {
  .screen.wk-editing { max-width: 1280px; }
  .wk-editing .wk-cols { display: flex; align-items: flex-start; gap: 20px; }
  .wk-editing .wk-main { flex: 1 1 auto; min-width: 0; }
  .wk-editing .wk-side { flex: 0 0 380px; position: sticky; top: 64px; }
  .wk-editing .wk-input { min-height: 62vh; }
  .wk-editing .wk-side .sandbox-output { max-height: 62vh; overflow: auto; margin-bottom: 12px; }
}

/* ============================================================
   Achievement toast (Minecraft advancement style)
   ============================================================ */
.toast-layer {
  position: fixed; top: calc(10px + env(safe-area-inset-top)); right: 10px; left: 10px;
  z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 12px;
  max-width: 340px; background: #1b1e24; color: var(--text);
  padding: 12px 14px; box-shadow: inset 3px 3px 0 var(--edge-light), inset -3px -3px 0 var(--edge-dark), 0 4px 12px rgba(0,0,0,.5);
  transform: translateX(120%); transition: transform .35s cubic-bezier(.2,.9,.3,1.2);
}
.toast.show { transform: translateX(0); }
.toast-ico { font-size: 1.8rem; flex: none; }
.toast-title { font-weight: 800; color: var(--gold); font-size: .85rem; }
.toast-desc { font-size: .95rem; }

@media (min-width: 520px) {
  .toast-layer { left: auto; }
}
