:root {
    --bg-base: #0d0f1c;
    --text-gold: #e8c988;
    --text-gold-dim: #c5a059;
    --text-body: #d1d1d1;
    --glass-empty: #262833;
    --glass-filled: #5a6270;
    --lead-unsolved: #1f222b;
    --lead-solved: #050505;
    --cell-size: 40px;
    --glass-color: #7a8ba8;

    /* Cathedral jewel palette */
    --jewel-cobalt:  #0e2459;
    --jewel-ruby:    #3d0a14;
    --jewel-emerald: #0a2b18;
    --jewel-amber:   #2e1a00;
    --jewel-violet:  #1c0b30;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    overflow-x: clip;
    /* No double-tap zoom (it eats the second of two quick taps); panning and
       pinch-zoom still work, so accessibility zoom is preserved. */
    touch-action: manipulation;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow-x: hidden;
    /* Cathedral base: very deep blue-violet with no distracting texture at body level */
    background-color: var(--bg-base);
    color: var(--text-body);
    font-family: 'Lora', serif;
    position: relative;
}

h1, h2, h3 {
    font-family: 'Cinzel', serif;
    font-weight: 600;
    color: var(--text-gold);
    text-align: center;
    margin: 0;
    /* Ensure text lifts off dark atmospheric backgrounds */
    text-shadow: 0 2px 4px rgba(0,0,0,0.9), 0 4px 20px rgba(0,0,0,0.6);
}

h1 {
    /* Fluid: was a fixed 2.8rem, which wrapped to three lines on phones */
    font-size: clamp(1.8rem, 7vw, 2.8rem);
    letter-spacing: 2px;
    margin-top: 40px;
    text-transform: uppercase;
    text-shadow: 0 2px 4px rgba(0,0,0,0.95), 0 4px 30px rgba(0,0,0,0.7), 0 0 60px rgba(212,154,42,0.15);
}

.subtitle {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.9rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #aaa;
    margin-top: 10px;
    margin-bottom: 20px;
}

/* =====================================================================
   BACKGROUND LAYER SYSTEM
   Three layers stack per screen:
   1. body bg-color  — the absolute base (#0d0f1c)
   2. .bg-rays       — fixed ambient light shafts (all screens)
   3. .bg-rose-window — fixed rose motif (menu only, fades out)
   4. .screen::before — per-screen jewel-tone gradient
   5. .screen::after  — per-screen lead-caming SVG pattern tile
   ===================================================================== */

/* --- Ambient light rays (fixed, behind everything) --- */
.bg-rays {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.ray {
    position: absolute;
    top: -10%;
    width: 2px;
    height: 130vh;
    transform-origin: top center;
    opacity: 0;
}

/* Each ray: slightly translucent warm gradient, slow drift */
.ray-1 {
    left: 18%;
    background: linear-gradient(to bottom, rgba(212,154,42,0.18) 0%, rgba(212,154,42,0.04) 55%, transparent 100%);
    transform: rotate(-6deg);
    animation: rayDrift 22s ease-in-out infinite;
    animation-delay: 0s;
}
.ray-2 {
    left: 32%;
    background: linear-gradient(to bottom, rgba(26,76,156,0.22) 0%, rgba(26,76,156,0.05) 50%, transparent 100%);
    transform: rotate(-2deg);
    animation: rayDrift 28s ease-in-out infinite;
    animation-delay: -7s;
}
.ray-3 {
    left: 50%;
    background: linear-gradient(to bottom, rgba(232,201,136,0.24) 0%, rgba(232,201,136,0.06) 45%, transparent 100%);
    transform: rotate(1deg);
    animation: rayDrift 18s ease-in-out infinite;
    animation-delay: -4s;
    width: 3px;
}
.ray-4 {
    left: 67%;
    background: linear-gradient(to bottom, rgba(191,21,49,0.18) 0%, rgba(191,21,49,0.04) 50%, transparent 100%);
    transform: rotate(4deg);
    animation: rayDrift 24s ease-in-out infinite;
    animation-delay: -12s;
}
.ray-5 {
    left: 82%;
    background: linear-gradient(to bottom, rgba(122,26,176,0.16) 0%, rgba(122,26,176,0.04) 50%, transparent 100%);
    transform: rotate(8deg);
    animation: rayDrift 20s ease-in-out infinite;
    animation-delay: -3s;
}

@keyframes rayDrift {
    0%, 100% { opacity: 0.6; transform: rotate(var(--r, -4deg)) translateX(0px); }
    25%       { opacity: 0.9; transform: rotate(var(--r, -4deg)) translateX(8px); }
    50%       { opacity: 0.5; transform: rotate(var(--r, -4deg)) translateX(-6px); }
    75%       { opacity: 0.85; transform: rotate(var(--r, -4deg)) translateX(4px); }
}

/* Fix each ray's --r so keyframe overrides don't stomp the initial rotation */
.ray-1 { --r: -6deg; }
.ray-2 { --r: -2deg; }
.ray-3 { --r:  1deg; }
.ray-4 { --r:  4deg; }
.ray-5 { --r:  8deg; }

/* --- Cathedral dust motes (floating particles in light beams) --- */
.bg-dust {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.dm {
    position: absolute;
    border-radius: 50%;
    background: rgba(232, 201, 136, 0.55);
    animation: dustFloat linear infinite;
    bottom: -4px;
}

@keyframes dustFloat {
    0%   { transform: translateY(0) translateX(0);                       opacity: 0;    }
    8%   {                                                               opacity: 0.65; }
    88%  {                                                               opacity: 0.4;  }
    100% { transform: translateY(-105vh) translateX(var(--dm-dx, 18px)); opacity: 0;    }
}

.dm-1 { left: 14%; width: 1px; height: 1px; animation-duration: 48s; animation-delay:   0s; --dm-dx:  12px; }
.dm-2 { left: 27%; width: 2px; height: 2px; animation-duration: 66s; animation-delay: -22s; --dm-dx: -16px; }
.dm-3 { left: 38%; width: 1px; height: 1px; animation-duration: 54s; animation-delay:  -8s; --dm-dx:  20px; }
.dm-4 { left: 49%; width: 2px; height: 2px; animation-duration: 82s; animation-delay: -36s; --dm-dx: -10px; }
.dm-5 { left: 57%; width: 1px; height: 1px; animation-duration: 45s; animation-delay: -14s; --dm-dx:  15px; }
.dm-6 { left: 68%; width: 2px; height: 2px; animation-duration: 75s; animation-delay: -48s; --dm-dx: -20px; }
.dm-7 { left: 78%; width: 1px; height: 1px; animation-duration: 60s; animation-delay:  -5s; --dm-dx:  10px; }
.dm-8 { left: 33%; width: 1px; height: 1px; animation-duration: 90s; animation-delay: -60s; --dm-dx: -14px; }

/* --- Rose window --- */
.bg-rose-window {
    position: fixed;
    top: 50%;
    left: 50%;
    width: min(720px, 96vw);
    height: min(720px, 96vw);
    transform: translate(-50%, -52%);
    pointer-events: none;
    z-index: 0;
    /* Always faintly present — gives the other screens subtle depth too */
    opacity: 0.12;
    transition: opacity 1.4s ease;
    animation: roseBreath 24s ease-in-out infinite;
}

.bg-rose-window svg {
    width: 100%;
    height: 100%;
}

/* Full brightness only on menu — :has() has broad 2024+ support */
body:has(#screen-menu.active) .bg-rose-window {
    opacity: 1;
}

/* Fallback for no :has() support — class added by JS screen switcher */
body.screen-menu-active .bg-rose-window {
    opacity: 1;
}

@keyframes roseBreath {
    0%, 100% { transform: translate(-50%, -52%) scale(1)    rotate(0deg); }
    33%       { transform: translate(-50%, -52%) scale(1.015) rotate(0.6deg); }
    66%       { transform: translate(-50%, -52%) scale(0.992) rotate(-0.4deg); }
}

/* --- Shared screen base --- */
.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 900px;
    padding: 20px;
    box-sizing: border-box;
    opacity: 0;
    transition: opacity 0.6s ease;
    position: relative;
    z-index: 1;
}

/* Full-viewport jewel wash behind every screen */
.screen::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -2;
    pointer-events: none;
    transition: opacity 1s ease;
}

