/*
 * keystro.ke
 * Copyright (C) 2026 Mike O'Riley
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 */

/**
 * ============================================================================
 * Main Menu
 * ============================================================================
 *
 * Responsibility
 * --------------
 * Presentation for the landing/main-menu screen (index.html).
 *
 * This is a deliberately separate visual world from the arcade stages: a
 * CRT-monitor bezel framing a boot sequence and a room-tile navigation
 * screen, styled entirely in monospace to read as an old terminal rather
 * than the sans-serif in-game HUD. It intentionally does not share
 * main.css - the menu has no word targets, no environment, no session
 * state, and pulling in that stylesheet would just be dead weight here.
 *
 * No-scroll design: the monitor fills whatever viewport it's given rather
 * than holding a fixed aspect ratio, so it reads as "this device's own
 * screen" - wide on a laptop, tall on a phone - instead of a fixed TV-shaped
 * box floating in whatever space is left. Every internal dimension scales
 * off vmin (the smaller of viewport width/height) rather than vw alone, so
 * a short-but-wide window (landscape phone, a shallow laptop browser) and
 * a narrow-but-tall one (portrait phone) both shrink correctly - vw alone
 * only reacts to width and will overflow vertically on the former.
 * ============================================================================
 */

:root {
    --ground: #070914;
    --ground-deep: #04050c;
    --bezel: #14131c;
    --bezel-hi: #24222e;

    --ink: #f3f7ff;
    --ink-dim: #8b93c2;

    --cyan: #7febff;
    --cyan-rgb: 127, 235, 255;
    --violet: #8274ff;
    --violet-rgb: 130, 116, 255;
    --magenta: #ff5ce0;
    --magenta-rgb: 255, 92, 224;
    --amber: #ffcb57;
    --amber-rgb: 255, 203, 87;
    --gold: #ffe778;
    --gold-rgb: 255, 231, 120;

    --mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
}

* {
    box-sizing: border-box;
}

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

body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    background: radial-gradient(circle at 50% 20%, #14131c, var(--ground-deep) 70%);
    color: var(--ink);
    font-family: var(--mono);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(6px, 2vmin, 24px);
}

/* Off-screen until focused, so a keyboard/screen-reader user can bypass
   the HUD and the wordmark/tagline to reach the room nav directly,
   without every sighted player seeing it. */
.skip-link {
    position: absolute;
    top: -100px;
    left: 1rem;
    z-index: 100;
    padding: 0.75rem 1.25rem;
    background: var(--ground);
    color: var(--ink);
    border: 2px solid var(--cyan);
    border-radius: 4px;
    font-family: var(--mono);
    font-weight: 700;
    text-decoration: none;
    transition: top 150ms ease;
}

.skip-link:focus {
    top: 1rem;
}

/* ================= CRT MONITOR BEZEL ================= */

.monitor {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 2400px;
    max-height: 1400px;
    background: linear-gradient(155deg, var(--bezel-hi), var(--bezel) 40%, #0c0b12);
    border-radius: clamp(10px, 2.4vmin, 28px);
    padding: clamp(8px, 1.6vmin, 22px);
    box-shadow:
        0 30px 70px rgba(0, 0, 0, 0.6),
        inset 0 2px 0 rgba(255, 255, 255, 0.05),
        inset 0 -6px 14px rgba(0, 0, 0, 0.5);
}

.monitor::after {
    content: "keystro.ke 9000";
    position: absolute;
    left: 50%;
    bottom: clamp(2px, 0.8vmin, 8px);
    transform: translateX(-50%);
    font-size: clamp(0.45rem, 1.1vmin, 0.6rem);
    letter-spacing: 0.3em;
    color: rgba(243, 247, 255, 0.18);
}

.screen {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: clamp(6px, 1.4vmin, 10px);
    background: var(--ground);
    box-shadow:
        inset 0 0 0 2px rgba(0, 0, 0, 0.6),
        inset 0 0 60px rgba(0, 0, 0, 0.7),
        inset 0 0 120px rgba(var(--cyan-rgb), 0.06);
}

.crt-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    pointer-events: none;
    background:
        repeating-linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0) 0px,
            rgba(0, 0, 0, 0.16) 1px,
            rgba(0, 0, 0, 0) 2px
        ),
        radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
    mix-blend-mode: multiply;
    animation: crt-flicker 6.5s steps(60, end) infinite;
}

