:root {
    --gold: #d7aa52;
    --gold-soft: #f6dd96;
    --deep: #050403;
    --velvet: #25040a;
    --line: rgba(246, 221, 150, .28);
    --progress: 0;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background: #111;
    font-family: Arial, sans-serif;
}

#unity-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* When #unity-container is the fullscreen element, html/body are no longer
   painted behind it, so it needs its own background and explicit sizing. */
#unity-container:fullscreen,
#unity-container:-webkit-full-screen {
    width: 100%;
    height: 100%;
    background: #111;
}

#game-wrapper {
    position: relative;
    width: min(100%, calc(100vh * 16 / 9));
    height: min(100%, calc(100vw * 9 / 16));
}

/* Focusable but invisible. Not display:none or [hidden] - neither can take focus, which is
   the only thing this element is for. */
#keyboard-anchor {
    position: fixed;
    left: -9999px;
    top: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    padding: 0;
    border: 0;
    background: none;
    pointer-events: none;
}

/* When the wrapper is fullscreen, stretch to fill.
   We use a JS-managed class instead of :fullscreen pseudo-class so the rule
   reliably stops applying when fullscreen exits across all browsers. */
#game-wrapper.fullscreen-mode {
    width: 100%;
    height: 100%;
    background: #111;
}

#unity-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

/* ✅ Rect (top/left/width/height) is set inline by main.js/webview.jslib to
   track the real iframe placement in both regular and fullscreen game
   modes. While the game is in iframe-fullscreen, webview.jslib shrinks the
   inline top/height by the #floor-chrome-bar's height via
   GetIframeTopInsetPx() (see index.html <style> + main.js) so the bar
   isn't covered - no rule here needs to change for that. */
#unity-iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    z-index: 10;

    opacity: 0;
    pointer-events: none;
    transition: opacity 0.6s ease;
}

/* ✅ Visibility toggle */
#unity-iframe.visible {
    opacity: 1;
    pointer-events: auto;
}

/* ✅ WHY: the DOM iframe sits at z-index 10, above the Unity canvas, so the Unity settings
   panel is unreadable unless the frame is hidden while that panel is open. `visibility`
   (not `display`) is used so the game's layout size doesn't change - a resize would make
   Unity think its canvas changed and could interrupt the running game. */
#game-wrapper.iframe-obscured #unity-iframe,
#game-wrapper.iframe-obscured #close-button,
#game-wrapper.iframe-obscured #fullscreen-button,
#game-wrapper.iframe-obscured #floor-chrome-bar {
    visibility: hidden;
    pointer-events: none;
}

/* ✅ CS-NEW-1: layered fallback so the loading screen reads as a lit casino
   floor even at 0 bytes of image (background-image on .cinema-bg hasn't
   decoded yet, or fails to load). Radial glow from --velvet at centre-bottom
   fading to --deep at the edges, roughly matching where the real backdrop's
   warm floor light sits. isolation/z-index stacking is unchanged. */
#loading-screen {
    position: absolute;
    inset: 0;
    overflow: hidden;
    isolation: isolate;
    background:
        radial-gradient(ellipse at 50% 85%, var(--velvet), transparent 60%),
        #020101;
    color: #fff;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    z-index: 1;
    transition: opacity 0.5s ease;
}

#loading-screen.fade-out {
    opacity: 0;
}

/* ✅ Finish sequence. Runs once Unity is up, across the hold that lets the game's
   Addressable content download behind this screen (CONTENT_PRELOAD_HOLD_MS in main.js):
   the loading chrome retires, the 21 swells, and the last stretch is the fade off the
   game. The two durations are handed down from main.js so the animation and the hold it
   has to fill cannot drift apart; the fallbacks match the defaults there. */

#loading-screen.finishing {
    transition: opacity var(--finish-fade-ms, 1200ms) ease;
}

/* The progress ring, the flavor text and the HUD have nothing left to report once Unity
   is loaded, so they leave early and hand the frame to the logo. */
