* {
    box-sizing: border-box;
}

:root {
    --gold: #e7b43b;
    --gold-light: #ffd875;
    --ink: #050608;
    --panel: rgba(8, 10, 14, 0.94);
    --line: rgba(231, 180, 59, 0.55);
    --text: #f4f4f5;
    --muted: #a1a1aa;
}

html,
body {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    margin: 0;
    padding: 16px 16px 0;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 0%, #222833 0%, #090b0f 55%, #020203 100%);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 16px;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 0%, #222833 0%, #090b0f 55%, #020203 100%);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

button,
select,
input {
    font: inherit;
}

button {
    color: inherit;
}

button:disabled {
    opacity: 0.35;
    cursor: not-allowed !important;
}

.hidden {
    display: none !important;
}

#game-shell {
    position: relative;
    width: min(
        1280px,
        calc(100vw - 48px),
        calc((100dvh - 64px) * 16 / 9)
    );
    max-height: calc(100dvh - 64px);
    aspect-ratio: 16 / 9;
    overflow: hidden;
    flex: 0 0 auto;
    background: #000;
    border: 1px solid rgba(255, 255, 255, 0.16);
    box-shadow: 0 24px 90px rgba(0, 0, 0, 0.75);
}

#game-container,
#game-container canvas {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
}

.front-screen {
    position: absolute;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #030405;
}

#loading-screen {
    transition: opacity 500ms ease;
}

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

.studio-mark {
    position: relative;
    display: grid;
    width: 112px;
    height: 112px;
    place-items: center;
    margin-bottom: 18px;
    border: 2px solid var(--gold);
    transform: rotate(45deg);
}

.studio-initials {
    color: var(--gold-light);
    font-size: 38px;
    font-weight: 900;
    letter-spacing: -4px;
    transform: rotate(-45deg);
}

.studio-crack {
    position: absolute;
    top: -8px;
    left: 52%;
    width: 2px;
    height: 126px;
    background: var(--gold);
    transform: rotate(16deg);
    box-shadow:
        -8px 34px 0 -0.5px var(--gold),
        8px 67px 0 -0.5px var(--gold);
}

.studio-name,
.studio-overline {
    margin: 0;
    color: var(--gold);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.34em;
    text-transform: uppercase;
}

.loading-line {
    width: min(280px, 68vw);
    height: 2px;
    margin: 28px 0;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.12);
}

.loading-line span {
    display: block;
    width: 42%;
    height: 100%;
    background: var(--gold);
    animation: loadingSweep 1.2s ease-in-out infinite;
}

@keyframes loadingSweep {
    0% { transform: translateX(-110%); }
    100% { transform: translateX(340%); }
}

.fiction-notice {
    width: min(620px, 82vw);
    margin: 0;
    color: #8c8f96;
    font-size: 13px;
    line-height: 1.65;
    text-align: center;
}

#main-menu {
    align-items: flex-start;
    justify-content: center;
    padding: 0 clamp(42px, 6.6vw, 104px);
    background:
        radial-gradient(circle at 78% 46%, rgba(140, 72, 24, 0.27), transparent 34%),
        linear-gradient(145deg, #14171d, #040506 70%);
}

