:root {
    --bg: #030405;
    --bg-soft: #080b0f;

    --panel: rgba(10, 14, 20, 0.88);
    --panel-strong: rgba(12, 17, 24, 0.97);

    --text: #f4f7f9;
    --muted: #7e8a94;

    --accent: #3545b0;
    --accent-bright: #5869e8;
    --accent-soft: rgba(53, 69, 176, 0.20);

    --danger: #db3f55;
    --border: rgba(255, 255, 255, 0.08);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

html {
    background: var(--bg);
}

body {
    min-height: 100vh;

    padding:
        max(18px, env(safe-area-inset-top))
        max(18px, env(safe-area-inset-right))
        max(18px, env(safe-area-inset-bottom))
        max(18px, env(safe-area-inset-left));

    background:
        radial-gradient(
            circle at 50% 0%,
            rgba(53, 69, 176, 0.18),
            transparent 34%
        ),
        radial-gradient(
            circle at 90% 80%,
            rgba(53, 69, 176, 0.06),
            transparent 28%
        ),
        linear-gradient(
            180deg,
            var(--bg-soft) 0%,
            var(--bg) 100%
        );

    color: var(--text);

    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Helvetica,
        Arial,
        sans-serif;

    -webkit-font-smoothing: antialiased;
}

button,
a {
    font: inherit;
}

.arcade-shell {
    width: min(100%, 1320px);
    margin: 0 auto;
}

.arcade-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 28px;

    margin-bottom: 26px;
}

.back-link {
    display: inline-block;

    margin-bottom: 24px;

    color: var(--muted);
    text-decoration: none;

    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.11em;

    transition:
        color 160ms ease,
        transform 160ms ease;
}

.back-link:hover,
.back-link:focus-visible {
    color: var(--text);
    transform: translateX(-3px);
}

.back-link:focus-visible,
.start-button:focus-visible,
.touch-button:focus-visible {
    outline: 2px solid var(--accent-bright);
    outline-offset: 4px;
}

.eyebrow {
    margin-bottom: 9px;

    color: var(--accent-bright);

    font-size: 12px;
    font-weight: 750;
    letter-spacing: 0.2em;
}

h1 {
    margin: 0;

    font-size: clamp(38px, 7vw, 82px);
    line-height: 0.95;
    letter-spacing: -0.055em;

    overflow-wrap: anywhere;
}

.subtitle {
    margin: 12px 0 0;

    color: var(--muted);

    font-size: 17px;
    letter-spacing: 0.03em;
}

.system-state {
    display: flex;
    align-items: center;
    gap: 9px;

    padding-bottom: 7px;

    color: var(--muted);

    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.12em;
    white-space: nowrap;
}

.system-dot,
.footer-dot {
    width: 7px;
    height: 7px;

    border-radius: 50%;

    background: var(--accent-bright);

    box-shadow:
        0 0 10px rgba(88, 105, 232, 0.92);
}

.game-frame {
    overflow: hidden;

    border: 1px solid rgba(53, 69, 176, 0.38);
    border-radius: 20px;

    background: var(--panel);

    box-shadow:
        0 28px 80px rgba(0, 0, 0, 0.38);
}

.hud {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));

    border-bottom: 1px solid var(--border);

    background:
        linear-gradient(
            90deg,
            rgba(53, 69, 176, 0.09),
            transparent 42%
        );
}

.hud-block {
    min-width: 0;

    padding: 18px 22px;

    border-right: 1px solid var(--border);
}

.hud-block:last-child {
    border-right: 0;
}

.hud-label {
    display: block;

    margin-bottom: 5px;

    color: var(--muted);

    font-size: 10px;
    font-weight: 750;
    letter-spacing: 0.18em;
}

.hud strong {
    display: block;

    overflow: hidden;

    color: var(--text);

    font-size: 20px;
    font-weight: 720;
    letter-spacing: 0.08em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lives strong {
    color: var(--accent-bright);
}

.canvas-wrap {
    position: relative;

    overflow: hidden;

    background: #020305;
}

#game {
    display: block;

    width: 100%;
    height: auto;

    aspect-ratio: 16 / 9;

    background: #020305;
}

.scanlines {
    position: absolute;
    inset: 0;

    pointer-events: none;

    opacity: 0.09;

    background:
        repeating-linear-gradient(
            180deg,
            rgba(255, 255, 255, 0.13) 0,
            rgba(255, 255, 255, 0.13) 1px,
            transparent 1px,
            transparent 4px
        );

    mix-blend-mode: soft-light;
}

