/* ============================================================
   NOSTROMO C64 — floating button + modal
   Scoped: nothing here touches the rest of the site.
   ============================================================ */

#c64-fab,
#c64-modal {
    --n-bg: #020D05;
    --n-panel: #061609;
    --n-panel-alt: #001B05;
    --n-green: #00FF22;
    --n-green-bright: #7CFF70;
    --n-green-mid: #008A12;
    --n-green-muted: #176B20;
    --n-border: #00CC18;
    --n-text: #00E51F;
    --n-red: #ff3333;
    --n-amber: #ffcc00;
    --n-mono: 'Courier Prime', 'Courier New', monospace;
    --n-crt: 'VT323', monospace;
}

/* ───────── FLOATING C64 BUTTON ───────── */

#c64-fab {
    position: fixed;
    right: 18px;
    bottom: 44px;
    z-index: 950;
    width: 56px;
    height: 56px;
    padding: 0;
    border: 1px solid var(--n-border);
    background: linear-gradient(180deg, #03170a 0%, #000a03 100%);
    color: var(--n-green-bright);
    cursor: pointer;
    font-family: var(--n-crt);
    font-size: 32px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 0 0 1px #001b05,
        0 0 18px rgba(0, 255, 34, .32),
        inset 0 0 18px rgba(0, 255, 34, .08);
    transition: color .2s, border-color .2s, box-shadow .2s, transform .12s, opacity .2s;
}

#c64-fab::before {
    content: '';
    position: absolute;
    inset: 4px;
    border: 1px solid rgba(0, 204, 24, .35);
    pointer-events: none;
}

#c64-fab::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(0deg, transparent 0 2px, rgba(0, 0, 0, .28) 2px 3px);
    opacity: .55;
}

#c64-fab:hover,
#c64-fab:focus-visible {
    color: #fff;
    border-color: var(--n-green);
    box-shadow:
        0 0 0 1px #002a08,
        0 0 24px rgba(0, 255, 34, .55),
        inset 0 0 22px rgba(0, 255, 34, .16);
    outline: none;
}

#c64-fab:active { transform: translateY(1px); }

#c64-fab .fab-c {
    position: relative;
    z-index: 2;
    text-shadow: 0 0 9px rgba(0, 255, 34, .8);
}

#c64-fab .fab-led {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 4px;
    height: 4px;
    background: var(--n-green);
    box-shadow: 0 0 6px var(--n-green);
    animation: c64-ledblink 2.6s steps(1) infinite;
    z-index: 3;
}

#c64-fab .fab-label {
    position: absolute;
    right: 68px;
    top: 50%;
    transform: translateY(-50%) translateX(6px);
    white-space: nowrap;
    font-family: var(--n-mono);
    font-size: 10px;
    letter-spacing: 2px;
    color: var(--n-text);
    background: rgba(0, 10, 3, .92);
    border: 1px solid var(--n-green-muted);
    padding: 5px 8px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s, transform .18s;
}

#c64-fab:hover .fab-label,
#c64-fab:focus-visible .fab-label {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

body.c64-open #c64-fab {
    opacity: 0;
    pointer-events: none;
}

@keyframes c64-ledblink {
    0%, 48% { opacity: 1; }
    49%, 100% { opacity: .15; }
}

/* ───────── MODAL ───────── */

#c64-modal {
    position: fixed;
    inset: 0;
    z-index: 1500;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(0, 4, 1, .88);
    backdrop-filter: blur(3px);
    font-family: var(--n-mono);
}

#c64-modal.open { display: flex; }

#c64-modal .c64-shell {
    width: min(1380px, 97vw);
    height: min(880px, 94dvh);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    background: var(--n-bg);
    border: 1px solid var(--n-border);
    box-shadow:
        0 0 0 1px #001b05,
        0 0 42px rgba(0, 255, 34, .22),
        inset 0 0 60px rgba(0, 255, 34, .035);
    position: relative;
    overflow: hidden;
}

#c64-modal .c64-shell::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 20;
    background: repeating-linear-gradient(0deg, transparent 0 2px, rgba(0, 0, 0, .16) 2px 3px);
    opacity: .5;
    mix-blend-mode: multiply;
}

#c64-modal .c64-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 14px;
    background: var(--n-panel-alt);
    border-bottom: 1px solid var(--n-green-mid);
    font-size: 11px;
    letter-spacing: 1px;
    min-width: 0;
}

