/* ============================================================
   YEEMS214.XYZ — SHIELA :: DIGITAL TWIN · twin.css
   ============================================================
   Loaded only by twin.html, AFTER style.css.

   Every colour, font and spacing value comes from the :root tokens
   already defined in style.css — this file adds layout, not a second
   design system. Components reused as-is: .mono .sr-only .band
   .page-hero .section-eyebrow .chip .btn .dot .meter__bar
   .meter__fill .page-cta .footer
   ============================================================ */

/* ---- state colours, resolved once ---- */

.twin {
    --st-ok: var(--accent);
    --st-warn: var(--amber);
    --st-err: var(--err);
    --st-down: #555;
}

/* style.css defines .dot--ok/--warn/--live; the twin needs two more
   states than the project cards ever did. */
.dot--err {
    background: var(--err);
    box-shadow: 0 0 6px var(--err);
}

.dot--down {
    background: #555;
    box-shadow: none;
}

/* ============ MODEL BADGE + DISCLOSURE ============ */

.twin-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--unit);
    border: 1px solid var(--amber);
    color: var(--amber);
    border-radius: 4px;
    padding: calc(var(--unit) * 0.5) calc(var(--unit) * 1.5);
    font-size: 0.62rem;
    white-space: nowrap;
}

.twin-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--amber);
}

.twin-disclosure {
    border-left: 2px solid var(--amber);
    background: rgba(255, 170, 0, 0.04);
    padding: calc(var(--unit) * 2) calc(var(--unit) * 3);
    margin-top: calc(var(--unit) * 4);
    max-width: 72ch;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.twin-disclosure strong {
    color: var(--amber);
    font-weight: 500;
}

/* ============ ROLLUP STRIP ============ */

.twin-rollup {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: calc(var(--unit) * 2);
    border-top: 1px solid var(--border-0);
    border-bottom: 1px solid var(--border-0);
    background: var(--bg-1);
    padding: calc(var(--unit) * 2) var(--pad-x);

    /* Pinned: SERVICES UP and BLAST RADIUS have to stay readable while you
       scroll the topology and fire chaos scenarios — a rollup that scrolls
       away defeats its own purpose.
       `top` clears the fixed .nav rather than sitting at 0. At top:0 the
       nav (z-index 100) renders straight over this strip and you get two
       layers of mono text in the same 40px, which is illegible. */
    position: sticky;
    top: var(--nav-h);
    z-index: 70;
}

/* Height of the fixed .nav: padding 2.5 units top + bottom, plus one line of
   0.72rem mono. On :root because .twin-rollup is a sibling of .twin, not a
   descendant, so a scoped declaration would not reach it. */
:root {
    --nav-h: 56px;
}

.twin-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 96px;
    padding-right: calc(var(--unit) * 3);
    border-right: 1px solid var(--border-0);
}

.twin-stat:last-of-type {
    border-right: 0;
}

.twin-stat__label {
    font-family: var(--font-mono);
    letter-spacing: 0.14em;
    font-size: 0.56rem;
    color: var(--text-dim);
}

.twin-stat__val {
    font-size: 1.15rem;
    font-weight: 500;
}

.twin-stat__val.is-ok { color: var(--accent); }
.twin-stat__val.is-warn { color: var(--amber); }
.twin-stat__val.is-err { color: var(--err); }

.twin-rollup__spacer {
    flex: 1;
}

.twin-incident {
    font-family: var(--font-mono);
    letter-spacing: 0.12em;
    font-size: 0.65rem;
    color: var(--err);
    border: 1px solid var(--err);
    border-radius: 4px;
    padding: calc(var(--unit) * 0.75) calc(var(--unit) * 2);
    animation: twin-pulse 1.6s ease-in-out infinite;
}

@keyframes twin-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

/* ---- tick controls ---- */

.twin-controls {
    display: flex;
    gap: var(--unit);
}

.twin-btn {
    font-family: var(--font-mono);
    letter-spacing: 0.12em;
    font-size: 0.62rem;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid var(--border-0);
    border-radius: 4px;
    padding: calc(var(--unit) * 1) calc(var(--unit) * 2);
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease;
    min-height: 32px;
}

.twin-btn:hover {
    border-color: var(--accent-muted);
    color: var(--accent);
}

.twin-btn[aria-pressed="true"] {
    border-color: var(--accent);
    color: var(--accent);
}

/* ============ MAIN THREE-PANE GRID ============ */

