:root {
  --bg: #050805;
  --bg-panel: rgba(5, 10, 6, 0.55);
  --fg: #00ff66;
  --fg-dim: #008a3a;
  --fg-dimmer: #035a26;
  --fg-bright: #d6ffe6;
  --accent-amber: #ffae00;
  --accent-cyan: #6cf2ff;
  --warn: #ff3860;

  --glow-sm: 0 0 4px rgba(0, 255, 102, 0.55);
  --glow-md: 0 0 8px rgba(0, 255, 102, 0.45), 0 0 18px rgba(0, 255, 102, 0.22);
  --glow-lg:
    0 0 12px rgba(0, 255, 102, 0.6), 0 0 28px rgba(0, 255, 102, 0.35),
    0 0 56px rgba(0, 255, 102, 0.12);
  --glow-amber:
    0 0 6px rgba(255, 174, 0, 0.7), 0 0 14px rgba(255, 174, 0, 0.35);
  --glow-cyan:
    0 0 6px rgba(108, 242, 255, 0.85), 0 0 16px rgba(108, 242, 255, 0.45);

  --font-display: "VT323", "Courier New", ui-monospace, monospace;
  --font-body:
    "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    monospace;

  --border: rgba(0, 255, 102, 0.22);
  --border-strong: rgba(0, 255, 102, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  text-shadow: var(--glow-sm);
  -webkit-font-smoothing: antialiased;
}

/* Custom block cursor — hollow green rectangle. Authentic terminal feel
   without obscuring the underlying text. */
body {
  cursor:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='20' viewBox='0 0 14 20'><rect x='1' y='1' width='12' height='18' fill='none' stroke='%2300ff66' stroke-width='1.6' filter='drop-shadow(0 0 2px %2300ff66)'/></svg>")
    7 10,
    crosshair;
}

a,
kbd,
button,
[role="button"] {
  cursor: pointer;
}

/* ------------------------------------------------------------------ */
/* background layers                                                  */
/* ------------------------------------------------------------------ */

#bg {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  display: block;
  opacity: 0.85;
}

.scanlines {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.22) 3px,
    rgba(0, 0, 0, 0) 4px
  );
  mix-blend-mode: multiply;
}

/* SVG fractal-noise overlay — adds film grain. Sits above scanlines
   so the noise pattern blends with the dimming, not the bare canvas. */
.grain {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 4;
  pointer-events: none;
  opacity: 0.07;
  mix-blend-mode: overlay;
}

/* Diagonal amber scan line — the deliberate grid-break. Single hairline
   crossing the screen at -14°, brightest at center, fading at the edges. */
.stripe {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  overflow: hidden;
}

.stripe::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -20%;
  right: -20%;
  height: 1px;
  transform: translateY(-50%) rotate(-14deg);
  transform-origin: center;
  background: linear-gradient(
    to right,
    transparent 0%,
    rgba(255, 174, 0, 0) 12%,
    rgba(255, 174, 0, 0.55) 50%,
    rgba(255, 174, 0, 0) 88%,
    transparent 100%
  );
  box-shadow:
    0 0 6px rgba(255, 174, 0, 0.4),
    0 0 18px rgba(255, 174, 0, 0.15);
}

/* Power-on intro: a horizontal line slams in, then expands into a glow. */
.poweron {
  position: fixed;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  background: var(--fg-bright);
  box-shadow: var(--glow-lg);
  transform-origin: center;
  transform: scaleX(0);
  z-index: 5;
  pointer-events: none;
  animation: poweron 1.4s cubic-bezier(0.16, 1, 0.3, 1) 0s 1 forwards;
}

@keyframes poweron {
  0% {
    transform: scaleX(0) scaleY(1);
    opacity: 1;
  }
  35% {
    transform: scaleX(1) scaleY(1);
    opacity: 1;
  }
  70% {
    transform: scaleX(1) scaleY(140);
    opacity: 0.16;
  }
  100% {
    transform: scaleX(1) scaleY(140);
    opacity: 0;
  }
}