#loading-screen.finishing .progress-orbit,
#loading-screen.finishing .metal-disc,
#loading-screen.finishing .copy-block,
#loading-screen.finishing .minimal-hud {
    opacity: 0;
    transition: opacity .7s ease;
}

#loading-screen.finishing .crest {
    transform: scale(1.5);
    transition: transform var(--finish-grow-ms, 3800ms) cubic-bezier(.16,.66,.3,1);
}

#loading-screen.finishing .logo {
    filter: drop-shadow(0 0 34px rgba(190,255,121,.4)) drop-shadow(0 16px 26px rgba(0,0,0,.6));
    transition: filter var(--finish-grow-ms, 3800ms) ease-out;
}

.cinema-bg {
    position: absolute;
    inset: -4%;
    /* ✅ CS-NEW-1: this layer is never transparent-black before the jpg
       decodes (or if it fails to load). background-color is the ultimate
       fallback; the radial-gradient is a second background-image layer
       sitting behind the jpg (a failed/undecoded image layer paints as
       transparent, letting the layer below it show through), so the
       velvet-to-deep glow is visible until the real photo is ready. */
    background-color: var(--velvet);
    background-image:
        url('img/casino-bg.jpg'),
        radial-gradient(ellipse at 50% 60%, var(--velvet), var(--deep) 75%);
    background-size: cover;
    background-position: center 53%;
    transform: scale(1.04);
    filter: contrast(1.08) saturate(.92) brightness(.72);
    animation: slowPush 18s ease-in-out infinite alternate;
    z-index: -8;
}

.cinema-grade {
    position: absolute;
    inset: 0;
    z-index: -6;
    background:
        radial-gradient(circle at 50% 45%, rgba(255,190,88,.15), transparent 24%),
        radial-gradient(circle at 48% 70%, rgba(115,12,20,.30), transparent 32%),
        linear-gradient(90deg, rgba(0,0,0,.82), rgba(0,0,0,.16) 34%, rgba(0,0,0,.16) 66%, rgba(0,0,0,.82)),
        linear-gradient(180deg, rgba(0,0,0,.48), transparent 30%, rgba(0,0,0,.88));
}

.cinema-grade:after {
    content: "";
    position: absolute;
    inset: 0;
    background-image: linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px);
    background-size: 100% 3px;
    mix-blend-mode: overlay;
    opacity: .18;
    pointer-events: none;
}

.volumetric-light {
    position: absolute;
    top: -20%;
    width: 34vw;
    height: 115vh;
    z-index: -5;
    opacity: .32;
    filter: blur(22px);
    background: linear-gradient(180deg, rgba(255,226,147,.48), rgba(255,194,91,.10) 40%, transparent 70%);
    transform-origin: top;
    animation: breathe 5.5s ease-in-out infinite;
}

.light-left { left: 15%; transform: rotate(14deg); }
.light-right { right: 12%; transform: rotate(-12deg); animation-delay: -2s; }

.floor-glass {
    position: absolute;
    left: 7%;
    right: 7%;
    bottom: -16%;
    height: 34%;
    z-index: -3;
    background: radial-gradient(ellipse at center, rgba(255,207,109,.16), transparent 62%);
    filter: blur(18px);
    opacity: .75;
    animation: floorPulse 6s ease-in-out infinite;
}

.gold-dust, .gold-dust:before, .gold-dust:after {
    position: absolute;
    inset: 0;
    content: "";
    z-index: -2;
    pointer-events: none;
    opacity: .55;
    background-image:
        radial-gradient(circle, rgba(255,219,143,.8) 0 1px, transparent 1.7px),
        radial-gradient(circle, rgba(255,255,255,.45) 0 1px, transparent 1.5px);
    background-size: 180px 180px, 260px 260px;
    background-position: 10% 20%, 70% 30%;
    animation: dustMove 22s linear infinite;
}

.gold-dust:before { opacity: .28; background-size: 120px 120px, 310px 310px; animation-duration: 28s; animation-direction: reverse; }
.gold-dust:after { opacity: .18; filter: blur(1px); background-size: 90px 90px, 210px 210px; animation-duration: 16s; }

