/* Spark Lab theme — purple, black, red, orange, blue.
 * Change the colours here and the whole game follows. */
:root {
  --bg: #0a0614;
  --bg2: #120a26;
  --panel: #160d2e;
  --panel2: #21134a;
  --line: #3a2a6e;
  --purple: #8b5cf6;
  --purple-l: #c4b5fd;
  --blue: #38bdf8;
  --blue-d: #2563eb;
  --orange: #fb923c;
  --red: #ef4444;
  --text: #f3edff;
  --muted: #a99dd4;
  --ok: #4ade80;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background:
    radial-gradient(1200px 600px at 80% -10%, #2a1363 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #3a0f2e 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overflow-x: hidden;
}
button { font-family: inherit; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: rgba(10, 6, 20, .6); backdrop-filter: blur(6px); }
.brand { border: 0; cursor: pointer; padding: 0; font-family: inherit; font-weight: 900; letter-spacing: .12em; font-size: 20px; background: linear-gradient(90deg, var(--purple-l), var(--blue)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand .bolt { -webkit-text-fill-color: var(--orange); filter: drop-shadow(0 0 6px var(--orange)); }
.levelname { flex: 1; text-align: center; font-weight: 700; color: var(--purple-l); font-size: 17px; }
.actions { display: flex; gap: 8px; }

.btn { border: 0; cursor: pointer; font-weight: 800; font-size: 15px; color: #fff; padding: 10px 18px; border-radius: 12px; background: linear-gradient(135deg, var(--purple), var(--blue-d)); box-shadow: 0 4px 0 #3b1d8f, 0 8px 20px rgba(139, 92, 246, .35); transition: transform .08s, filter .15s; }
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #3b1d8f; }
.btn.ghost { background: var(--panel2); box-shadow: 0 3px 0 #0d0620; border: 1px solid var(--line); padding: 8px 14px; }
.btn.small { padding: 7px 14px; font-size: 13px; }
.btn.orange { background: linear-gradient(135deg, var(--orange), var(--red)); box-shadow: 0 4px 0 #8f2a12; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr) 300px; gap: 18px; padding: 18px; height: calc(100vh - 60px); height: calc(100dvh - 60px); /* dvh = ignores phone address-bar jumps */ min-height: 0; }
.stage { position: relative; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.board-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; border-radius: 22px; border: 2px solid var(--line); background: linear-gradient(180deg, #120a28, #0b0618); box-shadow: inset 0 0 60px rgba(139, 92, 246, .12), 0 10px 40px rgba(0, 0, 0, .5); padding: 14px; }
#board { width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.status { margin-top: 12px; padding: 10px 16px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); font-weight: 700; color: var(--muted); text-align: center; transition: all .2s; }
.status.flow { color: var(--blue); border-color: var(--blue); box-shadow: 0 0 18px rgba(56, 189, 248, .25); }
.status.short { color: #fff; background: #5a0f1b; border-color: var(--red); animation: shake .35s infinite; }
.toast { position: absolute; top: 18px; left: 50%; transform: translate(-50%, -20px); opacity: 0; pointer-events: none; background: var(--panel2); border: 1px solid var(--orange); color: var(--text); padding: 9px 16px; border-radius: 12px; font-weight: 700; transition: all .25s; z-index: 5; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- side panel ---------- */
.side { display: flex; flex-direction: column; gap: 14px; overflow-y: auto; min-height: 0; padding-right: 2px; }
.card { background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card h3 { margin: 0 0 10px; font-size: 14px; letter-spacing: .12em; text-transform: uppercase; color: var(--purple-l); }
.tag { display: inline-block; font-size: 11px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; padding: 3px 10px; border-radius: 999px; background: var(--orange); color: #2a1200; margin-bottom: 8px; }
.tag.Broken { background: var(--red); color: #fff; }
.tag.Incomplete { background: var(--orange); }
.tag.Build { background: var(--blue); color: #04243a; }
.tag.Sandbox { background: var(--purple); color: #fff; }
.story { margin: 0 0 10px; line-height: 1.4; color: var(--text); }
/* Objectives: two groups (main + bonus), one card per goal */
.goal-group { margin: 0 0 12px; }
.goal-title { margin: 0 0 6px; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; }
.goal-title span { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); }
.goal-title.main { color: var(--blue); }
.goal-title.bonus { color: var(--orange); }
.goal-cards { display: grid; gap: 7px; }
.goal { display: flex; gap: 9px; align-items: flex-start; padding: 9px 11px; border-radius: 12px; background: #0d0720; border: 2px solid var(--line); border-left: 5px solid var(--blue); font-weight: 700; font-size: 14px; line-height: 1.3; color: var(--muted); }
.goal .box { flex: none; width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line); display: grid; place-items: center; font-size: 14px; color: transparent; background: var(--bg); }
.goal.met { color: var(--text); border-color: var(--ok); }
.goal.met .box { background: var(--ok); border-color: var(--ok); color: #052e12; }
#bonusGoals .goal { border-left-color: var(--orange); }
#bonusGoals .goal .box { border-color: var(--orange); color: var(--orange); }
#bonusGoals .goal.met { border-color: var(--orange); }
#bonusGoals .goal.met .box { background: var(--orange); border-color: var(--orange); color: #2a1200; }
.hint { margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; background: #0d0720; border-left: 4px solid var(--blue); color: var(--purple-l); font-size: 14px; line-height: 1.4; }

.bin { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 10px; }
.tile { position: relative; aspect-ratio: 1; border-radius: 14px; background: radial-gradient(circle at 50% 40%, #2b1a5e, #120a28); border: 2px solid var(--line); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; transition: transform .1s, border-color .15s; }
.tile:hover { border-color: var(--purple); transform: translateY(-2px); }
.tile svg { width: 100%; height: 100%; pointer-events: none; }
.tile .count { position: absolute; right: 5px; bottom: 4px; font-size: 12px; font-weight: 900; padding: 1px 7px; border-radius: 999px; background: var(--orange); color: #2a1200; }
.tile .name { position: absolute; left: 0; right: 0; top: 3px; text-align: center; font-size: 10px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; pointer-events: none; }
.tile.empty { opacity: .3; cursor: not-allowed; filter: grayscale(.6); }
.tile.empty:hover { transform: none; border-color: var(--line); }
.binwrap.dropping { outline: 3px dashed var(--orange); outline-offset: 2px; }
.tips { margin: 12px 0 0; font-size: 12.5px; line-height: 1.4; color: var(--muted); }

/* ---------- board artwork ---------- */
.cell-bg { fill: #140b2b; stroke: #271a4d; stroke-width: 2; }
.cell-dot { fill: #2f2060; }
.cell-hl-ok { fill: rgba(56, 189, 248, .18); stroke: var(--blue); stroke-width: 3; }
.cell-hl-bad { fill: rgba(239, 68, 68, .18); stroke: var(--red); stroke-width: 3; }
.part { cursor: grab; }
.part.locked { cursor: default; }
.part.shake { animation: shake .3s; }

.w-out { fill: none; stroke: #2b1d52; stroke-width: 17; stroke-linejoin: round; }
.w-in { fill: none; stroke: #9a86ee; stroke-width: 8; stroke-linejoin: round; }
.w-in.lk { stroke: #66559f; }
.w-in.live { stroke: var(--blue); animation: glow 1.2s ease-in-out infinite; animation-delay: var(--d, 0s); }
.w-in.hot { stroke: var(--red); animation: hot .25s ease-in-out infinite alternate; }
.w-dot { fill: #9a86ee; stroke: #2b1d52; stroke-width: 3; }
.w-dot.lk { fill: #66559f; }
.w-dot.live { fill: var(--blue); }
.w-dot.hot { fill: var(--red); }

.bat-neg { fill: #1c1238; stroke: #6d4fd6; stroke-width: 3; }
.bat-pos { fill: #ef4444; stroke: #ff8a4c; stroke-width: 3; }
.bat-pos.on { animation: batglow 1.2s ease-in-out infinite; }
.sym { fill: #fff; font: 900 26px "Trebuchet MS", sans-serif; text-anchor: middle; dominant-baseline: central; }
.glass { fill: #2a1d58; stroke: #9a86ee; stroke-width: 4; }
.glass.blown { fill: #0f0a1d; stroke: #5a4b8a; }
.bulb-base { fill: #4b3a8c; stroke: #2b1d52; stroke-width: 3; }
.filament { fill: none; stroke: #8f80d6; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.filament.lit { stroke: #fff; }
.crack { fill: none; stroke: #9d8cdb; stroke-width: 2.5; stroke-linecap: round; }
.smoke { fill: #8a85a8; opacity: .6; animation: smoke 1.6s ease-out infinite; }
.smoke.s2 { animation-delay: .6s; }
.bz-body { fill: #1c1238; stroke: #a78bfa; stroke-width: 4; }
.bz-hole { fill: #07030f; stroke: #5b3fbf; stroke-width: 2; }
.bz-dot { fill: #5b3fbf; }
.wave { fill: none; stroke: #5b3fbf; stroke-width: 4; stroke-linecap: round; opacity: .35; }
.buzz.on .bz-body { stroke: var(--orange); }
.buzz.on .wave { stroke: var(--orange); opacity: 1; animation: wave .5s ease-in-out infinite alternate; }
.buzz.on .w2 { animation-delay: .25s; }
.buzz.on { animation: shake .18s infinite; transform-origin: 50px 50px; }
.lever { stroke: var(--orange); stroke-width: 8; stroke-linecap: round; }
.lever.closed { filter: drop-shadow(0 0 4px var(--orange)); }
.contact { fill: #2b1d52; stroke: var(--orange); stroke-width: 3.5; }
.lock { font-size: 15px; opacity: .65; }

/* ---------- Engineer tier: schematic / blueprint look ---------- */
.s-wire { fill: none; stroke: #bcd3ff; stroke-width: 3; stroke-linejoin: round; stroke-linecap: butt; }
.s-wire.lk { stroke: #8497c4; }
.s-wire.live { stroke: var(--orange); animation: glow 1.2s ease-in-out infinite; animation-delay: var(--d, 0s); }
.s-wire.hot { stroke: var(--red); animation: hot .25s ease-in-out infinite alternate; }
.s-dot { fill: #bcd3ff; }
.s-dot.live { fill: var(--orange); }
.s-dot.hot { fill: var(--red); }
.s-sym { fill: none; stroke: #e6efff; stroke-width: 4; stroke-linecap: round; }
.s-sym.thick { stroke-width: 7; }
.defs-only { position: absolute; }
.s-sym.s-fill { fill: #0b1a3a; }
.s-sym.s-fill.on { fill: #3a1d08; stroke: var(--orange); }
.s-sym.blown { stroke: var(--red); stroke-dasharray: 5 6; }
.s-sym.on { stroke: var(--orange); }
.s-contact { fill: #0b1a3a; stroke: #e6efff; stroke-width: 3; }
.s-wave { fill: none; stroke: var(--orange); stroke-width: 3; stroke-linecap: round; }
.s-label { fill: #9fb8e8; font: 700 12px "Courier New", monospace; text-anchor: middle; dominant-baseline: central; }
body.schematic .board-wrap { background-color: #0a1633; background-image: linear-gradient(rgba(120, 160, 255, .09) 1px, transparent 1px), linear-gradient(90deg, rgba(120, 160, 255, .09) 1px, transparent 1px); background-size: 24px 24px; border-color: #2a4a8a; box-shadow: inset 0 0 60px rgba(56, 130, 248, .18), 0 10px 40px rgba(0, 0, 0, .5); }
body.schematic .cell-bg { fill: rgba(10, 22, 51, .55); stroke: #1c3366; stroke-dasharray: 4 6; }
body.schematic .tile { background: radial-gradient(circle at 50% 40%, #12285a, #0a1633); border-color: #2a4a8a; }
.key-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 13px; }
.key-row svg { width: 64px; height: 64px; flex: none; background: #0a1633; border-radius: 10px; border: 1px solid #2a4a8a; }
.key-row span { color: var(--muted); font-size: 12px; }

/* drag ghost */
.drag-ghost { position: fixed; z-index: 50; pointer-events: none; transform: translate(-50%, -50%) scale(1.08); filter: drop-shadow(0 10px 16px rgba(0, 0, 0, .6)); opacity: .96; }
.drag-ghost svg { width: 100%; height: 100%; overflow: visible; }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; background: rgba(5, 2, 12, .78); display: grid; place-items: center; z-index: 20; padding: 18px; backdrop-filter: blur(4px); }
.overlay[hidden] { display: none; }
.panel { position: relative; width: min(760px, 100%); max-height: 92vh; overflow: auto; background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 2px solid var(--purple); border-radius: 22px; padding: 24px; box-shadow: 0 0 60px rgba(139, 92, 246, .35); text-align: center; }
.panel h2 { margin: 0 0 16px; font-size: 26px; background: linear-gradient(90deg, var(--orange), var(--red), var(--purple-l)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tiers { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }
.tier-tab { cursor: pointer; border-radius: 12px; padding: 8px 14px; font-weight: 800; background: #0d0720; border: 2px solid var(--line); color: var(--text); }
.tier-tab:hover { border-color: var(--orange); }
.tier-tab.on { border-color: var(--purple-l); background: var(--purple); }
.tier-tab small { display: block; font-weight: 600; opacity: .7; }
.tier-blurb { margin: 0 0 14px; opacity: .8; }
.coming-soon { grid-column: 1 / -1; padding: 24px; border: 2px dashed var(--line); border-radius: 14px; opacity: .8; }
.levelgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.lcard { text-align: left; cursor: pointer; border-radius: 14px; padding: 12px; background: #0d0720; border: 2px solid var(--line); color: var(--text); transition: transform .1s, border-color .15s; }
.lcard:hover { transform: translateY(-3px); border-color: var(--orange); }
.lcard .num { font-size: 11px; font-weight: 900; letter-spacing: .12em; color: var(--blue); }
.lcard .nm { font-weight: 800; margin: 3px 0 6px; }
.lcard .st { color: var(--orange); letter-spacing: 3px; font-size: 16px; }
.lcard .st .off { color: #3a2a6e; }
.stars { font-size: 52px; letter-spacing: 8px; color: var(--orange); text-shadow: 0 0 18px var(--orange); margin: 4px 0 10px; }
.stars .off { color: #3a2a6e; text-shadow: none; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.winpanel p { color: var(--purple-l); font-size: 16px; margin: 0; }
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 2px; animation: fall linear forwards; }

/* ---------- animations ---------- */
@keyframes glow { 0%, 100% { filter: drop-shadow(0 0 2px var(--blue)); } 50% { filter: drop-shadow(0 0 9px #9be4ff); } }
@keyframes hot { from { filter: drop-shadow(0 0 3px var(--red)); stroke: #ff3b2f; } to { filter: drop-shadow(0 0 12px var(--orange)); stroke: var(--orange); } }
@keyframes batglow { 0%, 100% { filter: drop-shadow(0 0 2px var(--orange)); } 50% { filter: drop-shadow(0 0 10px var(--orange)); } }
@keyframes wave { from { opacity: .3; } to { opacity: 1; } }
@keyframes smoke { from { transform: translateY(0); opacity: .6; } to { transform: translateY(-14px); opacity: 0; } }
@keyframes shake { 0%, 100% { transform: translate(0, 0); } 25% { transform: translate(-1.5px, 1px); } 75% { transform: translate(1.5px, -1px); } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- small screens (tablet / phone friendly) ---------- */
/* Three sizes: desktop (above) = 3 columns. Tablet = narrower columns.
 * Phone portrait = ONE column: board first, parts bin right under it, mission last. */
@media (max-width: 1200px) {
  .layout { grid-template-columns: 240px minmax(0, 1fr) 220px; }
}
@media (max-width: 700px), (max-width: 900px) and (orientation: portrait) {
  .layout { grid-template-columns: 1fr; height: auto; gap: 12px; padding: 12px; }
  .stage { order: 1; }
  .side-right { order: 2; }
  .side-left { order: 3; }
  .board-wrap { flex: none; height: min(100vw - 24px, 58vh); height: min(100vw - 24px, 58dvh); padding: 8px; }
  .side { overflow: visible; }
  .levelname { display: none; }
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .brand { font-size: 17px; }
  .actions { margin-left: auto; }
  .bin { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
  .tips { display: none; } /* the welcome + mission screens already explain it */
}
@media (max-width: 600px) {
  .btn .lbl { display: none; } /* icon-only buttons on phones */
  .btn.ghost { padding: 8px 12px; }
}
/* Phone held sideways: short screen, so squeeze the 3 columns and the top bar */
@media (max-height: 520px) and (orientation: landscape) {
  .topbar { padding: 4px 12px; }
  .btn.ghost { padding: 5px 10px; }
  .layout { grid-template-columns: 210px minmax(0, 1fr) 150px; gap: 10px; padding: 8px 10px; height: calc(100vh - 44px); height: calc(100dvh - 44px); }
  .board-wrap { padding: 6px; }
  .status { margin-top: 6px; padding: 6px 10px; font-size: 14px; }
  .bin { grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); }
  .tips, .levelname { display: none; }
  .card { padding: 10px 12px; }
  .panel { max-height: 96vh; max-height: 96dvh; padding: 16px; }
  .stars { font-size: 36px; }
}

/* Touchscreens (no hover): bigger tap targets, no hover wobble, no text-select / callout popups */
@media (pointer: coarse) {
  .btn, .tier-tab, .lcard, .linkbtn { min-height: 44px; }
  .tile:hover, .lcard:hover { transform: none; }
  .tile, #board { -webkit-touch-callout: none; }
}
body { touch-action: manipulation; } /* no double-tap-to-zoom delay on buttons */
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); } /* keep clear of phone notches */

/* ---------- mission briefing wizard ---------- */
.overlay#intro { z-index: 30; }
.panel.intro { width: min(560px, 100%); padding: 28px 26px 20px; }
.intro-tag { display: inline-block; font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--blue); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; }
.intro-tag.bonus { color: var(--orange); border-color: var(--orange); }
.intro-icon { font-size: 64px; line-height: 1.2; margin: 10px 0 0; }
.panel.intro h2 { margin: 6px 0 10px; }
.intro-text { font-size: 22px; font-weight: 800; margin: 0 0 12px; color: var(--text); }
.intro-how { font-size: 16px; color: var(--muted); margin: 0 0 14px; line-height: 1.45; }
.intro-how[hidden] { display: none; }
.dots { display: flex; justify-content: center; gap: 8px; margin: 14px 0; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--orange); transform: scale(1.3); }
.panel.intro .row { display: flex; justify-content: space-between; gap: 12px; }
.linkbtn { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; margin-top: 14px; font-size: 14px; }
.linkbtn:hover { color: var(--text); }
a.linkbtn { display: inline-block; margin-top: 0; }
.w-privacy { margin: 14px 0 0; color: var(--muted); font-size: 14px; }

/* Plain text pages (privacy.html) */
.doc { max-width: 720px; margin: 0 auto; padding: 20px 16px 40px; line-height: 1.55; }
.doc h1 { font-size: 30px; margin: 8px 0 6px; background: linear-gradient(90deg, var(--orange), var(--red), var(--purple-l)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.doc-lead { font-size: 18px; color: var(--purple-l); }
.doc .card { margin: 16px 0; }
.doc ul { padding-left: 20px; margin: 0; }
.doc li { margin: 6px 0; }
.doc a { color: var(--blue); }
.doc-foot { color: var(--muted); font-size: 14px; }
.linkbtn[hidden] { display: none; }

/* ---------- welcome / home screen ---------- */
.brand:hover { filter: brightness(1.25); }
.overlay#welcome { z-index: 40; background: radial-gradient(circle at 50% 30%, rgba(139, 92, 246, .35), rgba(5, 2, 12, .94)); }
.panel.welcome { width: min(620px, 100%); padding: 32px 26px 24px; overflow-x: hidden; }
.w-bolt { font-size: 72px; line-height: 1.2; color: var(--orange); filter: drop-shadow(0 0 18px var(--orange)); animation: wpulse 1.6s ease-in-out infinite; }
@keyframes wpulse { 50% { transform: scale(1.08); } } /* scale only: no layout change, so no scrollbar flicker */
.panel.welcome h1 { margin: 6px 0 4px; font-size: 48px; letter-spacing: .1em; padding-left: .1em; background: linear-gradient(90deg, var(--orange), var(--red), var(--purple-l), var(--blue)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.w-sub { margin: 0 0 20px; font-size: 18px; color: var(--muted); }
.w-steps { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 22px; text-align: left; }
.w-steps div { display: flex; align-items: center; gap: 10px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-weight: 700; font-size: 14px; }
.w-steps b { font-size: 26px; }
.w-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn.big { font-size: 18px; padding: 14px 26px; }
.w-stars { margin: 16px 0 0; color: var(--orange); font-weight: 800; min-height: 1.2em; }
@media (max-width: 520px) { .w-steps { grid-template-columns: 1fr; } .panel.welcome h1 { font-size: 36px; } }
