/* Shared cinematic frame: picture and both caption bars scale as one composition. */
/* Let the image fill the viewport; reserve safe-area only for controls/text. */
html.cinema-dialogue, html.cinema-dialogue body {
    margin: 0; padding: 0; border: 0; background: #000;
    --screen-background-color: #000;
    width: 100vw; min-width: 100vw; max-width: none;
    height: 100vh; min-height: 100vh; max-height: none; overflow: hidden;
}
.cinema-dialogue #monogatari {
    position: fixed; inset: 0; margin: 0; padding: 0; border: 0;
    width: 100%; height: 100%; max-width: none; max-height: none; background: #000;
}
.cinema-dialogue #monogatari visual-novel {
    margin: 0; padding: 0; width: 100%; height: 100%; max-width: none; background: #000;
}
@supports (width: 100dvw) {
    html.cinema-dialogue, html.cinema-dialogue body { width: 100dvw; min-width: 100dvw; }
}
@supports (height: 100dvh) {
    html.cinema-dialogue, html.cinema-dialogue body { height: 100dvh; min-height: 100dvh; }
}
.cinema-dialogue #monogatari game-screen {
    /* Logical coordinates of the approved 1920 × 1080 composition. */
    --cinema-bar-height: calc((1080px - 1920px * 3 / 7) / 2);
    --cinema-caption-height: var(--cinema-bar-height);
    --cinema-wide-image-max-height: calc(1920px * 3 / 7);
    --story-wide-fit: cover;
    position: absolute !important; inset: auto !important;
    left: 50% !important; top: 50% !important;
    width: 1920px !important; height: var(--cinema-stage-height, 1080px) !important;
    min-width: 0 !important; min-height: 0 !important;
    max-width: none !important; max-height: none !important;
    margin: 0 !important; padding: 0 !important;
    transform-origin: center;
    transform: translate(-50%, -50%) scale(var(--cinema-scale, 1)) !important;
    box-sizing: border-box; overflow: hidden; background: #000;
}
@supports (height: 100dvh) {
    html, body, #monogatari, #monogatari visual-novel { height: 100dvh; }
}
/* The gear lives inside the scaled game screen, while fullscreen is fixed to the viewport. */
.story-scene.cinema-dialogue #monogatari game-screen #story-menu-toggle {
    box-sizing: border-box;
    top: calc(max(12px, env(safe-area-inset-top)) / var(--cinema-scale, 1));
    left: calc(max(12px, env(safe-area-inset-left)) / var(--cinema-scale, 1));
    width: calc(48px / var(--cinema-scale, 1));
    min-width: calc(48px / var(--cinema-scale, 1));
    height: calc(48px / var(--cinema-scale, 1));
    border-width: calc(1px / var(--cinema-scale, 1));
    border-radius: calc(12px / var(--cinema-scale, 1));
    font-size: calc(32px / var(--cinema-scale, 1));
}
.story-scene.cinema-dialogue #monogatari game-screen quick-menu {
    top: calc((max(12px, env(safe-area-inset-top)) + 60px) / var(--cinema-scale, 1));
    left: calc(max(12px, env(safe-area-inset-left)) / var(--cinema-scale, 1));
}
/* Full-screen image; the bars only mask it and never resize its rectangle. */
.cinema-dialogue #monogatari game-screen [data-ui="background"],
.cinema-dialogue #monogatari game-screen #scene-dissolve {
    position: absolute; inset: 0; width: 100%; height: 100%;
    background-size: cover !important; background-position: center !important;
}
/* Keep the wide picture inside the reference opening. */
.cinema-dialogue #monogatari game-screen :is([data-ui="background"], #scene-dissolve, #story-camera-viewport, #story-ghost)[data-story-image-fit="letterbox"] {
    top: var(--cinema-bar-height) !important;
    bottom: var(--cinema-bar-height) !important;
    left: 0 !important; right: 0 !important;
    width: 100% !important; height: auto !important;
    max-height: var(--cinema-wide-image-max-height) !important; margin-block: auto;
    background-size: var(--story-wide-fit) !important;
    background-repeat: no-repeat !important;
}
/* Center captions in the entire bar below a height-capped image. */
.cinema-dialogue #monogatari game-screen:has([data-ui="background"][data-story-image-fit="letterbox"]) {
    --cinema-caption-height: max(var(--cinema-bar-height),
        calc((var(--cinema-stage-height, 1080px) - var(--cinema-wide-image-max-height)) / 2));
}
/* Camera canvases and ghost copies follow the same fit, including fullscreen toggles. */
.cinema-dialogue #story-camera-viewport[data-story-image-fit="letterbox"] > :is(img, canvas),
.cinema-dialogue #scene-dissolve[data-story-image-fit="letterbox"] > :is(img, canvas) {
    object-fit: var(--story-wide-fit) !important;
}
.cinema-dialogue #story-ghost[data-story-image-fit="letterbox"] .story-ghost-picture {
    background-size: var(--story-wide-fit) !important;
}
.cinema-dialogue game-screen::after {
    content: ''; position: absolute; inset: 0; z-index: 3; pointer-events: none;
    background: linear-gradient(to bottom, #000 0, #000 var(--cinema-bar-height),
        transparent var(--cinema-bar-height), transparent calc(100% - var(--cinema-bar-height)),
        #000 calc(100% - var(--cinema-bar-height)), #000 100%);
}
.story-scene.cinema-dialogue #monogatari game-screen text-box {
    --story-font-size: 32px;
    --story-line-size: 1.3;
    position: absolute; z-index: 5;
    left: 6%;
    right: 6%;
    bottom: 0; width: auto; max-width: 1200px;
    height: var(--cinema-caption-height); min-height: var(--cinema-caption-height); max-height: var(--cinema-caption-height);
    margin: 0 auto; padding: 4px 0;
    display: flex !important; flex-direction: column; justify-content: center; align-items: stretch;
    box-sizing: border-box; border: 0; border-radius: 0; background: transparent; box-shadow: none;
    color: #f4f1ea; text-align: center; overflow-y: auto;
    text-shadow: 0 1px 3px #000;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
.story-scene.cinema-dialogue #monogatari game-screen text-box [data-content="text"] {
    position: absolute; top: 50%; left: 0; right: 0;
    transform: translateY(-50%);
    margin: 0; padding: 0; width: 100%; height: auto;
    display: block; overflow: visible; max-height: none;
}
.story-scene.cinema-dialogue #monogatari game-screen text-box :is([data-content="text"], [data-ui="say"], [data-content="dialog"], type-writer, p) {
    font-size: var(--cinema-fit-font, var(--story-font-size)); line-height: 1.3; text-align: center;
    margin: 0; padding: 0; box-sizing: border-box;
}
@media (pointer: coarse) and (orientation: portrait) {
    .story-scene.cinema-dialogue #monogatari game-screen text-box {
        --story-font-size: calc(18px / var(--cinema-scale, 1));
    }
}
/* Short caption bars keep the first line reachable when scrolling is necessary. */
.story-scene.cinema-dialogue #monogatari game-screen text-box.cinema-text-overflow [data-content="text"] {
    top: 0; transform: none;
}
/* The typewriter inserts another div; align every line inside it as well. */
.story-scene.cinema-dialogue #monogatari game-screen text-box [data-content="text"] :is(type-writer, .type-writer-container, p, div) {
    display: block; width: 100%; max-width: none;
    margin: 0 !important; padding: 0 !important;
    text-align: center !important; box-sizing: border-box;
}
/* Menu audio controls stay visible; main-screen owns their visibility. */

