/* =========================================
   LAST CITY · CINEMATIC OPENING
   -----------------------------------------
   A fullscreen stage that sits above everything while the opening plays.
   The canvas carries the picture; this file carries the frame around it —
   letterbox bars, film grain, chapter cards and the dialogue plate.
========================================= */

/* A <dialog>, so it shares the browser's top layer with the game's own modal
   start screen instead of rendering behind it. The default dialog chrome
   (border, padding, centred sizing) is cleared so it can fill the viewport. */
.cinematic-stage {
    position: fixed;
    inset: 0;
    z-index: 200;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: #000;
    color: inherit;
    opacity: 0;
    pointer-events: none;
    transition: opacity .7s ease;
    font-family: Inter, Arial, Helvetica, sans-serif;
    cursor: pointer;
    overflow: hidden;
}

.cinematic-stage:not([open]) { display: none; }

.cinematic-stage::backdrop { background: #000; }

.cinematic-stage.open {
    opacity: 1;
    pointer-events: auto;
}

.cinematic-stage.closing {
    opacity: 0;
    pointer-events: none;
    transition: opacity .6s ease;
}

.cinematic-stage[hidden] { display: none; }

#cinematicCanvas {
    position: absolute;
    inset: 0;
    display: block;
}

/* While the cinematic runs, nothing behind it should scroll or be reachable. */
body.cinematic-open {
    overflow: hidden;
}

/* -----------------------------------------
   Letterbox + grain
----------------------------------------- */

.cine-letterbox {
    position: absolute;
    left: 0;
    right: 0;
    height: 7vh;
    background: #000;
    z-index: 2;
    animation: cine-bars .9s ease both;
}

.cine-top { top: 0; }
.cine-bottom { bottom: 0; }

@keyframes cine-bars {
    from { height: 50vh; }
    to   { height: 7vh; }
}

/* A very faint moving grain, which keeps flat gradients from banding and
   sells the "recovered footage" feel. Pure CSS, no image. */
.cine-grain {
    position: absolute;
    inset: -50%;
    z-index: 3;
    pointer-events: none;
    opacity: .05;
    background-image:
        repeating-linear-gradient(0deg, rgba(255, 255, 255, .5) 0 1px, transparent 1px 2px),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, .35) 0 1px, transparent 1px 3px);
    animation: cine-grain 1.1s steps(4) infinite;
}

@keyframes cine-grain {
    0%   { transform: translate(0, 0); }
    25%  { transform: translate(-2%, 1%); }
    50%  { transform: translate(1%, -2%); }
    75%  { transform: translate(-1%, -1%); }
    100% { transform: translate(0, 0); }
}

/* -----------------------------------------
   Chapter card
----------------------------------------- */

.cine-chapter {
    position: absolute;
    top: 14vh;
    left: 0;
    right: 0;
    z-index: 5;
    margin: 0;
    text-align: center;
    font-size: clamp(.68rem, 1.9vw, .92rem);
    font-weight: 700;
    letter-spacing: .4em;
    text-transform: uppercase;
    color: rgba(245, 247, 250, .9);
    text-shadow: 0 2px 22px rgba(0, 0, 0, .95);
    opacity: 0;
}

.cine-chapter.show {
    animation: cine-chapter 4.6s ease both;
}

@keyframes cine-chapter {
    0%   { opacity: 0; letter-spacing: .7em; }
    14%  { opacity: 1; letter-spacing: .4em; }
    76%  { opacity: 1; letter-spacing: .4em; }
    100% { opacity: 0; letter-spacing: .34em; }
}

/* -----------------------------------------
   Dialogue
----------------------------------------- */

.cine-dialogue {
    position: absolute;
    left: 50%;
    bottom: 13vh;
    transform: translateX(-50%) translateY(14px);
    z-index: 6;
    width: min(760px, 88vw);
    padding: 16px 20px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, .1);
    border-left: 3px solid #65baff;
    background: linear-gradient(135deg, rgba(6, 10, 16, .88), rgba(6, 10, 16, .64));
    backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity .4s ease, transform .4s ease;
}