#c64-modal .c64-head .title {
    color: var(--n-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#c64-modal .c64-head .title b { color: var(--n-green-bright); font-weight: 400; }

#c64-modal .head-chips {
    margin-left: auto;
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

#c64-modal .chip {
    border: 1px solid var(--n-green-muted);
    background: #001006;
    color: var(--n-green-mid);
    font-size: 9px;
    letter-spacing: 1px;
    padding: 3px 6px;
    white-space: nowrap;
}

#c64-modal .chip b { color: var(--n-text); font-weight: 400; }

#c64-modal .head-close {
    background: none;
    border: 1px solid var(--n-green-muted);
    color: var(--n-green-mid);
    width: 26px;
    height: 24px;
    cursor: pointer;
    font-family: var(--n-mono);
    font-size: 13px;
    line-height: 1;
    flex-shrink: 0;
}

#c64-modal .head-close:hover { color: var(--n-red); border-color: var(--n-red); }

#c64-modal .c64-body {
    position: relative;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 270px;
    gap: 12px;
    padding: 12px;
    background: linear-gradient(180deg, rgba(0, 27, 5, .45), transparent 40%), var(--n-bg);
}

#c64-modal .screen-col {
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#c64-modal .screen-wrap {
    position: relative;
    width: min(100%, calc((94dvh - 210px) * 1.509));
    aspect-ratio: 320 / 212;
    max-width: 100%;
    background: #000;
    border: 1px solid var(--n-border);
    box-shadow:
        0 0 0 4px #000,
        0 0 0 5px rgba(0, 204, 24, .25),
        0 0 34px rgba(0, 255, 34, .18),
        inset 0 0 30px rgba(0, 255, 34, .06);
    overflow: hidden;
}

#c64-screen {
    position: absolute;
    inset: 0;
    z-index: 1;
}

#c64-screen iframe {
    width: 100% !important;
    height: 100% !important;
    border: 0 !important;
    display: block !important;
    background: #000 !important;
    image-rendering: pixelated;
}

#c64-modal .crt-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    pointer-events: none;
    opacity: 0;
    transition: opacity .25s;
    background: repeating-linear-gradient(0deg, transparent 0 2px, rgba(0, 0, 0, .30) 2px 3px);
    mix-blend-mode: multiply;
}

#c64-modal .crt-overlay::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 48%, rgba(0, 0, 0, .62) 100%);
}

#c64-modal .crt-overlay::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(255, 255, 255, .035), transparent 25%, transparent 75%, rgba(255, 255, 255, .025));
    animation: c64-flicker 5.6s infinite steps(1);
}

#c64-modal .screen-wrap.crt .crt-overlay { opacity: 1; }

#c64-modal .screen-wrap.crt #c64-screen {
    filter: contrast(1.15) brightness(1.02) saturate(1.05);
}

@keyframes c64-flicker {
    0%, 92%, 100% { opacity: .55; }
    93% { opacity: .85; }
    94% { opacity: .35; }
    95% { opacity: .75; }
}

#c64-modal .glow {
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
    box-shadow: inset 0 0 70px rgba(0, 0, 0, .38);
    background: transparent;
}

#c64-modal .screen-wrap.green .glow {
    box-shadow: inset 0 0 70px rgba(0, 255, 34, .12);
    background: radial-gradient(ellipse at 50% 0%, rgba(0, 255, 34, .10), transparent 55%);
}

#c64-modal .power-overlay {
    position: absolute;
    inset: 0;
    z-index: 8;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 10px;
    background: #000;
    color: var(--n-green-mid);
    font-family: var(--n-crt);
    font-size: 26px;
    letter-spacing: 5px;
}

#c64-modal .power-overlay.show { display: flex; }
#c64-modal .power-overlay small { font-family: var(--n-mono); font-size: 9px; color: var(--n-green-muted); letter-spacing: 2px; }

#c64-modal .boot {
    position: absolute;
    inset: 0;
    z-index: 9;
    background: #000;
    padding: 16px 18px;
    overflow: hidden;
    font-family: var(--n-crt);
    font-size: clamp(14px, 1.45vw, 20px);
    line-height: 1.35;
    color: var(--n-text);
    text-shadow: 0 0 8px rgba(0, 255, 34, .35);
    transition: opacity .7s ease;
}