/* Lead-caming geometry tile over jewel wash */
.screen::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    /* Diamond lead-line pattern encoded as data URI */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Cpath d='M30 0 L60 30 L30 60 L0 30 Z' fill='none' stroke='rgba(0%2C0%2C0%2C0.45)' stroke-width='1.2'/%3E%3Cpath d='M30 0 L60 30 L30 60 L0 30 Z' fill='none' stroke='rgba(197%2C160%2C89%2C0.06)' stroke-width='0.5'/%3E%3C/svg%3E");
    background-size: 60px 60px;
    opacity: 0;
    transition: opacity 1s ease;
}

.screen.active {
    display: flex;
    opacity: 1;
}

.screen.active::after {
    opacity: 1;
}

/* Game board: override to keep diamond grid subtle so it doesn't compete with puzzle cells */
#screen-game.active::after {
    opacity: 0.45;
}

/* =====================================================================
   PER-SCREEN JEWEL BACKGROUNDS
   ===================================================================== */

@keyframes glassPanelShimmer {
    0%, 100% {
        box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.3), 0 8px 32px rgba(0, 0, 0, 0.2);
        border-color: rgba(197, 160, 89, 0.15);
    }
    50% {
        box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.2), 0 8px 40px rgba(197, 160, 89, 0.15);
        border-color: rgba(197, 160, 89, 0.25);
    }
}

/* =====================================================================
   MENU — staged entrance + stained-glass crest centerpiece
   The whole menu "rises" once on load (and each time you return to it),
   like a curtain lifting. The crest medallion then lights pane-by-pane.
   ===================================================================== */

/* Each top-level menu element drifts up and fades in, staggered. */
@keyframes menuRise {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: translateY(0); }
}

#screen-menu.active > .menu-crest-wrap,
#screen-menu.active > h1,
#screen-menu.active > .subtitle,
#screen-menu.active > .menu-actions,
#screen-menu.active > .daily-status,
#screen-menu.active > .menu-footer {
    animation: menuRise 0.8s ease-out both;
}

#screen-menu.active > .menu-crest-wrap { animation-delay: 0.05s; }
#screen-menu.active > h1               { animation-delay: 0.30s; }
#screen-menu.active > .subtitle        { animation-delay: 0.45s; }
#screen-menu.active > .menu-actions    { animation-delay: 0.58s; }
#screen-menu.active > .daily-status    { animation-delay: 0.70s; }
#screen-menu.active > .menu-footer     { animation-delay: 0.80s; }

/* Illuminated wordmark on the title (menu only). Keep the lettering solid so
   the actual stained glass remains the only color-shifting focal point. */
#screen-menu.active h1 {
    color: oklch(92% 0.085 82);
    -webkit-text-fill-color: currentColor;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.85)) drop-shadow(0 0 26px rgba(212,154,42,0.22));
    animation: menuRise 0.8s ease-out 0.30s both;
}

/* --- Crest medallion --- */
.menu-crest-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 210px;
    height: 210px;
    margin: 30px 0 24px;
}

/* Soft halo of light pooling behind the crest */
.menu-crest-wrap::before {
    content: '';
    position: absolute;
    inset: -30%;
    border-radius: 50%;
    background: radial-gradient(circle at 50% 50%,
        rgba(212,154,42,0.22) 0%, rgba(212,154,42,0.08) 38%, transparent 70%);
    pointer-events: none;
    animation: crestHalo 7s ease-in-out infinite;
}

@keyframes crestHalo {
    0%, 100% { opacity: 0.7; transform: scale(1); }
    50%       { opacity: 1;   transform: scale(1.06); }
}

.menu-crest {
    display: grid;
    grid-template-columns: repeat(5, 26px);
    grid-template-rows: repeat(5, 26px);
    gap: 3px;
    padding: 6px;
    background: #05060a;
    border-radius: 8px;
    transform: rotate(45deg);
    position: relative;
    box-shadow:
        0 0 0 2px rgba(197,160,89,0.30),
        0 0 0 5px rgba(0,0,0,0.85),
        0 10px 40px rgba(0,0,0,0.7),
        0 0 50px rgba(197,160,89,0.18);
    animation: crestBreath 9s ease-in-out infinite;
}

@keyframes crestBreath {
    0%, 100% { box-shadow: 0 0 0 2px rgba(197,160,89,0.30), 0 0 0 5px rgba(0,0,0,0.85), 0 10px 40px rgba(0,0,0,0.7), 0 0 50px rgba(197,160,89,0.18); }
    50%       { box-shadow: 0 0 0 2px rgba(197,160,89,0.45), 0 0 0 5px rgba(0,0,0,0.85), 0 10px 40px rgba(0,0,0,0.7), 0 0 80px rgba(212,154,42,0.32); }
}

/* Diagonal sheen that drifts across the glass forever */
.menu-crest::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 8px;
    overflow: hidden;
    background: linear-gradient(115deg, transparent 38%, rgba(255,255,255,0.22) 50%, transparent 62%);
    background-size: 300% 300%;
    pointer-events: none;
    mix-blend-mode: screen;
    animation: crestSheen 6.5s ease-in-out infinite;
}

@keyframes crestSheen {
    0%   { background-position: 120% 0; opacity: 0; }
    35%  { opacity: 0.9; }
    70%  { background-position: -40% 0; opacity: 0; }
    100% { background-position: -40% 0; opacity: 0; }
}

.crest-pane {
    position: relative;
    background-color: var(--pane-color, #5a6270);
    overflow: hidden;
    /* Starts dark, then warms to full colour — lit like the in-game reveal */
    filter: brightness(0.16) saturate(0.45);
    animation: crestLight 1.6s ease-out var(--delay, 0s) forwards;
}

/* Glass highlight sheen on each pane */
.crest-pane::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.22) 0%, transparent 55%);
    pointer-events: none;
}

@keyframes crestLight {
    0%   { filter: brightness(0.16) saturate(0.45); }
    100% {
        filter: brightness(1.08) saturate(1.12);
        box-shadow: inset 0 0 9px rgba(255,255,255,0.32);
    }
}

.tooltip-wrapper {
    position: relative;
    margin-bottom: 40px;
    cursor: help;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.95rem;
    color: var(--text-gold);
    border-bottom: 1px dotted var(--text-gold);
    padding-bottom: 2px;
}

.tooltip-wrapper .icon {
    display: inline-block;
    width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    border-radius: 50%;
    border: 1px solid var(--text-gold);
    font-size: 0.8rem;
    margin-right: 5px;
}

.tooltip-content {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    top: 130%;
    left: 50%;
    transform: translateX(-50%);
    width: min(320px, 86vw);
    background: #1a1c29;
    border: 1px solid var(--text-gold-dim);
    padding: 15px;
    border-radius: 6px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.8);
    color: #ddd;
    font-family: 'Lora', serif;
    font-size: 0.9rem;
    line-height: 1.5;
    transition: all 0.3s ease;
    z-index: 100;
    text-align: left;
}

.tooltip-wrapper.is-open .tooltip-content {
    visibility: visible;
    opacity: 1;
    top: 150%;
}

/* Hover-reveal only where hover is real — on touch, Chrome's sticky :hover
   would otherwise pin the tip open with no way to dismiss it. */
@media (hover: hover) {
    .tooltip-wrapper:hover .tooltip-content {
        visibility: visible;
        opacity: 1;
        top: 150%;
    }
}

/* The How-to-Play trigger is a real <button> (tap/keyboard accessible) styled
   as the plain text label it always looked like. Scoped to the menu so the
   game screen's round .help-btn keeps its own look. */
.menu-footer .howto-toggle {
    background: none;
    border: none;
    padding: 0;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: none;
    cursor: help;
}

.menu-footer .howto-toggle:hover {
    background: none;
    color: var(--text-gold);
    box-shadow: none;
    transform: none;
}

.tooltip-content strong {
    color: var(--text-gold);
    font-family: 'Montserrat', sans-serif;
    display: block;
    margin-bottom: 8px;
}

.btn-group {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn-group.wide {
    flex-direction: column;
    align-items: center;
    width: 100%;
    background: rgba(26, 28, 41, 0.4);
    padding: 30px;
    border-radius: 8px;
    border: 1px solid rgba(197, 160, 89, 0.15);
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.3), 0 8px 32px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(4px);
    animation: glassPanelShimmer 6s ease-in-out infinite;
    transition: background-color 0.4s ease;
}

.btn-group.wide:hover {
    background: rgba(26, 28, 41, 0.6);
}

button,
.btn-link {
    background: rgba(0, 0, 0, 0.4);
    color: var(--text-gold);
    border: 1px solid var(--text-gold-dim);
    touch-action: manipulation;
    padding: 14px 28px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 4px;
    position: relative;
    z-index: 0;
}

