/* ───────────────────────────────────────────────────────────────────────
   Ship's Computer — TOS-1966 library computer OUTPUT SCREEN
   Scoped under .sci-console. Loaded only on /computer.

   Modeled on the actual on-screen library-computer readouts (e.g. the
   "DESTRUCT SEQUENCE ENGAGED" panel and the data-cell displays at Spock's
   station): warm amber/coral text on warm black, buff numbered squares as
   source markers, rows of small colored data-cells as ambient texture.
   ─────────────────────────────────────────────────────────────────────── */

.sci-console {
    --void:      #070503;
    --panel:     #0d0a07;   /* warm glossy black */
    --panel-2:   #120d08;
    --screen-bg: #0a0704;
    --bezel:     #2b2419;   /* warm gunmetal */
    --bezel-hi:  #4a3c28;

    --amber:     #e8973c;   /* the hero — readout text */
    --amber-hot: #ffc070;
    --coral:     #e8835a;   /* the warmer caps, as on the DESTRUCT panel */
    --cream:     #e7d7b0;   /* buff numbered source squares */
    --cream-ink: #1b1407;
    --green:     #74c24f;   /* data accent */
    --red:       #d2402b;   /* alert / data cell */

    --ink:       #e0c089;   /* dim readout amber */
    --ink-dim:   #8f7a54;
    --ink-bright:#ffd99f;

    --f-display: 'Michroma', 'Eurostile', 'Arial Narrow', sans-serif;
    --f-screen:  'Saira Semi Condensed', 'Oswald', system-ui, sans-serif;

    max-width: 1040px;
    margin: 0 auto;
    padding: 0 1.25rem;
    font-family: var(--f-screen);
    color: var(--ink);

    /* fill the height <main> already gives us, so the console isn't stranded
       at the top of a tall viewport */
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
}

/* page-scoped: this stylesheet only loads on /computer */
main:has(.sci-console) { display: flex; flex-direction: column; }

/* ── Console frame — warm glossy black, hard edges ─────────────────── */
.sci-console .console {
    border: 1px solid var(--bezel);
    border-radius: 8px;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(255, 200, 130, 0.04), transparent 120px),
        var(--panel);
    box-shadow:
        0 0 0 1px var(--void),
        0 24px 60px -40px rgba(0, 0, 0, 0.9);

    /* the head / control bank / presets stay their natural height; the screen
       takes all the surplus */
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
}

/* ── Status strip ──────────────────────────────────────────────────── */
.sci-console .console-head {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 0.85rem 1.1rem;
    background: var(--panel-2);
    border-bottom: 1px solid var(--bezel);
}

/* rows of small colored data-cells — the iconic TOS computer texture */
.sci-console .datacells {
    display: grid;
    grid-template-columns: repeat(6, 11px);
    grid-auto-rows: 5px;
    gap: 3px;
}
.sci-console .datacells i {
    display: block;
    width: 11px;
    height: 5px;
    border-radius: 1px;
    background: var(--bezel-hi);
    opacity: 0.45;
}
/* same cells, laid out as a single centered row (idle screen) */
.sci-console .datacells--row {
    display: flex;
    justify-content: center;
    gap: 4px;
}
.sci-console .datacells i.a { background: var(--amber); opacity: 0.9; }
.sci-console .datacells i.g { background: var(--green); opacity: 0.85; }
.sci-console .datacells i.r { background: var(--red); opacity: 0.85; }
.sci-console .datacells i.blink { animation: cell-blink 3.2s steps(1) infinite; }
.sci-console .datacells i.blink2 { animation: cell-blink 2.3s steps(1) 0.6s infinite; }
/* while processing (request in flight) AND while writing the answer to the
   screen, EVERY cell flickers — staggered durations/delays via nth-child so
   the whole grid churns asynchronously instead of a couple of cells winking */
.sci-console:is(.is-working, .is-writing) .datacells i {
    animation: cell-flicker 0.45s steps(1) infinite;
}
.sci-console:is(.is-working, .is-writing) .datacells i:nth-child(2n) { animation-duration: 0.30s; animation-delay: 0.06s; }
.sci-console:is(.is-working, .is-writing) .datacells i:nth-child(3n) { animation-duration: 0.38s; animation-delay: 0.13s; }
.sci-console:is(.is-working, .is-writing) .datacells i:nth-child(4n) { animation-duration: 0.24s; animation-delay: 0.20s; }
.sci-console:is(.is-working, .is-writing) .datacells i:nth-child(5n) { animation-duration: 0.42s; animation-delay: 0.28s; }
.sci-console:is(.is-working, .is-writing) .datacells i:nth-child(7n) { animation-duration: 0.20s; animation-delay: 0.35s; }
@keyframes cell-flicker { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0.15; } }
@keyframes cell-blink { 0%, 60% { opacity: 0.9; } 61%, 100% { opacity: 0.2; } }

