@property --angle {
    syntax: '<angle>';
    inherits: false;
    initial-value: 0deg;
}

@property --spot {
    syntax: '<number>';
    inherits: false;
    initial-value: 0;
}

:root {
    --bg: #03050c;
    --text: #e6f1ff;
    --muted: rgba(190, 215, 255, 0.55);
    --cyan: #00e5ff;
    --pink: #ff3d9a;
    --line: rgba(110, 170, 255, 0.08);
    /* Grid cell size. main.js reads it, so the shader pulses run on these lines. */
    --cell: 48px;
    --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    --edge-t: max(14px, env(safe-area-inset-top));
    --edge-r: max(14px, env(safe-area-inset-right));
    --edge-b: max(14px, env(safe-area-inset-bottom));
    --edge-l: max(14px, env(safe-area-inset-left));
    color-scheme: dark;
}

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.4;
    color: var(--text);
    /* Fallback when WebGL is not available. The canvas covers it otherwise. */
    background:
        radial-gradient(60% 50% at 25% 20%, rgba(30, 80, 200, 0.35), transparent 70%),
        radial-gradient(50% 45% at 80% 75%, rgba(0, 180, 220, 0.22), transparent 70%),
        var(--bg);
    background-attachment: fixed;
    -webkit-tap-highlight-color: transparent;
}

/* Scanlines. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 9;
    pointer-events: none;
    opacity: 0.45;
    background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.25) 0 1px, transparent 1px 3px);
}

/* Film grain, hides gradient banding. */
body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 10;
    pointer-events: none;
    opacity: 0.05;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Background layers. */

#bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    display: block;
    opacity: 0;
    transition: opacity 1.2s ease;
}

#bg.ready {
    opacity: 1;
}

/* Grid with dots on the crossings. Lines run through the center of the screen. */
.grid {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-image:
        radial-gradient(circle, rgba(150, 210, 255, 0.45) 0 1px, transparent 1.5px),
        linear-gradient(to bottom, transparent 50%, var(--line) 50% calc(50% + 1px), transparent calc(50% + 1px)),
        linear-gradient(to right, transparent 50%, var(--line) 50% calc(50% + 1px), transparent calc(50% + 1px));
    background-size: var(--cell) var(--cell);
    background-position: center;
    -webkit-mask-image: radial-gradient(ellipse 80% 75% at 50% 50%, #000 30%, transparent 100%);
    mask-image: radial-gradient(ellipse 80% 75% at 50% 50%, #000 30%, transparent 100%);
}

/* HUD frame. */

.hud {
    position: fixed;
    inset: 0;
    z-index: 5;
    pointer-events: none;
    font: 500 0.6875rem/1 var(--mono);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.hud > * {
    position: absolute;
}

.hud-corner {
    width: 14px;
    height: 14px;
    border: 1px solid rgba(0, 229, 255, 0.55);
}

.hud-corner.tl {
    top: var(--edge-t);
    left: var(--edge-l);
    border-right: 0;
    border-bottom: 0;
}

.hud-corner.tr {
    top: var(--edge-t);
    right: var(--edge-r);
    border-left: 0;
    border-bottom: 0;
}

.hud-corner.bl {
    bottom: var(--edge-b);
    left: var(--edge-l);
    border-right: 0;
    border-top: 0;
}

.hud-corner.br {
    bottom: var(--edge-b);
    right: var(--edge-r);
    border-left: 0;
    border-top: 0;
}

.hud-label.tl {
    top: calc(var(--edge-t) + 4px);
    left: calc(var(--edge-l) + 22px);
    color: var(--text);
}

.hud-label.tr {
    top: calc(var(--edge-t) + 4px);
    right: calc(var(--edge-r) + 22px);
}

.hud-label.bl {
    bottom: calc(var(--edge-b) + 4px);
    left: calc(var(--edge-l) + 22px);
}

.hud-label.br {
    bottom: calc(var(--edge-b) + 4px);
    right: calc(var(--edge-r) + 22px);
}

/* Content. */

main {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
    padding:
        calc(var(--edge-t) + 2.5rem)
        max(1rem, env(safe-area-inset-right))
        calc(var(--edge-b) + 2.5rem)
        max(1rem, env(safe-area-inset-left));
}

.prompt {
    margin: 0;
    font: 500 0.875rem/1 var(--mono);
    letter-spacing: 0.04em;
    color: var(--muted);
}

.prompt-sign {
    color: var(--cyan);
}

.cursor {
    display: inline-block;
    width: 0.55em;
    height: 1.05em;
    margin-left: 0.2em;
    vertical-align: -0.2em;
    background: var(--cyan);
    box-shadow: 0 0 8px rgba(0, 229, 255, 0.7);
    animation: blink 1.1s steps(1) infinite;
}

.tiles {
    width: 100%;
    max-width: 64rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 21rem));
    justify-content: center;
    gap: 1.5rem;
}

.tile {
    --x: 50%;
    --y: 50%;
    position: relative;
    isolation: isolate;
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: 5.5rem;
    padding: 1rem 1.25rem;
    border: 1px solid rgba(0, 229, 255, 0.18);
    border-radius: 0.5rem;
    color: var(--text);
    text-decoration: none;
    background:
        radial-gradient(20rem circle at var(--x) var(--y), rgb(0 229 255 / calc(var(--spot) * 0.14)), transparent 45%),
        linear-gradient(180deg, rgba(14, 24, 48, 0.72), rgba(6, 10, 22, 0.8));
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.9);
    transition:
        --spot 0.3s ease,
        transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1),
        border-color 0.3s ease,
        box-shadow 0.3s ease;
}