.npc-shadow {
    position: absolute;
    bottom: 14%;
    width: 42px;
    height: 140px;
    z-index: -1;
    border-radius: 46% 46% 16% 16%;
    background: linear-gradient(180deg, rgba(0,0,0,.05), rgba(0,0,0,.58));
    filter: blur(1px);
    opacity: 0;
    animation: npcCross 14s ease-in-out infinite;
}

.npc-a { left: -8%; animation-delay: 1.2s; }
.npc-b { right: -10%; height: 120px; width: 36px; animation-name: npcCrossReverse; animation-delay: 7s; }

.hero-loader {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 30px;
    transform: translateY(-1.5vh);
}

.crest {
    position: relative;
    /* ✅ CS-NEW-1: capped by vmin (not just vw) so a short viewport (landscape
       phone) can't blow the crest up to fill the screen height-wise - see the
       max-height landscape query below for the further-reduced short cap. */
    width: min(33vw, 52vmin, 330px);
    aspect-ratio: 1;
    display: grid;
    place-items: center;
}

.progress-orbit {
    position: absolute;
    inset: 0;
    filter: drop-shadow(0 0 20px rgba(215,170,82,.22));
    animation: orbitFloat 6s ease-in-out infinite;
}

.orbit-svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.orbit-track { fill: none; stroke: rgba(246,221,150,.10); stroke-width: 1.5; stroke-dasharray: 2 10; }
.orbit-progress {
    fill: none;
    stroke: var(--gold-soft);
    stroke-width: 3.2;
    stroke-linecap: round;
    stroke-dasharray: 590;
    stroke-dashoffset: calc(590 - (590 * var(--progress) / 100));
    transition: stroke-dashoffset .45s cubic-bezier(.22,.61,.36,1);
    filter: drop-shadow(0 0 10px rgba(246,221,150,.65));
}

.orbit-dot {
    position: absolute;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--gold-soft);
    box-shadow: 0 0 18px var(--gold-soft);
    left: 50%;
    top: 50%;
    transform-origin: 0 0;
}

.dot-one { animation: dotOrbit 5.2s linear infinite; }
.dot-two { width: 4px; height: 4px; animation: dotOrbit 8s linear infinite reverse; opacity: .65; }

.metal-disc {
    position: absolute;
    width: 72%;
    aspect-ratio: 1;
    border-radius: 50%;
    background:
        radial-gradient(circle at 42% 32%, rgba(255,236,184,.18), rgba(255,207,107,.05) 31%, rgba(0,0,0,.44) 63%, rgba(0,0,0,.78)),
        conic-gradient(from 180deg, transparent, rgba(246,221,150,.23), transparent, rgba(135,81,22,.25), transparent);
    border: 1px solid rgba(246,221,150,.20);
    box-shadow: inset 0 0 60px rgba(0,0,0,.74), 0 34px 70px rgba(0,0,0,.55);
    backdrop-filter: blur(7px);
}

.logo-shell {
    position: relative;
    width: 62%;
    min-width: 190px;
    padding: 26px 25px;
    border-radius: 26px;
    overflow: hidden;
    background: transparent;
    border: none;
    box-shadow: none;
}

.logo {
    display: block;
    width: 100%;
    height: auto;
    filter: drop-shadow(0 0 18px rgba(190,255,121,.25)) drop-shadow(0 12px 18px rgba(0,0,0,.65));
}

.specular-sweep {
    position: absolute;
    top: -40%;
    bottom: -40%;
    left: -75%;
    width: 46%;
    transform: rotate(18deg);
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.20), rgba(246,221,150,.34), transparent);
    animation: sweep 3.8s cubic-bezier(.2,.75,.24,1) infinite;
}

.copy-block {
    text-align: center;
    letter-spacing: .02em;
    transform: translateY(-12px);
}

.loading-message {
    margin: 0;
    font-size: clamp(20px, 2.4vw, 34px);
    font-weight: 500;
    text-shadow: 0 8px 24px rgba(0,0,0,.8);
}

