/*
 * Laser Maze Adventure — a dark optics lab in the PlayPuzzle Science Lab kit (/shared/lab/science-lab.css
 * brings the tokens, chunky buttons, Professor Ollie's coach bubble and confetti). Beams need a dark room to
 * glow, so the page is night-blue; cards and the coach stay light so text keeps full contrast.
 *
 * Piece buttons are laid over the board at each cell's projected centre and are never smaller than 44 px.
 * Colour is never the only clue: every coloured piece carries a letter, and the status line says in words
 * how many crystals are glowing.
 */

:root {
  --lab-night: #0b1026;
  --lab-deep: #121a3d;
  --lab-panel: #182253;
  --lab-line: rgba(160, 180, 255, .18);
  --lab-text: #eef2ff;
  --lab-soft: #b9c3ec;
  --beam: #ff4d4d;
  --focus: #ffd43b;
}

.laser-body { background: radial-gradient(1200px 600px at 20% -10%, #24306b 0%, transparent 60%), linear-gradient(180deg, var(--lab-deep), var(--lab-night)) fixed; color: var(--lab-text); }
.laser-body .eyebrow.on-dark { color: #9ff0e5; }
#app { width: 100%; min-height: calc(100dvh - 64px); outline: none; }
.screen { width: min(1280px, calc(100% - 32px)); margin-inline: auto; padding: clamp(14px, 2.6vw, 26px) 0 64px; }
.loading, .noscript { min-height: 70dvh; display: grid; place-content: center; justify-items: center; gap: 6px; text-align: center; padding: 30px; }
.loading svg { width: 72px; height: 72px; fill: none; stroke: var(--beam); stroke-width: 2; stroke-linecap: round; filter: drop-shadow(0 0 6px var(--beam)); }
.skip-link { position: fixed; left: 12px; top: -80px; z-index: 1000; padding: 12px 18px; border-radius: 12px; background: var(--k-ink); color: #fff; font-weight: 900; }
.skip-link:focus { top: 12px; }
.ui-icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.coach-bubble { color: var(--k-ink); }
.k-pill { color: var(--k-ink); }
.k-pill small { color: var(--k-ink-soft); font-weight: 800; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

/* ── Level map ────────────────────────────────────────────────────────────────────────────────────────── */
.hero { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(240px, .7fr); gap: 24px; align-items: end; padding: clamp(22px, 4vw, 44px); border-radius: 32px; border: 1px solid var(--lab-line);
  background: radial-gradient(600px 300px at 85% 20%, rgba(255, 77, 77, .22), transparent 70%), linear-gradient(120deg, #1a2459, #0f1534); box-shadow: 0 20px 50px rgba(0, 0, 0, .35); }
.hero h1 { margin: 0 0 12px; font-size: clamp(2.1rem, 5vw, 3.6rem); text-shadow: 0 0 24px rgba(255, 77, 77, .35); }
.hero-lead { max-width: 36rem; margin: 0 0 22px; font-size: clamp(1.05rem, 1.6vw, 1.2rem); font-weight: 700; line-height: 1.45; color: var(--lab-soft); }
.world { margin-top: 26px; }
.world > header { display: flex; flex-wrap: wrap; align-items: end; gap: 6px 14px; margin-bottom: 12px; }
.world > header h2 { margin: 0; font-size: 1.6rem; flex: 1 1 auto; }
.world > header .eyebrow { flex-basis: 100%; color: #9ff0e5; }
.world-soon { opacity: .8; padding: 16px 18px; border-radius: 22px; border: 1px dashed var(--lab-line); }
.world-soon > header { margin: 0; }
.world-teaser { margin: 6px 0 0; color: var(--lab-soft); font-weight: 700; }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin: 0; padding: 0; list-style: none; }
.level-card { position: relative; display: flex; align-items: center; gap: 12px; min-height: 76px; padding: 12px 14px; border-radius: 20px; border: 1px solid var(--lab-line); background: var(--lab-panel); color: var(--lab-text); text-decoration: none; transition: transform .2s var(--k-spring), border-color .2s; }
.level-card:hover { transform: translateY(-2px); border-color: rgba(255, 212, 59, .6); }
.level-card.next { border-color: #ff6b6b; box-shadow: 0 0 0 3px rgba(255, 77, 77, .25), 0 0 26px rgba(255, 77, 77, .25); }
.level-card.locked { opacity: .5; cursor: default; }
.level-card.locked:hover { transform: none; border-color: var(--lab-line); }
.level-num { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: #263170; font-family: Fredoka, sans-serif; font-size: 1.3rem; flex: none; }
.level-card.done .level-num { background: linear-gradient(180deg, #3ddc84, #2f9e44); color: #062b14; }
.level-copy { display: grid; gap: 2px; min-width: 0; }
.level-copy strong { font-family: Fredoka, sans-serif; font-weight: 600; font-size: 1.08rem; }
.level-copy small { color: var(--lab-soft); font-weight: 700; }
.level-perfect { position: absolute; top: 8px; right: 12px; color: var(--k-gold); font-size: 1.2rem; }

/* ── Play screen ──────────────────────────────────────────────────────────────────────────────────────── */
.play-top { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.play-title { flex: 1; min-width: 0; }
.play-title h1 { margin: 0; font-size: clamp(1.5rem, 3.2vw, 2.2rem); }
.play-top .eyebrow { margin: 0; }
.moves { margin: 0; }
.moves strong { font-family: Fredoka, sans-serif; font-size: 1.3rem; }
.play-body { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.stage-wrap { position: relative; aspect-ratio: 4 / 3; max-height: calc(100dvh - 190px); min-height: 300px; border-radius: 28px; overflow: hidden; border: 1px solid var(--lab-line); background: var(--lab-night); box-shadow: inset 0 0 60px rgba(0, 0, 0, .5), 0 18px 40px rgba(0, 0, 0, .35); }
.stage { position: absolute; inset: 0; }
.stage-canvas-3d, .stage-svg { display: block; width: 100%; height: 100%; touch-action: none; }
.stage-canvas-3d { cursor: grab; }
.stage-canvas-3d:active { cursor: grabbing; }
.piece-layer { position: absolute; inset: 0; pointer-events: none; }
.piece-hit { position: absolute; left: 0; top: 0; padding: 0; border: 0; border-radius: 50%; background: transparent; pointer-events: auto; cursor: pointer; touch-action: manipulation; -webkit-touch-callout: none; user-select: none; transition: box-shadow .15s; }
.piece-hit[aria-disabled="true"] { cursor: default; }
.piece-hit.can-turn:hover { box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .35); }
.piece-hit:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--focus), 0 0 18px rgba(255, 212, 59, .6); }
.piece-tag { display: none; position: absolute; right: -4px; top: -4px; min-width: 24px; height: 24px; padding: 0 5px; border-radius: 999px; background: #fff; color: #0b1026; font: 900 15px/24px Nunito, sans-serif; box-shadow: 0 2px 6px rgba(0, 0, 0, .45); pointer-events: none; }
.is-3d .piece-tag { display: block; }
.piece-hit.hint-target { box-shadow: 0 0 0 4px var(--focus); animation: lm-pulse 1.1s ease-in-out infinite; }
.stage-status, .stage-tip { position: absolute; left: 50%; transform: translateX(-50%); margin: 0; padding: 6px 14px; border-radius: 999px; background: rgba(11, 16, 38, .78); font-weight: 800; white-space: nowrap; pointer-events: none; }
.stage-status { bottom: 12px; }
.stage-tip { top: 12px; font-size: .85rem; color: var(--lab-soft); }
.play:not(.is-3d) .stage-tip { display: none; }
.is-solved .stage-status { color: #3ddc84; }
.side { display: grid; gap: 14px; }
.coach-slot { min-height: 96px; }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tools .k-btn { width: 100%; padding-inline: 12px; }
.tools [data-action="hint"] { grid-column: span 2; }
.done-slot { padding: 18px; border-radius: 24px; background: #fff; color: var(--k-ink); box-shadow: 0 0 0 3px #3ddc84, 0 16px 40px rgba(61, 220, 132, .25); animation: k-rise .4s var(--k-spring) both; }
.done-slot h2 { margin: 0 0 4px; }
.done-slot p { margin: 0 0 14px; font-weight: 800; color: var(--k-ink-soft); }
.done-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ── Flat view pieces ─────────────────────────────────────────────────────────────────────────────────── */
.lm-board { fill: #10173a; stroke: rgba(160, 180, 255, .25); stroke-width: 2; }
.lm-tile { fill: #1f2756; }
.lm-tile-alt { fill: #262f63; }
.lm-floor-label { fill: var(--lab-soft); font: 700 22px Nunito, sans-serif; }
.lm-turn { transition: transform .18s cubic-bezier(.2, .8, .3, 1.2); transform-origin: 0 0; }
.lm-rock { fill: #59607d; stroke: #3a3f58; stroke-width: 4; }
.lm-rock-crack { fill: none; stroke: #3a3f58; stroke-width: 4; stroke-linecap: round; }
.lm-nozzle { fill: #c9d2ff; }
.lm-emitter-body { fill: #3b4370; stroke: #c9d2ff; stroke-width: 4; }
.lm-mirror-face { stroke: #2a3160; stroke-width: 3; }
.lm-splitter-face { fill: rgba(143, 227, 255, .55); stroke: #8fe3ff; stroke-width: 3; }
.lm-prism-face { fill: rgba(223, 246, 255, .45); stroke: #dff6ff; stroke-width: 4; stroke-linejoin: round; }
.lm-filter-face { opacity: .55; stroke: #fff; stroke-width: 3; }
.lm-periscope-body { fill: #4c5bd4; }
.lm-periscope-arrow { fill: none; stroke: #c5f6fa; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.lm-sensor { fill: #ff6b6b; opacity: .7; }
.lm-sensor-eye { fill: #5a0d0d; }
.tripped .lm-sensor { fill: #ff2020; opacity: 1; }
.lm-crystal-face { opacity: .35; stroke: rgba(255, 255, 255, .5); stroke-width: 3; transition: opacity .25s; }
.lm-crystal-facets { fill: none; stroke: rgba(255, 255, 255, .35); stroke-width: 2; }
.lm-crystal.lit .lm-crystal-face { opacity: 1; filter: url(#lm-glow); }
.lm-letter { fill: #0b1026; font: 900 22px Nunito, sans-serif; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.lm-crystal .lm-letter { fill: #fff; paint-order: stroke; stroke: #0b1026; stroke-width: 4px; }
.lm-bolt { fill: #ffd43b; stroke: #b45309; stroke-width: 3; }
.lm-beam { stroke-linecap: round; }
.lm-beam-hop { stroke-dasharray: 10 14; }

/* ── Phase 3: draw-on, crystal pop, stars, lesson cards, settings ─────────────────────────────────────── */
.lm-beam.drawing { stroke-dasharray: 1 1.01; stroke-dashoffset: 1; animation-name: lm-draw; animation-timing-function: linear; animation-fill-mode: both; }
.lm-crystal.pop .lm-turn { animation: lm-pop .7s var(--k-spring); }
.lm-crystal.win .lm-turn { animation: lm-spin 1.6s cubic-bezier(.2, .8, .3, 1); }
.lm-crystal .lm-turn { transform-origin: 0 0; }
.done-slot .star-row { font-size: 2rem; margin-bottom: 6px; }
.done-slot .star-why { margin: -8px 0 14px; font-size: .9rem; font-weight: 700; }
.level-copy .star-row { font-size: 1rem; }
.level-card .k-star:not(.on) { color: #4a5490; }
.tools [data-action="lesson"] { grid-column: span 2; }
.lesson-list { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; padding: 0; list-style: none; }
.lesson-chip { display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 8px 16px; border: 1px solid var(--lab-line); border-radius: 999px; background: var(--lab-panel); color: var(--lab-text); font: 800 1rem Nunito, sans-serif; cursor: pointer; }
.lesson-chip:hover { border-color: rgba(255, 212, 59, .6); }
.badge-shelf { color: var(--k-ink); }
.lm-dialog { width: min(460px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 28px; background: #fff; color: var(--k-ink); box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }
.lm-dialog::backdrop { background: rgba(5, 8, 22, .7); backdrop-filter: blur(3px); }
.lm-dialog[open] { animation: k-rise .35s var(--k-spring) both; }
.lesson { display: grid; gap: 6px; padding: 18px 22px 22px; }
.lesson-picture { width: 100%; height: auto; border-radius: 18px; margin-bottom: 8px; }
.lesson h2 { margin: 0; font-size: 1.6rem; }
.lesson p:not(.eyebrow) { margin: 0 0 12px; font-size: 1.12rem; font-weight: 700; line-height: 1.45; }
.lesson .k-btn, .settings .k-btn { width: 100%; }
.lesson .lesson-more { margin: -4px 0 14px; font-size: 1rem; }
.lesson .lesson-more a { color: var(--k-accent-deep); font-weight: 900; }
.settings { display: grid; gap: 14px; padding: 22px; }
.settings h2 { margin: 0; }
.settings fieldset { margin: 0; padding: 0; border: 0; }
.settings legend { margin-bottom: 6px; font-weight: 900; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label, .switch { position: relative; cursor: pointer; }
.seg input, .switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: inline-flex; align-items: center; min-height: 44px; padding: 6px 14px; border-radius: 999px; background: #eef1fb; font-weight: 800; }
.seg input:checked + span { background: var(--k-accent); color: #fff; }
.seg input:focus-visible + span, .switch input:focus-visible + span { outline: 3px solid var(--k-accent-deep); outline-offset: 2px; }
.switch span { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding: 6px 4px; font-weight: 900; }
.switch span::after { content: ""; width: 52px; height: 30px; border-radius: 999px; background: #cfd6e1 radial-gradient(circle at 15px 15px, #fff 11px, transparent 12px); transition: background .2s; flex: none; }
.switch input:checked + span::after { background: var(--k-success) radial-gradient(circle at 37px 15px, #fff 11px, transparent 12px); }

/* ── Phase 4: fibres, linked mirrors, Premium worlds ───────────────────────────────────────────────────── */
.lm-cable { fill: none; stroke: rgba(76, 91, 212, .7); stroke-width: 18; stroke-linecap: round; }
.lm-fiber-end { fill: #4c5bd4; stroke: #c5f6fa; stroke-width: 4; }
.lm-fiber-mouth { fill: none; stroke: #c5f6fa; stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.lm-beam-fiber { stroke-dasharray: none; }
.lm-link { fill: none; stroke: #da77f2; stroke-width: 5; stroke-dasharray: 10 7; }
.world-premium { padding: 18px; border-radius: 22px; border: 1px solid rgba(255, 212, 59, .35); background: linear-gradient(120deg, rgba(255, 212, 59, .08), transparent); }
.world-premium > header { margin-bottom: 6px; }
.world-premium .world-teaser { margin: 0 0 12px; }
.paywall { display: grid; place-items: center; }
.paywall-card { width: min(640px, 100%); padding: clamp(18px, 4vw, 32px); border-radius: 32px; background: #fff; color: var(--k-ink); box-shadow: 0 0 0 3px rgba(255, 212, 59, .7), 0 24px 60px rgba(0, 0, 0, .4); }
.paywall-card .lesson-picture { width: 100%; height: auto; border-radius: 20px; margin-bottom: 12px; }
.paywall-card h1 { margin: 0 0 8px; font-size: clamp(1.8rem, 5vw, 2.6rem); }
.paywall-lead { margin: 0 0 14px; font-size: 1.12rem; font-weight: 700; line-height: 1.45; }
.paywall-list { margin: 0 0 18px; padding-left: 1.2em; font-weight: 700; line-height: 1.7; }
.paywall-actions { display: grid; gap: 10px; }
.paywall-actions .k-btn { width: 100%; }
.paywall-note { margin: 14px 0 0; color: var(--k-ink-soft); font-size: .92rem; font-weight: 700; }

@keyframes lm-draw { to { stroke-dashoffset: 0; } }
@keyframes lm-pop { 50% { transform: scale(1.35); } }
@keyframes lm-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
@keyframes lm-pulse { 50% { box-shadow: 0 0 0 8px rgba(255, 212, 59, .25); } }

@media (max-width: 860px) {
  .play-body { grid-template-columns: 1fr; }
  .stage-wrap { aspect-ratio: 1 / 1; max-height: 70dvh; }
  .tools { order: -1; }
  .coach-slot { min-height: 0; }
  .hero { grid-template-columns: 1fr; }
  .hero-ollie { display: none; }
}
@media (max-width: 480px) {
  .screen { width: calc(100% - 24px); }
  .play-top { flex-wrap: wrap; }
  .play-title { order: 3; flex-basis: 100%; }
  .play-top .moves { margin-left: auto; }
  .stage-status { font-size: .85rem; }
}
@media (prefers-reduced-motion: reduce) {
  .lm-beam.drawing, .lm-crystal.pop .lm-turn, .lm-crystal.win .lm-turn, .lm-dialog[open] { animation: none; stroke-dashoffset: 0; }
  .lm-turn, .lm-crystal-face, .level-card, .done-slot { transition: none; animation: none; }
  .piece-hit.hint-target { animation: none; }
}
