:root {
    --bg: #070a0f;
    --panel: rgba(9, 14, 21, 0.86);
    --panel-strong: rgba(12, 18, 27, 0.96);
    --line: rgba(136, 244, 255, 0.18);
    --text: #f0fff9;
    --muted: #8ca7ad;
    --cyan: #28e7d8;
    --pink: #ff4f91;
    --yellow: #f6d860;
    --green: #8dff9c;
    --mono: "Cascadia Code", "Fira Code", "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    color: var(--text);
    background:
        linear-gradient(120deg, rgba(40, 231, 216, 0.11), transparent 34%),
        linear-gradient(250deg, rgba(255, 79, 145, 0.12), transparent 32%),
        linear-gradient(180deg, #0b1018, #05070b);
    font-family: var(--sans);
}

a,
button {
    -webkit-tap-highlight-color: transparent;
}

button {
    font: inherit;
}

.boot {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 20px;
    background: #070a0f;
    transition: opacity 520ms ease, visibility 520ms ease;
}

.boot.is-hidden {
    opacity: 0;
    visibility: hidden;
}

.boot-inner {
    display: grid;
    gap: 10px;
    width: min(360px, 100%);
    padding: 18px;
    border: 1px solid rgba(40, 231, 216, 0.26);
    border-radius: 8px;
    background: rgba(10, 15, 22, 0.9);
    box-shadow: 0 0 52px rgba(40, 231, 216, 0.16);
    font-family: var(--mono);
}

.boot-inner span {
    color: var(--cyan);
    font-size: 13px;
    font-weight: 900;
}

.boot-inner strong {
    color: var(--text);
    font-size: clamp(28px, 9vw, 52px);
    line-height: 1;
}

.boot-inner i {
    display: block;
    height: 7px;
    overflow: hidden;
    border: 1px solid rgba(240, 255, 249, 0.16);
    border-radius: 999px;
}

.boot-inner i::before {
    content: "";
    display: block;
    width: 100%;
    height: 100%;
    transform-origin: left;
    animation: boot 850ms cubic-bezier(.22, 1, .36, 1) forwards;
    background: linear-gradient(90deg, var(--cyan), var(--yellow), var(--pink));
}

@keyframes boot {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
}

.matrix,
.scanline {
    position: fixed;
    inset: 0;
    pointer-events: none;
}

.matrix {
    z-index: 0;
    opacity: 0.2;
    transition: opacity 240ms ease;
}

body.matrix-on .matrix {
    opacity: 0.52;
}

.scanline {
    z-index: 1;
    background:
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 5px),
        linear-gradient(90deg, transparent, rgba(40, 231, 216, 0.035), transparent);
    mix-blend-mode: screen;
}

.page {
    position: relative;
    z-index: 2;
    display: grid;
    gap: 18px;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
}

.terminal-card {
    position: relative;
    width: min(880px, 100%);
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(12, 18, 27, 0.92), rgba(5, 8, 13, 0.92));
    box-shadow:
        0 28px 90px rgba(0, 0, 0, 0.46),
        0 0 0 1px rgba(255, 255, 255, 0.035) inset;
    backdrop-filter: blur(18px);
}

.terminal-card::before {
    content: "";
    position: absolute;
    inset: -2px;
    pointer-events: none;
    background: linear-gradient(90deg, transparent, rgba(40, 231, 216, 0.22), transparent);
    transform: translateX(-100%);
    animation: sweep 5.4s ease-in-out infinite;
}

.terminal-card::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), rgba(40, 231, 216, 0.12), transparent 28%);
    opacity: 0.8;
}

@keyframes sweep {
    45%, 100% { transform: translateX(100%); }
}

.terminal-bar {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    align-items: center;
    min-height: 52px;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(136, 244, 255, 0.14);
    background: rgba(5, 8, 13, 0.72);
}

.traffic {
    display: flex;
    gap: 7px;
}