.cine-dialogue.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.cine-dialogue.narrator {
    border-left-color: rgba(129, 147, 166, .7);
    background: linear-gradient(135deg, rgba(4, 7, 11, .8), rgba(4, 7, 11, .5));
}

.cine-speaker {
    margin: 0 0 5px;
    font-size: .66rem;
    font-weight: 700;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: #65baff;
}

.cine-speaker[hidden] { display: none; }

.cine-text {
    margin: 0;
    font-size: clamp(.95rem, 2.4vw, 1.2rem);
    line-height: 1.55;
    color: #f2f6fb;
    /* Reserve two lines so the plate does not resize as text types in. */
    min-height: 2.9em;
    text-shadow: 0 1px 12px rgba(0, 0, 0, .6);
}

.cine-dialogue.narrator .cine-text {
    font-style: italic;
    color: #dbe4ee;
}

/* A blinking caret while a line is typing. */
.cine-text::after {
    content: "▌";
    margin-left: 2px;
    opacity: .55;
    animation: cine-caret 1s steps(2) infinite;
}

@keyframes cine-caret {
    0%, 49%   { opacity: .55; }
    50%, 100% { opacity: 0; }
}

/* -----------------------------------------
   Controls
----------------------------------------- */

.cine-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 3.2vh;
    z-index: 7;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    padding: 0 18px;
}

.cine-progress {
    display: flex;
    gap: 7px;
}

.cine-progress i {
    width: 28px;
    height: 3px;
    border-radius: 2px;
    background: rgba(255, 255, 255, .18);
    position: relative;
    overflow: hidden;
}

.cine-progress i.done { background: rgba(255, 194, 71, .55); }

.cine-progress i.active::after {
    content: "";
    position: absolute;
    inset: 0;
    width: var(--p, 0%);
    background: #ffc247;
    border-radius: 2px;
}

.cine-skip {
    padding: 9px 16px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, .22);
    background: rgba(10, 14, 20, .72);
    color: #f5f7fa;
    font-size: .76rem;
    font-weight: 600;
    letter-spacing: .06em;
    cursor: pointer;
    backdrop-filter: blur(6px);
    transition: background .2s ease, border-color .2s ease, transform .15s ease;
}

.cine-skip:hover {
    background: rgba(26, 38, 52, .9);
    border-color: #65baff;
}

.cine-skip:active { transform: scale(.96); }

.cine-skip:focus-visible {
    outline: 2px solid #65baff;
    outline-offset: 2px;
}

/* -----------------------------------------
   Static storyboard mode
----------------------------------------- */

.cinematic-stage.cine-static .cine-grain,
.cinematic-stage.cine-static .cine-text::after {
    display: none;
}

.cinematic-stage.cine-static .cine-letterbox { animation: none; }

.cinematic-stage.cine-static .cine-dialogue::after {
    content: "Tap or press Enter for the next line";
    display: block;
    margin-top: 10px;
    font-size: .66rem;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: rgba(129, 147, 166, .9);
}

/* -----------------------------------------
   Small screens
----------------------------------------- */

@media (max-width: 720px) {
    .cine-letterbox { height: 4.5vh; }
    .cine-dialogue {
        bottom: 15vh;
        padding: 13px 15px;
        border-radius: 12px;
    }
    .cine-text { min-height: 4.2em; }
    .cine-chapter { top: 9vh; letter-spacing: .3em; }
    .cine-controls { flex-direction: column-reverse; gap: 10px; bottom: 2.4vh; }
}

/* -----------------------------------------
   Reduced motion
----------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    .cinematic-stage,
    .cine-dialogue { transition: none; }
    .cine-grain,
    .cine-letterbox,
    .cine-chapter,
    .cine-text::after { animation: none; }
    .cine-chapter { opacity: 1; }
    .cine-grain { display: none; }
}