.subcopy {
    margin: 8px 0 0;
    color: rgba(255,241,207,.58);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .42em;
}

.minimal-hud {
    position: absolute;
    right: 34px;
    bottom: 28px;
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 12px 15px;
    border: 1px solid rgba(246,221,150,.13);
    border-radius: 999px;
    background: rgba(0,0,0,.28);
    backdrop-filter: blur(10px);
    color: rgba(255,241,207,.75);
    letter-spacing: .16em;
    font-size: 11px;
    box-shadow: 0 14px 48px rgba(0,0,0,.45);
}

/* ✅ min-width grew from 38px and letter-spacing was reset to normal so the
   "12.3 / 68.1 MB · ~14s" readout (js/main.js UpdateLoadingReadout) doesn't get
   stretched by the HUD's wide .16em tracking or clipped against the divider —
   a bare "0%" still fits the same slot fine at this width. */
.percent { font-size: 13px; color: var(--gold-soft); min-width: 150px; text-align: right; letter-spacing: normal; white-space: nowrap; }
.divider { width: 1px; height: 14px; background: rgba(246,221,150,.22); }

@keyframes slowPush { from { transform: scale(1.035) translate3d(-.5%,0,0); } to { transform: scale(1.095) translate3d(.5%,-1%,0); } }
@keyframes breathe { 0%,100% { opacity: .22; } 50% { opacity: .43; } }
@keyframes floorPulse { 0%,100% { opacity: .48; transform: scaleX(.95); } 50% { opacity: .78; transform: scaleX(1.05); } }
@keyframes dustMove { to { background-position: 10% -180%, 70% -130%; } }
@keyframes npcCross { 0%,14% { transform: translateX(0) scale(.85); opacity: 0; } 25% { opacity: .32; } 55% { opacity: .22; } 75%,100% { transform: translateX(118vw) scale(1.08); opacity: 0; } }
@keyframes npcCrossReverse { 0%,20% { transform: translateX(0) scale(.8); opacity: 0; } 31% { opacity: .25; } 55% { opacity: .18; } 78%,100% { transform: translateX(-118vw) scale(1.05); opacity: 0; } }
@keyframes orbitFloat { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-6px) scale(1.012); } }
@keyframes dotOrbit { from { transform: rotate(0deg) translateX(47%); } to { transform: rotate(360deg) translateX(47%); } }
@keyframes sweep { 0% { left: -80%; opacity: 0; } 12% { opacity: 1; } 42%,100% { left: 130%; opacity: 0; } }

@media (max-width: 760px) {
    .crest { width: min(60vw, 280px); }
    .logo-shell { min-width: 165px; padding: 20px; }
    .subcopy { letter-spacing: .22em; }
    .minimal-hud { right: 18px; bottom: 18px; }
}

/* ✅ CS-NEW-1: the max-width rule above never matches a landscape phone
   (e.g. 844x390 - width is well over 760px), so without this the crest
   stays min(33vw,52vmin,330px) ≈ 278px against a 390px-tall viewport and
   the .metal-disc (72% of the crest) fills the screen. This targets short
   viewports by height/orientation instead, and shrinks/repositions the
   whole loader stack so the crest, copy and HUD all stay on-screen and
   legible at a ~390px height. */
@media (max-height: 520px) and (orientation: landscape) {
    .crest { width: min(40vmin, 210px); }
    .hero-loader { gap: 12px; transform: none; }
    .logo-shell { min-width: 0; padding: 12px; }
    .loading-message { font-size: clamp(15px, 3.4vh, 20px); }
    .subcopy { font-size: 10px; letter-spacing: .22em; }
    .copy-block { transform: none; }
    .minimal-hud { right: 12px; bottom: 10px; padding: 8px 12px; }
    .percent { min-width: 130px; }
}

/* ✅ CS-NEW-1: backdrop-filter over an animating layer re-blurs every frame,
   which stalls the very animation this screen is meant to show on the low-
   powered/coarse-pointer (touch) GPUs it runs on most. Drop it here and trim
   the volumetric light's blur instead of leaving mobile stuck re-computing a
   backdrop blur 60x a second. */