button:hover,
.btn-link:hover {
    background: var(--text-gold-dim);
    color: #000;
    box-shadow: 0 0 20px rgba(197, 160, 89, 0.4), 0 0 40px rgba(197, 160, 89, 0.15);
    transform: translateY(-2px);
}

button:active {
    transform: scale(0.97);
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    color: #666;
}

button:focus-visible,
.btn-link:focus-visible {
    outline: 3px solid oklch(88% 0.11 82);
    outline-offset: 3px;
}

.button-alt {
    background: transparent;
    border-color: #555;
    color: #aaa;
}

/* =====================================================================
   MENU ACTIONS — clear, generous, vertically-stacked buttons
   Large tap targets and an obvious primary CTA for a relaxed player.
   ===================================================================== */
.menu-actions {
    flex-direction: column;
    align-items: stretch;
    width: min(340px, 82vw);
    gap: 14px;
}

.menu-actions button {
    width: 100%;
    padding: 16px 28px;
    font-size: 1rem;
}

/* Primary call to action — a warm lit pane of gold glass */
.menu-primary {
    background: linear-gradient(180deg, #f3dca4 0%, #e0bd62 45%, #cf9f34 100%);
    color: #2a1c05;
    border: 1px solid #f6e6b8;
    font-weight: 600;
    box-shadow:
        0 0 24px rgba(212,154,42,0.35),
        inset 0 1px 0 rgba(255,255,255,0.5);
}

.menu-primary:hover {
    background: linear-gradient(180deg, #fff3cf 0%, #efce78 45%, #dcab3c 100%);
    color: #2a1c05;
    box-shadow:
        0 0 34px rgba(212,154,42,0.6),
        inset 0 1px 0 rgba(255,255,255,0.6);
}

.menu-footer {
    margin-top: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
}

.menu-footer .tooltip-wrapper {
    margin-bottom: 0;
}

.game-version {
    color: oklch(68% 0.02 82);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.66rem;
    letter-spacing: 0.12em;
}

/* =====================================================================
   SOUND TOGGLE — always-visible, unobtrusive control
   ===================================================================== */
.sound-toggle {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 3000;
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 1.15rem;
    letter-spacing: 0;
    text-transform: none;
    color: var(--text-gold);
    background: rgba(8, 10, 20, 0.6);
    border: 1px solid rgba(197, 160, 89, 0.4);
    backdrop-filter: blur(4px);
}

.sound-toggle:hover {
    color: #000;
    background: var(--text-gold-dim);
    border-color: var(--text-gold);
    box-shadow: 0 0 18px rgba(197, 160, 89, 0.4);
}

.sound-toggle .sound-icon {
    position: relative;
    line-height: 1;
}

/* Muted: dim it and strike the note through */
.sound-toggle.is-muted {
    color: #6a6a72;
    border-color: #3a3a42;
}

.sound-toggle.is-muted:hover {
    color: #000;
    background: #6a6a72;
    border-color: #8a8a92;
    box-shadow: none;
}

.sound-toggle.is-muted .sound-icon::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 26px;
    height: 2px;
    background: currentColor;
    transform: translate(-50%, -50%) rotate(-45deg);
    border-radius: 2px;
}

/* =====================================================================
   LEVEL SELECT — thumbnail gallery
   Each puzzle is a "window" card. Unsolved windows show a softened glimpse;
   once restored, the card reveals the finished stained-glass artwork as its
   thumbnail (click to admire it full-size). Title, author/place, and grid
   size sit beneath — like a video thumbnail.
   ===================================================================== */
.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 18px;
    width: 100%;
    max-height: 68vh;
    overflow-y: auto;
    padding: 24px;
    border-radius: 8px;
    background: rgba(26, 28, 41, 0.4);
    border: 1px solid rgba(197, 160, 89, 0.15);
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.3), 0 8px 32px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(4px);
    scrollbar-color: var(--text-gold-dim) transparent;
}

/* The card overrides the global <button> look entirely. */
.level-card {
    display: flex;
    flex-direction: column;
    padding: 0;
    text-align: left;
    text-transform: none;
    letter-spacing: normal;
    border-radius: 8px;
    overflow: hidden;
    background: rgba(8, 10, 20, 0.55);
    border: 1px solid rgba(197, 160, 89, 0.18);
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease, background 0.25s ease;
}

.level-card:hover {
    transform: translateY(-4px);
    border-color: var(--text-gold);
    background: rgba(10, 12, 24, 0.7);
    color: var(--text-body);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55), 0 0 24px rgba(197, 160, 89, 0.18);
}

.level-card:active {
    transform: translateY(-1px) scale(0.99);
}

/* --- Thumbnail: dark jewel wash + lead diamonds + glowing "?" --- */
.level-thumb {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    background:
        radial-gradient(ellipse 70% 60% at 50% 38%, rgba(26, 76, 156, 0.32) 0%, transparent 70%),
        radial-gradient(ellipse 55% 50% at 82% 82%, rgba(122, 26, 176, 0.24) 0%, transparent 65%),
        radial-gradient(ellipse 50% 45% at 15% 78%, rgba(191, 21, 49, 0.18) 0%, transparent 60%),
        linear-gradient(160deg, #0c1430 0%, #0a0c18 60%, #100818 100%);
}

/* Lead-caming diamond grid over the wash */
.level-thumb::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30'%3E%3Cpath d='M15 0 L30 15 L15 30 L0 15 Z' fill='none' stroke='rgba(0%2C0%2C0%2C0.45)' stroke-width='0.8'/%3E%3Cpath d='M15 0 L30 15 L15 30 L0 15 Z' fill='none' stroke='rgba(197%2C160%2C89%2C0.06)' stroke-width='0.4'/%3E%3C/svg%3E");
    background-size: 30px 30px;
    opacity: 0.6;
    pointer-events: none;
}

/* Glint sweep across the thumbnail on hover */
.level-thumb::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent 35%, rgba(255, 255, 255, 0.12) 50%, transparent 65%);
    transform: translate(-60%, -60%);
    transition: transform 0.6s ease-out;
    pointer-events: none;
    z-index: 2;
}

.level-card:hover .level-thumb::after {
    transform: translate(60%, 60%);
}

.level-thumb-mark {
    position: relative;
    z-index: 1;
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: 3rem;
    color: var(--text-gold);
    opacity: 0.92;
    text-shadow: 0 0 18px rgba(212, 154, 42, 0.55), 0 2px 6px rgba(0, 0, 0, 0.8);
    transition: transform 0.3s ease, text-shadow 0.3s ease;
}

.level-card:hover .level-thumb-mark {
    transform: scale(1.12);
    text-shadow: 0 0 30px rgba(212, 154, 42, 0.85), 0 2px 6px rgba(0, 0, 0, 0.8);
}

/* Completed-window checkmark badge */
.level-thumb-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--text-gold-dim);
    color: #000;
    font-size: 0.85rem;
    font-weight: 700;
    box-shadow: 0 0 12px rgba(212, 154, 42, 0.6);
}

/* --- Card text block --- */
.level-card-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 12px 14px 14px;
}

.level-card-title {
    font-family: 'Cinzel', serif;
    font-size: 0.95rem;
    line-height: 1.25;
    color: var(--text-gold);
}

.level-card-author {
    font-family: 'Lora', serif;
    font-style: italic;
    font-size: 0.8rem;
    color: #9a9aa6;
}

.level-card-date {
    align-self: flex-start;
    margin-top: 3px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.62rem;
    letter-spacing: 1.1px;
    text-transform: uppercase;
    color: #7fb1b0;
}

.level-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 5px;
}

.level-card-size {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.72rem;
    letter-spacing: 1px;
    color: #9298a5;
    flex-shrink: 0;
    white-space: nowrap;
}

.level-card-status {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.7rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-gold-dim);
}

/* Completed cards glow warmer — as if the glass behind is now lit */
.level-card.is-complete {
    border-color: rgba(212, 154, 42, 0.45);
}

