/* =========================================================================
   hacker.css — multi-pane console

   Depends on tokens.css for spacing/radius only. Colour is deliberately NOT
   token-driven here: the console owns its own palette so it can be recoloured
   (green / amber / ice / red) independently of the site theme.
   ========================================================================= */

.hx {
    --hx-bg:   #04070A;
    --hx-fg:   #22E06B;
    --hx-dim:  color-mix(in srgb, var(--hx-fg) 46%, transparent);
    --hx-line: color-mix(in srgb, var(--hx-fg) 22%, transparent);
    --hx-warn: #FFB020;
    --hx-bad:  #FF4D6D;

    position: relative;
    background: var(--hx-bg);
    border-radius: 22px;
    overflow: hidden;
    box-shadow: var(--lift-4),
                0 0 0 1px color-mix(in srgb, var(--hx-fg) 20%, transparent),
                0 24px 80px -28px color-mix(in srgb, var(--hx-fg) 34%, transparent);
    font-family: var(--font-mono);
    color: var(--hx-fg);
}

/* --------------------------------------------------------------- chrome */

.hx-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 14px;
    background: color-mix(in srgb, var(--hx-fg) 7%, transparent);
    border-bottom: 1px solid var(--hx-line);
    font-size: 12px;
    position: relative;
    z-index: 5;
}

.hx-dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.hx-title { margin-left: 8px; color: var(--hx-dim); }
.hx-bar__right { margin-left: auto; display: flex; align-items: center; gap: 14px; color: var(--hx-dim); }

.hx-btn {
    font: inherit;
    font-size: 11px;
    letter-spacing: .06em;
    background: transparent;
    color: var(--hx-dim);
    border: 1px solid var(--hx-line);
    border-radius: 5px;
    padding: 4px 9px;
    cursor: pointer;
}
.hx-btn:hover, .hx-btn[aria-pressed="true"] { color: var(--hx-fg); border-color: var(--hx-fg); }