/* Vignette + CRT flicker. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(
    ellipse at center,
    rgba(0, 0, 0, 0) 45%,
    rgba(0, 0, 0, 0.75) 100%
  );
  animation: flicker 5s infinite steps(1);
}

@keyframes flicker {
  0%,
  93%,
  100% {
    opacity: 1;
  }
  94% {
    opacity: 0.9;
  }
  95% {
    opacity: 1;
  }
  97% {
    opacity: 0.86;
  }
  98% {
    opacity: 1;
  }
}

/* ------------------------------------------------------------------ */
/* layout                                                             */
/* ------------------------------------------------------------------ */

.console {
  position: relative;
  z-index: 1;
  isolation: isolate;
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(240px, 26vw, 320px);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "top  top"
    "main rail"
    "log  log";
  gap: 1px;
  background: var(--border);
  padding: 0;
}

.console > * {
  background: var(--bg);
}

@media (max-width: 820px) {
  .console {
    grid-template-columns: 1fr;
    grid-template-areas:
      "top"
      "main"
      "rail"
      "log";
    height: auto;
    min-height: 100vh;
    /* Both axes explicit. Setting only overflow-y here makes the browser
       silently compute overflow-x to `auto` too (per CSS overflow spec:
       when one axis is non-visible, the other can no longer be `visible`,
       so `visible` resolves to `auto`). That auto-scroll-x is what let
       the user drag the page sideways and slide the K of KUFEL off the
       left edge — even with html/body locked. */
    overflow-x: clip;
    overflow-y: auto;
  }
  html,
  body {
    overflow-x: hidden;
    overflow-y: auto;
  }
  /* Desktop deliberately lets the logo bleed past .main-col into the rail
     column (the rail's solid background occludes it). On mobile the rail
     is below, not beside, so the bleed has nowhere to go — it overflows
     the viewport and makes the page horizontally draggable. Clip it. */
  .main-col {
    overflow: hidden;
  }
  .logo-wrap {
    max-width: 100%;
  }
  /* Without min-width:0 on these grid items, their default `min-width: auto`
     resolves to their min-content (the topbar's nowrap cell text, the rail's
     widest panel min-content, and the logstrip's nowrap log lines — which
     get extra wide when decrypt.js fills them with katakana glyphs). That
     min-content forces the `1fr` track to expand past the viewport.
     min-width:0 lets the track stay at viewport width and lets the items
     clip their own overflow via their existing overflow rules. */
  .topbar,
  .rail,
  .logstrip {
    min-width: 0;
  }
}

/* ------------------------------------------------------------------ */
/* top bar                                                            */
/* ------------------------------------------------------------------ */

.topbar {
  grid-area: top;
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1.4fr);
  align-items: center;
  gap: 1.5rem;
  padding: 0.65rem clamp(0.9rem, 2.5vw, 1.5rem);
  font-family: var(--font-body);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  opacity: 0;
  animation: rise 500ms ease-out 1500ms forwards;
}

.topbar__cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  /* Isolate so a value's width change (e.g. flash text-shadow repaints, or
     a fallback-font swap during font load) can't ripple into the grid. */
  contain: layout style;
  min-width: 0;
}

.topbar__center {
  justify-content: center;
}

.topbar__right {
  justify-content: flex-end;
}

.lbl {
  color: var(--fg-dim);
  font-weight: 400;
}

.val {
  color: var(--fg);
  font-weight: 500;
}

.val--bright {
  color: var(--fg-bright);
}

.sep {
  color: var(--fg-dimmer);
}

.dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--fg);
  box-shadow: var(--glow-md);
  animation: pulse 2.2s ease-in-out infinite;
  flex-shrink: 0;
}

.dot--ok {
  background: var(--fg);
}

.dot--warn {
  background: var(--accent-amber);
  box-shadow: var(--glow-amber);
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.12);
    opacity: 0.7;
  }
}

/* ------------------------------------------------------------------ */
/* main column                                                        */
/* ------------------------------------------------------------------ */

.main-col {
  grid-area: main;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2.25rem;
  padding: clamp(1rem, 4vw, 2.75rem);
  /* visible so the logo can deliberately bleed past its column into
     the rail area — the rail's solid background occludes the overflow,
     producing a "logo continues behind the UI" grid-break. */
  overflow: visible;
  min-width: 0;
}

.logo-wrap {
  position: relative;
  width: max-content;
  max-width: none;
  opacity: 0;
  transform: translateY(8px);
  animation: rise 600ms cubic-bezier(0.16, 1, 0.3, 1) 700ms forwards;
}