@keyframes crt-flicker {
    0%, 96%, 100% { opacity: 0.92; }
    97% { opacity: 0.98; }
    98% { opacity: 0.86; }
}

.screen-content {
    position: relative;
    z-index: 5;
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: clamp(8px, 1.6vmin, 20px) clamp(10px, 2vmin, 26px);
}

/* ================= BOOT SEQUENCE ================= */

.boot {
    position: absolute;
    inset: 0;
    z-index: 80;
    pointer-events: none;
    background: var(--ground);
    color: var(--cyan);
    font-size: clamp(9px, 1.6vmin, 15px);
    line-height: 1.55;
    padding: clamp(12px, 3vmin, 32px);
    white-space: pre-wrap;
    text-shadow: 0 0 6px rgba(var(--cyan-rgb), 0.55);
    animation: boot-hide 0.4s ease forwards;
    animation-delay: 2.4s;
}

.boot span {
    opacity: 0;
    animation: boot-line 0.18s steps(1, end) forwards;
}

@keyframes boot-line {
    to { opacity: 1; }
}

@keyframes boot-hide {
    to { opacity: 0; visibility: hidden; }
}

@media (prefers-reduced-motion: reduce) {
    .boot { animation: boot-hide 0.01s linear forwards; animation-delay: 0s; }
    .boot span { animation: none; opacity: 1; }
    .crt-overlay { animation: none; }
}

/* ================= HUD STRIP ================= */

.hud {
    display: flex;
    align-items: center;
    gap: clamp(8px, 2.4vmin, 30px);
    flex-wrap: wrap;
    padding-bottom: clamp(8px, 1.8vmin, 18px);
    border-bottom: 2px solid rgba(var(--cyan-rgb), 0.22);
    font-size: clamp(0.7rem, 2vmin, 1.05rem);
}

.hud-item {
    display: flex;
    align-items: center;
    gap: 0.5em;
    color: var(--ink-dim);
    letter-spacing: 0.04em;
}

.hud-item strong {
    color: var(--ink);
    font-weight: 700;
}

.xp-track {
    width: clamp(70px, 12vmin, 180px);
    height: 12px;
    border: 1px solid rgba(var(--gold-rgb), 0.5);
    background: rgba(var(--gold-rgb), 0.08);
    position: relative;
    overflow: hidden;
}

.xp-fill {
    position: absolute;
    inset: 1px;
    width: 0%;
    background: linear-gradient(90deg, rgba(var(--gold-rgb), 0.5), rgba(var(--gold-rgb), 0.95));
    box-shadow: 0 0 8px rgba(var(--gold-rgb), 0.6);
    transition: width 400ms ease;
}

.badges {
    display: flex;
    gap: 6px;
    margin-left: auto;
}

.badge {
    width: clamp(20px, 2.6vmin, 30px);
    height: clamp(20px, 2.6vmin, 30px);
    border-radius: 4px;
    display: grid;
    place-items: center;
    font-size: clamp(0.6rem, 1.3vmin, 0.85rem);
    font-weight: 700;
}

.badge.won {
    background: rgba(var(--amber-rgb), 0.18);
    border: 1px solid rgba(var(--amber-rgb), 0.7);
    color: var(--amber);
    box-shadow: 0 0 8px rgba(var(--amber-rgb), 0.35);
}

.badge.locked {
    background: rgba(243, 247, 255, 0.04);
    border: 1px dashed rgba(243, 247, 255, 0.18);
    color: var(--ink-dim);
}

.sound-toggle {
    appearance: none;
    /* min-height keeps this at or above the WCAG 2.5.8 24px minimum
       target size even at the smallest end of the vmin-based padding
       clamp below - a motor-disabled player shouldn't need to land a
       click inside a squeezed-down 21px strip. */
    min-height: 28px;
    background: rgba(var(--cyan-rgb), 0.08);
    border: 1px solid rgba(var(--cyan-rgb), 0.4);
    color: var(--cyan);
    font-family: var(--mono);
    font-size: clamp(0.62rem, 1.4vmin, 0.9rem);
    letter-spacing: 0.05em;
    padding: clamp(4px, 0.9vmin, 8px) clamp(8px, 1.4vmin, 14px);
    cursor: pointer;
}

.sound-toggle:hover,
.sound-toggle:focus-visible {
    background: rgba(var(--cyan-rgb), 0.18);
}

/* ================= WORDMARK ================= */

.wordmark-block {
    text-align: center;
    padding: clamp(6px, 2.6vmin, 26px) 0 clamp(4px, 2vmin, 18px);
}