#c64-modal .boot::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(0deg, transparent 0 2px, rgba(0, 0, 0, .35) 2px 3px);
    opacity: .55;
}

#c64-modal .boot.done { opacity: 0; pointer-events: none; }

#c64-modal .boot-line { opacity: 0; animation: c64-typein .18s forwards; }
#c64-modal .boot-line .ok { color: var(--n-green-bright); }
#c64-modal .boot-line .warn { color: var(--n-amber); }
#c64-modal .boot-line .err { color: var(--n-red); }
#c64-modal .boot-line .dim { color: var(--n-green-mid); }

@keyframes c64-typein { to { opacity: 1; } }

#c64-modal .boot-title {
    color: var(--n-green-bright);
    font-size: 1.15em;
    letter-spacing: 2px;
    margin-bottom: 6px;
}

#c64-modal .boot-cursor {
    display: inline-block;
    width: .55em;
    height: 1em;
    vertical-align: -2px;
    background: var(--n-green);
    animation: c64-blink 1s steps(1) infinite;
}

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

/* ───────── SIDE PANEL ───────── */

#c64-modal .side {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    padding-right: 2px;
}

#c64-modal .side::-webkit-scrollbar { width: 4px; }
#c64-modal .side::-webkit-scrollbar-thumb { background: var(--n-green-mid); }

#c64-modal .panel {
    border: 1px solid var(--n-green-muted);
    background: var(--n-panel);
    padding: 9px 10px;
}

#c64-modal .panel h3 {
    font-size: 9px;
    font-weight: 400;
    letter-spacing: 2px;
    color: var(--n-green-mid);
    margin-bottom: 7px;
    border-bottom: 1px solid #0a2a10;
    padding-bottom: 5px;
}

#c64-modal .kv {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 10px;
    line-height: 1.9;
    color: var(--n-green-muted);
}

#c64-modal .kv b {
    color: var(--n-text);
    font-weight: 400;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 62%;
}

#c64-modal .ctl-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

#c64-modal .cbtn {
    border: 1px solid var(--n-green-muted);
    background: #001006;
    color: var(--n-green-mid);
    font-family: var(--n-mono);
    font-size: 9px;
    letter-spacing: 1px;
    padding: 7px 5px;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
}

#c64-modal .cbtn:hover,
#c64-modal .cbtn.active {
    border-color: var(--n-green);
    color: var(--n-green-bright);
    box-shadow: inset 0 0 10px rgba(0, 255, 34, .08);
}

#c64-modal .cbtn.wide { grid-column: 1 / -1; }

#c64-modal .field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 9px;
    letter-spacing: 1px;
    color: var(--n-green-mid);
    margin-top: 7px;
}

#c64-modal .field select,
#c64-modal .field input[type=range] {
    width: 100%;
    background: #000;
    color: var(--n-text);
    border: 1px solid var(--n-green-muted);
    font-family: var(--n-mono);
    font-size: 10px;
    padding: 5px;
    outline: none;
}

#c64-modal .field input[type=range] { accent-color: var(--n-green); padding: 0; }

#c64-modal .toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 9px;
    letter-spacing: 1px;
    color: var(--n-green-mid);
    margin-top: 8px;
}

#c64-modal .toggle-row input { accent-color: var(--n-green); }

#c64-modal .load-status {
    margin-top: 7px;
    min-height: 24px;
    font-size: 9px;
    line-height: 1.5;
    color: var(--n-green-muted);
    word-break: break-word;
}

#c64-modal .load-status.ok { color: var(--n-green-bright); }
#c64-modal .load-status.err { color: var(--n-red); }

#c64-modal .hidden-file { display: none; }

/* ───────── FOOTER ───────── */

#c64-modal .c64-foot {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 14px;
    border-top: 1px solid var(--n-green-mid);
    background: var(--n-panel-alt);
    font-size: 9px;
    letter-spacing: 1px;
    color: var(--n-green-muted);
    min-width: 0;
}

#c64-modal .c64-foot .log {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--n-green-mid);
}

#c64-modal .c64-foot .log::before { content: '> '; color: var(--n-green-muted); }
#c64-modal .foot-clock { color: var(--n-green-muted); white-space: nowrap; }

/* ───────── BASIC HELP DRAWER ───────── */