.main-menu-art {
    position: absolute;
    z-index: 0;
    top: 0;
    right: 0;
    bottom: 0;
    width: 56%;
    pointer-events: none;
    background:
        linear-gradient(90deg, #030405 0%, rgba(3, 4, 5, 0.72) 13%, rgba(3, 4, 5, 0.08) 43%, rgba(3, 4, 5, 0) 100%),
        linear-gradient(0deg, rgba(3, 4, 5, 0.7) 0%, transparent 22%),
        url("assets/images/main_menu_art.png") center right / cover no-repeat;
}

.main-menu-backdrop {
    position: absolute;
    z-index: 1;
    inset: 0;
    pointer-events: none;
    opacity: 0.22;
    background:
        repeating-linear-gradient(110deg, transparent 0 45px, rgba(255,255,255,0.035) 46px 47px),
        linear-gradient(90deg, rgba(2, 3, 5, 0.97) 0%, rgba(2, 3, 5, 0.86) 38%, rgba(2, 3, 5, 0.1) 66%, transparent 100%),
        linear-gradient(transparent 64%, rgba(0,0,0,0.75));
}

.menu-content,

/* Support links use a distinct treatment so they stand out without breaking the noir menu style. */
.primary-menu .support-button {
    margin: 2px 0;
    border-left-width: 3px;
    border-radius: 0 6px 6px 0;
}

.primary-menu .patreon-button {
    color: #f1d9ff;
    background: linear-gradient(90deg, rgba(142, 68, 173, 0.22), rgba(142, 68, 173, 0.04) 72%, transparent);
    border-left-color: #a96bc8;
}

.primary-menu .donate-button {
    color: var(--gold-light);
    background: linear-gradient(90deg, rgba(231, 180, 59, 0.24), rgba(231, 180, 59, 0.04) 72%, transparent);
    border-left-color: var(--gold);
}

.primary-menu .patreon-button:hover:not(:disabled),
.primary-menu .patreon-button:focus-visible {
    color: #ffffff;
    background: linear-gradient(90deg, rgba(142, 68, 173, 0.42), rgba(142, 68, 173, 0.08) 76%, transparent);
    border-left-color: #cf8df0;
}

.primary-menu .donate-button:hover:not(:disabled),
.primary-menu .donate-button:focus-visible {
    color: #fff4cb;
    background: linear-gradient(90deg, rgba(231, 180, 59, 0.38), rgba(231, 180, 59, 0.08) 76%, transparent);
    border-left-color: var(--gold-light);
}

.contact-panel {
    display: grid;
    gap: 14px;
}

.contact-panel p {
    margin: 0;
}

.contact-email {
    width: fit-content;
    color: var(--gold-light);
    font-weight: 700;
    letter-spacing: 0.03em;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.contact-email:hover,
.contact-email:focus-visible {
    text-decoration: underline;
    outline: none;
}

.menu-footer {
    position: relative;
    z-index: 2;
}

.menu-content {
    width: min(690px, 53%);
    transform: translateY(-10%);
}

.title-lockup {
    margin-bottom: 18px;
}

.title-lockup h1 {
    margin: 10px 0 0;
    font-size: clamp(48px, 6.4vw, 82px);
    line-height: 0.88;
    letter-spacing: -0.075em;
}

.title-lockup h1 span {
    color: var(--gold);
}

.subtitle {
    margin: 10px 0 0;
    color: #b6b8bd;
    font-size: clamp(11px, 1.3vw, 16px);
    font-weight: 700;
    letter-spacing: 0.38em;
}

.primary-menu {
    display: grid;
    width: min(330px, 72vw);
    gap: 1px;
}

.primary-menu button,
.pause-card button,
.secondary-button {
    position: relative;
    padding: 9px 16px;
    color: #e8e8ea;
    background: transparent;
    border: 0;
    border-left: 2px solid transparent;
    cursor: pointer;
    font-size: 17px;
    font-weight: 700;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    transition: 150ms ease;
}

.primary-menu button:hover:not(:disabled),
.primary-menu button:focus-visible,
.pause-card button:hover:not(:disabled),
.pause-card button:focus-visible {
    padding-left: 25px;
    color: var(--gold-light);
    background: linear-gradient(90deg, rgba(231, 180, 59, 0.14), transparent);
    border-left-color: var(--gold);
    outline: none;
}


/* Support links use a distinct treatment so they stand out without breaking the noir menu style. */
.primary-menu .support-button {
    margin: 2px 0;
    border-left-width: 3px;
    border-radius: 0 6px 6px 0;
}

.primary-menu .patreon-button {
    color: #f1d9ff;
    background: linear-gradient(90deg, rgba(142, 68, 173, 0.22), rgba(142, 68, 173, 0.04) 72%, transparent);
    border-left-color: #a96bc8;
}

.primary-menu .donate-button {
    color: var(--gold-light);
    background: linear-gradient(90deg, rgba(231, 180, 59, 0.24), rgba(231, 180, 59, 0.04) 72%, transparent);
    border-left-color: var(--gold);
}

.primary-menu .patreon-button:hover:not(:disabled),
.primary-menu .patreon-button:focus-visible {
    color: #ffffff;
    background: linear-gradient(90deg, rgba(142, 68, 173, 0.42), rgba(142, 68, 173, 0.08) 76%, transparent);
    border-left-color: #cf8df0;
}

.primary-menu .donate-button:hover:not(:disabled),
.primary-menu .donate-button:focus-visible {
    color: #fff4cb;
    background: linear-gradient(90deg, rgba(231, 180, 59, 0.38), rgba(231, 180, 59, 0.08) 76%, transparent);
    border-left-color: var(--gold-light);
}

.contact-panel {
    display: grid;
    gap: 14px;
}

.contact-panel p {
    margin: 0;
}

.contact-email {
    width: fit-content;
    color: var(--gold-light);
    font-weight: 700;
    letter-spacing: 0.03em;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.contact-email:hover,
.contact-email:focus-visible {
    text-decoration: underline;
    outline: none;
}

.menu-footer {
    position: absolute;
    right: 30px;
    bottom: 22px;
    left: 30px;
    display: flex;
    justify-content: space-between;
    color: #777b82;
    font-size: 11px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

.menu-panel {
    width: min(560px, 82vw);
    max-height: 56%;
    overflow: auto;
    padding: 22px;
    background: rgba(5, 7, 10, 0.86);
    border: 1px solid rgba(231, 180, 59, 0.35);
}

.menu-panel h2,
.pause-card h2 {
    margin: 0 0 18px;
    color: var(--gold-light);
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.menu-panel .secondary-button {
    margin-top: 16px;
    border-left-color: var(--gold);
}

.achievement-list {
    display: grid;
    gap: 8px;
}

.achievement-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: rgba(255,255,255,0.035);
    border: 1px solid rgba(255,255,255,0.08);
}

.achievement-item.locked {
    opacity: 0.48;
}

.achievement-icon {
    color: var(--gold);
}

.achievement-item strong,
.achievement-item p {
    margin: 0;
}

.achievement-item p,
.menu-note,
.credits-block p {
    margin-top: 5px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

.settings-list {
    display: grid;
    gap: 10px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.setting-row select {
    min-width: 130px;
    padding: 7px;
    color: var(--text);
    background: #151820;
    border: 1px solid #444955;
}


.game-mute-button {
    position: absolute;
    z-index: 25;
    top: 14px;
    right: 88px;
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    padding: 0;
    color: var(--gold-light);
    background: rgba(5, 7, 10, 0.82);
    border: 1px solid var(--line);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}

.game-mute-button:hover,
.game-mute-button:focus-visible,
.game-mute-button.is-muted {
    border-color: var(--gold-light);
    background: rgba(15, 17, 22, 0.94);
}

.game-menu-button {
    position: absolute;
    z-index: 25;
    top: 14px;
    right: 14px;
    padding: 8px 13px;
    color: var(--gold-light);
    background: rgba(5, 7, 10, 0.82);
    border: 1px solid var(--line);
    cursor: pointer;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.16em;
}

.pause-overlay {
    position: absolute;
    inset: 0;
    z-index: 90;
    display: grid;
    place-items: center;
    background: rgba(0,0,0,0.76);
    backdrop-filter: blur(5px);
}

.pause-card {
    display: grid;
    width: min(390px, 82%);
    padding: 28px;
    background: rgba(7,9,13,0.98);
    border: 1px solid var(--line);
}

.pause-card button {
    width: 100%;
}

.shortcut-note {
    margin: 18px 0 0;
    color: #747881;
    font-size: 11px;
    text-align: center;
}

.system-toast {
    position: absolute;
    z-index: 150;
    top: 18px;
    left: 50%;
    padding: 10px 18px;
    color: #090a0c;
    background: var(--gold-light);
    transform: translateX(-50%);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.05em;
}

/* Full-screen visual novel mode */
#dialogue-layer {
    position: absolute;
    inset: 0;
    z-index: 40;
    overflow: hidden;
    background: #050505;
}

#visual-scene {
    position: absolute;
    inset: 0;
    background: linear-gradient(145deg, #202938, #090c12);
}

#scene-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    opacity: 0;
    transition: opacity 180ms ease;
}

#scene-image.loaded {
    opacity: 1;
}

#scene-placeholder {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, #252b35, #0b0d12 70%);
}

#scene-darkener {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(
            to bottom,
            transparent 36%,
            rgba(0, 0, 0, 0.12) 53%,
            rgba(0, 0, 0, 0.78) 78%,
            rgba(0, 0, 0, 0.96) 100%
        );
}