.level-card.is-complete .level-thumb {
    background:
        radial-gradient(ellipse 70% 60% at 50% 42%, rgba(212, 154, 42, 0.32) 0%, transparent 70%),
        radial-gradient(ellipse 55% 50% at 82% 82%, rgba(191, 21, 49, 0.24) 0%, transparent 65%),
        radial-gradient(ellipse 50% 45% at 15% 78%, rgba(26, 76, 156, 0.20) 0%, transparent 60%),
        linear-gradient(160deg, #1a1605 0%, #0c0a14 60%, #140a08 100%);
}

.level-card.is-complete .level-thumb-mark {
    color: rgba(232, 201, 136, 0.5);
    text-shadow: 0 0 14px rgba(212, 154, 42, 0.4);
}

/* --- Restored artwork thumbnail: the finished glass, lit --- */
.level-thumb-art {
    position: relative;
    z-index: 1;
    width: 86%;
    height: 82%;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    border-radius: 3px;
    filter: drop-shadow(0 0 9px rgba(212, 154, 42, 0.45)) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.7));
    transition: transform 0.3s ease, filter 0.3s ease;
}

.level-card:hover .level-thumb-art {
    transform: scale(1.05);
    filter: drop-shadow(0 0 16px rgba(212, 154, 42, 0.7)) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.7));
}

/* Playable but not-yet-restored windows show a soft color/shape invitation;
   the finished, crisp artwork remains reserved for the reward state. */
.level-thumb-art.is-preview {
    filter: blur(2.8px) brightness(0.64) saturate(0.88) drop-shadow(0 0 8px rgba(212, 154, 42, 0.3));
    opacity: 0.84;
    transform: scale(1.07);
}

.level-card:hover .level-thumb-art.is-preview {
    filter: blur(2px) brightness(0.76) saturate(0.98) drop-shadow(0 0 14px rgba(212, 154, 42, 0.52));
    transform: scale(1.11);
}

/* --- Most-recently restored window: warm ring + label accent --- */
.level-card.is-recent {
    border-color: var(--text-gold);
    box-shadow: 0 0 0 1px rgba(212, 154, 42, 0.35), 0 0 22px rgba(212, 154, 42, 0.25);
}

.level-card.is-recent .level-card-status {
    color: var(--text-gold);
    font-weight: 600;
}

.gallery-empty {
    grid-column: 1 / -1;
    padding: 48px 24px;
    text-align: center;
    font-family: 'Lora', serif;
    font-style: italic;
    font-size: 0.95rem;
    color: #9a9aa6;
}

/* =====================================================================
   GALLERY FILTER TABS
   ===================================================================== */
.gallery-filters {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin: 4px 0 22px;
}

.gallery-filter {
    padding: 8px 20px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.74rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: #9a9aa6;
    background: rgba(8, 10, 20, 0.5);
    border: 1px solid rgba(197, 160, 89, 0.18);
    border-radius: 20px;
    transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.gallery-filter:hover {
    color: var(--text-body);
    border-color: rgba(197, 160, 89, 0.4);
    transform: none;
}

.gallery-filter.is-active {
    color: #1a1205;
    background: var(--text-gold-dim);
    border-color: var(--text-gold);
    box-shadow: 0 0 14px rgba(212, 154, 42, 0.35);
}

/* =====================================================================
   ADMIRE LIGHTBOX — view a restored window's finished artwork
   ===================================================================== */
.admire-overlay {
    position: fixed;
    inset: 0;
    z-index: 2500;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(4, 5, 10, 0.82);
    backdrop-filter: blur(6px);
}

.admire-overlay.is-open {
    display: flex;
    animation: admireFade 0.3s ease-out;
}

@keyframes admireFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.admire-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: min(92vw, 560px);
    padding: 28px 28px 24px;
    border-radius: 12px;
    background: linear-gradient(160deg, rgba(20, 22, 36, 0.96) 0%, rgba(10, 11, 20, 0.96) 100%);
    border: 1px solid rgba(197, 160, 89, 0.35);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.7), inset 0 0 40px rgba(0, 0, 0, 0.4);
    animation: admireRise 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes admireRise {
    from { transform: translateY(18px) scale(0.97); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.admire-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 34px;
    height: 34px;
    padding: 0;
    font-size: 1rem;
    color: #9a9aa6;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(197, 160, 89, 0.2);
    border-radius: 50%;
    line-height: 1;
}

.admire-close:hover {
    color: var(--text-gold);
    border-color: var(--text-gold);
    transform: none;
}

/* The pane frames the artwork like a lit window in a dark cathedral wall */
.admire-pane {
    display: flex;
    align-items: center;
    justify-content: center;
    width: min(74vw, 64vh, 420px);
    height: min(74vw, 64vh, 420px);
    padding: 18px;
    border-radius: 8px;
    background:
        radial-gradient(ellipse 70% 70% at 50% 45%, rgba(212, 154, 42, 0.14) 0%, transparent 70%),
        linear-gradient(160deg, #0c1430 0%, #0a0c18 60%, #100818 100%);
    border: 1px solid rgba(0, 0, 0, 0.6);
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.7);
}

.admire-art-img {
    width: 100%;
    height: 100%;
    position: relative;   /* anchor for the overlaid PixiJS glass canvas */
    overflow: hidden;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    filter: drop-shadow(0 0 26px rgba(212, 154, 42, 0.4)) drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6));
    animation: admireGlow 4s ease-in-out infinite alternate;
}

/* Backlit stained-glass canvas (PixiJS), overlaid on the win-reveal board and
   the Admire view. Exact position/size are set inline by the renderer; these are
   just safe defaults. */
.glass-canvas {
    display: block;
    pointer-events: none;
}

/* =====================================================================
   TITLE-SCREEN GLASS HERO (js/menuHero.js) — a real backlit stained-glass
   window replaces the tiny DOM crest as the menu centrepiece. The crest
   markup remains as the automatic no-WebGL fallback.
   ===================================================================== */
.menu-crest-wrap.has-hero .menu-crest { display: none; }
.menu-crest-wrap.has-hero { margin: 18px 0 8px; }

#menu-hero-wrap.hero-rose {
    width: min(46vh, 440px, 84vw);
    height: min(46vh, 440px, 84vw);
}
#menu-hero-wrap.hero-lancet {
    height: min(54vh, 500px);
    width: calc(min(54vh, 500px) * 26 / 44);
    max-width: 84vw;
}
#menu-hero-wrap.hero-triptych {
    width: min(560px, 92vw);
    height: calc(min(560px, 92vw) * 36 / 46);
    max-height: 50vh;
}

/* Wordmark lockup for Lumen. Cinzel 700 gives the title a crafted window-card
   presence while the rest of the interface stays readable and practical. */
h1.wordmark {
    font-weight: 700;
    font-size: clamp(2.1rem, 8.5vw, 3.5rem);
    letter-spacing: 0.16em;
    margin-top: 8px;
}
.menu-rule {
    position: relative;
    width: min(320px, 68vw);
    height: 1px;
    margin: 14px auto 2px;
    background: linear-gradient(90deg,
        transparent, rgba(197,160,89,0.8) 20%, #e8c988 50%,
        rgba(197,160,89,0.8) 80%, transparent);
}
.menu-rule::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 7px;
    height: 7px;
    transform: translate(-50%, -50%) rotate(45deg);
    background: #e8c988;
    box-shadow: 0 0 10px rgba(232, 201, 136, 0.9);
}
#screen-menu.active > .menu-rule {
    animation: menuRise 0.8s ease-out both;
    animation-delay: 0.38s;
}

/* Volumetric light shafts: the original rays were 2–3px hairlines that read
   as scratches. Widen + blur them into soft beams (overrides per-ray widths). */
.bg-rays .ray {
    width: 26px;
    filter: blur(13px) saturate(1.3);
}

/* ---- Small screens (the stylesheet previously had NO width breakpoints) ---- */
@media (max-width: 640px) {
    .screen { padding: 12px; }
    .game-topbar {
        flex-wrap: wrap;
        gap: 8px;
    }
    .game-controls { flex-wrap: wrap; }
    .menu-actions { width: min(320px, 90vw); }
    .admire-card { padding: 18px 14px; }
    h2 { font-size: 1.35rem; }
}

@keyframes admireGlow {
    from { filter: drop-shadow(0 0 18px rgba(212, 154, 42, 0.3)) drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6)); }
    to { filter: drop-shadow(0 0 34px rgba(212, 154, 42, 0.55)) drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6)); }
}

.admire-title {
    margin: 20px 0 0;
    font-family: 'Cinzel', serif;
    font-size: 1.3rem;
    color: var(--text-gold);
    text-align: center;
}

.admire-author {
    margin-top: 4px;
    font-family: 'Lora', serif;
    font-style: italic;
    font-size: 0.92rem;
    color: #9a9aa6;
    text-align: center;
}

.admire-actions {
    margin-top: 22px;
}

.level-progress {
    margin-top: 22px;
    text-align: center;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.82rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: #9a9aa6;
}