.logo {
  margin: 0 0 0.6rem;
  font-family: var(--font-display);
  font-size: clamp(0.55rem, 2vw, 1.55rem);
  line-height: 1.05;
  color: var(--fg-bright);
  text-shadow: var(--glow-md);
  white-space: pre;
}

.tagline {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 2.2vw, 1.4rem);
  color: var(--fg);
  letter-spacing: 0.04em;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.45em;
}

.tagline .bracket {
  color: var(--accent-amber);
  text-shadow: var(--glow-amber);
}

.tagline .sep {
  color: var(--fg-dim);
}

.shell {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: clamp(0.85rem, 1.45vw, 0.98rem);
  font-family: var(--font-body);
}

.line {
  margin: 0;
  opacity: 0;
  transform: translateY(2px);
  animation: rise 400ms ease-out forwards;
}

.line:nth-of-type(1) {
  animation-delay: 1500ms;
}
.line:nth-of-type(2) {
  animation-delay: 1900ms;
}
.line:nth-of-type(3) {
  animation-delay: 2300ms;
}
.line:nth-of-type(4) {
  animation-delay: 2700ms;
}
.line:nth-of-type(5) {
  animation-delay: 3100ms;
}

.line.reply {
  color: var(--fg-bright);
  font-weight: 500;
}

.dim {
  color: var(--fg-dim);
  margin-right: 0.55em;
}

.cursor {
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  margin-left: 0.25em;
  vertical-align: text-bottom;
  /* Single cyan-accent use on the page: the shell cursor block. */
  background: var(--accent-cyan);
  box-shadow: var(--glow-cyan);
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  to {
    visibility: hidden;
  }
}

/* ------------------------------------------------------------------ */
/* right rail / panels                                                */
/* ------------------------------------------------------------------ */

.rail {
  grid-area: rail;
  position: relative;
  /* Stacks above .main-col so the bleed of the logo gets occluded
     by the rail's solid background — the grid-break effect. */
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border-left: 1px solid var(--border);
  overflow: hidden;
}

@media (max-width: 820px) {
  .rail {
    border-left: 0;
    border-top: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
  }
  .panel {
    flex: 1 1 calc(50% - 1px);
    /* min-width: 0 overrides the flex item default of `auto` (= min-content),
       so the panel actually honors its 50% basis instead of growing whenever
       the rx / tx value's character count crosses a format boundary. */
    min-width: 0;
  }
}

.panel {
  position: relative;
  background: var(--bg-panel);
  padding: 1rem 1.1rem;
  opacity: 0;
  transform: translateY(8px);
  animation: rise 500ms cubic-bezier(0.16, 1, 0.3, 1) var(--panel-delay, 1800ms)
    forwards;
  /* Hard layout boundary: internal stat updates (rx / tx growing, flash
     repaints, dot pulses) must not propagate into the rail's flex layout. */
  contain: layout style;
}

/* HUD corner brackets — shared with the help overlay. */
.panel::before,
.panel::after,
.helppanel::before,
.helppanel::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  border-color: var(--border-strong);
  border-style: solid;
  pointer-events: none;
}

.panel::before,
.helppanel::before {
  top: 6px;
  left: 6px;
  border-width: 1px 0 0 1px;
}

.panel::after,
.helppanel::after {
  bottom: 6px;
  right: 6px;
  border-width: 0 1px 1px 0;
}

.panel__head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.7rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px dashed var(--border);
}

.panel__head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 400;
  letter-spacing: 0.12em;
  color: var(--fg-bright);
  text-shadow: var(--glow-md);
  flex: 1;
}

.panel__tag {
  font-family: var(--font-body);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  text-transform: lowercase;
}

.kv {
  margin: 0;
  display: grid;
  /* minmax(0, 1fr) on the value column means the column never demands more
     space than the track allots — without this, when rx grows from `0b` to
     `1.45mb` the column's min-content widens, which on mobile would cascade
     into the panel's flex sizing and shuffle the row. */
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  gap: 0.35rem 0.85rem;
  align-items: baseline;
}

.kv dt {
  font-family: var(--font-body);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-dim);
}

.kv dd {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--fg-bright);
  text-shadow: var(--glow-md);
  text-align: right;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