#dialogue-panel {
    position: absolute;
    z-index: 2;
    right: 36px;
    bottom: 24px;
    left: 36px;
    min-height: 0;
    padding: 18px 10px 4px;
    color: #f9fafb;
    background: transparent;
    border: 0;
}

#speaker-name {
    margin: 0 0 8px;
    color: var(--gold-light);
    font-size: 20px;
    font-weight: 900;
    text-transform: uppercase;
}

#dialogue-text {
    min-height: 48px;
    margin: 0 0 16px;
    font-size: 18px;
    line-height: 1.5;
}

body[data-text-size="large"] #dialogue-text {
    font-size: 22px;
}

#choice-list {
    display: grid;
    gap: 8px;
}

.choice-button,
#next-button {
    padding: 11px 14px;
    color: #f9fafb;
    background: rgba(5, 7, 10, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.72);
    cursor: pointer;
    backdrop-filter: blur(2px);
}

.choice-button {
    width: 100%;
    text-align: left;
}

#next-button {
    display: block;
    min-width: 140px;
    margin-top: 14px;
    margin-left: auto;
    text-align: center;
}

.choice-button:hover,
#next-button:hover {
    background: rgba(231, 180, 59, 0.12);
    border-color: var(--gold);
}

.choice-button:focus,
#next-button:focus {
    outline: 3px solid var(--gold);
    outline-offset: 2px;
}