.section-description {
    text-align: center;
    max-width: 600px;
    margin-bottom: 40px;
    color: #ccc;
}

.premium-list {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.premium-card {
    border: 1px solid var(--text-gold-dim);
    background: rgba(0, 0, 0, 0.6);
    padding: 25px;
    text-align: center;
    border-radius: 6px;
    max-width: 320px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
    transition: all 0.4s ease;
    backdrop-filter: blur(2px);
    position: relative;
    overflow: hidden;
}

.premium-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(232, 201, 136, 0.1) 0%, transparent 50%);
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

.premium-card:hover {
    background: rgba(0, 0, 0, 0.5);
    border-color: var(--text-gold);
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5), 0 0 30px rgba(197, 160, 89, 0.2);
    transform: translateY(-4px);
}

.premium-card:hover::before {
    opacity: 1;
}

.premium-card h3 {
    font-size: 1.3rem;
    margin-bottom: 10px;
}

.premium-price {
    font-family: 'Montserrat', sans-serif;
    color: #fff;
    font-size: 1.2rem;
    margin: 15px 0;
    font-weight: 600;
}

#game-container {
    display: grid;
    gap: 1px;
    margin-top: 20px;
    position: relative;
    background: var(--lead-unsolved);
    border: 2px solid #1a1c28;
    padding: 2px;
    /* Safety net: if clues still outgrow the estimate, scroll inside the
       board instead of being clipped by the page's overflow-x: hidden. */
    max-width: 96vw;
    overflow: auto;
    /* Touch: no double-tap zoom on rapid play, no tap highlight flash */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    transition: background 1s ease, border 1s ease, box-shadow 2s ease;
    /* Cathedral frame: outer glow fades into dark bg, lead border glints gold */
    box-shadow:
        0 0  4px 2px  rgba(0,0,0,0.9),
        0 0 40px 8px  rgba(0,0,0,0.7),
        0 0 80px 20px rgba(0,0,0,0.5),
        0 0  0px 1px  rgba(197,160,89,0.12);
}

.clue-row,
.clue-col {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.75rem, 1.8vw, 0.95rem);
    color: #bfc3ce;
    font-family: 'Montserrat', sans-serif;
    font-weight: 500;
    transition: opacity 1.5s ease;
}

.clue-row {
    flex-direction: row;
    justify-content: flex-end;
    padding-right: 12px;
    gap: 8px;
}

.clue-col {
    flex-direction: column;
    justify-content: flex-end;
    padding-bottom: 12px;
    gap: 6px;
}

.clue-row span,
.clue-col span {
    display: inline-block;
}

.clue-row.is-solved,
.clue-col.is-solved {
    color: oklch(84% 0.1 82);
    opacity: 1;
    text-shadow: 0 0 10px oklch(75% 0.13 82 / 0.45);
}

@keyframes clueLinePop {
    0% { transform: scale(1); }
    45% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

.clue-row.line-pop,
.clue-col.line-pop {
    animation: clueLinePop 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background-color: var(--glass-empty);
    cursor: pointer;
    transition: background-color 0.1s, transform 120ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 160ms ease;
    position: relative;
    box-sizing: border-box;
    overflow: hidden;
    border: 1px solid rgba(90, 98, 112, 0.1);
    /* Deterministic touch gestures (tap confirmation + long-press) — no scroll hijack,
       no double-tap zoom, no grey tap flash. */
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.cell::before {
    display: none;
}

.cell:hover {
    background-color: #303a47;
    box-shadow: inset 0 0 8px rgba(232, 201, 136, 0.1);
}

.cell:active {
    transform: scale(0.92);
    box-shadow: inset 0 0 12px oklch(80% 0.08 82 / 0.22);
}

.cell.filled {
    background-color: color-mix(in oklab, var(--pane-color, var(--glass-filled)) 42%, var(--glass-filled));
    background-image:
        linear-gradient(
            var(--pane-angle),
            oklch(98% 0.025 85 / var(--pane-highlight, 0.14)) 0%,
            transparent 27%,
            transparent 64%,
            oklch(10% 0.025 265 / 0.18) 100%
        );
    box-shadow:
        inset 1px 1px 0 oklch(98% 0.025 85 / 0.18),
        inset -1px -1px 0 oklch(8% 0.025 265 / 0.32),
        inset 0 0 8px oklch(90% 0.08 82 / 0.1);
}

.cell.filled::before {
    content: '';
    display: block;
    position: absolute;
    inset: 1px;
    background:
        linear-gradient(
            calc(var(--pane-angle) + 45deg),
            oklch(98% 0.025 85 / calc(var(--pane-highlight, 0.14) * 0.42)) 0%,
            transparent 48% 100%
        );
    clip-path: polygon(
        0 0,
        var(--pane-cut, 48%) 0,
        100% var(--pane-notch, 36%),
        100% 100%,
        var(--pane-cut, 48%) 100%,
        0 var(--pane-low, 64%)
    );
    opacity: 0.8;
    pointer-events: none;
}

.cell.filled::after {
    content: '';
    position: absolute;
    inset: 0;
    background:
        linear-gradient(
            var(--pane-angle),
            transparent 0 48%,
            oklch(98% 0.025 85 / 0.13) 49% 51%,
            transparent 52% 100%
        );
    clip-path: polygon(
        0 0,
        var(--pane-cut, 48%) 0,
        100% var(--pane-notch, 36%),
        100% 100%,
        var(--pane-cut, 48%) 100%,
        0 var(--pane-low, 64%)
    );
    opacity: 0.62;
    pointer-events: none;
}

.cell.marked::after {
    content: '×';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #a8aeb9;
    font-size: calc(var(--cell-size) * 0.5);
}

/* Auto-flagged wrong placements: the ✕ reads as a warning, not a note */
.cell.mistake {
    background-color: rgba(191, 21, 49, 0.18);
}

.cell.mistake::after {
    color: #d0616e;
}

@keyframes mistakeShake {
    0%, 100% { transform: translateX(0); }
    20%      { transform: translateX(-3px); }
    40%      { transform: translateX(3px); }
    60%      { transform: translateX(-2px); }
    80%      { transform: translateX(2px); }
}

/* Keyboard navigation cursor on the board */
#game-container:focus-visible {
    outline: 2px solid var(--text-gold);
    outline-offset: 4px;
}

.cell.kb-focus {
    outline: 2px solid var(--text-gold);
    outline-offset: -2px;
    z-index: 2;
}

.solved-phase-1 #game-container {
    gap: 3px;
    background: var(--lead-solved);
    border-color: #000;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), inset 0 0 30px rgba(0, 0, 0, 0.6);
}

.solved-phase-1 .clue-row,
.solved-phase-1 .clue-col {
    opacity: 0;
}

.solved-phase-1 .cell {
    pointer-events: none;
}

.solved-phase-1 .cell.marked::after {
    display: none;
}

.solved-phase-2 .cell.filled {
    background-color: var(--glass-color);
    /* Keep the authored facet surface in the CSS fallback. The WebGL renderer
       covers it when available, while low-power devices still get material
       variation instead of a flat color block. */
    filter: none;
    box-shadow:
        inset 1px 1px 0 oklch(98% 0.025 85 / 0.2),
        inset -1px -1px 0 oklch(8% 0.025 265 / 0.34),
        inset 0 0 7px oklch(98% 0.03 82 / 0.2);
    animation: innerGlow 2s forwards ease-in-out;
    animation-delay: var(--delay);
}

/* One board-level sweep gives the software fallback a readable light-catch
   moment without multiplying filters or shadows across every pane. Keep it
   below Pixi's z-index 2 canvas: the WebGL path already has its own sweep,
   while the CSS path gets this inexpensive single-layer version. */
.solved-phase-2 #game-container::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
    background: linear-gradient(108deg,
        transparent 34%,
        rgba(255, 255, 255, 0.04) 46%,
        rgba(255, 237, 183, 0.24) 50%,
        rgba(255, 255, 255, 0.07) 54%,
        transparent 66%);
    transform: translateX(-120%);
    animation: revealLightSweep 1.5s cubic-bezier(0.22, 1, 0.36, 1) 0.28s both;
}

@keyframes revealLightSweep {
    0% { opacity: 0; transform: translateX(-120%); }
    18% { opacity: 0.75; }
    100% { opacity: 0; transform: translateX(120%); }
}

@keyframes innerGlow {
    0% {
        opacity: 0.35;
    }
    68% {
        opacity: 1;
    }
    100% {
        opacity: 1;
    }
}