/* Corner brackets. */
.tile::before {
    --c: rgba(0, 229, 255, 0.9);
    --l: 12px;
    content: "";
    position: absolute;
    inset: -7px;
    pointer-events: none;
    background:
        linear-gradient(var(--c), var(--c)) top left / var(--l) 1px no-repeat,
        linear-gradient(var(--c), var(--c)) top left / 1px var(--l) no-repeat,
        linear-gradient(var(--c), var(--c)) top right / var(--l) 1px no-repeat,
        linear-gradient(var(--c), var(--c)) top right / 1px var(--l) no-repeat,
        linear-gradient(var(--c), var(--c)) bottom left / var(--l) 1px no-repeat,
        linear-gradient(var(--c), var(--c)) bottom left / 1px var(--l) no-repeat,
        linear-gradient(var(--c), var(--c)) bottom right / var(--l) 1px no-repeat,
        linear-gradient(var(--c), var(--c)) bottom right / 1px var(--l) no-repeat;
    transition: inset 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Two light pulses running around the border. */
.tile::after {
    content: "";
    position: absolute;
    inset: -1px;
    padding: 1px;
    border-radius: inherit;
    pointer-events: none;
    background: conic-gradient(
        from var(--angle),
        transparent 0 28%,
        var(--cyan) 45%,
        transparent 45.5% 78%,
        var(--pink) 95%,
        transparent 95.5%
    );
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
    animation: spin 5s linear infinite;
}

.tile:hover,
.tile:focus-visible,
.tile:active {
    --spot: 1;
    border-color: rgba(0, 229, 255, 0.45);
}

.tile:focus-visible {
    outline: none;
    box-shadow:
        0 20px 50px -20px rgba(0, 0, 0, 0.9),
        0 0 0 2px var(--bg),
        0 0 0 4px var(--cyan);
}

.tile:active {
    transform: scale(0.98);
}

@media (hover: hover) {
    .tile:hover {
        transform: translateY(-2px);
        box-shadow:
            0 24px 60px -20px rgba(0, 0, 0, 0.9),
            0 0 32px -6px rgba(0, 229, 255, 0.35);
    }

    .tile:hover::before {
        inset: -11px;
    }

    .tile:hover::after {
        animation-duration: 2s;
    }

    .tile:hover .tile-arrow {
        transform: translate(3px, -3px);
        color: var(--cyan);
    }
}

.tile-icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    border: 1px solid rgba(0, 229, 255, 0.3);
    border-radius: 0.375rem;
    color: var(--cyan);
    background: rgba(0, 229, 255, 0.07);
    box-shadow: inset 0 0 14px rgba(0, 229, 255, 0.15);
}

.tile-icon svg {
    width: 1.6rem;
    height: 1.6rem;
    filter: drop-shadow(0 0 6px rgba(0, 229, 255, 0.6));
}

.tile-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.tile-title {
    font: 700 1.15rem/1.2 var(--mono);
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.tile-url {
    font: 0.8125rem/1.2 var(--mono);
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tile-url .dim {
    opacity: 0.5;
}

.tile-arrow {
    flex: none;
    width: 1.4rem;
    height: 1.4rem;
    color: var(--muted);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), color 0.3s ease;
}

.tile-arrow svg {
    width: 100%;
    height: 100%;
}

@media (max-width: 420px) {
    .hud {
        font-size: 0.625rem;
    }
}

@keyframes spin {
    to {
        --angle: 360deg;
    }
}

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

@media (prefers-reduced-motion: reduce) {
    .tile,
    .tile::before,
    .tile-arrow,
    #bg {
        transition: none;
    }

    .tile::after,
    .cursor {
        animation: none;
    }
}