@media (max-width: 650px) {
    body {
        padding: 0;
    }

    #game-shell {
        width: 100vw;
        border: 0;
    }

    #main-menu {
        justify-content: center;
        padding: 26px 24px;
    }

    .main-menu-art {
        width: 76%;
        opacity: 0.45;
    }

    .menu-content {
        width: 100%;
        transform: translateY(-6%);
    }

    .title-lockup h1 {
        font-size: 50px;
    }

    #dialogue-panel {
        right: 12px;
        bottom: 10px;
        left: 12px;
        min-height: 0;
        padding: 10px 2px 2px;
    }

    #speaker-name {
        font-size: 16px;
    }

    #dialogue-text {
        font-size: 15px;
    }

    .choice-button,
    #next-button {
        padding: 8px 10px;
    }
}


.name-card {
    display: grid;
    width: min(460px, 84%);
    padding: 30px;
    background: rgba(7, 9, 13, 0.98);
    border: 1px solid var(--line);
}

.name-card h2 {
    margin: 8px 0 10px;
    color: var(--gold-light);
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.name-description,
.name-default {
    color: var(--muted);
    line-height: 1.45;
}

.name-card label {
    margin: 16px 0 7px;
    color: #e8e8ea;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.name-card input {
    width: 100%;
    padding: 12px 14px;
    color: var(--text);
    background: #151820;
    border: 1px solid #444955;
    outline: none;
}

.name-card input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 2px rgba(231, 180, 59, 0.18);
}

.name-default {
    margin: 8px 0 18px;
    font-size: 12px;
}

.name-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.name-actions button {
    padding: 11px 14px;
    color: #f9fafb;
    background: #242a35;
    border: 1px solid #596171;
    cursor: pointer;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.name-actions button:hover,
.name-actions button:focus-visible {
    color: var(--gold-light);
    border-color: var(--gold);
    outline: none;
}


#name-screen {
    z-index: 130;
}


/* =========================================================
   SAVE SLOTS, LOG, TRANSITIONS AND FEEDBACK
========================================================= */

.system-overlay {
    position: absolute;
    inset: 0;
    z-index: 135;
    display: grid;
    place-items: center;
    padding: 28px;
    background: rgba(0, 0, 0, 0.82);
    backdrop-filter: blur(5px);
}

.system-panel {
    display: flex;
    flex-direction: column;
    width: min(820px, 92%);
    max-height: 86%;
    padding: 26px;
    overflow: hidden;
    background: rgba(7, 9, 13, 0.98);
    border: 1px solid var(--line);
}

.system-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
}