#win-message {
    display: none;
    font-family: 'Cinzel', serif;
    font-size: 1.8rem;
    letter-spacing: 2px;
    color: var(--text-gold);
    margin-top: 30px;
    animation: fadeIn 2s forwards;
    text-align: center;
    opacity: 0;
    text-transform: uppercase;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

/* Post-win actions: admire the gallery (primary) or replay via ad */
.win-actions {
    display: none;
    flex-wrap: wrap;
    gap: 14px;
    justify-content: center;
    align-items: center;
    margin-top: 24px;
    animation: fadeIn 1.2s forwards;
    opacity: 0;
}

/* Primary call-to-action — leads back to the freshly-lit gallery */
.win-primary {
    background: var(--text-gold-dim);
    color: #1a1205;
    border: 1px solid var(--text-gold);
    box-shadow: 0 0 22px rgba(212, 154, 42, 0.35);
}

.win-primary:hover {
    background: var(--text-gold);
    color: #1a1205;
}

@keyframes hintFlash {
    0% {
        background-color: var(--glass-color);
        box-shadow: 0 0 12px rgba(255, 255, 255, 0.6);
    }
    100% {
        background-color: var(--glass-color);
        box-shadow: none;
    }
}

.ad-banner {
    width: 100%;
    max-width: 550px;
    margin: 20px auto 0;
    padding: 14px 18px;
    border: 1px solid rgba(233, 200, 124, 0.2);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: #d8d2b1;
    text-align: center;
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.ad-banner:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(233, 200, 124, 0.35);
    box-shadow: 0 4px 24px rgba(232, 201, 136, 0.15);
}

.ad-label {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.75rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-gold);
    margin-bottom: 8px;
}

.ad-copy {
    font-size: 0.9rem;
    line-height: 1.5;
    color: #ccc;
}

.ad-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.ad-overlay.visible {
    display: flex;
}

.ad-card {
    width: min(420px, 100%);
    border-radius: 14px;
    background: oklch(18% 0.025 265);
    border: 1px solid oklch(68% 0.07 82 / 0.55);
    padding: 28px 24px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    animation: adCardSlideIn 0.4s ease-out;
}

.ad-window-mark {
    width: 42px;
    height: 52px;
    display: grid;
    place-items: center;
    margin: 0 auto 14px;
    border: 1px solid oklch(68% 0.07 82 / 0.7);
    border-radius: 22px 22px 5px 5px;
    color: oklch(86% 0.1 82);
    background: oklch(26% 0.07 75);
}

.ad-card p {
    max-width: 36ch;
    margin: 0 auto;
    color: oklch(87% 0.015 82);
    line-height: 1.6;
}

@keyframes adCardSlideIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.ad-card-title {
    font-family: 'Cinzel', serif;
    font-size: 1.4rem;
    color: var(--text-gold);
    margin-bottom: 14px;
}

.ad-action {
    margin-top: 18px;
    width: 100%;
    background: var(--text-gold-dim);
    border: none;
    color: #000;
    padding: 12px 18px;
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    letter-spacing: 1px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.ad-action:hover {
    background: #fff;
}

.ad-actions {
    display: grid;
    gap: 10px;
    margin-top: 20px;
}

.ad-actions .ad-action {
    margin-top: 0;
}

.ad-actions .ad-cancel {
    width: 100%;
}

/* =====================================================================
   DEBUG / TEST MODE  (enabled via ?debug in the URL)
   ===================================================================== */
body.debug-mode::after {
    content: 'DEBUG';
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 3000;
    padding: 4px 10px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: #000;
    background: #e0a82e;
    border-radius: 4px;
    box-shadow: 0 0 14px rgba(224, 168, 46, 0.6);
    pointer-events: none;
}

#debug-solve-button {
    display: inline-flex;
    border-color: #e0a82e;
    color: #e0a82e;
    font-size: 0.78rem;
    padding: 8px 14px;
    letter-spacing: 0.8px;
    white-space: nowrap;
}

#debug-solve-button:hover {
    background: #e0a82e;
    color: #000;
}

/* =====================================================================
   GAME SCREEN LAYOUT
   Center the whole puzzle composition vertically so it sits balanced in
   the viewport instead of clinging to the top with empty space below.
   ===================================================================== */
#screen-game.active {
    min-height: 100vh;
    justify-content: center;
    padding-top: 12px;
    padding-bottom: 28px;
}

/* =====================================================================
   GAME SCREEN TOPBAR
   ===================================================================== */
.game-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 600px;
    padding: 0 0 6px;
    gap: 12px;
}

.game-title-area {
    flex: 1;
    min-width: 0;
}

.game-topbar h2 {
    font-size: 1.5rem;
    text-align: left;
    margin-bottom: 0;
    line-height: 1.15;
}

/* Origin/artist byline — small italic gold with a leading ornament rule,
   visually distinct from the Cinzel title. Hides itself when there's no origin. */
.puzzle-byline {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 5px;
    font-family: 'Lora', serif;
    font-style: italic;
    font-size: 0.82rem;
    letter-spacing: 1px;
    color: var(--text-gold-dim);
    text-align: left;
}

.puzzle-byline::before {
    content: '';
    flex: 0 0 auto;
    width: 24px;
    height: 1px;
    background: linear-gradient(90deg, var(--text-gold-dim), transparent);
}

.puzzle-byline:empty {
    display: none;
}

.puzzle-progress {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    width: min(280px, 100%);
    margin-top: 12px;
    color: oklch(72% 0.025 263);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.progress-copy {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 3px 10px;
    min-width: 0;
    min-height: 1em;
}

#progress-label {
    white-space: nowrap;
    min-width: 0;
    flex: 1 1 12rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* The control is injected only for ?debug, but keep the production surface
   safe if a harness or host removes the body marker after boot. */
body:not(.debug-mode) #debug-solve-button {
    display: none;
}

.progress-track {
    display: block;
    grid-column: auto;
    width: 100%;
    min-width: 0;
    height: 4px;
    overflow: hidden;
    border-radius: 999px;
    background: oklch(18% 0.025 263);
    box-shadow: inset 0 1px 2px oklch(5% 0.01 263 / 0.65);
}

#progress-bar {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: oklch(82% 0.12 82);
    box-shadow: 0 0 10px oklch(78% 0.13 82 / 0.6);
    transition: width 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

#combo-label {
    min-width: 0;
    max-width: 100%;
    flex: 0 1 auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: oklch(72% 0.028 265);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.63rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0;
    transform: translateY(2px);
    transition: color 180ms ease, opacity 180ms ease, transform 180ms ease;
}

#combo-label.is-hot {
    color: oklch(83% 0.12 82);
    opacity: 1;
    transform: translateY(0);
    animation: comboRise 260ms ease-out;
}

#combo-label.is-super {
    color: oklch(88% 0.15 66);
    text-shadow: 0 0 12px oklch(78% 0.14 82 / 0.35);
}

@media (max-width: 480px) {
    .puzzle-progress {
        gap: 7px;
    }

    .progress-copy {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 3px;
    }

    #progress-label,
    #combo-label {
        display: block;
        font-size: 0.54rem;
        letter-spacing: 0.045em;
    }

    #combo-label {
        justify-self: start;
    }
}