.twin {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr) 330px;
    gap: 1px;
    background: var(--border-0);
    border-bottom: 1px solid var(--border-0);
    /* 1px gaps + this background give hairline dividers between panes
       without four separate border declarations. */
}

.twin-pane {
    background: var(--bg-0);
    padding: calc(var(--unit) * 3);
    min-width: 0;
    /* min-width:0 is load-bearing: without it the canvas pane refuses
       to shrink below its intrinsic width and overflows the grid. */
}

.twin-pane__title {
    font-family: var(--font-mono);
    letter-spacing: 0.15em;
    font-size: 0.6rem;
    color: var(--accent);
    margin-bottom: calc(var(--unit) * 2);
}

/* ============ RACK ELEVATION ============ */

.twin-rack {
    display: flex;
    flex-direction: column;
    gap: var(--unit);
}

.rack-unit {
    display: flex;
    flex-direction: column;
    gap: var(--unit);
    width: 100%;
    text-align: left;
    background: var(--surface-0);
    border: 1px solid var(--border-0);
    border-left: 3px solid var(--st-ok);
    border-radius: 6px;
    padding: calc(var(--unit) * 1.5) calc(var(--unit) * 2);
    cursor: pointer;
    font: inherit;
    color: inherit;
    transition: border-color 0.25s ease, background 0.25s ease;
}

.rack-unit:hover {
    background: var(--surface-1);
}

.rack-unit.is-selected {
    border-color: var(--accent-muted);
}

.rack-unit.is-warn { border-left-color: var(--st-warn); }
.rack-unit.is-err { border-left-color: var(--st-err); }
.rack-unit.is-down {
    border-left-color: var(--st-down);
    opacity: 0.55;
}

.rack-unit__top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--unit);
}

.rack-unit__name {
    font-size: 0.78rem;
    color: var(--text-0);
    font-weight: 500;
}

.rack-unit__state {
    font-size: 0.55rem;
    color: var(--accent);
}

.rack-unit.is-down .rack-unit__state { color: var(--err); }

.rack-unit__os {
    font-size: 0.56rem;
    color: var(--text-dim);
    letter-spacing: 0.1em;
}

.rack-unit__meters {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.rack-meter {
    display: flex;
    align-items: center;
    gap: var(--unit);
}

.rack-meter__label {
    font-size: 0.5rem;
    color: var(--text-dim);
    width: 30px;
    flex-shrink: 0;
}

/* .meter__bar from style.css is a block element; inside the rack it has
   to flex, so the display is overridden rather than re-styled. */
.rack-meter .meter__bar {
    flex: 1;
    display: block;
    height: 3px;
}

.rack-unit__count {
    font-size: 0.55rem;
    color: var(--text-muted);
    letter-spacing: 0.12em;
}

.twin-rack__lore {
    margin-top: calc(var(--unit) * 2);
    font-size: 0.72rem;
    color: var(--text-dim);
    line-height: 1.5;
    border-top: 1px solid var(--border-0);
    padding-top: calc(var(--unit) * 2);
}

/* Chaos console group headings. Thirteen buttons in one flat grid is a
   wall; three named groups is a console. */
.twin-chaos__group {
    font-size: 0.58rem;
    font-weight: 400;
    letter-spacing: 0.16em;
    color: var(--accent-muted-text);
    margin: calc(var(--unit) * 2.5) 0 var(--unit);
    text-transform: uppercase;
}

.twin-chaos__group:first-of-type {
    margin-top: var(--unit);
}

/* Graph pane header: title left, camera controls right. Baseline-aligned
   so the mono title and the buttons sit on the same line. */
.twin-pane__head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--unit);
    flex-wrap: wrap;
}

.twin-pane__head .twin-pane__title {
    margin: 0;
}

.twin-controls--cam {
    flex: 0 0 auto;
}

/* ============ TOPOLOGY CANVAS ============ */

/* The 3D view wants height, not width. Widening the centre column would
   cost either the rack or the inspector, both already dense — whereas
   vertical room is what lets the tier depth actually read. */
.twin-canvas-wrap {
    position: relative;
    width: 100%;
    height: clamp(460px, 72vh, 820px);
}

@media (min-height: 900px) {
    .twin-canvas-wrap {
        height: min(78vh, 900px);
    }
}

/* Both canvases fill the wrap and stack. Only one is ever un-hidden:
   the GL one when WebGL2 is available, the 2D one otherwise. */