.system-panel h2 {
    margin: 7px 0 0;
    color: var(--gold-light);
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.system-description {
    margin: 12px 0 18px;
    color: var(--muted);
    font-size: 14px;
}

.icon-button {
    width: 38px;
    height: 38px;
    color: #e8e8ea;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.28);
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
}

.icon-button:hover,
.icon-button:focus-visible {
    color: var(--gold-light);
    border-color: var(--gold);
    outline: none;
}

.save-slot-list {
    display: grid;
    gap: 9px;
    overflow: auto;
    padding-right: 5px;
}

.save-slot {
    display: grid;
    grid-template-columns: 74px 1fr auto;
    align-items: center;
    gap: 16px;
    min-height: 82px;
    padding: 13px 15px;
    color: #f4f4f5;
    background: rgba(255,255,255,0.025);
    border: 1px solid rgba(255,255,255,0.12);
    cursor: pointer;
    text-align: left;
    transition: 150ms ease;
}

.save-slot:hover,
.save-slot:focus-visible {
    background: rgba(231,180,59,0.08);
    border-color: var(--gold);
    outline: none;
}

.save-slot-label {
    color: var(--gold-light);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.save-slot-main strong {
    display: block;
    margin-bottom: 5px;
    font-size: 16px;
}

.save-slot-main span,
.save-slot-time {
    color: var(--muted);
    font-size: 12px;
}

.save-slot.empty .save-slot-main strong {
    color: #8b8e95;
}

.save-slot-time {
    text-align: right;
}

.log-panel {
    width: min(900px, 94%);
}

.dialogue-log-list {
    display: grid;
    gap: 14px;
    overflow: auto;
    padding: 8px 8px 8px 0;
}

.log-entry {
    padding-bottom: 13px;
    border-bottom: 1px solid rgba(255,255,255,0.09);
}

.log-entry:last-child {
    border-bottom: 0;
}

.log-speaker {
    margin: 0 0 5px;
    color: var(--gold-light);
    font-size: 13px;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.log-text {
    margin: 0;
    color: #f4f4f5;
    font-size: 15px;
    line-height: 1.48;
}

.log-empty {
    padding: 36px 0;
    color: var(--muted);
    text-align: center;
}

.dialogue-log-button {
    position: absolute;
    z-index: 4;
    top: 15px;
    right: 16px;
    padding: 8px 12px;
    color: var(--gold-light);
    background: rgba(5, 7, 10, 0.56);
    border: 1px solid rgba(231,180,59,0.55);
    cursor: pointer;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.14em;
}

.dialogue-log-button:hover,
.dialogue-log-button:focus-visible {
    background: rgba(231,180,59,0.12);
    border-color: var(--gold);
    outline: none;
}

.scene-transition {
    position: absolute;
    inset: 0;
    z-index: 120;
    pointer-events: none;
    opacity: 0;
    background: #020203;
    transition: opacity 320ms ease;
}

.scene-transition.active {
    opacity: 1;
}

.stat-feedback-area {
    position: absolute;
    z-index: 70;
    top: 22px;
    left: 22px;
    display: grid;
    gap: 8px;
    pointer-events: none;
}

.stat-feedback {
    min-width: 230px;
    padding: 11px 14px;
    opacity: 0;
    transform: translateX(-10px);
    background: linear-gradient(90deg, rgba(5,7,10,0.78), rgba(5,7,10,0.1));
    border-left: 2px solid var(--gold);
    transition: opacity 220ms ease, transform 220ms ease;
}

.stat-feedback.visible {
    opacity: 1;
    transform: translateX(0);
}

.stat-feedback-message {
    display: block;
    color: #ffffff;
    font-size: 13px;
    font-weight: 800;
    text-shadow: 0 2px 4px #000000;
}

.stat-feedback-detail {
    display: block;
    margin-top: 4px;
    color: var(--gold-light);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

@media (max-width: 650px) {
    .system-overlay {
        padding: 12px;
    }

    .system-panel {
        width: 100%;
        max-height: 92%;
        padding: 18px;
    }

    .save-slot {
        grid-template-columns: 58px 1fr;
    }

    .save-slot-time {
        display: none;
    }

    .dialogue-log-button {
        top: 8px;
        right: 8px;
    }

    .stat-feedback-area {
        top: 10px;
        left: 10px;
    }
}


/* =========================================================
   CINEMATIC TRANSITIONS — NO DIALOGUE BOXES ADDED
========================================================= */

#scene-image,
#dialogue-panel,
#choice-list {
    will-change: opacity, transform, filter;
}

#scene-image {
    transition:
        opacity 560ms ease,
        transform 900ms cubic-bezier(0.22, 1, 0.36, 1),
        filter 560ms ease;
    transform: scale(1);
    filter: brightness(1);
}

#dialogue-panel,
#choice-list {
    transition:
        opacity 300ms ease,
        transform 360ms cubic-bezier(0.22, 1, 0.36, 1);
}

#dialogue-layer.transition-out #scene-image {
    opacity: 0;
    transform: scale(1.035);
    filter: brightness(0.42);
}

#dialogue-layer.transition-out #dialogue-panel,
#dialogue-layer.transition-out #choice-list {
    opacity: 0;
    transform: translateY(10px);
}

#dialogue-layer.transition-in #scene-image {
    animation: cinematic-scene-in 820ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

#dialogue-layer.transition-in #dialogue-panel {
    animation: cinematic-dialogue-in 420ms ease 300ms both;
}

#dialogue-layer.transition-in #choice-list {
    animation: cinematic-dialogue-in 420ms ease 410ms both;
}

.scene-transition {
    background:
        radial-gradient(circle at center, rgba(10, 12, 18, 0.86), #020203 72%);
    transition: opacity 420ms ease;
}

@keyframes cinematic-scene-in {
    0% {
        opacity: 0;
        transform: scale(1.025);
        filter: brightness(0.45) blur(1px);
    }
    100% {
        opacity: 1;
        transform: scale(1);
        filter: brightness(1) blur(0);
    }
}

@keyframes cinematic-dialogue-in {
    0% {
        opacity: 0;
        transform: translateY(10px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    #scene-image,
    #dialogue-panel,
    #choice-list,
    .scene-transition {
        animation: none !important;
        transition-duration: 1ms !important;
    }
}


/* =========================================================
   V0.15 POLISH
========================================================= */

button {
    transition: transform 120ms ease, border-color 160ms ease, background 160ms ease,
                color 160ms ease, opacity 160ms ease, filter 160ms ease;
}

button:not(:disabled):hover {
    transform: translateY(-1px);
    filter: brightness(1.12);
}

button:not(:disabled):active {
    transform: translateY(1px) scale(0.99);
}

button:disabled,
.choice-button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
    filter: grayscale(0.65);
    border-style: dashed;
}

.choice-button:focus-visible,
#next-button:focus-visible,
.save-slot:focus-visible {
    outline: 3px solid rgba(255,255,255,0.9);
    outline-offset: 3px;
}

#next-button.reveal-locked {
    opacity: 0;
    pointer-events: none;
}

.log-entry.choice {
    border-left: 4px solid #d8b35c;
    background: rgba(216, 179, 92, 0.08);
}

.log-entry.choice .log-speaker {
    color: #e4c574;
}

.log-entry.stat {
    border-left: 4px solid #7f8c9f;
    background: rgba(127, 140, 159, 0.08);
}

.log-entry.stat .log-speaker {
    color: #aab4c1;
}

.save-slot {
    display: grid !important;
    grid-template-columns: 92px auto 1fr auto;
    align-items: center;
    gap: 14px;
}

.save-thumb {
    width: 92px;
    aspect-ratio: 16 / 9;
    border-radius: 6px;
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(255,255,255,0.16);
}

.save-thumb.empty-thumb {
    background: linear-gradient(135deg, rgba(255,255,255,0.05), rgba(255,255,255,0.01));
}

.save-slot-main small {
    display: block;
    margin-top: 4px;
    opacity: 0.72;
}

#ending-screen {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 28px;
    color: #fff;
    background: radial-gradient(circle at 50% 20%, rgba(82, 16, 20, 0.25), transparent 38%), #030405;
    font-family: Arial, Helvetica, sans-serif;
}

