:root {
    --bg: #000000;
    --fg: #ffffff;
    --accent: #ff0000;
    --dim: #333333;
    --border: 1px solid var(--fg);
}

body.theme-light {
    --bg: #ffffff;
    --fg: #000000;
    --accent: #ff0000;
    --dim: #cccccc;
    --border: 1px solid var(--fg);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: 'Space Mono', monospace;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: background 0.3s ease, color 0.3s ease;
}

body::before {
    content: "";
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-image: linear-gradient(var(--dim) 1px, transparent 1px);
    background-size: 100% 50px;
    opacity: 0.2;
    pointer-events: none;
    z-index: 0;
}

.terminal-wrapper {
    position: relative;
    z-index: 10;
    width: 85vw;
    max-width: 1400px;
    height: 90vh;
    max-height: 900px;
    min-height: 300px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.nav-cluster {
    display: flex;
    justify-content: flex-start;
    flex-shrink: 0;
    margin-bottom: -1px;
    z-index: 20;
}

.nav-item {
    text-decoration: none;
    color: var(--fg);
    background: var(--bg);
    border: 1px solid var(--fg);
    border-bottom: none;
    padding: 10px 24px;
    font-size: 11px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s;
    margin-right: -1px;
    white-space: nowrap;
}

.nav-item:hover { background: var(--fg); color: var(--bg); }
.nav-item[data-pos="6"] { border-color: var(--accent); color: var(--accent); }
.nav-item[data-pos="6"]:hover { background: var(--accent); color: var(--bg); }

.nav-dropdown {
    position: relative;
    display: flex;
    margin-right: -1px;
    z-index: 30;
}

.sub-menu {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-5px);
    transition: transform 0.2s ease, opacity 0.2s ease, visibility 0.2s ease;
    z-index: 30;
}

.nav-dropdown:hover .sub-menu,
.nav-dropdown.active .sub-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.sub-item {
    text-decoration: none;
    color: var(--fg);
    background: var(--bg);
    border: 1px solid var(--fg);
    padding: 10px 24px;
    font-size: 11px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    margin-top: -1px;
    width: 100%;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
}

.sub-item:hover {
    background: var(--fg);
    color: var(--bg);
}

.nav-bottom { display: none; }

.content-frame {
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 0;
    border: 1px solid var(--fg);
    background: var(--bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#home-view {
    flex: 1;
    padding: 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: left;
    overflow: hidden;
}

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

h2#scramble-text {
    font-size: 8vw;
    font-weight: 400;
    line-height: 0.8;
    margin: 0;
    letter-spacing: -4px;
    color: var(--fg);
    cursor: default;
}

.manifesto {
    margin-top: 40px;
    font-size: 12px;
    line-height: 1.6;
    max-width: 500px;
    border-left: 1px solid var(--accent);
    padding-left: 20px;
    color: var(--fg);
    min-height: 6em;
}

.system-badge {
    display: inline-block;
    background: var(--fg);
    color: var(--bg);
    padding: 0 5px;
    animation: pulse 2s step-end infinite;
}

@keyframes pulse { 0%, 80%, 100% { opacity: 1; } 40% { opacity: 0.3; } }

.load-counter { font-size: 12px; opacity: 0.5; display: inline; }
.meta-data { position: absolute; bottom: 20px; left: 20px; font-size: 9px; opacity: 0.6; }

.poem-data {
    position: absolute;
    bottom: 20px;
    right: 20px;
    font-size: 9px;
    opacity: 0;
    max-width: 340px;
    line-height: 1.8;
    text-align: left;
    transition: opacity 1.2s ease;
}

.poem-fn { display: block; color: var(--accent); font-weight: 700; margin-bottom: 2px; }
.poem-body { display: block; color: var(--fg); word-break: break-word; }

.barcode-strip { position: absolute; top: 20px; right: 20px; font-size: 9px; text-align: right; line-height: 1.2; }

iframe#frame-view { width: 100%; height: 100%; border: none; display: none; }

footer {
    flex-shrink: 0;
    margin-top: 12px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--dim);
    padding-top: 10px;
    font-size: 10px;
    gap: 12px;
}

.audio-trigger {
    background: transparent;
    border: 1px solid var(--fg);
    color: var(--fg);
    padding: 5px 15px;
    cursor: pointer;
    text-transform: uppercase;
    font-size: 10px;
    font-family: 'Space Mono', monospace;
    white-space: nowrap;
}

.audio-trigger:hover { background: var(--fg); color: var(--bg); }
.footer-track { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.running-text { color: var(--accent); }
.running-text a { color: inherit; text-decoration: none; }

@media (max-width: 1024px) {
    .terminal-wrapper { width: 90vw; height: 90vh; }
    .nav-item { padding: 10px 12px; font-size: 10px; }
    .nav-cluster { overflow: visible; }
}

@media (max-width: 768px) {
    .nav-cluster { flex-wrap: nowrap; width: 100%; }
    .nav-item[data-pos="4"], .nav-item[data-pos="5"], .nav-item[data-pos="6"] { display: none; }
    .nav-dropdown { flex: 1; }
    .nav-dropdown .nav-item { width: 100%; }
    .sub-item {
        padding: 8px 10px;
        font-size: 9px;
        text-align: center;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .nav-item { 
        padding: 8px 10px; 
        font-size: 9px; 
        flex: 1; 
        text-align: center; 
        margin-right: -1px; 
    }
    .nav-item[data-pos="3"] {
        margin-right: 0;
        border-right: 1px solid var(--fg);
    }
    .nav-bottom {
        display: flex; justify-content: flex-end;
        margin-top: -1px; z-index: 20; flex-shrink: 0;
    }
    .nav-bottom-item {
        text-decoration: none; color: var(--fg); background: var(--bg);
        border: 1px solid var(--fg); border-top: none;
        padding: 8px 12px; font-size: 9px; margin-left: -1px;
        text-transform: uppercase;
    }
    .nav-bottom-item:last-child { margin-right: 0; }
    footer { margin-top: 8px; padding-top: 8px; }
    .poem-data { display: none; }
    .nav-bottom-item.accent { border-color: var(--accent); color: var(--accent); }
    h2#scramble-text { 
        font-size: 14vw !important; 
        letter-spacing: -2px !important; 
    }
    .manifesto { font-size: 10px; margin-top: 15px; }
}

@media (max-height: 500px) and (orientation: landscape) {
    body { align-items: flex-start; padding-top: 5px; }
    .terminal-wrapper { width: 98vw; height: 96vh; justify-content: flex-start; }
    .content-frame { flex: 1; margin-bottom: 2px; }
    .nav-item[data-pos="4"], .nav-item[data-pos="5"] { display: block; }
    .nav-dropdown { flex: 1; }
    .nav-dropdown .nav-item { width: 100%; }
    .sub-item {
        padding: 5px 6px;
        font-size: 8px;
        text-align: center;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .nav-item { padding: 5px 6px; font-size: 8px; flex: 1; text-align: center; }
    .nav-bottom { display: none; }
    h2#scramble-text { font-size: 8vw !important; }
    .manifesto { margin-top: 5px; font-size: 9px; min-height: 0; border: none; padding-left: 0; text-align: center; }
    .meta-data, .barcode-strip, .poem-data { display: none; }
    footer { margin-top: 2px; padding-top: 2px; border: none; justify-content: center; gap: 5px; }
    .footer-track { display: none; }
}