/* Legotronics — set-box front, instruction-booklet pages */
:root {
  --red: #e3000b;
  --yellow: #ffd500;
  --blue: #006cb7;
  --blue-dk: #004f8a;
  --ink: #141414;
  --ink-2: #4b5563;
  --ink-3: #8a94a3;
  --paper: #ffffff;
  --page: #f1f5f9;
  --callout: #dcebf8;
  --callout-line: #9cc3e6;
  --sky-1: #f4f9ff;
  --sky-2: #bcdaf4;
  --line: #e2e8f0;
  --display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --text: Barlow, system-ui, -apple-system, sans-serif;
  font-family: var(--text);
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); min-height: 100vh; display: flex; flex-direction: column; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 56px; padding: 0 20px; background: var(--paper);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brick { width: 34px; height: 26px; }
.wordmark { font-family: var(--display); font-style: italic; font-weight: 900; font-size: 24px; letter-spacing: .02em; color: var(--ink); }
.top-actions { display: flex; gap: 8px; }

/* ---------- buttons ---------- */
.btn {
  font: 700 15px/1 var(--text); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 18px; border-radius: 10px; border: 1px solid #cbd5e1; background: var(--paper); color: var(--ink);
  transition: background .15s, transform .08s;
}
.btn:hover { background: #f8fafc; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); }
.btn.primary:hover { background: #f0121c; }
.btn.light { background: rgba(255,255,255,.92); border-color: transparent; }
.btn.big { font-size: 17px; padding: 15px 22px; border-radius: 12px; }
.btn.small { font-size: 13px; padding: 8px 12px; border-radius: 8px; }
.btn.ghost { background: transparent; }
.btn:focus-visible, .chip:focus-visible, .nav-btn:focus-visible, .seg:focus-visible, summary:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* =========================================================
   HOME — the box front
   ========================================================= */
#home { width: 100%; }
.box {
  position: relative; overflow: hidden; height: max(600px, calc(100vh - 56px));
  background: radial-gradient(120% 90% at 70% 35%, var(--sky-1) 0%, var(--sky-2) 70%, #9cc6ec 100%);
  isolation: isolate;
}
.box-stage { position: absolute; inset: 0 0 0 30%; z-index: 0; }
.box-stage .vp-tools, .box-stage .vp-hint { display: none; }
.box-bands { position: absolute; left: -10%; right: -10%; bottom: -24px; height: 96px; transform: skewY(-4deg); transform-origin: left bottom; z-index: 1; pointer-events: none; }
.box-bands i { position: absolute; left: 0; right: 0; display: block; }
.box-bands i:nth-child(1) { bottom: 66px; height: 10px; background: var(--yellow); }
.box-bands i:nth-child(2) { bottom: 0; height: 66px; background: var(--red); }
.box-bands i:nth-child(3) { bottom: 76px; height: 5px; background: var(--blue); }
.box-meta {
  position: absolute; top: 22px; left: 28px; right: 28px; display: flex; justify-content: space-between; align-items: center; z-index: 2;
  font-family: var(--display); font-weight: 800; text-transform: uppercase; letter-spacing: .08em; font-size: 15px; pointer-events: none;
}
.series { background: var(--blue); color: #fff; padding: 6px 12px; border-radius: 6px; }
.setno { color: var(--blue-dk); }
.box-copy { position: relative; z-index: 2; max-width: 640px; padding: 86px 28px 130px; }
.age {
  display: inline-grid; place-items: center; min-width: 64px; height: 64px; padding: 0 8px; border-radius: 12px; margin-bottom: 18px;
  background: var(--paper);
}
.age b { font-family: var(--display); font-weight: 800; font-size: 28px; color: var(--ink); }
.box h1, .cover-copy h1 {
  font-family: var(--display); font-style: italic; font-weight: 900; line-height: .9;
  letter-spacing: -.005em; color: var(--ink); text-transform: uppercase;
}
.box h1 { font-size: clamp(48px, 7vw, 88px); margin: 0 0 18px; }
.box-copy p { font-size: 19px; line-height: 1.5; color: #263241; margin: 0 0 26px; max-width: 470px; font-weight: 500; }
.cta { display: flex; flex-wrap: wrap; gap: 10px; }
.box-facts, .cover-facts { position: absolute; right: 28px; bottom: 10px; z-index: 2; display: flex; gap: 24px; color: #fff; pointer-events: none; }
.box-facts div, .cover-facts div { display: flex; flex-direction: column; align-items: flex-end; }
.box-facts b, .cover-facts b { font-family: var(--display); font-style: italic; font-weight: 900; font-size: 32px; line-height: 1; }
.box-facts span, .cover-facts span { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; opacity: .92; }

/* ---------- box back: how to build ---------- */
.back { max-width: 1120px; margin: 0 auto; padding: 64px 20px 32px; }
.back-head { margin-bottom: 26px; }
.kicker { font-family: var(--display); font-weight: 800; text-transform: uppercase; letter-spacing: .1em; color: var(--red); font-size: 15px; }
.back-head h2 { font-family: var(--display); font-weight: 800; font-size: clamp(30px, 4vw, 44px); margin: 4px 0 0; line-height: 1; }
.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel {
  background: var(--paper); border-radius: 16px; padding: 24px; display: flex; gap: 18px; align-items: flex-start;
  box-shadow: 0 1px 2px rgba(15,23,42,.06), 0 6px 24px rgba(15,23,42,.05); min-width: 0;
}
.panel-wide { grid-column: 1 / -1; }
.pnum { font-weight: 800; font-size: 64px; line-height: .8; min-width: 44px; letter-spacing: -.04em; }
.panel-body { flex: 1; min-width: 0; }
.panel h3 { font-family: var(--display); font-weight: 800; font-size: 28px; margin: 0 0 6px; line-height: 1; }
.panel p { margin: 0 0 16px; color: var(--ink-2); font-size: 16px; line-height: 1.5; font-weight: 500; }
.row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.quote { background: var(--callout); border-radius: 10px; padding: 12px 14px; color: #1e3a5f; font-weight: 600; font-style: italic; }
details { flex-basis: 100%; }
summary { cursor: pointer; font-weight: 700; color: var(--blue); }
#promptText {
  max-height: 320px; overflow: auto; white-space: pre-wrap; font: 12px/1.55 'JetBrains Mono', monospace;
  background: var(--page); border-radius: 10px; padding: 14px; margin: 10px 0 0;
}
textarea {
  width: 100%; min-height: 200px; resize: vertical; font: 13px/1.55 'JetBrains Mono', monospace;
  padding: 14px; border-radius: 12px; border: 1px solid #cbd5e1; background: #f8fafc; color: var(--ink); margin-bottom: 14px;
}
textarea:focus { outline: none; border-color: var(--blue); background: #fff; box-shadow: 0 0 0 3px rgba(0,108,183,.15); }
.error { margin: -2px 0 14px; background: #fff1f1; border-left: 4px solid var(--red); border-radius: 8px; padding: 12px 14px; font-weight: 600; color: #7f1d1d; }
.foot { text-align: center; color: var(--ink-3); font-size: 13px; font-weight: 600; margin: 36px 0 0; }

/* =========================================================
   BOOKLET
   ========================================================= */
#book { flex: 1; display: flex; flex-direction: column; min-height: 0; height: calc(100vh - 56px); }
.warnings { background: #fff8db; border-bottom: 1px solid #f3e3a1; padding: 8px 20px; font-weight: 600; font-size: 14px; }
.warnings ul { margin: 8px 0; padding-left: 20px; }
.warnings p { margin: 0 0 6px; color: var(--ink-2); }
.page { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.sheet { position: relative; flex: 1; min-height: 0; background: var(--page); overflow: hidden; }

.viewport { position: absolute; inset: 0; }
.stage-canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; touch-action: none; cursor: grab; }
.stage-canvas:active { cursor: grabbing; }
.vp-tools { position: absolute; top: 16px; right: 16px; display: flex; gap: 6px; z-index: 3; }
.chip {
  font: 700 13px/1 var(--text); padding: 9px 12px; border-radius: 999px; cursor: pointer;
  background: rgba(255,255,255,.92); border: 1px solid var(--line); color: var(--ink);
}
.chip:hover { background: #fff; }
.chip[aria-pressed="false"] { color: var(--ink-3); }
.vp-hint { position: absolute; right: 18px; bottom: 14px; font-size: 12px; font-weight: 600; color: var(--ink-3); pointer-events: none; z-index: 2; }
.page-no { position: absolute; right: 18px; bottom: 34px; font-weight: 800; font-size: 15px; color: var(--ink-3); z-index: 2; pointer-events: none; }

/* ----- step page ----- */
.step-head { position: absolute; top: 18px; left: 22px; display: flex; align-items: flex-start; gap: 14px; z-index: 3; pointer-events: none; }
.step-num { font-weight: 800; font-size: 96px; line-height: .78; letter-spacing: -.045em; }
.callout {
  background: var(--callout); border: 1.5px solid var(--callout-line); border-radius: 12px; padding: 8px 10px 6px;
  display: flex; flex-wrap: wrap; gap: 4px 10px; max-width: 420px; pointer-events: auto;
}
.ci { display: flex; flex-direction: column; align-items: center; min-width: 56px; }
.ci img { width: 60px; height: 60px; object-fit: contain; }
.ci b { font-size: 15px; font-weight: 800; }
.step-card {
  position: absolute; left: 22px; bottom: 22px; width: min(380px, calc(100% - 44px)); max-height: calc(100% - 210px); overflow: auto;
  background: rgba(255,255,255,.96); border-radius: 14px; padding: 16px 18px; z-index: 3;
  box-shadow: 0 1px 2px rgba(15,23,42,.06), 0 10px 30px rgba(15,23,42,.08);
}
.step-card h2 { font-family: var(--display); font-weight: 800; font-size: 26px; margin: 0 0 6px; line-height: 1.05; }
.step-text { font-size: 16px; line-height: 1.5; margin: 0; color: #1f2937; font-weight: 500; }
.conns { list-style: none; margin: 12px 0 0; padding: 12px 0 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 7px; font-size: 14px; line-height: 1.45; color: var(--ink-2); }
.conns b { color: var(--ink); font-weight: 700; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 7px; vertical-align: -1px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.2); }
.note { margin-top: 12px; border-radius: 10px; padding: 10px 12px; font-size: 14px; line-height: 1.45; font-weight: 600; display: flex; gap: 10px; align-items: flex-start; }
.note .ico { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 14px; color: #fff; }
.note.warn { background: #fff1f1; color: #7f1d1d; }
.note.warn .ico { background: var(--red); }
.note.tip { background: #fff8db; color: #5c4400; }
.note.tip .ico { background: #e0a800; }
.note.test { background: #e8f6ec; color: #14532d; }
.note.test .ico { background: #16a34a; }

/* ----- cover + done (box art inside the booklet) ----- */
.sheet.cover, .sheet.done { background: radial-gradient(120% 90% at 65% 40%, var(--sky-1) 0%, var(--sky-2) 72%, #9cc6ec 100%); }
.cover .viewport, .done .viewport { left: 30%; }
.cover-copy { position: absolute; left: 28px; top: 74px; z-index: 3; max-width: 440px; }
.cover-copy h1 { font-size: clamp(44px, 5.6vw, 76px); margin: 0 0 12px; }
.cover-copy .sub { margin: 0 0 22px; font-size: 18px; font-weight: 600; color: #263241; line-height: 1.4; }
.cover-copy .note { margin: 0 0 18px; }
.cover-copy .row { margin-top: 4px; }
.sheet .box-meta { z-index: 3; }
.cover .vp-tools, .done .vp-tools { top: 62px; }
.cover .vp-hint, .done .vp-hint { display: none; }

/* ----- inventory ----- */
.sheet.inventory { background: var(--paper); overflow: auto; }
.inv-wrap { max-width: 1120px; margin: 0 auto; padding: 30px 24px 70px; }
.page-title { font-family: var(--display); font-weight: 800; font-size: 40px; margin: 0; line-height: 1; }
.page-lead { margin: 6px 0 24px; color: var(--ink-2); font-weight: 500; }
.inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(138px, 1fr)); gap: 6px; }
.inv { border-radius: 12px; padding: 12px 8px 10px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.inv:hover { background: var(--page); }
.inv img, .inv .inv-icon { width: 104px; height: 104px; object-fit: contain; }
.inv .qty { font-size: 19px; font-weight: 800; margin-top: 4px; }
.inv span { font-size: 13px; font-weight: 600; line-height: 1.3; color: #1f2937; }
.inv small { font-size: 11px; color: var(--ink-3); font-weight: 600; letter-spacing: .04em; margin-top: 2px; }
.inv-icon { display: grid; place-items: center; }
.inv-icon svg { width: 88px; height: 88px; }

/* ----- code ----- */
.sheet.codepage { overflow: auto; }
.code-wrap { max-width: 980px; margin: 0 auto; padding: 30px 24px 70px; }
.ide-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 18px; }
.ide-get { font-weight: 600; color: var(--blue); text-decoration: underline; text-underline-offset: 3px; }
.howto code { font: 600 12.5px 'JetBrains Mono', monospace; background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; }
.howto { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 0; margin: 20px 0; list-style: none; counter-reset: h; }
.howto li { background: var(--paper); border-radius: 12px; padding: 14px 16px 14px 52px; position: relative; font-weight: 500; line-height: 1.45; counter-increment: h; }
.howto li::before { content: counter(h); position: absolute; left: 16px; top: 10px; font-weight: 800; font-size: 28px; }
.codebox { position: relative; background: #111827; border-radius: 14px; overflow: hidden; }
.codebox .btn { position: absolute; top: 12px; right: 12px; }
.codebox pre { margin: 0; padding: 22px; overflow: auto; color: #e5e7eb; font: 13.5px/1.65 'JetBrains Mono', monospace; }
.codebox .c { color: #7c8799; font-style: italic; }
.codebox .s { color: #a5e07a; }
.codebox .k { color: #ff7b85; }
.codebox .n { color: #ffd166; }
.codebox .f { color: #6cc3ff; }

/* ----- pager ----- */
.pager { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--paper); border-top: 1px solid var(--line); position: relative; z-index: 10; }
.nav-btn {
  width: 52px; height: 44px; border-radius: 12px; border: 1px solid #cbd5e1; background: var(--paper);
  cursor: pointer; flex: none; display: grid; place-items: center; color: var(--ink);
}
.nav-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.nav-btn.next { background: var(--yellow); border-color: #e9c300; }
.nav-btn:disabled { opacity: .35; cursor: default; }
.pager-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.pager-label { font-size: 13px; font-weight: 700; color: var(--ink-2); display: flex; justify-content: space-between; gap: 12px; }
.pager-label b { color: var(--ink); }
.progress { display: flex; gap: 3px; height: 8px; }
.seg { flex: 1; min-width: 3px; border: 0; padding: 0; border-radius: 3px; background: #e2e8f0; cursor: pointer; }
.seg.past { background: #93c5e8; }
.seg.on { background: var(--red); }
.seg:hover { background: #64a7d8; }

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-weight: 700; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); max-width: calc(100vw - 32px); text-align: center;
}

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .topbar { padding: 0 16px; }
  .wordmark { font-size: 21px; }
  .top-actions .ghost { display: none; }
  .box { height: auto; }
  .box-stage { position: relative; inset: auto; height: 300px; margin-top: 54px; }
  .box-copy { padding: 8px 16px 150px; }
  .box-meta { left: 16px; right: 16px; top: 16px; }
  .box-facts, .cover-facts { right: 16px; gap: 14px; }
  .box-facts b, .cover-facts b { font-size: 24px; }
  .panels, .howto { grid-template-columns: 1fr; }
  .panel { padding: 18px; gap: 12px; }
  .pnum { font-size: 48px; min-width: 32px; }
  #book { height: auto; min-height: calc(100vh - 56px); }
  .page { overflow: visible; }
  .sheet { display: flex; flex-direction: column; overflow: visible; }
  .sheet .viewport { position: relative; inset: auto; height: 52vh; order: 2; }
  .step-head { position: relative; top: auto; left: auto; padding: 16px 16px 8px; order: 1; }
  .step-num { font-size: 72px; }
  .step-card { position: relative; left: auto; bottom: auto; width: auto; max-height: none; margin: 0 16px 16px; order: 3; }
  .page-no { display: none; }
  .cover .viewport, .done .viewport { left: auto; height: 44vh; order: 1; margin-top: 50px; }
  .cover-copy { position: relative; left: auto; top: auto; padding: 8px 16px 150px; order: 2; }
  .pager { position: sticky; bottom: 0; padding: 8px 12px; gap: 10px; }
}