#c64-modal .basic-help {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: none;
    align-items: stretch;
    justify-content: flex-end;
    background: rgba(0, 5, 2, .72);
    backdrop-filter: blur(2px);
}

#c64-modal .basic-help.open { display: flex; }

#c64-modal .help-panel {
    width: min(560px, 100%);
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--n-bg);
    border-left: 1px solid var(--n-border);
    box-shadow: -18px 0 40px rgba(0, 0, 0, .55), inset 0 0 40px rgba(0, 255, 34, .03);
}

#c64-modal .help-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-bottom: 1px solid var(--n-green-mid);
    background: var(--n-panel-alt);
    font-size: 10px;
    letter-spacing: 1px;
    color: var(--n-text);
    flex-shrink: 0;
}

#c64-modal .help-head span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#c64-modal .help-head b { color: var(--n-green-bright); font-weight: 400; }

#c64-modal .help-head button {
    background: none;
    border: 1px solid var(--n-green-muted);
    color: var(--n-green-mid);
    width: 26px;
    height: 24px;
    cursor: pointer;
    font-family: var(--n-mono);
    font-size: 13px;
    line-height: 1;
    flex-shrink: 0;
}

#c64-modal .help-head button:hover { color: var(--n-red); border-color: var(--n-red); }

#c64-modal .help-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 14px 16px;
}

#c64-modal .help-body::-webkit-scrollbar { width: 4px; }
#c64-modal .help-body::-webkit-scrollbar-thumb { background: var(--n-green-mid); }

#c64-modal .help-section { margin-bottom: 16px; }

#c64-modal .help-section h4 {
    font-size: 9px;
    font-weight: 400;
    letter-spacing: 2px;
    color: var(--n-green-mid);
    margin-bottom: 7px;
    border-bottom: 1px solid #0a2a10;
    padding-bottom: 5px;
}

#c64-modal .help-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

#c64-modal .help-chips code {
    font-family: var(--n-mono);
    font-size: 10px;
    color: var(--n-text);
    background: #001006;
    border: 1px solid var(--n-green-muted);
    padding: 3px 5px;
    white-space: nowrap;
}

#c64-modal .help-code {
    background: #000;
    border: 1px solid var(--n-green-muted);
    color: var(--n-green-bright);
    font-family: var(--n-mono);
    font-size: 10px;
    line-height: 1.7;
    padding: 8px 10px;
    overflow-x: auto;
    white-space: pre;
}

#c64-modal .help-note {
    font-size: 10px;
    line-height: 1.7;
    color: var(--n-green-muted);
    border-left: 2px solid var(--n-green-mid);
    padding-left: 9px;
}

#c64-modal .help-note b { color: var(--n-text); font-weight: 400; }

#c64-modal .help-foot {
    flex-shrink: 0;
    border-top: 1px solid var(--n-green-mid);
    padding: 7px 12px;
    font-size: 9px;
    letter-spacing: 1px;
    color: var(--n-green-muted);
    background: var(--n-panel-alt);
}

/* ───────── RESPONSIVE ───────── */

@media (max-width: 900px) {
    #c64-modal { padding: 0; }
    #c64-modal .c64-shell { width: 100vw; height: 100dvh; border: 0; }
    #c64-modal .c64-body {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) auto;
        padding: 8px;
        gap: 8px;
        overflow-y: auto;
    }
    #c64-modal .screen-col { min-height: 0; }
    #c64-modal .screen-wrap {
        width: 100%;
        max-height: 52dvh;
        aspect-ratio: 320 / 212;
        margin: 0 auto;
    }
    #c64-modal .side {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        overflow: visible;
    }
    #c64-modal .panel { min-width: 0; }
    #c64-modal .head-chips { display: none; }
    #c64-modal .c64-head { padding: 7px 10px; }
    #c64-modal .help-panel { width: 100%; border-left: 0; }
    #c64-modal .help-body { padding: 12px; }
    #c64-modal .basic-help { position: fixed; inset: 0; z-index: 1400; }

    #c64-fab { width: 52px; height: 52px; font-size: 29px; right: 12px; bottom: calc(env(safe-area-inset-bottom, 0px) + 40px); }
    #c64-fab .fab-label { display: none; }
}

@media (max-width: 620px) {
    #c64-modal .side { grid-template-columns: 1fr; }
    #c64-modal .screen-wrap { max-height: 42dvh; }
    #c64-modal .foot-clock { display: none; }
}