@media (pointer: coarse) {
    .metal-disc {
        backdrop-filter: none;
        background:
            radial-gradient(circle at 42% 32%, rgba(255,236,184,.18), rgba(255,207,107,.05) 31%, rgba(0,0,0,.44) 63%, rgba(0,0,0,.58)),
            conic-gradient(from 180deg, transparent, rgba(246,221,150,.23), transparent, rgba(135,81,22,.25), transparent);
    }

    .minimal-hud { backdrop-filter: none; }
    .volumetric-light { filter: blur(12px); }
}

@media (prefers-reduced-motion: reduce) {
    #loading-screen *, #loading-screen *:before, #loading-screen *:after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition: none !important;
    }

    /* The rule above kills the swell's transition but not the transform itself, which
       would leave the logo snapping to 1.5x in a single frame - the one thing reduced
       motion is asking us not to do. Drop the swell; the screen still holds and fades. */
    #loading-screen.finishing .crest {
        transform: none !important;
    }
}

#iframe-overlay {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 11;

    opacity: 0;
    pointer-events: none;
}

#rotate-message {
    display: none;
    position: fixed;
    inset: 0;
    background: #111;
    color: #fff;
    font-size: 32px;
    z-index: 10000;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex-direction: column;
}

#rotate-icon {
    width: 120px;
    height: auto;
    margin-bottom: 20px;
}

@media (orientation: portrait) {
    #rotate-message {
        display: flex;
    }

    #unity-container {
        display: none;
    }
}

/* ✅ iOS home screen toast */
#ios-toast {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    font-size: 14px;
    padding: 12px 40px 12px 16px;
    border-radius: 10px;
    z-index: 9999;
    max-width: 90%;
    text-align: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

#ios-toast.visible {
    display: block;
}

#ios-toast-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    color: #aaa;
    font-size: 16px;
    cursor: pointer;
    padding: 0 4px;
}

/* ✅ CS-256 iOS reload-loop guard. Fixed above everything (loading screen z-index:1,
   leave-confirm 30, our own buttons 20) since it can replace the boot sequence entirely -
   toggled by js/main.js via the "visible" class, same pattern as #ios-toast/#leave-confirm.
   Palette matches #leave-confirm-panel (gold-on-charcoal) rather than introducing a new one. */
#reload-guard {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9998;

    align-items: center;
    justify-content: center;

    background: rgba(2, 4, 9, 0.86);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

#reload-guard.visible {
    display: flex;
}

#reload-guard-panel {
    width: min(86vw, 420px);
    padding: 30px 28px 26px;
    border: 1px solid rgba(246, 221, 150, 0.22);
    border-radius: 14px;
    background: rgba(10, 17, 28, 0.98);
    color: #fff;
    text-align: center;
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6);
}

#reload-guard-panel h2 {
    margin: 0 0 10px;
    font-size: clamp(19px, 3.2vw, 24px);
    color: var(--gold-soft);
    letter-spacing: 0.02em;
}

#reload-guard-panel p {
    margin: 0 0 14px;
    font-size: clamp(14px, 2.2vw, 16px);
    line-height: 1.45;
    color: rgba(226, 232, 240, 0.86);
}

/* The low-memory hint: visually distinct (smaller, warm tint) from the main
   explanation above it, so it reads as a tip rather than a repeat of the same line. */
#reload-guard-hint {
    margin-bottom: 22px;
    font-size: 12.5px;
    color: rgba(255, 200, 140, 0.78);
}

#reload-guard-retry {
    min-height: 52px;
    width: 100%;
    padding: 0 22px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    font-size: clamp(14px, 2.1vw, 16px);
    font-weight: 600;
    color: #050403;
    background: var(--gold-soft);
    cursor: pointer;
}

#reload-guard-retry:active {
    transform: translateY(1px);
}

#reload-guard-retry:focus-visible {
    outline: 2px solid rgba(96, 165, 250, 0.9);
    outline-offset: 2px;
}