.wordmark {
    margin: 0;
    font-size: clamp(2rem, 9.5vmin, 6.5rem);
    font-weight: 800;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--ink);
    text-shadow:
        0 0 2px rgba(var(--cyan-rgb), 0.9),
        0 0 22px rgba(var(--cyan-rgb), 0.45),
        4px 4px 0 rgba(var(--violet-rgb), 0.5);
}

/* The period glyph carries a lot of built-in side bearing, which read as
   a much wider gap around it than around any other letter pair - pulled
   in with a negative margin rather than removed outright, so there's
   still a deliberate small gap, just not the font's default one. */
.wordmark .dot {
    display: inline-block;
    margin: 0 -0.14em;
    color: var(--magenta);
    text-shadow: 0 0 14px rgba(var(--magenta-rgb), 0.7);
}

.tagline {
    margin: 0.35em 0 0;
    font-size: clamp(0.7rem, 2.2vmin, 1.15rem);
    letter-spacing: 0.34em;
    text-transform: uppercase;
    color: var(--ink-dim);
}

/* A solid reverse-video block over whatever character sits at the
   cursor position - text-mode terminals recolored the character under
   the cursor in place rather than displacing it, so the base (0%/50%)
   state here is "inverted", and blinking toggles that off rather than
   fading an empty bar's opacity. The character itself never
   disappears, only its coloring toggles. */
.daily .cursor {
    display: inline-block;
    background: var(--cyan);
    color: var(--ground);
    animation: cursor-blink 1s steps(1, end) infinite;
}

@keyframes cursor-blink {
    0%, 50% {
        background: var(--cyan);
        color: var(--ground);
    }

    50.01%, 100% {
        background: transparent;
        color: inherit;
    }
}

@media (prefers-reduced-motion: reduce) {
    .daily .cursor {
        animation: none;
    }
}

/* ================= ROOM GRID ================= */

.rooms {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: clamp(10px, 2.6vmin, 28px);
    align-content: center;
    padding: clamp(4px, 1vmin, 10px) 0;
}

.room {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(6px, 1.6vmin, 14px);
    padding: clamp(12px, 3vmin, 34px) clamp(8px, 1.6vmin, 16px) clamp(16px, 3vmin, 30px);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.015));
    border: 1px solid rgba(243, 247, 255, 0.14);
    border-top: 4px solid var(--tile-accent, var(--cyan));
    cursor: pointer;
    font-family: var(--mono);
    color: var(--ink);
    text-align: center;
    text-decoration: none;
    transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

/* border-color used to hardcode cyan here regardless of which room's
   own theme was being hovered, so every tile but Lesson Hall changed to
   a color that didn't match its own accent - muted further by the low
   opacity, which read as a flat gray instead of a color at all. Now
   pulled from the same --tile-glow each tile already uses for its glow
   shadow, so the border brightens into the room's own hue. */
.room:hover,
.room:focus-visible {
    transform: translateY(-3px);
    border-color: rgba(var(--tile-glow, var(--cyan-rgb)), 0.85);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4), 0 0 22px rgba(var(--tile-glow, var(--cyan-rgb)), 0.28);
}

/* :focus-visible gets its own real outline on top of the hover glow -
   a border/shadow tint alone is easy to miss for a keyboard user, and
   should never be the only sign focus moved. */
.room:focus-visible {
    outline: 3px solid var(--ink);
    outline-offset: 3px;
}

/* Disabled tiles used to dim the icon plate via filter, back when the
   plate was a flat color square drawn by this stylesheet and the room
   name was separate text alongside it. Now that the room's name is
   baked directly into the artwork itself, a filter on the image would
   dim that text along with the graphic - the same contrast mistake
   already found and fixed once for room-blurb/the SOON flag (opacity
   crushed them under WCAG minimums). The SOON flag and suppressed
   hover/focus glow below already carry the "not available yet" signal
   without needing to touch the image itself. */
.room:disabled {
    cursor: default;
}

/* No lift or glow-shadow, so a disabled tile still doesn't feel
   interactive - but the border still brightens into the room's own
   hue rather than resetting to flat gray, matching every other tile. */
.room:disabled:hover {
    transform: none;
    box-shadow: none;
    border-color: rgba(var(--tile-glow, var(--cyan-rgb)), 0.85);
}

.room-icon {
    display: grid;
    place-items: center;
    width: clamp(76px, 15vmin, 160px);
    height: clamp(76px, 15vmin, 160px);
}