/* Film grain sits above scene layers and below bars, captions, fades and controls. */
.cinema-dialogue #story-film-grain {
    display: none; position: absolute; z-index: 2;
    top: var(--cinema-bar-height); bottom: var(--cinema-bar-height);
    left: 0; right: 0; overflow: hidden; pointer-events: none;
    opacity: .10; mix-blend-mode: soft-light;
}
.cinema-dialogue game-screen.active.story-film-grain #story-film-grain { display: block; }
.story-film-grain-noise {
    position: absolute; inset: -32px; background-repeat: repeat; background-size: 256px 256px;
    animation: story-film-grain-drift 400ms steps(1, end) infinite;
}
@keyframes story-film-grain-drift {
    0%, 100% { transform: translate(0, 0); }
    12.5% { transform: translate(-11px, 7px); }
    25% { transform: translate(15px, -9px); }
    37.5% { transform: translate(-7px, -14px); }
    50% { transform: translate(9px, 12px); }
    62.5% { transform: translate(-15px, 3px); }
    75% { transform: translate(4px, -7px); }
    87.5% { transform: translate(-3px, 15px); }
}
@media (prefers-reduced-motion: reduce) {
    .story-film-grain-noise { animation: none; }
}

/* Use the full caption bar on phones; all measurements are in scaled stage coordinates. */
.story-scene.cinema-dialogue #monogatari game-screen text-box[data-phone-caption] {
    --phone-caption-size: min(calc(24px / var(--cinema-scale, 1)), calc((var(--cinema-caption-height) - 8px) / 1.3));
    max-width: none;
    left: max(4%, calc(env(safe-area-inset-left) / var(--cinema-scale, 1)));
    right: max(4%, calc(env(safe-area-inset-right) / var(--cinema-scale, 1)));
    overflow: hidden;
}
.story-scene.cinema-dialogue #monogatari game-screen text-box[data-phone-caption] :is([data-content="text"], [data-ui="say"], [data-content="dialog"], type-writer, p) {
    font-size: var(--phone-caption-size);
    white-space: nowrap;
}

#chapter-one-end {position:absolute;inset:0;z-index:100;display:flex;flex-direction:column;align-items:center;justify-content:safe center;box-sizing:border-box;overflow:auto;gap:clamp(8px,3vh,24px);background:radial-gradient(ellipse at center,#201d19,#090908 70%);color:#eee6d7;text-align:center;padding:24px;}
#chapter-one-end h1 {margin:0;color:#ead7b1;font-size:clamp(32px,min(8vw,10vh),64px);font-weight:500;}
#chapter-one-end p {margin:0 0 .4em;font-size:clamp(22px,5vh,36px);font-style:italic;color:#d7c7a5;}
#chapter-one-end > div {display:flex;flex-wrap:wrap;justify-content:center;align-items:stretch;gap:12px;width:100%;}
#chapter-one-end button {display:inline-flex;align-items:center;justify-content:center;box-sizing:border-box;width:auto;height:auto;min-height:44px;max-width:100%;white-space:normal;line-height:1.2;text-align:center;font-family:inherit;font-size:clamp(20px,3vw,26px);color:inherit;background:transparent;border-radius:6px;border:1px solid #736650;padding:12px 24px;margin:0;cursor:pointer;}