.traffic span {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.traffic span:nth-child(1) { background: var(--pink); }
.traffic span:nth-child(2) { background: var(--yellow); }
.traffic span:nth-child(3) { background: var(--green); }

.terminal-path,
.matrix-toggle,
.hero-line,
.terminal-footer,
.link-command {
    font-family: var(--mono);
}

.terminal-path {
    overflow: hidden;
    color: var(--muted);
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.matrix-toggle {
    min-height: 34px;
    padding: 0 10px;
    color: var(--cyan);
    border: 1px solid rgba(40, 231, 216, 0.22);
    border-radius: 8px;
    background: rgba(40, 231, 216, 0.08);
    cursor: pointer;
}

.matrix-toggle:hover {
    border-color: rgba(40, 231, 216, 0.55);
    box-shadow: 0 0 18px rgba(40, 231, 216, 0.18);
}

.terminal-body {
    position: relative;
    z-index: 2;
    display: grid;
    gap: 22px;
    padding: clamp(20px, 5vw, 42px);
}

.hero-line {
    display: flex;
    align-items: center;
    min-height: 24px;
    color: var(--muted);
}

.prompt {
    margin-right: 8px;
    color: var(--green);
}

.hero-line b {
    width: 9px;
    height: 18px;
    margin-left: 3px;
    background: var(--cyan);
    box-shadow: 0 0 18px rgba(40, 231, 216, 0.78);
    animation: blink 1s steps(1) infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

h1 {
    margin: 0;
    color: var(--text);
    font-size: clamp(44px, 10vw, 112px);
    line-height: 1.02;
    font-weight: 950;
    letter-spacing: 0;
}

.links-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 2px;
}

.link-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
}

.link-card {
    position: relative;
    display: grid;
    grid-template-columns: 54px 1fr auto;
    gap: 13px;
    align-items: center;
    min-height: 82px;
    padding: 14px;
    overflow: hidden;
    color: var(--text);
    border: 1px solid rgba(136, 244, 255, 0.14);
    border-radius: 10px;
    background: rgba(240, 255, 249, 0.035);
    text-decoration: none;
    transform: translateY(0);
    transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.link-card::before {
    content: "";
    position: absolute;
    inset: 0;
    width: 5px;
    background: var(--accent);
}

.link-card::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent) 18%, transparent), transparent);
    opacity: 0;
    transform: translateX(-70%);
    transition: opacity 180ms ease;
}

.link-card:hover,
.link-card:focus-visible {
    border-color: color-mix(in srgb, var(--accent) 62%, white);
    background: rgba(240, 255, 249, 0.065);
    box-shadow: 0 16px 42px color-mix(in srgb, var(--accent) 20%, transparent);
    transform: translateY(-3px);
    outline: 0;
}

.link-card:hover::after,
.link-card:focus-visible::after {
    opacity: 1;
    animation: link-scan 900ms ease;
}

@keyframes link-scan {
    to { transform: translateX(70%); }
}

.link-icon {
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    color: #061016;
    border-radius: 10px;
    background: var(--accent);
    box-shadow: 0 0 26px color-mix(in srgb, var(--accent) 36%, transparent);
}

.link-icon svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

.link-icon svg rect,
.link-icon svg circle {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}

.link-text {
    min-width: 0;
}

.link-text strong,
.link-text small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.link-text strong {
    font-size: 18px;
    font-weight: 900;
}

.link-text small {
    color: var(--muted);
    margin-top: 4px;
}

.link-command {
    padding: 5px 8px;
    color: var(--cyan);
    border: 1px solid rgba(40, 231, 216, 0.18);
    border-radius: 999px;
    background: rgba(40, 231, 216, 0.06);
    font-size: 12px;
    white-space: nowrap;
}

.terminal-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
}

.terminal-footer span {
    padding: 6px 9px;
    border: 1px solid rgba(136, 244, 255, 0.14);
    border-radius: 999px;
    background: rgba(240, 255, 249, 0.035);
}

