/* Header Styles */
header {
    backdrop-filter: blur(20px);
    background: rgba(255, 255, 255, 0.8);
    border-bottom: 1px solid var(--border-light);
    padding: 1.5rem 2rem;
    position: sticky;
    top: 0;
    z-index: 1000;
    animation: slideDown 0.6s ease-out;
}

body.dark header {
    background: var(--glass-dark);
    border-bottom-color: var(--border-dark);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

/* Logo */
.logo {
    font-family: 'Press Start 2P', 'Noto Sans SC', cursive;
    font-size: 1.2rem;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.3s ease;
    letter-spacing: 0.05em;
    text-decoration: none;
}

.logo:hover {
    opacity: 0.7;
}

body.dark .logo {
    color: var(--text-dark);
}

/* Navigation */
nav {
    display: flex;
    gap: 2rem;
    align-items: center;
}

nav a {
    color: inherit;
    text-decoration: none;
    font-weight: 600;
    position: relative;
    padding: 0.5rem 1rem;
    transition: all 0.3s ease;
}

nav a::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--accent-primary);
    transition: width 0.3s ease;
}

nav a:hover::before,
nav a.active::before {
    width: 100%;
}

nav a:hover {
    opacity: 0.6;
}

/* Controls */
.controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* ============================================================
   Language + Theme device (header)
   One case = language LCD (switch locale) + backlight key (theme).
   Uses existing tokens: --orange, --border-*, --glass-*, VT323.
   ============================================================ */

/* VT323 has no CJK, so the LCD's 文 would fall through to the OS default
   (PingFang / YaHei) and render as a sans-serif next to a bitmap EN.
   Fusion Pixel (OFL, see fusion-pixel-OFL.txt) subset to that one glyph
   keeps both labels pixel type — 720 bytes for the whole face.
   Drawn on an 8px grid: only render it at a whole multiple of 8px. */
@font-face {
    font-family: 'Fusion Pixel';
    src: url('/assets/fonts/fusion-pixel-8px-subset.woff2') format('woff2');
    font-display: block;
    unicode-range: U+6587;
}

.lang-theme {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 3px;
    background: #eceee8;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8),
                inset 0 -1px 0 rgba(0, 0, 0, 0.12),
                0 1px 1px rgba(0, 0, 0, 0.08);
    transition: background 0.3s ease;
}

body.dark .lang-theme {
    background: #20221e;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08),
                0 1px 1px rgba(0, 0, 0, 0.4);
}

/* language LCD screen */
.lang-lcd {
    position: relative;
    width: 52px;
    height: 28px;
    padding: 0;
    border: 0;
    cursor: pointer;
    overflow: hidden;
    /* glass, not paint: a shallow diagonal tint plus a four-sided inner
       vignette, so the screen reads as recessed under a pane. */
    background: linear-gradient(158deg, #eef2ea, #e6ebe1, #edf0ea);
    box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.24),
                inset 0 0 5px rgba(0, 0, 0, 0.13);
    transition: background 0.3s ease, filter 0.2s ease;
}

body.dark .lang-lcd {
    background: #232720;
    box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.6);
}

.lang-lcd:hover {
    filter: brightness(0.97);
}

.lang-lcd .lcd-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'VT323', 'Fusion Pixel', 'DM Mono', 'Noto Sans SC', monospace;
    font-size: 16px;
    line-height: 1;
    color: #33372f;
    transition: color 0.3s ease, text-shadow 0.3s ease;
}

/* The label names the locale the button switches *to*: data-other="zh" is the
   文 screen, data-other="en" the EN one. 文 is Fusion Pixel at 2× its 8px grid
   (the 16px base above); EN is VT323 and sets its own size. Don't make 文 a
   non-multiple of 8 — the pixels stop landing on device pixels and the glyph
   goes soft. */
.lang-lcd[data-other="en"] .lcd-label {
    font-size: 19px;
}

body.dark .lang-lcd .lcd-label {
    color: oklch(0.78 0.13 55);
    text-shadow: 0 0 6px oklch(0.72 0.12 55 / 0.6);
}

.lang-lcd .lcd-dots {
    position: absolute;
    right: 3px;
    bottom: 3px;
    display: flex;
    gap: 2px;
}