.room-icon img {
    width: 100%;
    height: 100%;
    border-radius: clamp(8px, 1.6vmin, 14px);
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    box-shadow: 0 0 16px rgba(var(--tile-glow, var(--cyan-rgb)), 0.35);
}

.room-blurb {
    font-size: clamp(0.62rem, 1.5vmin, 0.98rem);
    color: var(--ink-dim);
    line-height: 1.4;
}

.room-flag {
    position: absolute;
    top: -10px;
    right: -8px;
    font-size: clamp(0.5rem, 1.1vmin, 0.7rem);
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: clamp(2px, 0.5vmin, 4px) clamp(5px, 1vmin, 8px);
    background: var(--ground);
    border: 1px solid currentColor;
    text-transform: uppercase;
}

/* ================= DAILY PROMPT ================= */

/* The line's box (height + margin) is reserved at all times, even while
   empty, rather than only appearing once a command result fills it in -
   .rooms sits above this in the same flex column with flex:1, so if this
   line's height changed based on its content, the room grid above it
   would resize/shift every time a command ran. Blank text in a
   fixed-height line just looks empty; nothing needs to move for that. */
.daily-status {
    margin: clamp(4px, 1vmin, 10px) 0 0;
    min-height: 1.3em;
    font-size: clamp(0.72rem, 1.8vmin, 1.05rem);
    letter-spacing: 0.03em;
    color: var(--cyan);
    text-shadow: 0 0 8px rgba(var(--cyan-rgb), 0.4);
}

.daily-status.is-denied {
    color: var(--magenta);
    text-shadow: 0 0 8px rgba(var(--magenta-rgb), 0.4);
}

.daily {
    margin-top: clamp(6px, 1.8vmin, 16px);
    font-size: clamp(0.72rem, 1.8vmin, 1.05rem);
    color: var(--cyan);
    letter-spacing: 0.03em;
    text-shadow: 0 0 8px rgba(var(--cyan-rgb), 0.4);
}

/* ================= TICKER ================= */

.ticker-bar {
    margin-top: clamp(6px, 2vmin, 18px);
    overflow: hidden;
    background: linear-gradient(90deg, rgba(var(--violet-rgb), 0.22), rgba(var(--magenta-rgb), 0.18));
    border-top: 1px solid rgba(var(--magenta-rgb), 0.4);
    border-bottom: 1px solid rgba(var(--magenta-rgb), 0.4);
    padding: clamp(4px, 1vmin, 8px) 0;
}

.ticker-track {
    display: inline-flex;
    white-space: nowrap;
    animation: ticker-scroll 26s linear infinite;
    font-size: clamp(0.68rem, 1.5vmin, 0.95rem);
    letter-spacing: 0.03em;
    color: var(--ink);
}

.ticker-track span {
    padding: 0 2em;
}

.ticker-track strong {
    color: var(--gold);
}

@keyframes ticker-scroll {
    from { transform: translateX(0); }
    to { transform: translateX(-50%); }
}

@media (prefers-reduced-motion: reduce) {
    .ticker-track {
        animation: none;
    }
}

/* ================= FOOTER ================= */

.screen-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: clamp(6px, 1.6vmin, 14px);
    padding-top: clamp(4px, 1.2vmin, 10px);
    font-size: clamp(0.6rem, 1.3vmin, 0.85rem);
    color: var(--ink-dim);
}

.screen-footer a {
    color: var(--ink-dim);
    text-decoration: none;
}

.screen-footer a:hover,
.screen-footer a:focus-visible {
    color: var(--cyan);
}

/* ================= RESPONSIVE FALLBACKS ================= */
/* vmin sizing above handles most shapes gracefully; these two rules cover
   the extremes where there just isn't room for everything at once. */

@media (max-width: 620px) {
    .rooms {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-height: 480px) {
    .tagline,
    .ticker-bar,
    .room-blurb {
        display: none;
    }

    .wordmark-block {
        padding: 2px 0;
    }
}

/* Manual override for the Options Terminal "Reduce motion" toggle
   (src/settings.js sets data-motion="reduce" on <html>) - a blanket
   animation/transition kill switch, unlike the hand-tuned
   prefers-reduced-motion blocks above which only target this page's own
   specific animated elements. Lets someone reduce motion on this site
   without changing their OS-wide setting. */
:root[data-motion="reduce"] *,
:root[data-motion="reduce"] *::before,
:root[data-motion="reduce"] *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}