/* Cyan-accent flash on stat update — the only place cyan glow appears
   besides the cursor. Triggered by removing/re-adding .flash in JS. */
.kv dd span.flash {
  animation: statFlash 320ms ease-out;
}

@keyframes statFlash {
  0% {
    color: var(--accent-cyan);
    text-shadow: var(--glow-cyan);
  }
  100% {
    color: var(--fg-bright);
    text-shadow: var(--glow-md);
  }
}

.bar {
  height: 0.45rem;
  background: rgba(0, 255, 102, 0.08);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.bar__fill {
  display: block;
  height: 100%;
  width: 42%;
  background: linear-gradient(
    to right,
    var(--fg-dim),
    var(--fg),
    var(--fg-bright)
  );
  box-shadow: var(--glow-sm);
  transition: width 1.2s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ------------------------------------------------------------------ */
/* log strip — multi-line tail                                        */
/* ------------------------------------------------------------------ */

.logstrip {
  grid-area: log;
  display: flex;
  align-items: stretch;
  gap: 0.85rem;
  padding: 0.55rem clamp(0.9rem, 2.5vw, 1.5rem) 0.6rem;
  border-top: 1px solid var(--border);
  font-family: var(--font-body);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: var(--fg);
  opacity: 0;
  animation: rise 500ms ease-out 2700ms forwards;
}

.logstrip__tag {
  color: var(--accent-amber);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-shadow: var(--glow-amber);
  flex-shrink: 0;
  align-self: flex-end;
}

.logstrip__feed {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-width: 0;
  height: 5.25rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
}

.log-line {
  font-family: var(--font-body);
  font-size: 0.74rem;
  line-height: 1.45;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--fg);
  transition:
    opacity 600ms ease-out,
    color 600ms ease-out;
}

.log-line:nth-last-child(1) {
  color: var(--fg-bright);
  opacity: 1;
}
.log-line:nth-last-child(2) {
  opacity: 0.6;
}
.log-line:nth-last-child(3) {
  opacity: 0.38;
}
.log-line:nth-last-child(4) {
  opacity: 0.22;
}
.log-line:nth-last-child(n + 5) {
  opacity: 0.1;
}

.logstrip__hint {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--fg-dim);
  flex-shrink: 0;
  align-self: flex-end;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4em;
  height: 1.4em;
  padding: 0 0.35em;
  border: 1px solid var(--border-strong);
  background: rgba(0, 255, 102, 0.06);
  color: var(--fg-bright);
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.04em;
}

/* ------------------------------------------------------------------ */
/* help overlay                                                       */
/* ------------------------------------------------------------------ */

.helppanel {
  position: fixed;
  bottom: 5.25rem;
  right: clamp(0.9rem, 2.5vw, 1.5rem);
  z-index: 10;
  width: 240px;
  background: var(--bg-panel);
  padding: 1rem 1.1rem;
  border: 1px solid var(--border-strong);
  opacity: 0;
  transform: translateY(8px) scale(0.96);
  transform-origin: bottom right;
  pointer-events: none;
  transition:
    opacity 240ms ease-out,
    transform 240ms cubic-bezier(0.16, 1, 0.3, 1);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.helppanel[aria-hidden="false"] {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.kv--help dd {
  font-family: var(--font-body);
  font-size: 0.78rem;
  text-align: left;
  text-shadow: none;
  color: var(--fg-bright);
  letter-spacing: 0;
}

.kv--help dd.dim {
  color: var(--fg-dim);
  margin: 0;
}

.kv--help dt {
  display: flex;
  align-items: center;
}

.helppanel__foot {
  margin: 0.75rem 0 0;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--border);
  font-size: 0.7rem;
  color: var(--fg-dim);
  font-style: italic;
}

/* ------------------------------------------------------------------ */
/* shared animations                                                  */
/* ------------------------------------------------------------------ */

@keyframes rise {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ------------------------------------------------------------------ */
/* accessibility                                                      */
/* ------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  .topbar,
  .main-col .logo-wrap,
  .line,
  .panel,
  .logstrip {
    opacity: 1;
    transform: none;
    animation: none;
  }
  .cursor,
  body::after,
  .poweron,
  .dot,
  .kv dd span.flash {
    animation: none;
  }
  .poweron {
    display: none;
  }
}