.game-card {
    position: relative;
    width: min(880px, 100%);
    overflow: hidden;
    border: 1px solid rgba(136, 244, 255, 0.15);
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(9, 14, 21, 0.78), rgba(5, 8, 13, 0.88));
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.34);
    backdrop-filter: blur(16px);
}

.game-bar,
.game-footer {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 13px;
}

.game-bar {
    border-bottom: 1px solid rgba(136, 244, 255, 0.12);
}

.game-bar span {
    color: var(--green);
}

.game-bar button {
    min-height: 32px;
    padding: 0 12px;
    color: var(--cyan);
    border: 1px solid rgba(40, 231, 216, 0.22);
    border-radius: 8px;
    background: rgba(40, 231, 216, 0.08);
    cursor: pointer;
    font-family: var(--mono);
}

.game-bar button:hover {
    border-color: rgba(40, 231, 216, 0.55);
    box-shadow: 0 0 18px rgba(40, 231, 216, 0.16);
}

.game-canvas {
    position: relative;
    z-index: 2;
    display: block;
    width: calc(100% - 28px);
    aspect-ratio: 19 / 6;
    margin: 14px;
    border: 1px solid rgba(136, 244, 255, 0.12);
    border-radius: 10px;
    background: #070b12;
    touch-action: none;
    user-select: none;
}

.game-footer {
    flex-wrap: wrap;
    border-top: 1px solid rgba(136, 244, 255, 0.12);
}

.game-footer b {
    color: var(--text);
}

body.scroll-locked {
    position: fixed;
    left: 0;
    right: 0;
    width: 100%;
    overflow: hidden;
}

@media (max-width: 720px) {
    .page {
        align-items: start;
        padding: 10px;
    }

    .terminal-bar {
        grid-template-columns: auto 1fr;
    }

    .matrix-toggle {
        grid-column: 1 / -1;
        width: 100%;
    }

    .terminal-path {
        text-align: right;
    }

    .links-grid {
        grid-template-columns: 1fr;
    }

    .link-card:last-child:nth-child(odd) {
        grid-column: auto;
    }

    .link-card {
        grid-template-columns: 50px 1fr;
    }

    .link-command {
        grid-column: 2;
        justify-self: start;
    }

    .game-canvas {
        aspect-ratio: 4 / 2.4;
    }

    .game-card.is-playing {
        position: fixed;
        z-index: 40;
        top: calc(var(--game-viewport-top, 0px) + max(10px, env(safe-area-inset-top)));
        left: max(10px, env(safe-area-inset-left));
        right: max(10px, env(safe-area-inset-right));
        height: calc(var(--game-viewport-height, 100dvh) - max(10px, env(safe-area-inset-top)) - max(10px, env(safe-area-inset-bottom)) - 20px);
        width: auto;
        max-height: none;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        border-color: rgba(40, 231, 216, 0.36);
        background:
            radial-gradient(circle at 50% 14%, rgba(40, 231, 216, 0.14), transparent 38%),
            linear-gradient(180deg, rgba(8, 13, 20, 0.98), rgba(5, 8, 13, 0.98));
        box-shadow: 0 0 0 999px rgba(2, 5, 9, 0.78), 0 22px 80px rgba(40, 231, 216, 0.16);
    }

    .game-card.is-playing .game-bar,
    .game-card.is-playing .game-footer {
        flex: 0 0 auto;
        padding: 10px 12px;
    }

    .game-card.is-playing .game-canvas {
        flex: 1 1 auto;
        width: calc(100% - 20px);
        min-height: 0;
        margin: 10px;
        aspect-ratio: auto;
    }
}

@media (max-width: 420px) {
    .terminal-body {
        padding: 16px;
    }

    h1 {
        font-size: 42px;
    }

    .hero-line,
    .terminal-path,
    .link-command,
    .terminal-footer {
        font-size: 12px;
    }
}

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