:root {
    color-scheme: dark;
    --bg: #071315;
    --line: #2c4547;
    --ink: #eff9f4;
    --muted: #adc7c1;
    --gold: #ffd79a;
    --aqua: #91f5db;
    --board-ink: #0b2429;
    --tile: #122e34;
    --tile-edge: #365b5d;
    --accent: #84ead6;
    --brass: #e0bb78;
    font-family: system-ui, Tahoma, sans-serif;
}
* { box-sizing: border-box; }
body {
    background:
        radial-gradient(ellipse at 23% 10%, #132c35 0%, transparent 55%),
        radial-gradient(ellipse at 84% 2%, #122533 0%, transparent 58%),
        #071215;
    color: var(--ink);
    min-height: 100svh;
    margin: 0;
}
a { color: inherit; text-decoration: none; }
button, .lr-primary {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #172b2d;
    color: var(--ink);
    font: inherit;
    font-weight: 650;
    cursor: pointer;
    min-height: 44px;
    padding: 0.58rem 0.84rem;
}
button:disabled { cursor: default; opacity: 0.55; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
button:not(:disabled):hover { border-color: var(--aqua); }
button[aria-pressed="true"] { color: var(--aqua); }
[hidden] { display: none !important; }

.lr-shell { width: min(1120px, calc(100% - 44px)); margin-inline: auto; }
.lr-header, .lr-header-actions { display: flex; align-items: center; gap: 8px; }
.lr-header { justify-content: space-between; padding: 16px 0; }
.lr-header-actions > a, .lr-library {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #132628;
    padding-inline: 12px;
    font-size: 0.86rem;
    font-weight: 680;
}
.lr-library span, .lr-coins span { color: var(--gold); }
#lr-sound { min-width: 44px; padding: 3px 8px; font-size: 1.16rem; }
#lr-sound[aria-pressed="false"] span { opacity: .55; }
.lr-layout {
    display: grid;
    grid-template-columns: minmax(260px, 0.77fr) minmax(340px, 1fr);
    align-items: start;
    gap: 18px;
}
.lr-panel {
    overflow: hidden;
    background: linear-gradient(145deg, #152b32 0%, #0d2026 65%, #0c191f);
    border: 1px solid #3c5a59;
    border-radius: 21px;
    box-shadow: inset 0 1px 0 #ffffff0e, 0 18px 55px #0006;
}
.lr-hero { position: relative; isolation: isolate; aspect-ratio: 1.38; }
.lr-hero picture, .lr-hero img, .lr-hero::after { position: absolute; inset: 0; width: 100%; height: 100%; }
.lr-hero img { object-fit: cover; }
.lr-hero::after { content: ''; background: linear-gradient(to top, #0e2022 1%, #0b2327a0 26%, transparent 62%); }
.lr-heading { position: absolute; inset: auto 20px 5px; z-index: 1; }
.lr-heading p { color: var(--gold); font-weight: 650; margin: 0 0 4px; }
.lr-heading h1 { font-size: clamp(1.55rem, 3.12vw, 2.8rem); margin: 0; line-height: 1.18; letter-spacing: -.025em; text-wrap: balance; }
.lr-intro-content { padding: 12px 20px 21px; }
.lr-intro-copy { color: var(--muted); margin: 0 0 16px; line-height: 1.6; }
.lr-instructions { padding: 14px; background: #142d2d; border: 1px solid #2c4b48; border-radius: 13px; }
.lr-instructions strong { color: var(--aqua); }
.lr-instructions p { color: #e0f0e9; margin: 5px 0 0; line-height: 1.55; }
.lr-menu { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.lr-menu button { flex: 1 1 auto; font-size: .88rem; }
.lr-menu span:not([hidden]) { color: var(--gold); }

.lr-play { padding: 14px 16px 8px; }
.lr-board-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-bottom: 8px; }
.lr-board-header strong, .lr-board-header div > span { display: block; }
.lr-board-header strong { font-size: 1.08rem; }
.lr-board-header div > span { font-size: .82rem; color: var(--muted); }
.lr-board-header output { font-variant-numeric: tabular-nums; color: var(--gold); font-weight: 750; }
.lr-zoom { display: flex; gap: 6px; direction: ltr; }
.lr-zoom button { width: 44px; padding: 2px; font-size: 1.19rem; }
#lr-meter { width: 100%; height: 4px; display: block; border-radius: 4px; overflow: hidden; accent-color: var(--aqua); margin: 0 0 10px; }
#lr-meter::-webkit-progress-bar { background: #294344; }
#lr-meter::-webkit-progress-value { background: linear-gradient(90deg, #73e6cf, #f5d493); }

.lr-pan {
    width: 100%;
    max-width: 500px;
    aspect-ratio: 1;
    margin-inline: auto;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #4e7371 #091719;
    border: 1px solid color-mix(in srgb, var(--brass) 53%, #253138);
    border-radius: 16px;
    direction: ltr;
    box-shadow: inset 0 0 0 3px #081418, inset 0 0 0 4px #bb985044, inset 0 0 30px #0008, 0 14px 28px #0004;
    background:
        radial-gradient(ellipse at 46% 39%, color-mix(in srgb, var(--accent) 11%, var(--board-ink)), transparent 76%),
        repeating-linear-gradient(132deg, #ffffff02 0 1px, transparent 1px 4px),
        var(--board-ink);
}
.lr-board { display: block; width: 100%; min-width: 100%; aspect-ratio: 1; touch-action: manipulation; user-select: none; }
.lr-inlay { fill: #020f1870; stroke: color-mix(in srgb, var(--brass) 55%, transparent); stroke-width: 1; }
.lr-cell { fill: var(--tile); stroke: var(--tile-edge); stroke-width: .75; }
.lr-cell-edge { fill: none; stroke: #e3faff16; stroke-width: .9; stroke-linecap: round; }
.lr-board-stud { fill: #263137; stroke: color-mix(in srgb, var(--brass) 72%, transparent); stroke-width: 1.5; }
.lr-stud-cut { fill: none; stroke: var(--brass); stroke-width: .75; opacity: .68; }
.lr-route { cursor: pointer; outline: none; }
.lr-hit, .lr-casing, .lr-core, .lr-sleeve, .lr-glint { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.lr-hit { stroke: transparent; pointer-events: stroke; }
.lr-casing { stroke: var(--route); stroke-opacity: .22; pointer-events: none; }
.lr-sleeve { stroke: color-mix(in srgb, var(--route) 48%, #091721); pointer-events: none; }
.lr-core { stroke: var(--route); pointer-events: none; }
.lr-glint { stroke: color-mix(in srgb, var(--route) 31%, white); opacity: .82; pointer-events: none; }
.lr-cap { fill: var(--board-ink); stroke: var(--route); stroke-width: 2.6; pointer-events: none; }
.lr-arrow { fill: var(--route); stroke: color-mix(in srgb, var(--route) 26%, #fff); stroke-width: .65; stroke-linejoin: round; pointer-events: none; }
.lr-route:focus-visible .lr-casing, .lr-route:hover .lr-casing { stroke-opacity: .8; }
.lr-highlight .lr-casing { stroke: #fff; stroke-opacity: .85; animation: lr-pulse 1.2s ease-in-out infinite alternate; }
.lr-highlight .lr-arrow { stroke: #fff; stroke-width: 1.6; }
.lr-key { fill: #173735; stroke: var(--route); stroke-width: 1.5; pointer-events: none; }
.lr-device-symbol, .lr-key-symbol { fill: #fff1bd; font: 750 14px system-ui, sans-serif; pointer-events: none; }
.lr-key-symbol { fill: var(--route); font-size: 13px; }
.lr-gate rect { fill: #4a3429; stroke: var(--brass); stroke-width: 1.8; }
.lr-gate-dot { fill: #080f19; stroke: var(--brass); stroke-width: .9; }
.lr-gate-dot.is-lit { fill: #fff0af; }
.lr-portal-rim { fill: #18142e; stroke: var(--portal); stroke-width: 1.75; stroke-dasharray: 5 2; }
.lr-portal-core { fill: color-mix(in srgb, var(--portal) 26%, #15142d); stroke: color-mix(in srgb, var(--portal) 66%, white); stroke-width: .8; }
.lr-portal-symbol { fill: #fff6fc; font: 800 14px system-ui, sans-serif; }
.lr-portal-flash { fill: #f1e7ff40; stroke: #f6e8ff; stroke-width: 2; transform-origin: center; transform-box: fill-box; animation: lr-portal-use .58s ease-out both; }
@keyframes lr-portal-use { from { transform: scale(.65); opacity: .95; } to { transform: scale(1.65); opacity: 0; } }
.lr-gate.is-open { opacity: .36; }
.lr-gate.is-open rect { fill: transparent; stroke-dasharray: 3 3; }
.lr-mirror { fill: #1c4761; stroke: #92d4e6; stroke-width: 1; }
.lr-mirror-face { fill: none; stroke: #c4fcff; stroke-width: 3.5; stroke-linecap: round; }
#lr-effects { pointer-events: none; }
.lr-beam, .lr-obstruction, .lr-impact { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.lr-beam {
    stroke: color-mix(in srgb, var(--beam) 65%, white);
    stroke-width: 7;
    stroke-dasharray: 12 100;
    animation: lr-travel .48s linear both;
}
.lr-obstruction { stroke: #ffb9a0; stroke-width: 2.2; stroke-dasharray: 4 5; animation: lr-fade .72s ease-out both; }
.lr-impact { stroke: #ffb9a0; stroke-width: 3; animation: lr-fade .72s ease-out both; }
@keyframes lr-pulse { from { stroke-opacity: .35; } to { stroke-opacity: .9; } }
@keyframes lr-travel { from { stroke-dashoffset: 13; opacity: .95; } to { stroke-dashoffset: -100; opacity: .05; } }
@keyframes lr-fade { from { opacity: 1; } to { opacity: .25; } }

.lr-play-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.lr-play-actions button { flex: 1; }
.lr-play-actions #lr-result-action { flex-basis: 100%; }
.lr-play-actions small { color: inherit; opacity: .82; margin-inline-start: 4px; }
.lr-primary { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: #aef3d7; border-color: #aef3d7; color: #122d29; }
.lr-status { min-height: 1.45em; margin: 7px 0 1px; color: var(--muted); font-size: .85rem; }
.lr-footer { display: flex; justify-content: center; padding: 12px 0 19px; font-size: .86rem; color: var(--muted); }
.lr-footer a:hover { color: var(--gold); }
.lr-dialog {
    width: min(480px, calc(100% - 24px));
    max-height: min(80svh, 720px);
    overflow: auto;
    border: 1px solid #597570;
    border-radius: 18px;
    background: #13292b;
    color: var(--ink);
    padding: 16px;
    box-shadow: 0 18px 65px #0009;
}
.lr-dialog::backdrop { background: #030b0bd6; }
.lr-dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.lr-dialog h2 { font-size: 1.3rem; margin: 0; }
.lr-dialog-head button { width: 44px; padding: 2px; font-size: 1.45rem; }
#lr-dialog-body > button + button { margin-inline-start: 7px; }
.lr-chapter h3 { font-size: .92rem; color: var(--muted); margin: 14px 0 6px; }
.lr-levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(44px, 1fr)); gap: 5px; }
.lr-levels button { min-width: 0; min-height: 49px; padding: 3px; }
.lr-levels .is-current { border-color: var(--aqua); }
.lr-levels small { display: block; font-size: .65rem; color: var(--gold); }
.lr-stars { font-size: 1.6rem; color: var(--gold); letter-spacing: .1em; }
.lr-finish-list { display: grid; gap: 7px; }
.lr-finish { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 8px; padding: 6px; border-radius: 10px; border: 1px solid var(--line); }
.lr-swatches { display: grid; gap: 4px; }
.lr-swatches span { display: block; height: 3px; border-radius: 3px; }
.lr-error { color: #ffb9a0; }

.lr-shell[data-chapter="1"] { --accent: #78deee; --board-ink: #102832; --tile: #1a3441; --tile-edge: #3a5765; }
.lr-shell[data-chapter="2"] { --accent: #ffd292; --board-ink: #322924; --tile: #352f30; --tile-edge: #59494c; --brass: #fdd498; }
.lr-shell[data-chapter="3"] { --accent: #90dafe; --board-ink: #101e36; --tile: #1a2b44; --tile-edge: #395579; --brass: #9cbfe4; }
.lr-shell[data-chapter="4"] { --accent: #dfa3ff; --board-ink: #251a3a; --tile: #2d2344; --tile-edge: #564270; --brass: #bea1ee; }
.lr-shell[data-chapter="5"] { --accent: #ffa9c3; --board-ink: #321b2d; --tile: #3a293b; --tile-edge: #62435c; --brass: #ffc69f; }
.lr-shell[data-chapter="6"] { --accent: #f6c986; --board-ink: #252843; --tile: #272d49; --tile-edge: #4b5373; --brass: #f6c986; }
.lr-shell .lr-instructions strong { color: var(--accent); }
.lr-journey {
    display: block;
    width: 100%;
    margin-block: 0 12px;
    color: var(--ink);
    background: #0e1d27;
    text-align: start;
    padding: 9px 12px 11px;
    font-size: .9rem;
}
.lr-journey-copy { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.lr-journey-copy b { color: var(--gold); font-variant-numeric: tabular-nums; }
.lr-chapter-map { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; margin-top: 8px; }
.lr-chapter-map i { min-height: 5px; border-radius: 8px; background: #2e404e; }
.lr-chapter-map .is-here { background: color-mix(in srgb, var(--accent) 53%, #233a4c); outline: 1px solid var(--accent); outline-offset: 1px; }
.lr-chapter-map .is-lit { background: var(--accent); box-shadow: 0 0 9px color-mix(in srgb, var(--accent) 40%, transparent); }
.lr-dialog:has(.lr-stars) {
    border-color: #e0b97d;
    background: radial-gradient(ellipse at 50% 110%, #33585a, transparent 72%), #111f2c;
    animation: lr-win .25s ease-out both;
}
@keyframes lr-win { from { opacity: .74; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 735px) {
    .lr-shell { width: min(540px, calc(100% - 22px)); }
    .lr-header { padding: 5px 0; }
    .lr-layout { grid-template-columns: minmax(0, 1fr); gap: 9px; }
    .lr-hero { aspect-ratio: auto; height: 64px; }
    .lr-hero img { object-position: center 46%; }
    .lr-hero::after { background: linear-gradient(to top, #0e2022 3%, #0b232780 78%); }
    .lr-heading { inset-inline: 12px; bottom: 3px; }
    .lr-heading p { font-size: .73rem; margin-bottom: 1px; }
    .lr-heading h1 { font-size: clamp(1.35rem, 5.2vw, 1.8rem); }
    .lr-intro-content { padding: 5px 9px 8px; }
    .lr-intro-copy { display: none; }
    .lr-instructions { padding: 5px 8px; }
    .lr-instructions strong { font-size: .78rem; }
    .lr-instructions p { font-size: .82rem; line-height: 1.45; margin: 1px 0 0; }
    .lr-menu { gap: 4px; margin-top: 5px; }
    .lr-journey { margin-block: 3px 5px; padding: 5px 8px 6px; font-size: .76rem; }
    .lr-chapter-map { margin-top: 5px; }
    .lr-chapter-map i { min-height: 3px; }
    .lr-menu button { padding: 4px; font-size: .78rem; }
    .lr-play { padding: 6px; }
    .lr-board-header { padding: 0 2px 4px; }
    .lr-board-header strong { font-size: .92rem; }
    #lr-meter { margin-bottom: 4px; }
    .lr-play-actions { margin-top: 6px; }
}
@media (prefers-reduced-motion: reduce) {
    .lr-highlight .lr-casing, .lr-obstruction, .lr-impact, .lr-beam, .lr-portal-flash, .lr-dialog:has(.lr-stars) { animation: none; }
}

.lr-shell { width: min(1260px, calc(100% - 36px)); }
.lr-layout { grid-template-columns: minmax(255px, .58fr) minmax(350px, 1fr); }
.lr-play { padding-block-start: 12px; }
.lr-pan { max-width: min(660px, max(375px, calc(100svh - 366px))); }
.lr-mode {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    padding: 4px;
    margin-bottom: 10px;
    border: 1px solid #405051;
    border-radius: 14px;
    background: #09191d;
}
.lr-mode button { border-color: transparent; background: transparent; color: var(--muted); }
.lr-mode button[aria-pressed="true"] {
    background: linear-gradient(174deg, color-mix(in srgb, var(--accent) 22%, #12232b), #132a30);
    color: #fff5e6;
    border-color: color-mix(in srgb, var(--brass) 65%, #2e3f46);
    box-shadow: inset 0 1px 0 #fff1;
}
.lr-mode span { color: var(--brass); font-size: 1.02em; }
.lr-compact-rule { display: none; }
.lr-cube-stage {
    max-width: 660px;
    margin-inline: auto;
    border-radius: 16px;
    background:
        radial-gradient(ellipse at 50% 44%, #2c2943 0%, #0d1f2c 57%, #081722 100%);
    border: 1px solid #826d54;
    box-shadow: inset 0 0 0 3px #15202a;
}
.lr-cube-viewport {
    width: 100%;
    height: clamp(315px, 55svh, 565px);
    max-height: 125vw;
    overflow: hidden;
    display: grid;
    place-items: center;
    perspective: 900px;
    direction: ltr;
    touch-action: none;
    cursor: grab;
    position: relative;
}
.lr-cube-viewport.is-dragging { cursor: grabbing; }
.lr-cube-solid {
    --edge: clamp(174px, min(32vw, 35svh), 330px);
    width: var(--edge);
    height: var(--edge);
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(-24deg) rotateY(-36deg);
    transition: transform 150ms ease-out;
}
.lr-cube-viewport.is-dragging .lr-cube-solid { transition: none; }
.lr-cube-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    background: radial-gradient(ellipse at 15% 9%, #252c47, #101c2e);
    box-shadow: inset 0 0 0 1px #e6c59199, inset 0 0 0 3px #e2bd7740, inset 0 0 20px #121c2f;
}
.lr-cube-face::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: .65;
    background:
        linear-gradient(to right, #879bc323 1px, transparent 1px),
        linear-gradient(to bottom, #879bc323 1px, transparent 1px);
    background-size: calc(100% / var(--face-cells)) calc(100% / var(--face-cells));
}
.lr-cube-face svg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; overflow: hidden; }
.lr-cube-front { transform: translateZ(calc(var(--edge) / 2)); }
.lr-cube-right { transform: rotateY(90deg) translateZ(calc(var(--edge) / 2)); background-color: #231d30; }
.lr-cube-back { transform: rotateY(180deg) translateZ(calc(var(--edge) / 2)); }
.lr-cube-left { transform: rotateY(-90deg) translateZ(calc(var(--edge) / 2)); }
.lr-cube-top { transform: rotateX(90deg) translateZ(calc(var(--edge) / 2)); }
.lr-cube-bottom { transform: rotateX(-90deg) translateZ(calc(var(--edge) / 2)); }
.lr-cube-top, .lr-cube-left { filter: brightness(1.13); }
.lr-cube-bottom, .lr-cube-right { filter: brightness(.88); }
.lr-cube-effects { pointer-events: none; }
.lr-cube-controls { display: flex; justify-content: center; gap: 8px; padding: 0 8px 8px; }
.lr-cube-controls button { width: 44px; padding: 2px; font-size: 1.1rem; }
#lr-scan { color: #f4d6a5; background: #302736; border-color: #9b7a53; }
#lr-scan small { white-space: nowrap; }
@media (max-width: 760px) {
    .lr-shell { width: min(550px, calc(100% - 12px)); }
    .lr-layout { grid-template-columns: minmax(0, 1fr); gap: 8px; }
    .lr-play { grid-row: 1; padding: 5px; }
    .lr-intro { grid-row: 2; }
    .lr-instructions { display: none; }
    .lr-mode { margin-bottom: 4px; }
    .lr-mode button { font-size: .88rem; }
    .lr-pan { max-width: 100%; }
    .lr-compact-rule {
        display: block;
        margin: 3px 0 7px;
        padding-inline: 4px;
        font-size: .78rem;
        color: var(--muted);
        line-height: 1.4;
    }
    .lr-cube-viewport { perspective: 700px; height: clamp(280px, 79vw, 440px); }
    .lr-cube-solid { --edge: clamp(147px, 46vw, 245px); }
    .lr-play-actions button { min-width: 64px; font-size: .82rem; padding-inline: 6px; }
    .lr-play-actions small { margin-inline-start: 2px; }
}
@media (prefers-reduced-motion: reduce) {
    .lr-cube-solid { transition: none; }
}