.ending-content {
    width: min(820px, 94vw);
    text-align: center;
}

.ending-kicker {
    margin-bottom: 12px;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0.22em;
    opacity: 0.75;
}

.ending-title {
    font-size: clamp(34px, 7vw, 68px);
    font-weight: 900;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.ending-summary {
    margin-top: 30px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.summary-grid.compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.summary-grid > div {
    min-height: 94px;
    padding: 16px;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.035);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 7px;
}

.summary-grid span {
    font-size: 12px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    opacity: 0.58;
}

.summary-grid strong {
    font-size: 20px;
}

.ending-note {
    margin: 18px 0 0;
    color: #c7cbd1;
}

.ending-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 28px;
}

.ending-actions button {
    padding: 13px 24px;
    border: 2px solid #fff;
    border-radius: 7px;
    background: #fff;
    color: #050607;
    font-weight: 850;
}

.ending-actions .secondary-ending-button {
    background: transparent;
    color: #fff;
}

.locked-setting {
    opacity: 0.62;
    font-style: italic;
}

@media (max-width: 680px) {
    .summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .save-slot {
        grid-template-columns: 72px 1fr;
    }

    .save-thumb {
        width: 72px;
    }

    .save-slot-label,
    .save-slot-time {
        grid-column: 2;
    }
}


/* =========================================================
   V0.16 MOUSE / TOUCH + AUDIO
========================================================= */

#game-container canvas {
    cursor: auto;
    touch-action: none;
}

.settings-audio-test {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 14px 0;
    flex-wrap: wrap;
}

.settings-audio-test button {
    padding: 10px 15px;
    border: 1px solid rgba(255,255,255,0.65);
    border-radius: 7px;
    background: rgba(255,255,255,0.08);
    color: #fff;
    font-weight: 800;
    letter-spacing: 0.05em;
}

.settings-audio-test span {
    font-size: 13px;
    opacity: 0.72;
}


/* =========================================================
   V0.19 ENDING SCREEN — COMPACT AND SCROLL SAFE
========================================================= */

#ending-screen {
    overflow-y: auto;
    align-items: flex-start;
    padding: 18px 20px;
}

#ending-screen .ending-content {
    width: min(760px, 94vw);
    margin: auto;
    padding: 14px 0 20px;
}

#ending-screen .ending-kicker {
    margin-bottom: 7px;
    font-size: clamp(12px, 1.5vw, 16px);
}

#ending-screen .ending-title {
    font-size: clamp(28px, 5vw, 52px);
    line-height: 1.08;
}

#ending-screen .ending-summary {
    margin-top: 20px;
}

#ending-screen .summary-grid {
    gap: 8px;
}

#ending-screen .summary-grid > div {
    min-height: 76px;
    padding: 11px 13px;
    gap: 5px;
}

#ending-screen .summary-grid span {
    font-size: 10px;
}

#ending-screen .summary-grid strong {
    font-size: clamp(16px, 2vw, 19px);
    line-height: 1.15;
}

#ending-screen .ending-note {
    margin-top: 12px;
    font-size: 14px;
}

#ending-screen .ending-actions {
    margin-top: 17px;
    padding-bottom: 8px;
}

#ending-screen .ending-actions button {
    padding: 10px 20px;
}

@media (max-height: 760px) {
    #ending-screen {
        padding-top: 10px;
        padding-bottom: 10px;
    }

    #ending-screen .ending-content {
        padding-top: 5px;
    }

    #ending-screen .ending-title {
        font-size: clamp(25px, 4.5vw, 42px);
    }

    #ending-screen .ending-summary {
        margin-top: 14px;
    }

    #ending-screen .summary-grid > div {
        min-height: 64px;
        padding: 8px 10px;
    }

    #ending-screen .ending-actions {
        margin-top: 12px;
    }
}