@keyframes comboRise {
    0% { opacity: 0; transform: translateY(5px) scale(0.94); }
    65% { transform: translateY(-1px) scale(1.03); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

.game-topbar .subtitle {
    margin: 4px 0 0;
    text-align: left;
    font-size: 0.78rem;
    letter-spacing: 1.5px;
}

/* Collapse the status line until it actually has text, so it adds no height during play */
.game-topbar .subtitle:empty {
    display: none;
}

.game-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* --- How-to-play help control (puzzle screen) --- */
.help-wrapper {
    position: relative;
    display: flex;
}

.help-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Montserrat', sans-serif;
    font-size: 1rem;
    background: transparent;
    border: 1px solid var(--text-gold-dim);
    color: var(--text-gold);
    border-radius: 50%;
    cursor: help;
    letter-spacing: 0;
    text-transform: none;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.help-btn:hover {
    border-color: var(--text-gold);
    background: rgba(197, 160, 89, 0.12);
    box-shadow: 0 0 14px rgba(197, 160, 89, 0.3);
    transform: none;
}

/* Reuse the menu tooltip card, but anchor it below-right so it never
   overflows the viewport edge from the top-right controls. */
.help-tip {
    top: 130%;
    left: auto;
    right: 0;
    transform: none;
    width: min(300px, 80vw);
}

.help-wrapper.is-open .help-tip {
    visibility: visible;
    opacity: 1;
    top: 145%;
}

@media (hover: hover) {
    .help-wrapper:hover .help-tip {
        visibility: visible;
        opacity: 1;
        top: 145%;
    }
}

.hint-btn {
    font-size: 0.78rem;
    padding: 8px 14px;
    letter-spacing: 0.8px;
    white-space: nowrap;
}

.quit-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.62rem;
    font-weight: 600;
    background: transparent;
    border: 1px solid #444;
    color: #777;
    border-radius: 4px;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.quit-btn:hover {
    border-color: #bf1531;
    color: #bf1531;
    background: rgba(191, 21, 49, 0.08);
    transform: none;
    box-shadow: none;
}

/* =====================================================================
   CELL INTERACTION ANIMATIONS
   ===================================================================== */
@keyframes cellPop {
    0%   { transform: scale(1); }
    35%  { transform: scale(0.82); }
    65%  { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes cellUnpop {
    0%   { transform: scale(1); }
    50%  { transform: scale(0.9); }
    100% { transform: scale(1); }
}

.game-info {
    margin-top: 24px;
    text-align: center;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.78rem;
    color: #8a8f9c;
    letter-spacing: 0.5px;
}

.info-action {
    color: var(--text-gold-dim);
}

/* =====================================================================
   ROSE WINDOW MOUSE PARALLAX
   JS sets --rose-px / --rose-py in the [-1, 1] range from pointer.
   Falls back gracefully when JS is absent (vars resolve to 0).
   ===================================================================== */
.bg-rose-window {
    --rose-px: 0;
    --rose-py: 0;
    --rose-tx: calc(-50% + (var(--rose-px) * 14px));
    --rose-ty: calc(-52% + (var(--rose-py) * 10px));
    transform: translate(var(--rose-tx), var(--rose-ty));
}

@keyframes roseBreath {
    0%, 100% { transform: translate(var(--rose-tx), var(--rose-ty)) scale(1)    rotate(0deg); }
    33%       { transform: translate(var(--rose-tx), var(--rose-ty)) scale(1.015) rotate(0.6deg); }
    66%       { transform: translate(var(--rose-tx), var(--rose-ty)) scale(0.992) rotate(-0.4deg); }
}

/* =====================================================================
   REDUCED MOTION
   Honors OS-level setting and Arcadium accessibility expectations.
   Ambient/decorative animation is suspended; gameplay feedback
   (innerGlow on solve, hintFlash, ad slide-in, button hovers) is preserved.
   ===================================================================== */
@media (prefers-reduced-motion: reduce) {
    .boot-art img,
    .boot-progress span {
        animation: none !important;
    }

    .boot-art img {
        opacity: 1;
        filter: none;
    }

    .boot-loader {
        transition: none;
    }

    .ray,
    .bg-rose-window,
    #screen-menu::before,
    #screen-commissions::before,
    #screen-store::before,
    body.solved-phase-2 #screen-game::before,
    .btn-group.wide,
    #screen-menu.active > .menu-crest-wrap,
    #screen-menu.active > h1,
    #screen-menu.active > .subtitle,
    #screen-menu.active > .menu-actions,
    #screen-menu.active > .menu-footer,
    .menu-crest-wrap::before,
    .menu-crest,
    .menu-crest::after,
    .crest-pane {
        animation: none !important;
    }

    /* Crest stays fully lit when motion is reduced */
    .crest-pane {
        filter: brightness(1.08) saturate(1.12) !important;
    }

    .bg-dust {
        display: none;
    }

    .ray {
        opacity: 0.6;
    }

    .bg-rose-window {
        /* Keep parallax static — no transition lag — but lock breath */
        --rose-px: 0;
        --rose-py: 0;
    }

    .screen,
    .screen::before,
    .screen::after,
    .bg-rose-window {
        transition: opacity 0.2s ease !important;
    }

    button,
    .btn-link,
    .premium-card {
        transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease !important;
    }

    button:hover,
    .btn-link:hover,
    .premium-card:hover {
        transform: none !important;
    }

    .level-card,
    .level-thumb-mark,
    .level-thumb::after {
        transition: border-color 0.2s ease, background 0.2s ease !important;
    }

    .level-card:hover .level-thumb-mark,
    .level-card:hover .level-thumb::after,
    .level-card:hover .level-thumb-art {
        transform: none !important;
    }

    .admire-overlay.is-open,
    .admire-card,
    .admire-art-img {
        animation: none !important;
    }

    .premium-card.is-highlight,
    .store-toast {
        animation: none !important;
    }
}

/* =====================================================================
   PREMIUM STORE — pack cards, gem balance, purchase feedback
   ===================================================================== */
.store-intro {
    text-align: center;
    max-width: 640px;
    margin: 0 auto 22px;
    line-height: 1.6;
    color: #cfcfd6;
}

.store-balance {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.95rem;
    letter-spacing: 1px;
    color: var(--text-gold);
    padding: 7px 18px;
    margin-bottom: 26px;
    border: 1px solid rgba(197, 160, 89, 0.35);
    border-radius: 22px;
    background: rgba(8, 10, 20, 0.55);
    box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.4);
}

.store-balance .gem { filter: drop-shadow(0 0 4px rgba(120, 200, 255, 0.6)); }

.store-packs {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: center;
    width: 100%;
    max-width: 860px;
}

/* =====================================================================
   LEADERBOARD
   A quiet ranked ledger set into the nave, optimized for fast comparison.
   ===================================================================== */
#screen-leaderboard.active {
    min-height: 100dvh;
    justify-content: center;
    padding-block: 48px;
}

.leaderboard-heading {
    max-width: 620px;
    text-align: center;
}

.leaderboard-heading h2 {
    margin: 6px 0 8px;
}

.leaderboard-heading p,
.leaderboard-note {
    margin: 0;
    color: oklch(80% 0.02 82);
    line-height: 1.55;
}

.leaderboard-kicker {
    color: oklch(84% 0.09 82);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.leaderboard-shell {
    width: min(620px, 94vw);
    margin: 26px auto 18px;
    overflow: hidden;
    border: 1px solid oklch(66% 0.055 82 / 0.58);
    border-radius: 8px;
    background: oklch(14% 0.026 255 / 0.96);
    box-shadow: 0 22px 70px oklch(4% 0.01 260 / 0.62);
}

.leaderboard-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border-bottom: 1px solid oklch(45% 0.03 82 / 0.5);
}

.leaderboard-tab {
    min-width: 0;
    min-height: 44px;
    padding: 13px 8px;
    border: 0;
    border-radius: 0;
    background: oklch(17% 0.028 255);
    color: oklch(76% 0.02 82);
    font-size: 0.7rem;
    letter-spacing: 0.08em;
}

.leaderboard-tab + .leaderboard-tab {
    border-left: 1px solid oklch(38% 0.025 82 / 0.5);
}

.leaderboard-tab:hover,
.leaderboard-tab.is-active {
    transform: none;
    box-shadow: none;
    background: oklch(27% 0.055 82);
    color: oklch(93% 0.07 82);
}

.leaderboard-summary {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px 14px;
    color: oklch(76% 0.02 82);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.72rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.leaderboard-summary strong {
    color: oklch(90% 0.1 82);
    font-size: 1.2rem;
    font-variant-numeric: tabular-nums;
}

.leaderboard-status {
    min-height: 42px;
    padding: 0 20px 12px;
    color: oklch(79% 0.018 82);
    font-size: 0.82rem;
    line-height: 1.45;
}

.leaderboard-list {
    margin: 0;
    padding: 0;
    list-style: none;
    border-top: 1px solid oklch(38% 0.025 82 / 0.48);
}

.leaderboard-row {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    align-items: center;
    min-height: 52px;
    padding: 7px 20px;
    border-bottom: 1px solid oklch(32% 0.02 255 / 0.74);
}

.leaderboard-row:nth-child(-n + 3) .leaderboard-rank {
    color: oklch(88% 0.11 82);
}

.leaderboard-rank {
    color: oklch(68% 0.03 82);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

.leaderboard-identity {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 10px;
}

.leaderboard-avatar {
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    border: 1px solid oklch(64% 0.05 82 / 0.6);
    border-radius: 50%;
    object-fit: cover;
}

.leaderboard-name {
    overflow: hidden;
    color: oklch(91% 0.012 82);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-score {
    color: oklch(88% 0.08 82);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.86rem;
    font-variant-numeric: tabular-nums;
}

.leaderboard-row.is-loading span {
    height: 10px;
    border-radius: 3px;
    background: oklch(32% 0.025 255);
    animation: leaderboardShimmer 1.2s ease-in-out infinite alternate;
}

.leaderboard-row.is-loading span:first-child { width: 14px; }
.leaderboard-row.is-loading span:nth-child(2) { width: min(180px, 70%); }
.leaderboard-row.is-loading span:last-child { width: 72px; }

@keyframes leaderboardShimmer {
    from { opacity: 0.45; }
    to { opacity: 0.9; }
}

.leaderboard-auth {
    display: block;
    width: calc(100% - 40px);
    margin: 16px 20px 20px;
}

.leaderboard-auth[hidden] {
    display: none;
}

.leaderboard-note {
    max-width: 590px;
    margin-bottom: 22px;
    text-align: center;
    font-size: 0.78rem;
}

.daily-play-note {
    max-width: 620px;
    margin: 0 auto 24px;
    padding: 10px 16px;
    border: 1px solid oklch(66% 0.055 82 / 0.45);
    border-radius: 6px;
    background: oklch(16% 0.02 265 / 0.88);
    color: oklch(84% 0.025 82);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.78rem;
    line-height: 1.55;
    text-align: center;
}

.daily-play-note strong {
    color: oklch(90% 0.075 82);
}

/* The shared .premium-card gains a flex column layout so prices/buttons align
   across cards of differing blurb length, plus a per-pack accent edge. */
.premium-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 260px;
    border-top: 3px solid var(--accent, var(--text-gold-dim));
}

.pack-theme {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.64rem;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    color: oklch(84% 0.07 82);
    opacity: 0.95;
    margin-bottom: 6px;
}

.premium-card h3 { margin-bottom: 8px; }

.pack-blurb {
    font-size: 0.9rem;
    line-height: 1.5;
    color: #c2c2ca;
    margin: 0 0 14px;
    flex: 1 0 auto;
}

.pack-count {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.72rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: #8d8f99;
    margin-bottom: 4px;
}

.pack-save {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.72rem;
    color: #5fc27e;
    margin-bottom: 2px;
}

.premium-price .gem { filter: drop-shadow(0 0 4px rgba(120, 200, 255, 0.6)); }

.premium-price .was {
    color: #8d8f99;
    text-decoration: line-through;
    font-size: 0.85em;
    margin-right: 4px;
}

.premium-price.is-owned-price {
    color: var(--text-gold);
    font-size: 1rem;
    letter-spacing: 0.5px;
}

.owned-check {
    color: #5fc27e;
    font-weight: 700;
    margin-right: 4px;
}

.pack-buy { width: 100%; }

.pack-buy:disabled {
    cursor: default;
    opacity: 0.85;
    color: var(--text-gold);
    border-color: rgba(197, 160, 89, 0.4);
    background: rgba(212, 154, 42, 0.08);
}

.pack-buy:disabled:hover { transform: none; box-shadow: none; }

/* Owned packs: warm, "lit" tone */
.premium-card.is-owned {
    border-color: var(--text-gold);
    background: oklch(20% 0.035 75);
    box-shadow: inset 0 0 20px oklch(8% 0.015 265 / 0.45), 0 0 22px oklch(72% 0.1 82 / 0.2);
}

.premium-card.is-owned .pack-theme,
.premium-card.is-owned h3,
.premium-card.is-owned .premium-price {
    color: oklch(91% 0.085 82);
    text-shadow: 0 2px 7px oklch(7% 0.015 265 / 0.8);
}

.premium-card.is-owned .pack-blurb {
    color: oklch(91% 0.015 82);
}

.premium-card.is-owned .pack-count {
    color: oklch(79% 0.035 82);
}

.premium-card.is-owned .pack-buy:disabled {
    opacity: 1;
    color: oklch(18% 0.025 75);
    border-color: oklch(91% 0.09 82);
    background: oklch(80% 0.1 82);
    font-weight: 700;
}

/* All-access bundle: the hero card */
.premium-card.is-bundle {
    width: 280px;
    border-width: 3px;
    border-style: solid;
    border-color: var(--text-gold-dim);
    border-top-color: var(--accent, var(--text-gold));
    background: rgba(20, 14, 4, 0.6);
}

.pack-ribbon {
    position: absolute;
    top: 12px;
    right: -34px;
    transform: rotate(45deg);
    width: 130px;
    text-align: center;
    padding: 4px 0;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.62rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: #1a1205;
    background: var(--text-gold-dim);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* Flash when arriving from a locked puzzle */
.premium-card.is-highlight {
    animation: packPulse 0.7s ease-in-out 0s 3;
}

@keyframes packPulse {
    0%, 100% { box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5); }
    50%      { box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5), 0 0 26px rgba(212, 154, 42, 0.6); border-color: var(--text-gold); }
}

/* Transient purchase-feedback toast */
.store-toast {
    position: fixed;
    left: 50%;
    bottom: 36px;
    transform: translate(-50%, 20px);
    z-index: 3000;
    max-width: 90vw;
    padding: 14px 26px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.9rem;
    letter-spacing: 0.5px;
    color: var(--text-gold);
    background: rgba(12, 14, 26, 0.96);
    border: 1px solid var(--text-gold-dim);
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 22px rgba(212, 154, 42, 0.2);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.store-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* Simulated-purchase fallback (preview builds without a gem wallet) */
.sim-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 18px;
}

/* =====================================================================
   GALLERY — locked premium windows (teaser + lock)
   ===================================================================== */
.level-card.is-locked { border-color: rgba(197, 160, 89, 0.22); }

.level-card.is-locked:hover {
    border-color: var(--text-gold-dim);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55), 0 0 22px rgba(212, 154, 42, 0.12);
}

/* Artwork shown as a dimmed, blurred tease behind the lock */
.level-thumb-art.is-locked {
    filter: blur(5px) brightness(0.45) saturate(0.8);
    opacity: 0.7;
    transform: scale(1.04);
}

.level-card.is-locked:hover .level-thumb-art.is-locked {
    filter: blur(4px) brightness(0.6) saturate(0.95);
    transform: scale(1.08);
}

.level-lock {
    position: absolute;
    z-index: 3;
    font-size: 1.7rem;
    filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.9));
    opacity: 0.92;
    transition: transform 0.3s ease;
}

