:root {
    --ui-bg: rgba(6, 18, 48, 0.82);
    --ui-border: #b8d8ff;
    --ui-border-dark: #28406e;
    --ui-shadow: rgba(0,0,0,0.45);
    --text: #e8f0ff;
    --accent: #8fd0ff;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: #000;
    color: var(--text);
    font-family: "Press Start 2P", system-ui, monospace;
}

.game {
    position: -ms-device-fixed;
    height: 100dvh;
    width: 100%;
    overflow: hidden;
}

.bg {
    position: absolute;
    inset: 0;

    /* Center the art and keep full image visible (no cropping) */
    background-color: #000;             /* letterbox bars */
    background-position: center center;
    background-repeat: no-repeat;
    background-size: contain;

    transition: opacity 300ms ease;
    image-rendering: pixelated;
}

.hud {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    width: min(900px, 92vw);

    background: linear-gradient(180deg, var(--ui-bg), rgba(6, 18, 48, 0.9));
    border: 3px solid var(--ui-border);
    border-radius: 14px;
    box-shadow: 0 8px 24px var(--ui-shadow), inset 0 0 0 3px var(--ui-border-dark);
    padding: 18px 20px 14px 20px;

    max-height: 70vh;
    overflow-y: auto;
}

.nameplate {
    display: inline-block;
    background: rgba(20, 36, 84, 0.95);
    border: 2px solid var(--ui-border);
    border-radius: 10px;
    padding: 6px 10px;
    margin-bottom: 12px;
    color: var(--accent);
    text-shadow: 0 1px 0 #18345a;
    font-size: 14px;
}

.dialog {
    min-height: 3.5rem;
    line-height: 1.5;
    font-size: 14px;
    margin-bottom: 10px;
}

.menu {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    user-select: none;
}

.menu-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cursor {
    width: 16px;
    display: inline-block;
    text-align: center;
    transform: translateY(1px);
}

.cursor.ghost {
    opacity: 0;
}

.menu-btn {
    appearance: none;
    background: transparent;
    border: none;
    color: var(--text);
    padding: 6px 10px;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.menu-btn:focus-visible {
    outline: 2px dashed var(--accent);
    outline-offset: 4px;
}

.menu-btn:hover {
    color: #fff;
    text-shadow: 0 0 6px rgba(143,208,255,0.6);
}

.gate {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: grid;
    place-items: center;
}

.gate.hidden { display: none; }

.gate-card {
    background: var(--ui-bg);
    border: 2px solid var(--ui-border);
    border-radius: 12px;
    padding: 16px 20px;
    text-align: center;
    box-shadow: 0 10px 24px var(--ui-shadow);
}

.gate button {
    margin-top: 10px;
    padding: 8px 12px;
    border: 2px solid var(--ui-border);
    background: rgba(30,50,95,0.9);
    color: var(--text);
    font: inherit;
    border-radius: 8px;
    cursor: pointer;
}

.input-row {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.input-row.hidden { display: none; }

.input-row input {
    flex: 1;
    padding: 8px 10px;
    border-radius: 8px;
    border: 2px solid var(--ui-border);
    background: rgba(20, 36, 84, 0.95);
    color: var(--text);
    font: inherit;
}

.input-row button {
    padding: 8px 12px;
    border: 2px solid var(--ui-border);
    background: rgba(30,50,95,0.9);
    color: var(--text);
    font: inherit;
    border-radius: 8px;
    cursor: pointer;
}

.hud.closing {
    animation: hudClose 380ms ease forwards;
}

@keyframes hudClose {
    0%   { opacity: 1; transform: translateX(-50%) scale(1); }
    100% { opacity: 0; transform: translateX(-50%) scale(0.96); }
}

.credits {
    position: fixed;
    inset: 0;
    background: #000;            /* black for initial half-second */
    color: #e8f0ff;
    font-family: "Press Start 2P", system-ui, monospace;
    letter-spacing: 0.5px;
    line-height: 1.8;
    overflow: hidden;
    z-index: 9999;
    opacity: 0;                  /* hidden until .show */
    transition: opacity 400ms ease;
}

.credits.show { opacity: 1; }

/* After 0.5s we fade it out so the background image is visible "in front" */
.credits.fadeout {
    opacity: 0;
    pointer-events: none;        /* let clicks pass through after fade */
}

/* When the fadeout transition finishes, we’ll drop z-index via JS (optional) */

.credits-inner {
    position: absolute;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    width: min(800px, 92vw);
    text-align: center;
    animation-name: creditsScroll;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
}

/* Simple fade-in for each line (optional) */
.credits-inner > * {
    opacity: 0;
    animation: linePop 600ms ease forwards;
}
.credits-inner > *:nth-child(n) { animation-delay: calc(0.08s * var(--line-index, 0)); }

@keyframes creditsScroll {
    from { transform: translateX(-50%) translateY(100%); }
    to   { transform: translateX(-50%) translateY(-100%); }
}

@keyframes linePop {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Small heading & spacing helpers for variety */
.credits-title { font-size: 18px; margin: 36px 0 12px; color: #8fd0ff; }
.credits-line  { font-size: 14px; margin: 8px 0; }
.credits-gap   { height: 24px; }

/* Optional subtle glow */
.credits-inner, .credits-inner * {
    text-shadow: 0 1px 0 #18345a;
}