@media (max-width: 680px) {
    #ending-screen {
        padding: 12px;
    }

    #ending-screen .summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #ending-screen .ending-actions {
        flex-wrap: wrap;
    }
}


/* =========================================================
   V0.21 ALL ENDINGS SHOW FULL SUMMARY
========================================================= */

#ending-screen .summary-grid.compact {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

#ending-screen .summary-grid.compact > div {
    min-height: 70px;
    padding: 9px 11px;
}

@media (max-width: 760px) {
    #ending-screen .summary-grid.compact {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 460px) {
    #ending-screen .summary-grid.compact {
        grid-template-columns: 1fr;
    }
}


/* =========================================================
   V0.22 MUSIC VOLUME CONTROL
========================================================= */

.setting-volume-row {
    align-items: center;
}

.volume-control {
    display: flex;
    align-items: center;
    gap: 12px;
    width: min(280px, 55%);
}

.volume-control input[type="range"] {
    flex: 1;
    min-width: 130px;
    accent-color: #f4c542;
}

.volume-control strong {
    width: 48px;
    text-align: right;
    font-size: 13px;
}


/* =========================================================
   V0.23 ACHIEVEMENTS
========================================================= */

.achievement-item {
    align-items: center;
    min-height: 78px;
}

.achievement-item.unlocked {
    border-color: rgba(244, 197, 66, 0.42);
    background: rgba(244, 197, 66, 0.055);
}

.achievement-item.locked {
    opacity: 0.58;
}

.achievement-medal {
    display: grid;
    place-items: center;
    flex: 0 0 52px;
    width: 52px;
    height: 52px;
    border: 1px solid rgba(244, 197, 66, 0.34);
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.32);
    font-size: 28px;
}

.achievement-item.locked .achievement-medal {
    color: rgba(255, 255, 255, 0.5);
    border-color: rgba(255, 255, 255, 0.14);
    font-size: 20px;
    font-weight: 900;
}

.achievement-progress {
    text-align: center;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.achievement-unlock {
    position: fixed;
    z-index: 9999;
    top: 50%;
    left: 50%;
    display: grid;
    place-items: center;
    width: min(430px, calc(100vw - 36px));
    padding: 26px 30px;
    border: 1px solid rgba(244, 197, 66, 0.72);
    border-radius: 10px;
    background: rgba(5, 7, 10, 0.95);
    box-shadow:
        0 24px 80px rgba(0, 0, 0, 0.72),
        inset 0 0 35px rgba(244, 197, 66, 0.06);
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, -44%) scale(0.94);
    visibility: hidden;
}

.achievement-unlock.visible {
    visibility: visible;
    animation: achievement-unlock-in 420ms ease forwards;
}

.achievement-unlock.visible.fade-out {
    animation: achievement-unlock-out 950ms ease forwards;
}

.achievement-unlock-medal {
    margin-bottom: 8px;
    font-size: 54px;
    filter: drop-shadow(0 5px 14px rgba(244, 197, 66, 0.2));
}

.achievement-unlock-kicker {
    color: var(--gold-light);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.24em;
}