.hx-field { display: inline-flex; align-items: center; gap: 5px; font-size: 10px; letter-spacing: .06em; }
.hx-field select {
    font: inherit;
    font-family: var(--font-mono);
    font-size: 10px;
    background: transparent;
    color: var(--hx-fg);
    border: 1px solid var(--hx-line);
    border-radius: 5px;
    padding: 3px 4px;
    cursor: pointer;
}
.hx-field select option { background: #0b0f12; color: #d6ffe6; }

/* The toolbar carries a lot of controls now. On desktop it wraps. On a phone
   wrapping would eat the console's fixed height, and hiding the overflow buried
   the FULLSCREEN button entirely, so there it scrolls sideways instead: every
   control stays reachable and the bar height stays predictable. */
.hx-bar { flex-wrap: wrap; height: auto; min-height: 40px; padding-top: 6px; padding-bottom: 6px; }
.hx-bar__right { flex-wrap: wrap; gap: 8px; row-gap: 6px; }

@media (max-width: 820px) {
    .hx-bar {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .hx-bar::-webkit-scrollbar { display: none; }
    .hx-bar__right { flex-wrap: nowrap; }
    .hx-bar > *, .hx-bar__right > * { flex: none; }
    /* Fade on the right edge so it is obvious there is more to scroll to. */
    .hx-bar { -webkit-mask-image: linear-gradient(to right, #000 88%, transparent 100%);
              mask-image: linear-gradient(to right, #000 88%, transparent 100%); }
}

/* ---------------------------------------------------------------- panes */

.hx-grid {
    display: grid;
    grid-template-columns: 1.35fr 1fr;
    grid-template-areas:
        "boot boot"
        "term host"
        "map  stat"
        "log  log";
    gap: 1px;
    background: var(--hx-line);
    position: relative;
    z-index: 2;
}

.hx-pane { background: var(--hx-bg); padding: 12px 14px; min-width: 0; }
.hx-pane--boot { grid-area: boot; }
.hx-pane--term { grid-area: term; }
.hx-pane--host { grid-area: host; }
.hx-pane--map  { grid-area: map;  }
.hx-pane--stat { grid-area: stat; }
.hx-pane--log  { grid-area: log;  }

.hx-pane__h {
    font-size: 10px;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: var(--hx-dim);
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
}

/* Panels must NEVER resize as content arrives. Growing a pane shoves every
   panel below it down the page, which made the whole console jump on each
   keypress. Fixed height + internal scroll + min-height:0 on the grid children
   (without that, a CSS grid item refuses to shrink below its content and the
   fixed height is silently ignored). */
.hx-scroll {
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--hx-line) transparent;
}
.hx-scroll::-webkit-scrollbar { width: 6px; }
.hx-scroll::-webkit-scrollbar-thumb { background: var(--hx-line); border-radius: 3px; }
.hx-scroll::-webkit-scrollbar-track { background: transparent; }


/* The console owns a fixed viewport-relative height and every pane scrolls
   INSIDE it. Two bugs this fixes, both found by measuring rather than guessing:
     1. rows sized in px meant the console total could exceed the viewport, so
        the page scrolled and the lower panes were pushed off screen;
     2. the map and status panes had no scroll container, so `overflow:hidden`
        on the pane silently CLIPPED the node list instead of scrolling it.
   Rows are now fr units against a fixed container, so the console always fits
   and nothing is ever cut off. */
.hx { height: clamp(520px, 76vh, 780px); display: flex; flex-direction: column; }
.hx-grid {
    flex: 1;
    min-height: 0;
    /* Map row gets the most: it carries both the world art and the node strip. */
    grid-template-rows: minmax(0, 0.8fr) minmax(0, 1.3fr) minmax(0, 2fr) minmax(0, 0.65fr);
}
.hx-pane, .hx-scroll { min-height: 0; }
.hx-pane { overflow: hidden; display: flex; flex-direction: column; }

/* Every pane scrolls internally. No exceptions — that is what stopped the map
   and status panes clipping. */
.hx-pane > .hx-scroll,
.hx-pane > .hx-map,
.hx-pane > .hx-meters { flex: 1; min-height: 0; overflow-y: auto; }

/* Block cursor on the line currently being typed. */
.hx-line.typing::after {
    content: "\2588";
    margin-left: 1px;
    animation: hxCaret .8s steps(1) infinite;
}
@keyframes hxCaret { 0%,55% { opacity: 1; } 56%,100% { opacity: 0; } }

/* The "press any key" gate between acts. */
.hx-line.gate {
    color: #fff;
    background: color-mix(in srgb, var(--hx-fg) 18%, transparent);
    padding: 3px 8px;
    margin: 4px 0;
    border-left: 2px solid var(--hx-fg);
    animation: hxBlink 1.1s steps(1) infinite;
}

/* Block cursor on the line currently being typed. */

/* ---------------------------------------------------------------- lines */

.hx-line {
    font-size: 12.5px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    text-shadow: 0 0 8px color-mix(in srgb, var(--hx-fg) 45%, transparent);
}

.hx-line.banner { font-size: 11px; line-height: 1.15; white-space: pre; }
.hx-line.cmd  { color: #fff; }
.hx-line.cmd::before { content: ""; }
.hx-line.ok   { color: var(--hx-fg); font-weight: 700; }
.hx-line.dim  { color: var(--hx-dim); }
.hx-line.warn { color: var(--hx-warn); }
.hx-line.blink { animation: hxBlink 1.1s steps(1) infinite; }
@keyframes hxBlink { 0%,55% { opacity: 1; } 56%,100% { opacity: .25; } }

/* ---------------------------------------------------------------- table */

.hx-row {
    display: grid;
    grid-template-columns: 1fr .8fr 1fr 1.4fr;
    gap: 6px;
    font-size: 11.5px;
    line-height: 1.7;
}
.hx-row--head { color: var(--hx-dim); border-bottom: 1px solid var(--hx-line); }
.hx-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hx-row .ok   { color: var(--hx-fg); }
.hx-row .warn { color: var(--hx-warn); }

/* ------------------------------------------------------------------ map */

/* The map is scaled by JS to fit its pane exactly, so it must never scroll.
   line-height:0 kills the inline-block baseline gap: an inline-block reserves
   room for descenders below it, which left a couple of stray pixels of overflow
   and put the scrollbar back even once the art itself fitted. */
.hx-map { position: relative; overflow: hidden !important; line-height: 0; font-size: 0; }
/* Markers are positioned as a percentage of the MAP ART, not the pane, so the
   inner wrapper is sized by the <pre> and becomes the positioning context. */
.hx-map__inner { position: relative; display: block; max-width: 100%; }
.hx-map pre {
    margin: 0;
    line-height: 1;
    color: color-mix(in srgb, var(--hx-fg) 42%, transparent);
    white-space: pre;
    overflow: hidden;
    text-shadow: 0 0 6px color-mix(in srgb, var(--hx-fg) 30%, transparent);
}

/* Before the console is armed, say so rather than looking broken or idle. */
.hx:not(.is-armed) .hx-pane--term .hx-scroll::after {
    content: "click the console to start";
    display: block;
    color: var(--hx-dim);
    font-size: 11.5px;
    padding-top: 2px;
}
.hx.is-armed .hx-pane--term .hx-scroll::after { content: none; }

.hx-dotmark {
    position: absolute;
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--hx-line);
    transform: translate(-50%, -50%);
    transition: background .2s, box-shadow .2s;
}
.hx-dotmark.live      { background: var(--hx-fg); box-shadow: 0 0 10px 2px var(--hx-fg); }
.hx-dotmark.live.warn { background: var(--hx-warn); box-shadow: 0 0 10px 2px var(--hx-warn); }

/* The node table is a flex SIBLING of the map. Left to grow it took almost the
   whole pane and squeezed the map down to a 3px font that still overflowed.
   Pin it to a scrollable strip so the map keeps the majority of the height. */
.hx-nodes {
    flex: none;
    max-height: 84px;
    overflow-y: auto;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid var(--hx-line);
    font-size: 10px;
    line-height: 1.5;
    scrollbar-width: thin;
    scrollbar-color: var(--hx-line) transparent;
}
.hx-nodes::-webkit-scrollbar { width: 5px; }
.hx-nodes::-webkit-scrollbar-thumb { background: var(--hx-line); border-radius: 3px; }
.hx-node { display: grid; grid-template-columns: 1.1fr 1.2fr .5fr; gap: 6px; color: var(--hx-dim); }
.hx-node.live { color: var(--hx-fg); }
.hx-node.live[data-st="warn"] { color: var(--hx-warn); }

/* --------------------------------------------------------------- meters */

.hx-meter { margin-bottom: 10px; font-size: 11px; }
.hx-meter__top { display: flex; justify-content: space-between; color: var(--hx-dim); margin-bottom: 4px; }
.hx-meter__track {
    height: 8px;
    background: color-mix(in srgb, var(--hx-fg) 12%, transparent);
    border-radius: 2px;
    overflow: hidden;
}
.hx-meter__fill {
    height: 100%;
    width: 0%;
    background: var(--hx-fg);
    box-shadow: 0 0 10px var(--hx-fg);
    transition: width .35s cubic-bezier(.4,0,.2,1);
}

/* ------------------------------------------------------------ CRT layer */

.hx-scan, .hx-vig { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.hx-scan {
    background: repeating-linear-gradient(to bottom, rgba(0,0,0,.26) 0 1px, transparent 1px 3px);
}
.hx-vig {
    background: radial-gradient(120% 90% at 50% 50%, transparent 40%, rgba(0,0,0,.6) 100%);
}
.hx[data-crt="0"] .hx-scan, .hx[data-crt="0"] .hx-vig { display: none; }

/* ------------------------------------------------------------ fullscreen */

/* Square off completely in fullscreen. A rounded corner against a black bezel
   reads as a bug, and the glow has nothing to sit on once the page is gone.
   `.is-fs` is set from JS as well as the pseudo-classes, because :fullscreen
   support varies and a stale prefix here silently leaves the corners rounded. */
.hx:fullscreen,
.hx:-webkit-full-screen,
.hx:-moz-full-screen,
.hx:-ms-fullscreen,
.hx.is-fs {
    border-radius: 0;
    box-shadow: none;
    height: 100%;
    width: 100%;
    max-width: none;
}

.hx:fullscreen .hx-grid,
.hx:-webkit-full-screen .hx-grid,
.hx.is-fs .hx-grid {
    height: calc(100% - 40px);
    grid-template-rows: auto 1fr 1fr auto;
}

.hx:fullscreen .hx-scroll,
.hx:-webkit-full-screen .hx-scroll,
.hx.is-fs .hx-scroll { height: auto; }

.hx:fullscreen .hx-pane--term .hx-scroll,
.hx:fullscreen .hx-pane--host .hx-scroll,
.hx:-webkit-full-screen .hx-pane--term .hx-scroll,
.hx:-webkit-full-screen .hx-pane--host .hx-scroll,
.hx.is-fs .hx-pane--term .hx-scroll,
.hx.is-fs .hx-pane--host .hx-scroll { height: 100%; }

/* The scanline and vignette layers inherit the radius, so square them too or
   a faint curved edge survives in the corners. */
.hx:fullscreen .hx-scan, .hx:fullscreen .hx-vig,
.hx.is-fs .hx-scan, .hx.is-fs .hx-vig { border-radius: 0; }

/* ------------------------------------------------------------- responsive
   Phones get a single column, terminal first and map last. The ASCII art is
   built to ~46 columns precisely so it survives this width. */

@media (max-width: 820px) {
    .hx-grid {
        grid-template-columns: 1fr;
        /* Terminal first: it is the thing you are driving. Map last, since it
           is the tallest and the least useful on a small screen. */
        grid-template-areas: "boot" "term" "host" "stat" "map" "log";
        grid-template-rows: auto auto auto auto auto auto;
    }
                    .hx-line { font-size: 12px; }
    .hx-line.banner { font-size: 8.5px; }
    .hx-map pre { font-size: 8px; }
    .hx-row { grid-template-columns: 1fr .7fr 1fr; }
    .hx-row span:nth-child(4) { display: none; }   /* VERSION column */
    .hx-node { grid-template-columns: 1fr 1fr; }
    .hx-node span:nth-child(3) { display: none; }  /* coordinates */
}

@media (max-width: 480px) {
    .hx { border-radius: 16px; }
    .hx-pane { padding: 10px 11px; }
    .hx-bar { height: 38px; padding: 0 10px; }
    .hx-title { display: none; }
    .hx-bar__right { gap: 6px; font-size: 10px; }
    .hx-btn { padding: 4px 7px; font-size: 10px; letter-spacing: .02em; }
    .hx-line { font-size: 11.5px; }
    .hx-line.banner { font-size: 6.5px; line-height: 1.1; }
    .hx-map pre { font-size: 6.5px; }
        .hx-row { font-size: 10.5px; }
    .hx-nodes { font-size: 9.5px; }
}

/* Very narrow phones: drop the clock and the boot pane's version tag so the
   toolbar buttons stay reachable rather than wrapping. */
@media (max-width: 380px) {
    [data-clock] { display: none; }
    .hx-line.banner { font-size: 5.5px; }
}

/* Big tap target on touch devices: the whole console advances a beat. */
.hx-tap {
    position: absolute;
    inset: 40px 0 0 0;
    z-index: 3;
    display: none;
}
@media (pointer: coarse) { .hx-tap { display: block; } }

@media (prefers-reduced-motion: reduce) {
    .hx-line.blink { animation: none; }
    .hx-meter__fill { transition: none; }
}