.sci-console .console-id { display: flex; flex-direction: column; line-height: 1; }
.sci-console .console-title {
    font-family: var(--f-display);
    font-size: 1.15rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-bright);
}
.sci-console .console-sub {
    margin-top: 0.45rem;
    font-size: 0.66rem;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--ink-dim);
}

.sci-console .console-meta {
    margin-left: auto;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    text-align: right;
    font-size: 0.66rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-dim);
}
.sci-console .status {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.4rem;
    color: var(--ink-dim);   /* standby is neutral — not claiming readiness */
}
.sci-console .status .dot {
    width: 7px;
    height: 7px;
    border-radius: 1px;
    background: var(--ink-dim);
}
/* active from request in flight through writing the answer to the screen */
.sci-console:is(.is-working, .is-writing) .status { color: var(--amber-hot); }
.sci-console:is(.is-working, .is-writing) .status .dot {
    background: var(--amber-hot);
    animation: dot-pulse 0.9s ease-in-out infinite;
}
@keyframes dot-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* Master sound toggle — sits in the console meta column */
.sci-console .sound-toggle {
    align-self: flex-end;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.1rem;
    padding: 0.18rem 0.5rem;
    font: inherit;
    font-size: 0.62rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-dim);
    background: transparent;
    border: 1px solid var(--ink-dim);
    border-radius: 2px;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.sci-console .sound-toggle:hover { color: var(--ink-bright); border-color: var(--ink-bright); }
.sci-console .sound-toggle:focus-visible { outline: 2px solid var(--ink-bright); outline-offset: 2px; }
.sci-console .sound-toggle .sound-icon { font-size: 0.8rem; line-height: 1; }
/* lit-up state when sound is on — faint amber glow, not a white slab */
.sci-console .sound-toggle[aria-pressed="true"] {
    color: var(--amber-hot);
    border-color: var(--amber);
    background: rgba(232, 151, 60, 0.14);
}

/* ── The screen — warm black readout panel ─────────────────────────── */
.sci-console .screen {
    position: relative;
    flex: 1 1 auto;          /* grow into the surplus vertical space */
    min-height: 232px;
    padding: 2rem 2.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-bottom: 1px solid var(--bezel);
    background:
        radial-gradient(120% 80% at 50% 42%, rgba(232, 151, 60, 0.07), transparent 62%),
        var(--screen-bg);
}
/* idle / "WORKING" stays centered; an actual answer reads from the top so it
   uses the tall screen instead of floating in the middle */
.sci-console .screen:has(.readout) {
    align-items: flex-start;   /* top-align vertically; stay centered horizontally */
}
/* warm CRT scanlines */
.sci-console .screen::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(
        0deg, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 3px);
    opacity: 0.5;
}
.sci-console #output {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 680px;
}
.sci-console .idle { text-align: center; }
.sci-console .idle-cells { margin-top: 1.2rem; opacity: 0.75; }
.sci-console .screen-idle {
    text-align: center;
    font-family: var(--f-display);
    font-size: 0.74rem;
    letter-spacing: 0.34em;
    text-transform: uppercase;
    color: var(--ink-dim);
}
.sci-console .working {
    text-align: center;
    font-family: var(--f-display);
    font-size: 0.95rem;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    color: var(--amber-hot);
    text-shadow: 0 0 14px rgba(232, 151, 60, 0.6);
}
.sci-console .working::after {
    content: '';
    animation: work-dots 1.3s steps(1) infinite;
}
@keyframes work-dots {
    0% { content: ''; } 25% { content: '.'; }
    50% { content: '..'; } 75%, 100% { content: '...'; }
}

/* ── The answer readout — numbered source squares + amber caps ─────── */
.sci-console .readout {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
}
.sci-console .refs {
    flex: 0 0 auto;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}