#twinCanvas,
#twinCanvasGL {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* The `hidden` attribute has to beat the display:block above. */
#twinCanvas[hidden],
#twinCanvasGL[hidden] {
    display: none;
}

/* Dragging the 3D view must not scroll the page on touch. Applied only
   when GL is actually live, so the 2D fallback keeps native behaviour. */
.twin-canvas-wrap.is-gl #twinCanvasGL {
    touch-action: none;
    cursor: grab;
}

.twin-canvas-wrap.is-gl #twinCanvasGL:active {
    cursor: grabbing;
}

.twin-canvas-hint {
    font-size: 0.58rem;
    color: var(--text-dim);
    letter-spacing: 0.12em;
    margin-top: var(--unit);
}

/* ============ SERVICE LIST (a11y mirror + fallback) ============ */

.twin-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr));
    gap: calc(var(--unit) * 2);
    margin-top: calc(var(--unit) * 3);
    border-top: 1px solid var(--border-0);
    padding-top: calc(var(--unit) * 3);
}

.twin-group__label {
    font-family: var(--font-mono);
    letter-spacing: 0.15em;
    font-size: 0.55rem;
    color: var(--accent-muted-text);
    margin-bottom: var(--unit);
}

.twin-group__list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.twin-chip {
    display: flex;
    align-items: center;
    gap: var(--unit);
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 5px var(--unit);
    cursor: pointer;
    font: inherit;
    color: var(--text-muted);
    text-align: left;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.twin-chip:hover {
    background: var(--surface-0);
    color: var(--text-0);
}

.twin-chip.is-selected {
    border-color: var(--accent-muted);
    background: rgba(0, 240, 255, 0.05);
    color: var(--accent);
}

.twin-chip__label {
    flex: 1;
    font-size: 0.72rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.twin-chip__state {
    font-size: 0.5rem;
    color: var(--text-dim);
    flex-shrink: 0;
}

.twin-chip.is-warn .twin-chip__state { color: var(--amber); }
.twin-chip.is-err .twin-chip__state { color: var(--err); }
.twin-chip.is-down .twin-chip__state { color: #666; }
.twin-chip.is-down .twin-chip__label { text-decoration: line-through; }

/* ============ INSPECTOR ============ */

.twin-insp__head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--unit);
    margin-bottom: var(--unit);
}

.twin-insp__name {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.twin-insp__state {
    font-size: 0.58rem;
    flex-shrink: 0;
}

.twin-insp__state.is-ok { color: var(--accent); }
.twin-insp__state.is-warn { color: var(--amber); }
.twin-insp__state.is-err { color: var(--err); }
.twin-insp__state.is-down { color: #777; }

.twin-insp__note {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.55;
    margin-bottom: calc(var(--unit) * 2);
}

.twin-spark {
    width: 100%;
    height: 40px;
    display: block;
    color: var(--accent);
    border: 1px solid var(--border-0);
    border-radius: 4px;
    background: var(--bg-1);
    margin-bottom: calc(var(--unit) * 2);
}

.twin-spark.is-warn { color: var(--amber); }
.twin-spark.is-err,
.twin-spark.is-down { color: var(--err); }

.twin-spark__label {
    font-family: var(--font-mono);
    letter-spacing: 0.12em;
    font-size: 0.52rem;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.twin-kv {
    display: grid;
    grid-template-columns: 78px 1fr;
    gap: 5px var(--unit);
    font-size: 0.68rem;
    margin-bottom: calc(var(--unit) * 2);
}

.twin-kv dt {
    font-family: var(--font-mono);
    letter-spacing: 0.1em;
    font-size: 0.55rem;
    color: var(--text-dim);
    padding-top: 2px;
}

.twin-kv dd {
    margin: 0;
    color: var(--text-muted);
    word-break: break-word;
}

.twin-kv dd.is-mono {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    color: var(--accent-muted-text);
}

/* ============ CHAOS CONSOLE ============ */

.twin-chaos {
    border-top: 1px solid var(--border-0);
    background: var(--bg-1);
    padding: calc(var(--unit) * 3) var(--pad-x);
}

.twin-chaos__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: calc(var(--unit) * 2);
    margin-bottom: calc(var(--unit) * 2);
}

.twin-chaos__title {
    font-family: var(--font-mono);
    letter-spacing: 0.15em;
    font-size: 0.62rem;
    color: var(--err);
}

.twin-chaos__hint {
    font-size: 0.72rem;
    color: var(--text-dim);
}

.twin-chaos__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
    gap: var(--unit);
}

.chaos-btn {
    display: flex;
    flex-direction: column;
    gap: 3px;
    align-items: flex-start;
    text-align: left;
    background: var(--surface-0);
    border: 1px solid var(--border-0);
    border-radius: 6px;
    padding: calc(var(--unit) * 1.5) calc(var(--unit) * 2);
    cursor: pointer;
    font: inherit;
    color: var(--text-0);
    transition: border-color 0.2s ease, background 0.2s ease;
    min-height: 44px;
}

.chaos-btn:hover {
    border-color: var(--err);
    background: rgba(255, 51, 51, 0.05);
}

.chaos-btn__name {
    font-family: var(--font-mono);
    letter-spacing: 0.1em;
    font-size: 0.62rem;
}

.chaos-btn__desc {
    font-size: 0.65rem;
    color: var(--text-dim);
    line-height: 1.4;
}

.chaos-btn--restore:hover {
    border-color: var(--ok);
    background: rgba(0, 255, 65, 0.05);
}

.chaos-btn--restore .chaos-btn__name {
    color: var(--ok);
}

/* ============ LOG ============ */

.twin-log {
    height: 260px;
    overflow-y: auto;
    background: #060606;
    border: 1px solid var(--border-0);
    border-radius: 6px;
    padding: var(--unit);
    font-family: var(--font-mono);
    font-size: 0.6rem;
    line-height: 1.65;
    letter-spacing: 0;
    scrollbar-width: thin;
}

.twin-log__line {
    display: flex;
    gap: var(--unit);
    color: var(--text-dim);
    white-space: nowrap;
}

.twin-log__t {
    color: #444;
    flex-shrink: 0;
}

.twin-log__src {
    color: var(--accent-muted-text);
    flex-shrink: 0;
    min-width: 74px;
}

.twin-log__msg {
    white-space: normal;
    word-break: break-word;
}

.twin-log__line.is-ok .twin-log__msg { color: var(--ok); }
.twin-log__line.is-warn .twin-log__msg { color: var(--amber); }
.twin-log__line.is-err .twin-log__msg { color: var(--err); }

/* ============ MOBILE ============ */

@media (max-width: 1100px) {
    .twin {
        grid-template-columns: 220px minmax(0, 1fr);
    }

    /* The inspector moves below and spans the full width rather than
       being squeezed into a third column. */
    .twin-pane--inspect {
        grid-column: 1 / -1;
    }
}

@media (max-width: 768px) {
    .twin {
        grid-template-columns: 1fr;
    }

    .twin-pane--inspect {
        grid-column: auto;
    }

    /* The canvas is decorative on a phone — the service list carries the
       same information in a form that actually fits. */
    .twin-canvas-wrap,
    .twin-canvas-hint {
        display: none;
    }

    .twin-list {
        border-top: 0;
        padding-top: 0;
        margin-top: 0;
    }

    .twin-rollup {
        gap: calc(var(--unit) * 1.5);
    }

    .twin-stat {
        min-width: 72px;
        padding-right: calc(var(--unit) * 1.5);
    }

    .twin-stat__val {
        font-size: 0.95rem;
    }

    .twin-log {
        height: 200px;
    }

    /* Chaos console sticks to the bottom so it stays reachable while
       scrolling through the service list. */
    .twin-chaos {
        position: sticky;
        bottom: 0;
        z-index: 60;
        border-top: 1px solid var(--accent-muted);
        background: rgba(10, 10, 10, 0.96);
        backdrop-filter: blur(8px);
        /* Thirteen buttons across three groups instead of nine in one
           grid, so the sticky drawer needs a little more room before it
           starts scrolling. */
        max-height: 50vh;
        overflow-y: auto;
    }

    .twin-chaos__grid {
        grid-template-columns: 1fr 1fr;
    }

    .twin-chaos__group {
        margin: calc(var(--unit) * 1.5) 0 calc(var(--unit) * 0.5);
    }

    .chaos-btn__desc {
        display: none;
    }
}

/* ============ REDUCED MOTION ============ */

@media (prefers-reduced-motion: reduce) {

    .twin-incident {
        animation: none;
    }

    /* twin.js already skips packet animation; this covers the CSS-driven
       transitions so nothing here moves either. */
    .rack-unit,
    .twin-chip,
    .chaos-btn,
    .twin-btn,
    .rack-meter .meter__fill {
        transition: none;
    }
}