.achievement-unlock-name {
    margin-top: 8px;
    color: #fff;
    font-size: clamp(21px, 4vw, 31px);
    font-weight: 900;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

@keyframes achievement-unlock-in {
    from {
        opacity: 0;
        transform: translate(-50%, -44%) scale(0.94);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes achievement-unlock-out {
    from {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
        filter: blur(0);
    }
    to {
        opacity: 0;
        transform: translate(-50%, -56%) scale(1.035);
        filter: blur(5px);
        visibility: hidden;
    }
}


@supports not (height: 100dvh) {
    #game-shell {
        width: min(
            1280px,
            calc(100vw - 48px),
            calc((100vh - 64px) * 16 / 9)
        );
        max-height: calc(100vh - 64px);
    }
}

/* =========================================================
   V0.10 MOBILE LANDSCAPE MENU FIX
   Keeps the full main menu inside short phone viewports.
========================================================= */
@media (orientation: landscape) and (max-height: 520px) {
    html,
    body {
        width: 100%;
        height: 100%;
        min-height: 0;
        padding: 0;
        overflow: hidden;
    }

    #game-shell {
        width: 100vw;
        height: 100dvh;
        max-height: none;
        aspect-ratio: auto;
        border: 0;
        box-shadow: none;
    }

    #main-menu {
        justify-content: center;
        padding: 8px clamp(22px, 5vw, 54px);
    }

    .main-menu-art {
        width: 62%;
        opacity: 0.82;
        background-position: center right;
    }

    .menu-content {
        width: min(360px, 43%);
        transform: none;
    }

    .title-lockup {
        position: absolute;
        top: 12px;
        left: clamp(22px, 5vw, 54px);
        display: block;
        margin: 0;
        pointer-events: none;
    }

    .title-lockup .studio-overline {
        font-size: clamp(6px, 1.45vh, 8px);
        letter-spacing: 0.22em;
    }

    .title-lockup h1 {
        margin: 4px 0 0;
        font-size: clamp(27px, 8.4vh, 38px);
        line-height: 0.88;
    }

    .title-lockup .subtitle {
        margin-top: 5px;
        font-size: clamp(6px, 1.35vh, 8px);
        letter-spacing: 0.2em;
        white-space: nowrap;
    }

    .primary-menu {
        width: min(300px, 100%);
        gap: 0;
    }

    .primary-menu button {
        min-height: 0;
        margin: 0;
        padding: 4px 12px;
        font-size: clamp(11px, 2.5vh, 14px);
        line-height: 1.1;
        letter-spacing: 0.07em;
    }

    .primary-menu .support-button {
        margin: 1px 0;
        padding-top: 5px;
        padding-bottom: 5px;
        border-radius: 0 4px 4px 0;
    }

    .primary-menu button:hover:not(:disabled),
    .primary-menu button:focus-visible {
        padding-left: 18px;
    }

    .menu-footer {
        right: 22px;
        bottom: 6px;
        left: 22px;
        display: flex;
        font-size: clamp(6px, 1.3vh, 8px);
        letter-spacing: 0.11em;
    }

    .menu-panel {
        width: min(520px, 88vw);
        max-height: 86dvh;
        padding: 14px;
        font-size: 13px;
    }

    .menu-panel h2 {
        margin-bottom: 10px;
        font-size: 18px;
    }

    .menu-panel .secondary-button {
        margin-top: 10px;
        padding: 6px 12px;
        font-size: 13px;
    }
}

@supports not (height: 100dvh) {
    @media (orientation: landscape) and (max-height: 520px) {
        #game-shell {
            height: 100vh;
        }

        .menu-panel {
            max-height: 86vh;
        }
    }
}

/* Mobile only: submenu panels cover the whole menu until Back is pressed. */
@media (orientation: landscape) and (max-height: 520px) {
    #main-menu .menu-panel:not(.hidden) {
        position: absolute;
        z-index: 50;
        inset: 0;
        width: 100%;
        max-height: none;
        margin: 0;
        padding: 18px 22px;
        overflow-y: auto;
        background: rgba(5, 7, 10, 0.985);
        border: 0;
    }
}


/* =========================================================
   IOS / IPHONE VIEWPORT COMPATIBILITY
   Scoped to iOS only; desktop and Android layouts are unchanged.
========================================================= */
html.ios-device,
html.ios-device body {
    min-height: var(--ios-viewport-height, 100dvh);
}

html.ios-device body {
    padding-top: max(0px, env(safe-area-inset-top));
    padding-right: max(0px, env(safe-area-inset-right));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
    padding-left: max(0px, env(safe-area-inset-left));
}

html.ios-device #game-shell {
    max-width: calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right));
    max-height: calc(var(--ios-viewport-height, 100dvh) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

@media (orientation: landscape) and (max-height: 520px) {
    html.ios-device,
    html.ios-device body {
        width: 100%;
        height: var(--ios-viewport-height, 100dvh);
        min-height: var(--ios-viewport-height, 100dvh);
    }

    html.ios-device body {
        padding: 0;
    }

    html.ios-device #game-shell {
        width: calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right));
        height: calc(var(--ios-viewport-height, 100dvh) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        margin-top: env(safe-area-inset-top);
        margin-right: env(safe-area-inset-right);
        margin-bottom: env(safe-area-inset-bottom);
        margin-left: env(safe-area-inset-left);
    }

    html.ios-device #main-menu,
    html.ios-device .front-screen,
    html.ios-device .pause-overlay,
    html.ios-device .system-overlay,
    html.ios-device #dialogue-layer {
        padding-top: max(8px, env(safe-area-inset-top));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: max(8px, env(safe-area-inset-bottom));
        padding-left: max(12px, env(safe-area-inset-left));
    }

    html.ios-device #main-menu .menu-panel:not(.hidden),
    html.ios-device .system-panel,
    html.ios-device .pause-card,
    html.ios-device .name-card {
        max-height: calc(var(--ios-viewport-height, 100dvh) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    html.ios-device #main-menu .menu-panel:not(.hidden) {
        padding-top: max(18px, env(safe-area-inset-top));
        padding-right: max(22px, env(safe-area-inset-right));
        padding-bottom: max(18px, env(safe-area-inset-bottom));
        padding-left: max(22px, env(safe-area-inset-left));
    }
}