.sci-console .refs li {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.sci-console .ref-key {
    flex: 0 0 auto;
    width: 1.8rem;
    height: 1.8rem;
    display: grid;
    place-items: center;
    border-radius: 3px;
    background: var(--cream);
    color: var(--cream-ink);
    font-weight: 700;
    font-size: 1rem;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.sci-console .ref-name {
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-dim);
    white-space: nowrap;
}
.sci-console .answer-text {
    flex: 1;
    min-width: 0;
    font-size: 1.05rem;
    line-height: 1.6;
    letter-spacing: 0.01em;
    color: var(--coral);
    text-shadow: 0 0 8px rgba(232, 131, 90, 0.4);
}
.sci-console .answer-error { color: var(--red); }
.sci-console .cursor {
    display: inline-block;
    width: 0.55ch;
    background: var(--amber-hot);
    animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── Control bank ──────────────────────────────────────────────────── */
.sci-console .access {
    padding: 1.4rem 1.6rem;
    border-bottom: 1px solid var(--bezel);
    border-top: 1px solid var(--bezel-hi);
    background: linear-gradient(180deg, #181109, var(--panel));
}
.sci-console .access-label {
    display: block;
    margin-bottom: 0.7rem;
    font-family: var(--f-display);
    font-size: 0.66rem;
    letter-spacing: 0.26em;
    text-transform: uppercase;
    color: var(--amber);
}
.sci-console .access-row { display: flex; align-items: stretch; gap: 0.6rem; }
.sci-console .access-prompt {
    display: flex;
    align-items: center;
    padding: 0 0.2rem;
    font-weight: 700;
    color: var(--amber);
}
.sci-console .access input {
    flex: 1;
    min-width: 0;
    padding: 0.7rem 0.9rem;
    font-family: var(--f-screen);
    font-size: 1rem;
    letter-spacing: 0.02em;
    color: var(--ink-bright);
    background: var(--void);
    border: 1px solid var(--bezel);
    border-radius: 3px;
}
.sci-console .access input::placeholder { color: var(--ink-dim); }
.sci-console .access input:focus {
    outline: none;
    border-color: var(--amber);
    box-shadow: inset 0 0 0 1px var(--amber);
}

/* ── Keys — flat lit gels, warm TOS palette ────────────────────────── */
.sci-console .key {
    font-family: var(--f-screen);
    font-weight: 600;
    font-size: 0.82rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    border: 1px solid rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    padding: 0.65rem 1.1rem;
    color: #2a1402;
    background: var(--amber);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.18),
        inset 0 -3px 5px rgba(0, 0, 0, 0.28);
    transition: filter 0.12s ease, transform 0.04s ease;
}
.sci-console .key:hover { filter: brightness(1.1); }
.sci-console .key:active {
    transform: translateY(1px);
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.45);
}
.sci-console .key:focus-visible { outline: 2px solid var(--ink-bright); outline-offset: 2px; }
.sci-console .key[disabled] { filter: grayscale(0.55) brightness(0.65); cursor: wait; }

.sci-console .key-amber { background: var(--amber); color: #2a1402; }
.sci-console .key-green { background: var(--green); color: #0c1c06; }
.sci-console .key-red   { background: var(--red);   color: #f7e6e2; }
.sci-console .key-cream { background: var(--cream); color: var(--cream-ink); }

/* ── Quick-access keys row ─────────────────────────────────────────── */
.sci-console .presets {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1.1rem 1.6rem 1.5rem;
}
.sci-console .presets-label {
    font-size: 0.62rem;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: var(--ink-dim);
}
.sci-console .presets-row { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.sci-console .presets .key { font-size: 0.72rem; padding: 0.5rem 0.85rem; }

/* ── Footnote ──────────────────────────────────────────────────────── */
.sci-console .console-foot {
    margin-top: 1rem;
    text-align: center;
    font-size: 0.72rem;
    line-height: 1.7;
    letter-spacing: 0.04em;
    color: var(--ink-dim);
}
.sci-console .console-foot a { color: var(--amber); }

/* ── Screen-reader-only live region ────────────────────────────────── */
.sci-console .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 720px) {
    .sci-console .console-head { flex-wrap: wrap; }
    .sci-console .console-meta {
        margin-left: 0;
        width: 100%;
        text-align: left;
        align-items: flex-start;
    }
    .sci-console .status-online { justify-content: flex-start; }
    .sci-console .screen { padding: 1.6rem 1.1rem; }
    .sci-console .readout { flex-direction: column; gap: 1rem; }
    .sci-console .refs { flex-direction: row; flex-wrap: wrap; }
    .sci-console .ref-name { display: none; }
    .sci-console .access-row { flex-wrap: wrap; }
    .sci-console .access input { flex-basis: 100%; }
    .sci-console .access-prompt { display: none; }
    .sci-console .key-query { flex: 1; }
}

/* ── Reduced motion ────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .sci-console .datacells i,
    .sci-console .status .dot,
    .sci-console .working::after,
    .sci-console .cursor { animation: none !important; }
}