.game-overlay {
    position: absolute;
    inset: 0;

    display: grid;
    place-items: center;

    padding: 28px;

    overflow: auto;

    background:
        radial-gradient(
            circle at 50% 50%,
            rgba(53, 69, 176, 0.10),
            rgba(2, 3, 5, 0.76) 52%,
            rgba(2, 3, 5, 0.92) 100%
        );

    backdrop-filter: blur(2px);
}

.overlay-panel {
    width: min(100%, 560px);

    padding: 34px;

    text-align: center;

    border: 1px solid rgba(53, 69, 176, 0.38);
    border-radius: 18px;

    background: rgba(7, 10, 15, 0.88);
}

.overlay-kicker {
    margin-bottom: 12px;

    color: var(--accent-bright);

    font-size: 11px;
    font-weight: 780;
    letter-spacing: 0.2em;
}

.overlay-kicker.danger {
    color: var(--danger);
}

.overlay-panel h2 {
    margin: 0;

    font-size: clamp(32px, 6vw, 54px);
    line-height: 1;
    letter-spacing: -0.045em;

    overflow-wrap: anywhere;
}

.overlay-copy {
    margin: 18px 0 25px;

    color: var(--muted);

    font-size: 16px;
    line-height: 1.6;
}

.overlay-copy strong {
    color: var(--text);
}

.start-button {
    min-height: 48px;

    padding: 0 24px;

    border: 1px solid var(--accent-bright);
    border-radius: 999px;

    background: var(--accent);
    color: white;

    font-weight: 760;
    letter-spacing: 0.11em;

    cursor: pointer;

    transition:
        transform 160ms ease,
        background 160ms ease;
}

.start-button:hover {
    transform: translateY(-2px);
    background: var(--accent-bright);
}

.controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 16px;

    margin-top: 24px;

    color: var(--muted);

    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
}

.mobile-controls-hint {
    display: none;
}

.pause-indicator {
    position: absolute;
    top: 50%;
    left: 50%;

    transform: translate(-50%, -50%);

    padding: 14px 18px;

    border: 1px solid rgba(53, 69, 176, 0.50);
    border-radius: 12px;

    background: rgba(5, 7, 10, 0.88);

    color: var(--text);

    font-size: 14px;
    font-weight: 750;
    letter-spacing: 0.16em;
}

.hidden {
    display: none !important;
}


/* --------------------------------------------------------------------------
   TOUCH CONTROLS
   -------------------------------------------------------------------------- */

.touch-controls {
    display: none;

    align-items: stretch;
    justify-content: space-between;
    gap: 18px;

    padding: 16px;

    border-top: 1px solid var(--border);

    background:
        linear-gradient(
            180deg,
            rgba(53, 69, 176, 0.06),
            rgba(5, 7, 10, 0.72)
        );

    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.touch-move,
.touch-actions {
    display: flex;
    gap: 12px;
}

.touch-button {
    min-width: 72px;
    min-height: 64px;

    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;

    background: rgba(255, 255, 255, 0.055);
    color: var(--text);

    font-size: 24px;
    font-weight: 800;

    cursor: pointer;

    touch-action: none;
    user-select: none;
    -webkit-user-select: none;

    transition:
        transform 80ms ease,
        background 80ms ease,
        border-color 80ms ease;
}

.touch-button.is-active,
.touch-button:active {
    transform: scale(0.96);

    background: rgba(53, 69, 176, 0.28);
    border-color: rgba(88, 105, 232, 0.72);
}

.touch-button.fire {
    min-width: 112px;

    background: var(--accent);
    border-color: var(--accent-bright);

    font-size: 15px;
    letter-spacing: 0.12em;
}

.touch-button.fire.is-active,
.touch-button.fire:active {
    background: var(--accent-bright);
}

.touch-button.pause {
    min-width: 64px;

    font-size: 16px;
    letter-spacing: 0.08em;
}


/* --------------------------------------------------------------------------
   FOOTER
   -------------------------------------------------------------------------- */

.game-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;

    padding: 16px 20px;

    border-top: 1px solid var(--border);

    color: var(--muted);

    font-size: 11px;
}

.footer-status {
    display: flex;
    align-items: center;
    gap: 8px;

    font-weight: 700;
    letter-spacing: 0.1em;
}

.footer-copy {
    text-align: right;
}


/* --------------------------------------------------------------------------
   MOBILE
   -------------------------------------------------------------------------- */