.lang-lcd .lcd-dots i {
    width: 3px;
    height: 3px;
    background: rgba(0, 0, 0, 0.15);
}

body.dark .lang-lcd .lcd-dots i {
    background: rgba(255, 255, 255, 0.16);
}

.lang-lcd .lcd-dots i.on {
    background: var(--orange);
}

.lang-lcd .lcd-sheen {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(115deg, rgba(255, 255, 255, 0.45) 0%, rgba(255, 255, 255, 0) 32%);
}

body.dark .lang-lcd .lcd-sheen {
    background: linear-gradient(115deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0) 32%);
}

/* ---- signal snow ----------------------------------------------------------
   Analog-TV static over the LCD. Two triggers:
     .snow    the periodic "bad signal" blip JS schedules
     :hover   held for as long as the pointer is on the screen
   Semi-opaque either way, so 文/EN still shows through.
   The grayscale grain is an inline SVG feTurbulence (no image request);
   crt-snow shifts its background so the grain shimmers.
   Sits under .lcd-sheen so the glass streak stays on top. */
.lang-lcd .lcd-noise {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='70' height='70'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.45' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 70px 70px;
}

.lang-lcd.snow .lcd-noise {
    opacity: 0.9;
    animation: crt-snow 0.09s steps(2) infinite;
}

/* hover:hover only — on a touchscreen :hover sticks after the tap, and the
   page is already navigating away by then. */
@media (hover: hover) {
    .lang-lcd:hover .lcd-noise {
        opacity: 0.9;
        animation: crt-snow 0.09s steps(2) infinite;
    }
}

@keyframes crt-snow {
    0%   { background-position: 0 0; }
    20%  { background-position: 17px -23px; }
    40%  { background-position: -31px 11px; }
    60%  { background-position: 24px 29px; }
    80%  { background-position: -13px -19px; }
    100% { background-position: 9px 14px; }
}

@media (prefers-reduced-motion: reduce) {
    .lang-lcd .lcd-noise { display: none; }
}

/* backlight key = theme toggle */
.backlight-key {
    width: 18px;
    height: 28px;
    padding: 0;
    border: 0;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: #e6e8e2;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9),
                inset 0 -1px 0 rgba(0, 0, 0, 0.15);
    transition: background 0.3s ease, filter 0.2s ease;
}

body.dark .backlight-key {
    background: #2a2d27;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.backlight-key:hover {
    filter: brightness(0.9);
}

.backlight-key .led {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    box-sizing: border-box;
    background: transparent;
    border: 1px solid rgba(0, 0, 0, 0.45);
    transition: background 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

body.dark .backlight-key .led {
    background: var(--orange);
    border-color: transparent;
    box-shadow: 0 0 5px oklch(0.72 0.12 55 / 0.8);
}

.backlight-key .key-groove {
    width: 8px;
    height: 1.5px;
    background: rgba(127, 127, 127, 0.5);
}

/* Buttons */
.btn {
    background: transparent;
    border: 1px solid var(--border-light);
    color: inherit;
    padding: 0.5rem 1rem;
    font-family: 'IBM Plex Mono', 'Noto Sans SC', monospace;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

body.dark .btn {
    border-color: var(--border-dark);
}

.btn:hover {
    background: var(--accent-primary);
    color: var(--bg-light);
    border-color: var(--accent-primary);
}

body.dark .btn:hover {
    color: var(--bg-dark);
}

/* Submit Button (Orange) */
.submit-btn {
    background: var(--orange);
    border: none;
    color: #fff;
    padding: 0.85rem 2rem;
    font-family: 'IBM Plex Mono', 'Noto Sans SC', monospace;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 3px;
}

.submit-btn:hover {
    background: #ff9d5c;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 140, 66, 0.3);
}

.submit-btn:active {
    transform: translateY(0);
}

/* Filter Buttons */
.filter-btn {
    padding: 0.4rem 1rem;
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--accent-secondary);
    cursor: pointer;
    font-family: 'IBM Plex Mono', 'Noto Sans SC', monospace;
    font-size: 0.8rem;
    transition: all 0.3s ease;
    border-radius: 3px;
}

body.dark .filter-btn {
    border-color: var(--border-dark);
}

.filter-btn.active {
    background: var(--accent-primary);
    color: var(--bg-light);
    border-color: var(--accent-primary);
}

body.dark .filter-btn.active {
    color: var(--bg-dark);
}

.filter-btn:hover {
    border-color: var(--accent-primary);
}

/* Tags */
.tag {
    padding: 0.25rem 0.6rem;
    background: rgba(0, 0, 0, 0.05);
    color: var(--accent-secondary);
    font-size: 0.7rem;
    border: 1px solid var(--border-light);
    transition: all 0.3s ease;
}

body.dark .tag {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--border-dark);
}

