:root {
    --ink: #0a0e1a;
    --panel: rgba(11, 16, 33, 0.88);
    --gold: #facc15;
    --crimson: #ef4444;
    --cyan: #22d3ee;
    --cobalt: #2563eb;
    --emerald: #34d399;
    --comic-border: 3px solid #090d16;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #060913;
    color: #f8fafc;
    font-family: 'Trebuchet MS', 'Arial Black', Impact, sans-serif;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

#gameContainer {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.crt-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0) 0px,
        rgba(0, 0, 0, 0) 2px,
        rgba(0, 0, 0, 0.08) 3px
    );
    z-index: 4;
}

.hidden {
    display: none !important;
}

/* 1991 Sega Arcade HUD */
#arcadeHud {
    position: absolute;
    top: 10px;
    left: 12px;
    right: 12px;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    pointer-events: none;
}

.hud-left, .hud-right, .hud-center {
    pointer-events: auto;
}

.hud-left {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--panel);
    border: 2px solid rgba(250, 204, 21, 0.75);
    box-shadow: 4px 4px 0 #000, 0 0 18px rgba(34, 211, 238, 0.2);
    border-radius: 10px;
    padding: 7px 11px;
    backdrop-filter: blur(6px);
}

.portrait-frame {
    width: 54px;
    height: 54px;
    border-radius: 8px;
    background: linear-gradient(145deg, #dc2626, #1d4ed8);
    border: 2px solid var(--gold);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
    flex-shrink: 0;
}

.portrait-frame.ironman {
    background: linear-gradient(145deg, #b91c1c, #eab308);
    border-color: var(--cyan);
}

.portrait-icon {
    font-size: 1.35rem;
    line-height: 1;
}

.portrait-tag {
    font-size: 0.6rem;
    font-weight: 900;
    letter-spacing: 0.06em;
    color: #fff;
    text-shadow: 1px 1px 0 #000;
    margin-top: 2px;
}

.bars-stack {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 165px;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.bar-label {
    width: 28px;
    font-size: 0.7rem;
    font-weight: 900;
    color: var(--gold);
    text-shadow: 1px 1px 0 #000;
}

.meter-track {
    flex: 1;
    height: 11px;
    background: #111827;
    border: 1.5px solid #475569;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.meter-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #ef4444, #22c55e);
    transition: width 0.1s linear;
}

.o2-fill {
    background: linear-gradient(90deg, #0284c7, #22d3ee, #a5f3fc);
}

.o2-fill.critical {
    background: linear-gradient(90deg, #dc2626, #f97316);
    animation: pulseWarn 0.45s infinite alternate;
}

.en-fill {
    background: linear-gradient(90deg, #eab308, #fde047);
}

.bar-val {
    width: 40px;
    text-align: right;
    font-size: 0.72rem;
    font-weight: 900;
    color: #e2e8f0;
    font-variant-numeric: tabular-nums;
}

.hud-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.stage-badge {
    background: linear-gradient(180deg, #1e293b, #0f172a);
    border: 2px solid var(--cyan);
    box-shadow: 3px 3px 0 #000;
    padding: 5px 14px;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    color: #fff;
    text-shadow: 2px 2px 0 #000;
}

.objective-pill {
    background: rgba(250, 204, 21, 0.16);
    border: 1.5px solid var(--gold);
    color: var(--gold);
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.05em;
}

.hud-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.score-box {
    background: var(--panel);
    border: 2px solid var(--crimson);
    box-shadow: 4px 4px 0 #000;
    border-radius: 8px;
    padding: 5px 12px;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.score-title {
    font-size: 0.7rem;
    color: #fca5a5;
    font-weight: 900;
}

.score-num {
    font-size: 1.05rem;
    font-weight: 900;
    color: var(--gold);
    letter-spacing: 0.08em;
    font-variant-numeric: tabular-nums;
    text-shadow: 2px 2px 0 #000;
}

.hud-actions {
    display: flex;
    gap: 6px;
}

.arcade-chip {
    background: linear-gradient(135deg, #0ea5e9, #2563eb);
    color: #fff;
    border: 2px solid #fff;
    box-shadow: 2px 2px 0 #000;
    border-radius: 7px;
    padding: 5px 10px;
    font-size: 0.74rem;
    font-weight: 900;
    cursor: pointer;
    letter-spacing: 0.04em;
}

.arcade-chip.locked {
    background: #1e293b;
    border-color: #475569;
    color: #94a3b8;
    cursor: not-allowed;
}

.arcade-chip.iron-active {
    background: linear-gradient(135deg, #dc2626, #eab308);
    border-color: #fde047;
}

.icon-chip {
    background: #1e293b;
    padding: 5px 8px;
}

/* Shark Warning Banner */
.shark-alert {
    position: absolute;
    top: 96px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 12;
    background: linear-gradient(90deg, rgba(185, 28, 28, 0.94), rgba(220, 38, 38, 0.94));
    border: 3px solid var(--gold);
    box-shadow: 4px 4px 0 #000, 0 0 24px rgba(239, 68, 68, 0.65);
    color: #fff;
    padding: 7px 18px;
    border-radius: 8px;
    font-size: 0.92rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    animation: pulseWarn 0.42s infinite alternate;
    pointer-events: none;
    text-align: center;
}

@keyframes pulseWarn {
    from { transform: translateX(-50%) scale(1); }
    to { transform: translateX(-50%) scale(1.04); }
}

/* Cutscene Comic Caption Panel */
.cutscene-overlay {
    position: absolute;
    bottom: 68px;
    left: 50%;
    transform: translateX(-50%);
    width: min(740px, 92vw);
    z-index: 18;
    pointer-events: auto;
}

.comic-dialogue-box {
    background: linear-gradient(180deg, #0f172a 0%, #090d16 100%);
    border: 3px solid var(--gold);
    box-shadow: 6px 6px 0 #000, 0 0 28px rgba(250, 204, 21, 0.25);
    border-radius: 12px;
    padding: 16px 20px 14px;
    position: relative;
}

.comic-speaker {
    position: absolute;
    top: -15px;
    left: 18px;
    background: var(--crimson);
    color: #fff;
    border: 2px solid #fff;
    box-shadow: 2px 2px 0 #000;
    padding: 2px 12px;
    font-size: 0.78rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    border-radius: 6px;
}

.comic-text {
    font-size: 1.02rem;
    line-height: 1.42;
    color: #f8fafc;
    font-family: system-ui, -apple-system, sans-serif;
    font-weight: 700;
    padding-right: 96px;
}

.skip-btn {
    position: absolute;
    right: 12px;
    bottom: 12px;
    background: #1e293b;
    color: var(--cyan);
    border: 1.5px solid var(--cyan);
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.7rem;
    font-weight: 900;
    cursor: pointer;
}

/* Title & Result Screens */
.modal-screen {
    position: absolute;
    inset: 0;
    z-index: 25;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, rgba(15, 23, 42, 0.78), rgba(5, 8, 18, 0.94));
    backdrop-filter: blur(5px);
    padding: 16px;
}

.arcade-marquee {
    width: min(680px, 95vw);
    background: linear-gradient(170deg, #111827 0%, #090d1a 100%);
    border: 4px solid var(--gold);
    box-shadow: 10px 10px 0 #000, 0 0 40px rgba(34, 211, 238, 0.25);
    border-radius: 16px;
    padding: 26px 24px;
    text-align: center;
}

.marquee-kicker {
    display: inline-block;
    background: var(--crimson);
    color: #fff;
    padding: 4px 14px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 900;
    letter-spacing: 0.12em;
    border: 2px solid #fff;
    margin-bottom: 10px;
}

.arcade-title {
    font-size: clamp(2.1rem, 6vw, 3.6rem);
    letter-spacing: 0.04em;
    line-height: 1.05;
    text-shadow: 4px 4px 0 #000;
    margin-bottom: 10px;
}

.t-red { color: #f87171; }
.t-gold { color: #facc15; }
.t-cyan { color: #22d3ee; }
.t-year { color: #fde047; font-size: 0.75em; }

.arcade-sub, .result-desc {
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 0.98rem;
    color: #cbd5e1;
    line-height: 1.45;
    margin: 0 auto 18px;
    max-width: 560px;
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(115px, 1fr));
    gap: 8px;
    margin-bottom: 20px;
}

.ctrl-card {
    background: rgba(30, 41, 59, 0.75);
    border: 1.5px solid #334155;
    border-radius: 8px;
    padding: 8px 6px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.ctrl-card b {
    font-size: 0.68rem;
    color: var(--gold);
    letter-spacing: 0.05em;
}

.ctrl-card span {
    font-family: system-ui, sans-serif;
    font-size: 0.76rem;
    color: #e2e8f0;
    font-weight: 700;
}

.title-btns {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
}

.coin-btn {
    background: linear-gradient(180deg, #fde047 0%, #eab308 100%);
    color: #090d16;
    border: 3px solid #fff;
    box-shadow: 4px 4px 0 #000, 0 0 20px rgba(250, 204, 21, 0.45);
    border-radius: 10px;
    padding: 12px 26px;
    font-size: 1.05rem;
    font-weight: 900;
    letter-spacing: 0.06em;
    cursor: pointer;
}

.coin-btn:active {
    transform: translate(2px, 2px);
}

.back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #1e293b;
    color: #e2e8f0;
    border: 2px solid #64748b;
    box-shadow: 3px 3px 0 #000;
    border-radius: 10px;
    padding: 11px 18px;
    font-size: 0.88rem;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

.result-title {
    font-size: 2rem;
    color: var(--cyan);
    text-shadow: 3px 3px 0 #000;
    margin-bottom: 8px;
}

.result-stats {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.stat-pill {
    background: rgba(15, 23, 42, 0.85);
    border: 2px solid var(--cyan);
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 0.86rem;
    font-weight: 800;
    color: #fff;
}

/* Mobile / Tablet Touch Controls */
.touch-controls {
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: 14px;
    z-index: 15;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
}

.dpad-cluster, .action-cluster {
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
}

.dpad-vert {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pad-btn, .act-btn {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: 2.5px solid rgba(255, 255, 255, 0.85);
    background: rgba(15, 23, 42, 0.72);
    color: #fff;
    font-size: 1.15rem;
    font-weight: 900;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    touch-action: none;
}

.act-btn {
    width: 66px;
    height: 66px;
    font-size: 0.78rem;
}

.jump-btn {
    background: rgba(220, 38, 38, 0.78);
    border-color: var(--gold);
}

.atk-btn {
    background: rgba(37, 99, 235, 0.78);
    border-color: var(--cyan);
}

.swap-btn {
    width: 54px;
    height: 54px;
    background: rgba(234, 179, 8, 0.85);
    color: #090d16;
}

.swap-btn.locked {
    opacity: 0.35;
}

.pad-btn.active, .act-btn.active {
    transform: scale(0.92);
    filter: brightness(1.25);
}

@media (max-width: 780px) {
    #arcadeHud {
        flex-wrap: wrap;
    }
    .hud-center {
        order: 3;
        width: 100%;
    }
    .bars-stack {
        min-width: 120px;
    }
    .portrait-frame {
        width: 44px;
        height: 44px;
    }
}