@media (max-width: 760px), (pointer: coarse) {
    body {
        padding:
            max(12px, env(safe-area-inset-top))
            max(12px, env(safe-area-inset-right))
            max(12px, env(safe-area-inset-bottom))
            max(12px, env(safe-area-inset-left));
    }

    .arcade-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 14px;

        margin-bottom: 18px;
    }

    .back-link {
        margin-bottom: 16px;
    }

    .system-state {
        display: none;
    }

    .hud {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .hud-block {
        padding: 10px 6px;
        text-align: center;
    }

    .hud-label {
        font-size: 8px;
        letter-spacing: 0.10em;
    }

    .hud strong {
        font-size: 14px;
        letter-spacing: 0.03em;
    }

    /*
     * Wichtig für iOS mit vergrößerter Systemschrift:
     * Vor dem Spiel darf der Startscreen höher als 16:9 werden.
     * Das Canvas dient in diesem Zustand nur als Hintergrund.
     */
    .game-frame.is-idle .canvas-wrap,
    .game-frame.is-gameover .canvas-wrap {
        min-height: 500px;
    }

    .game-frame.is-idle #game,
    .game-frame.is-gameover #game {
        position: absolute;
        inset: 0;

        width: 100%;
        height: 100%;

        aspect-ratio: auto;
    }

    .game-frame.is-playing #game {
        position: static;

        width: 100%;
        height: auto;

        aspect-ratio: 16 / 9;
    }

    .game-overlay {
        place-items: start center;

        padding: 18px 14px;

        -webkit-overflow-scrolling: touch;
    }

    .overlay-panel {
        display: flex;
        flex-direction: column;
        align-items: stretch;

        width: 100%;
        max-width: 560px;

        margin: auto 0;

        padding: 22px 16px;
    }

    .overlay-kicker {
        order: 1;
        margin-bottom: 10px;
    }

    .overlay-panel h2 {
        order: 2;

        font-size: clamp(30px, 10vw, 48px);
        line-height: 0.98;
    }

    /*
     * INITIALIZE / REBOOT steht bewusst direkt unter der Überschrift.
     * Selbst bei sehr großer iOS-Schrift bleibt der wichtigste Button sichtbar.
     */
    .start-button {
        order: 3;

        width: 100%;
        min-height: 54px;

        margin-top: 20px;
    }

    .overlay-copy {
        order: 4;

        margin: 18px 0 0;

        font-size: 14px;
        line-height: 1.45;
    }

    .controls {
        order: 5;
    }

    .desktop-controls {
        display: none;
    }

    .mobile-controls-hint {
        display: flex;

        margin-top: 16px;
    }

    /*
     * Vor dem Start keine nutzlosen Pfeil-/Fire-Buttons anzeigen.
     */
    .game-frame.is-playing .touch-controls {
        display: flex;
    }

    .game-footer {
        display: none;
    }
}

@media (max-width: 520px) {
    .touch-controls {
        gap: 10px;
        padding: 12px;
    }

    .touch-move,
    .touch-actions {
        gap: 8px;
    }

    .touch-button {
        min-width: 58px;
        min-height: 58px;

        border-radius: 14px;

        font-size: 22px;
    }

    .touch-button.fire {
        min-width: 92px;
        font-size: 13px;
    }

    .touch-button.pause {
        min-width: 52px;
    }
}