.tag:hover {
    background: var(--accent-primary);
    color: var(--bg-light);
    border-color: var(--accent-primary);
}

body.dark .tag:hover {
    color: var(--bg-dark);
}

/* Footer */
footer {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--accent-secondary);
    font-size: 0.85rem;
}

/* Window Component */
.window {
    background: var(--glass-light);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: var(--shadow-subtle);
    backdrop-filter: blur(20px);
}

body.dark .window {
    background: var(--glass-dark);
    border-color: var(--border-dark);
}

.window-header {
    background: rgba(0, 0, 0, 0.02);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-light);
}

body.dark .window-header {
    background: rgba(255, 255, 255, 0.02);
    border-bottom-color: var(--border-dark);
}

.window-title {
    font-family: 'IBM Plex Mono', 'Noto Sans SC', monospace;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-light);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

body.dark .window-title {
    color: var(--text-dark);
}

.window-controls {
    display: flex;
    gap: 0.5rem;
}

.window-controls span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ccc;
    cursor: pointer;
    transition: opacity 0.2s ease;
    opacity: 0.5;
}

.window-controls span:hover {
    opacity: 1;
}

/* Mobile navigation drawer — hidden on desktop */
.pull-tab,
.nav-backdrop {
    display: none;
}

@media (max-width: 968px) {
    header {
        padding: 1.1rem 1.25rem;
        z-index: 1000;
    }

    .header-content {
        gap: 0.75rem 1rem;
        justify-content: center;
    }

    .controls {
        display: contents;
    }

    .logo {
        font-size: clamp(0.85rem, 4.4vw, 1.1rem);
        letter-spacing: 0.02em;
    }

    .pull-tab {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        bottom: -2.5px;
        width: 56px;
        height: 4px;
        display: block;
        background: var(--orange);
        border: 0;
        padding: 0;
        cursor: pointer;
        touch-action: none;
    }

    .pull-tab::after {
        content: '';
        position: absolute;
        inset: -16px -24px;
    }

    .pull-tab:hover {
        opacity: 0.85;
    }

    /* A backdrop filter creates a containing block for fixed descendants. */
    header.menu-open,
    body.dark header.menu-open {
        backdrop-filter: none;
        animation: none;
    }

    header.menu-open .logo {
        position: relative;
        z-index: 901;
    }

    header.menu-open .pull-tab {
        bottom: auto;
        top: 385.5px;
        z-index: 901;
    }

    header nav {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 388px;
        z-index: 900;
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        gap: 0.7rem;
        padding-top: 88px;
        background: var(--bg-light);
        border-bottom: 1px solid var(--border-light);
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    }

    body.dark header nav {
        background: var(--bg-dark);
        border-bottom-color: var(--border-dark);
    }

    header.menu-open nav {
        display: flex;
    }

    header nav::before {
        content: '— MENU —';
        font-size: 10px;
        letter-spacing: 0.45em;
        opacity: 0.5;
        margin-bottom: 0.3rem;
    }

    header nav a {
        font-size: 1rem;
        letter-spacing: 0.18em;
        padding: 0.45rem 1.6rem;
        text-transform: uppercase;
    }

    header nav a::before {
        display: none;
    }

    header nav a.active::after {
        content: ' ◀';
        color: var(--orange);
    }

    /* language + theme device stays visible next to the logo on mobile */
    .controls .lang-theme {
        order: 3;
    }

    body.nav-open .nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 899;
        background: rgba(0, 0, 0, 0.28);
    }

    body.dark.nav-open .nav-backdrop {
        background: rgba(0, 0, 0, 0.5);
    }
}