.level-card.is-locked:hover .level-lock { transform: scale(1.12); }

/* Collection tag on premium cards (owned, locked, or restored) */
.level-card-pack {
    align-self: flex-start;
    margin-top: 2px;
    padding: 2px 8px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.6rem;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-gold-dim);
    background: rgba(212, 154, 42, 0.1);
    border: 1px solid rgba(197, 160, 89, 0.25);
    border-radius: 4px;
}

.level-card-status.is-locked-status { color: var(--text-gold-dim); }

.level-card-status.is-ad-status {
    color: oklch(86% 0.09 82);
    font-weight: 600;
}

/* =====================================================================
   VISUALLY HIDDEN — screen-reader-only content (aria-live announcer)
   ===================================================================== */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* =====================================================================
   FATAL ERROR SCREEN — visible fallback when boot fails (levels.json
   unreachable, etc.). Shown by app.js; never leaves a silently dead menu.
   ===================================================================== */
.fatal-error {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(4, 5, 10, 0.94);
}

.fatal-error[hidden] {
    display: none;
}

.fatal-card {
    max-width: 420px;
    padding: 36px 30px;
    text-align: center;
    border-radius: 14px;
    background: rgba(18, 21, 35, 0.98);
    border: 1px solid rgba(197, 160, 89, 0.25);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.fatal-icon {
    font-size: 2rem;
    color: var(--text-gold);
    margin-bottom: 10px;
}

.fatal-card p {
    color: #c2c2ca;
    line-height: 1.6;
    margin: 14px 0 4px;
}

#fatal-reload {
    margin-top: 18px;
    min-width: 160px;
}

/* =====================================================================
   DAILY STREAK + WIN NOTE
   ===================================================================== */
.daily-status {
    margin-top: 16px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.78rem;
    letter-spacing: 1px;
    color: var(--text-gold-dim);
    text-align: center;
}

.daily-status:empty {
    display: none;
}

.win-note {
    margin-top: 12px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.85rem;
    letter-spacing: 1px;
    color: var(--text-gold);
    text-align: center;
    opacity: 0;
    animation: fadeIn 1.2s forwards;
}

.win-note:empty {
    display: none;
}

/* Global toast (achievements/streaks) sits above the game-info footer */
.global-toast {
    bottom: 64px;
}