@media (max-width: 390px) {
    .game-frame.is-idle .canvas-wrap,
    .game-frame.is-gameover .canvas-wrap {
        min-height: 520px;
    }

    .touch-button {
        min-width: 52px;
    }

    .touch-button.fire {
        min-width: 82px;
    }

    .touch-controls {
        padding: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}


/* ------------------------------------------------------------------ */
/* ARCADE DIRECTORY                                                   */
/* ------------------------------------------------------------------ */

.arcade-directory {
    margin: 0 0 28px;

    overflow: hidden;

    background: rgba(8, 13, 18, .84);

    border: 1px solid rgba(83, 103, 215, .38);
    border-radius: 18px;
}

.arcade-directory-head {
    min-height: 128px;

    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 28px;

    padding: 25px 28px;

    background:
        linear-gradient(
            110deg,
            rgba(53, 69, 176, .16),
            rgba(53, 69, 176, .035) 52%,
            transparent 82%
        );

    border-bottom: 1px solid rgba(255, 255, 255, .065);
}

.arcade-directory-kicker {
    color: #6679f2;

    font-size: 10px;
    font-weight: 850;
    letter-spacing: .18em;
}

.arcade-directory-head h2 {
    margin: 10px 0 6px;

    color: #f1f4f6;

    font-size: 27px;
    line-height: 1.05;
}

.arcade-directory-head p {
    margin: 0;

    color: #7f8d98;

    font-size: 13px;
    line-height: 1.55;
}

.arcade-directory-count {
    flex: 0 0 auto;

    padding: 7px 10px;

    color: #50c995;
    background: rgba(80, 201, 149, .055);

    border: 1px solid rgba(80, 201, 149, .28);
    border-radius: 999px;

    font-size: 9px;
    font-weight: 850;
    letter-spacing: .12em;
}

.arcade-games {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.arcade-game-card {
    position: relative;

    min-width: 0;
    min-height: 235px;

    padding: 22px 20px;

    display: flex;
    flex-direction: column;

    color: inherit;
    text-decoration: none;

    border-right: 1px solid rgba(255, 255, 255, .055);

    transition:
        background 160ms ease,
        transform 160ms ease;
}

.arcade-game-card:last-child {
    border-right: 0;
}

.arcade-game-card:hover,
.arcade-game-card:focus-visible {
    background:
        linear-gradient(
            140deg,
            rgba(53, 69, 176, .16),
            rgba(53, 69, 176, .025)
        );

    transform: translateY(-1px);
}

.arcade-game-card:focus-visible {
    outline: 2px solid #6679f2;
    outline-offset: -2px;
}

.arcade-game-card.is-active {
    background:
        linear-gradient(
            140deg,
            rgba(53, 69, 176, .20),
            rgba(53, 69, 176, .035)
        );

    box-shadow:
        inset 0 3px 0 #5367e8;
}

.arcade-game-card.is-danger {
    background:
        linear-gradient(
            140deg,
            rgba(239, 98, 112, .055),
            transparent 55%
        );
}

.arcade-game-card.is-danger:hover,
.arcade-game-card.is-danger:focus-visible {
    background:
        linear-gradient(
            140deg,
            rgba(239, 98, 112, .11),
            rgba(53, 69, 176, .025)
        );
}

.arcade-game-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.arcade-game-number {
    color: #6578ef;

    font-size: 11px;
    font-weight: 900;
    letter-spacing: .16em;
}

.arcade-game-state {
    color: #50c995;

    font-size: 8px;
    font-weight: 900;
    letter-spacing: .13em;
}

.arcade-game-card.is-danger .arcade-game-state {
    color: #ef6270;
}

.arcade-game-card h3 {
    margin: 28px 0 8px;

    color: #eef1f4;

    font-size: 17px;
    line-height: 1.15;
    letter-spacing: -.015em;
}

.arcade-game-card p {
    margin: 0;

    min-height: 42px;

    color: #7f8d98;

    font-size: 12px;
    line-height: 1.55;
}

.arcade-game-meta {
    margin-top: 19px;

    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.arcade-game-meta span {
    padding: 5px 7px;

    color: #65747f;
    background: rgba(255,255,255,.018);

    border: 1px solid rgba(255,255,255,.065);
    border-radius: 999px;

    font-size: 7px;
    font-weight: 850;
    letter-spacing: .09em;
}

.arcade-game-action {
    margin-top: auto;
    padding-top: 22px;

    color: #7889f2;

    font-size: 9px;
    font-weight: 900;
    letter-spacing: .12em;
}

.arcade-game-card.is-active .arcade-game-action {
    color: #50c995;
}

.arcade-game-card.is-danger .arcade-game-action {
    color: #ef7180;
}


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

    .arcade-game-card {
        border-bottom: 1px solid rgba(255, 255, 255, .055);
    }

    .arcade-game-card:nth-child(2n) {
        border-right: 0;
    }

    .arcade-game-card:nth-last-child(-n + 2) {
        border-bottom: 0;
    }
}


@media (max-width: 620px) {
    .arcade-directory {
        margin-bottom: 18px;
    }

    .arcade-directory-head {
        min-height: 0;

        flex-direction: column;

        padding: 22px 20px;
    }

    .arcade-games {
        grid-template-columns: 1fr;
    }

    .arcade-game-card,
    .arcade-game-card:nth-child(2n),
    .arcade-game-card:nth-last-child(-n + 2) {
        min-height: 190px;

        border-right: 0;
        border-bottom: 1px solid rgba(255, 255, 255, .055);
    }

    .arcade-game-card:last-child {
        border-bottom: 0;
    }

    .arcade-game-card h3 {
        margin-top: 20px;
    }
}
