/* TSDB Format Explorer — "engineer's bench" theme.
   Night mode is the native look (dark like the hex tooling it descends from);
   day mode swaps every token for a light-tuned variant. Color is semantic
   either way: every hue names a field kind, identical across all formats.
   The night field colors are ~Material 200–300 pastels (contrast against
   near-black); day uses the same hues at ~700–800 depth (contrast on white).
   JS resolves the day/night/system preference to data-theme="light|dark" on
   <html>; an inline head script does it pre-paint to avoid a flash.

   Neither this app nor github.com/lamida/probably loads a webfont (no
   @font-face, no Google Fonts link), so a named font like "Avenir Next"
   only renders for visitors who happen to have it installed -- in practice
   it silently falls back to the OS's native UI font, which differs by
   platform. Both apps' font stacks are kept textually identical, OS-native
   font first, so the two sibling apps under apps.lamida.org actually look
   the same on a given machine instead of just naming different fonts. */

:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #10151b;
  --panel: #161d25;
  --panel-2: #1b232d;
  --line: #2a3542;
  --ink: #dbe4ec;
  --ink-dim: #8fa0b0;
  --strong-ink: #ffffff;       /* text on highlighted/selected surfaces */
  --torch: #e6522c;            /* Prometheus orange, accents only */

  --k-magic: #b39ddb;
  --k-meta: #90a4ae;
  --k-len: #ffca28;
  --k-count: #4db6ac;
  --k-ref: #64b5f6;
  --k-time: #81c784;
  --k-value: #ffb74d;
  --k-string: #f48fb1;
  --k-crc: #e57373;
  --k-pad: #546e7a;
  --k-group: #78909c;

  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, monospace;
  --sans: ui-sans-serif, system-ui, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f4f6;
  --panel: #ffffff;
  --panel-2: #e8edf2;
  --line: #d4dce3;
  --ink: #1e2a35;
  --ink-dim: #5c6e7d;
  --strong-ink: #0b1218;
  --torch: #d13c17;            /* deepened for contrast on light */

  --k-magic: #6642a8;
  --k-meta: #52676f;
  --k-len: #7d6300;
  --k-count: #00695c;
  --k-ref: #1259a6;
  --k-time: #2e6b31;
  --k-value: #b45309;
  --k-string: #b0246e;
  --k-crc: #bb2020;
  --k-pad: #6d838f;
  --k-group: #54697a;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition: none !important; } }

body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 15.5px; line-height: 1.55;
  display: grid; grid-template-columns: 250px 1fr; min-height: 100vh;
}
a { color: var(--k-ref); }
code { font-family: var(--mono); font-size: 0.88em; background: var(--panel-2); padding: 1px 5px; border-radius: 3px; }
h1, h2 { font-weight: 700; letter-spacing: -0.01em; }

/* --- nav: the data directory --- */
#nav {
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 22px 16px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand {
  display: block; font-weight: 800; font-size: 17px; line-height: 1.2;
  color: var(--ink); text-decoration: none; margin-bottom: 22px; letter-spacing: 0.02em;
}
.brand .flame { color: var(--torch); }
.navdir { font-family: var(--mono); font-size: 12.5px; }
.navdir > a, .navdir > span { display: block; padding: 3px 6px; white-space: nowrap; }
.navplain { color: var(--ink-dim); }
.navlink { color: var(--ink); text-decoration: none; border-radius: 4px; }
.navlink:hover { background: var(--panel-2); }
.navlink.current { background: var(--panel-2); box-shadow: inset 2px 0 0 var(--torch); color: var(--strong-ink); }
.navlink.extra { margin-top: 16px; font-family: var(--sans); font-size: 13.5px; }
.navfoot { margin-top: 26px; font-size: 11.5px; color: var(--ink-dim); line-height: 1.6; }
.navfoot code { font-size: 10.5px; }
.themetoggle {
  display: flex; gap: 2px; margin-top: 18px;
  border: 1px solid var(--line); border-radius: 6px; padding: 2px;
  background: var(--bg); width: fit-content;
}
.themetoggle button {
  border: 0; background: none; color: var(--ink-dim); cursor: pointer;
  font-family: var(--mono); font-size: 10.5px; padding: 4px 8px; border-radius: 4px;
}
.themetoggle button:hover { color: var(--ink); }
.themetoggle button[aria-pressed="true"] {
  background: var(--panel-2); color: var(--strong-ink);
  box-shadow: inset 0 0 0 1px var(--line);
}
.navcredit {
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--ink-dim); line-height: 1.7;
}
.navcredit a { color: var(--ink); text-decoration: none; }
.navcredit a:hover { color: var(--torch); }

/* --- main --- */
/* margin: 0 auto centers the column inside the 1fr grid track so leftover
   space on ultra-wide viewports splits evenly either side instead of
   collecting as one dead slab on the right (nav is fixed-width, so without
   this #app just hugs it and the rest of a wide monitor sits empty). */
#app { padding: 34px 44px 80px; max-width: 1200px; margin: 0 auto; }
@media (min-width: 1600px) {
  #app { max-width: 1440px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .lens { grid-template-columns: minmax(430px, 40%) 1fr; }
}
.eyebrow {
  font-family: var(--mono); font-size: 11.5px; text-transform: uppercase;
  letter-spacing: 0.14em; color: var(--torch); margin-bottom: 8px;
}
.hero h1, .pagehead h1 { font-size: 40px; margin: 0 0 14px; line-height: 1.08; }
.lede { max-width: 62ch; color: var(--ink-dim); font-size: 17px; }
.intro { max-width: 72ch; }
.intro p, .intro li { color: var(--ink); }
h2 { font-size: 20px; margin: 34px 0 10px; }

/* overview cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-top: 30px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 16px 18px; text-decoration: none; color: var(--ink);
  transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: var(--torch); transform: translateY(-2px); }
.card h2 { margin: 6px 0 8px; font-size: 19px; }
.card-file { font-family: var(--mono); font-size: 11px; color: var(--ink-dim); }
.card-size { font-family: var(--mono); font-size: 11.5px; color: var(--torch); }
.card-extra { border-style: dashed; }
.lifecycle ol { max-width: 68ch; }
.lifecycle li { margin: 6px 0; }

/* overflow-wrap: captions embed raw series notation like
   go_goroutines{instance="localhost:9090",job="prometheus"} -- one
   unbroken run with no spaces. Without this, the browser can't wrap it,
   the box grows to fit that single "word", and drags the whole
   single-column mobile layout wider than the viewport with it. */
.caption { color: var(--ink-dim); max-width: 78ch; margin-top: -2px; overflow-wrap: anywhere; }
.notes ul { max-width: 80ch; padding-left: 20px; }
.notes li { margin: 8px 0; }
.srcfoot { margin-top: 40px; color: var(--ink-dim); font-size: 13px; }

/* --- chunk encoding toggle (Chunks page) --- */
.enctoggle-row { margin: 10px 0 2px; }
.enctoggle {
  display: inline-flex; flex-wrap: wrap; gap: 2px;
  border: 1px solid var(--line); border-radius: 6px; padding: 2px;
  background: var(--panel);
}
.enctoggle button {
  border: 0; background: none; color: var(--ink-dim); cursor: pointer;
  font-family: var(--mono); font-size: 11.5px; padding: 5px 10px; border-radius: 4px;
  white-space: nowrap;
}
.enctoggle button:hover { color: var(--ink); }
.enctoggle button[aria-pressed="true"] {
  background: var(--panel-2); color: var(--strong-ink);
  box-shadow: inset 0 0 0 1px var(--line);
}

/* --- legend --- */
/* flex-wrap alone doesn't help on desktop: #app is wide enough (up to 1200-1440px)
   that all ten kind labels fit on one packed row, which reads as cramped rather
   than as a legend. Mobile already looks fine because its narrower viewport
   forces a natural wrap. Capping the legend's own width forces the same
   multi-line wrap at desktop widths too, without touching mobile (where the
   viewport is already narrower than this cap, so it's a no-op there). 480px
   specifically splits the ten kinds 5-and-5 -- a wider cap (620px) let 7 fit
   on the first row and stranded a sparse 3 on the second, which still read
   as lopsided/cramped rather than as a legibly wrapped legend. */
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin: 12px 0; max-width: 480px; }
.lg { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11.5px; color: var(--ink-dim); }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* semantic kind colors */
.k-magic { --kc: var(--k-magic); } .k-meta { --kc: var(--k-meta); }
.k-len { --kc: var(--k-len); } .k-count { --kc: var(--k-count); }
.k-ref { --kc: var(--k-ref); } .k-time { --kc: var(--k-time); }
.k-value { --kc: var(--k-value); } .k-string { --kc: var(--k-string); }
.k-crc { --kc: var(--k-crc); } .k-pad { --kc: var(--k-pad); }
.k-group { --kc: var(--k-group); }
.sw, .dot, .seg { background: color-mix(in srgb, var(--kc) 30%, var(--panel)); border: 1px solid var(--kc); }

/* --- section map --- */
/* Every segment is sized to its own label and the row wraps as many times as
   that needs -- see the comment in lens.ts for why this stopped being a
   single proportional bar. */
.secmap { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.seg {
  flex: 0 1 auto; border-radius: 4px; min-width: 0; padding: 0 10px; height: 34px;
  cursor: pointer; font-family: var(--mono); font-size: 10.5px; color: var(--ink);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.seg:hover { background: color-mix(in srgb, var(--kc) 55%, var(--panel)); }
.seg span { overflow: hidden; text-overflow: ellipsis; display: block; }

/* --- the lens --- */
.lens { display: grid; grid-template-columns: minmax(430px, 46%) 1fr; gap: 16px; align-items: start; }
.lens-hex {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; max-height: 640px; overflow: auto; -webkit-overflow-scrolling: touch;
}
.hexgrid { font-family: var(--mono); font-size: 12.5px; line-height: 1.75; }
.hexrow { white-space: nowrap; }
.off { color: var(--ink-dim); margin-right: 12px; user-select: none; }
.byte {
  display: inline-block; width: 24px; text-align: center; border-radius: 3px;
  color: var(--kc, var(--ink)); cursor: pointer; margin-right: 1px;
}
.byte.packed { text-decoration: underline dotted; text-underline-offset: 3px; }
.byte:hover { outline: 1px solid var(--kc); }
.byte.hl, .ach.hl { background: color-mix(in srgb, var(--kc, #fff) 28%, transparent); color: var(--strong-ink); }
.byte.empty { cursor: default; }
.ascii { margin-left: 14px; color: var(--ink-dim); }
.ach { display: inline-block; width: 8.5px; text-align: center; }

/* tree */
.lens-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.tree {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 8px; max-height: 480px; overflow: auto; -webkit-overflow-scrolling: touch;
  font-family: var(--mono); font-size: 12px;
}
.tkids { margin-left: 16px; border-left: 1px solid var(--line); padding-left: 4px; }
.tnode.collapsed > .tkids { display: none; }
.trow {
  display: flex; align-items: center; gap: 6px; padding: 2px 6px;
  border-radius: 4px; cursor: pointer; white-space: nowrap;
}
.trow:hover { background: var(--panel-2); }
.trow.active { background: var(--panel-2); box-shadow: inset 2px 0 0 var(--torch); }
.twist { width: 10px; cursor: pointer; user-select: none; flex: none; }
.twist::before { content: '▾'; color: var(--ink-dim); font-size: 10px; }
.tnode.collapsed > .trow .twist::before { content: '▸'; }
.twist-spacer { width: 10px; flex: none; }
.dot { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.tname { overflow: hidden; text-overflow: ellipsis; }
.ttype { color: var(--ink-dim); background: none; padding: 0; font-size: 11px; }
.tsize { margin-left: auto; color: var(--ink-dim); font-size: 10.5px; flex: none; }

/* detail panel */
.detail {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; min-height: 118px; font-size: 13.5px;
}
.detail-empty { color: var(--ink-dim); font-style: italic; }
.d-crumbs {
  font-family: var(--mono); font-size: 10.5px; color: var(--ink-dim); margin-bottom: 6px;
  overflow-wrap: anywhere;
}
.d-crumbs .sep { color: var(--torch); }
/* min-width: 0 lets a flex item shrink below its content's intrinsic width --
   without it, a long unbroken series name (e.g. a metric + label-set string
   with no spaces) forces the item, and the .detail box around it, wider than
   the viewport instead of wrapping. overflow-wrap breaks the text itself once
   it's allowed to shrink. */
.d-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.d-title strong { min-width: 0; overflow-wrap: anywhere; }
.d-type { color: var(--ink-dim); min-width: 0; overflow-wrap: anywhere; }
.chip {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  padding: 1px 7px; border-radius: 10px; border: 1px solid var(--kc);
  color: var(--kc); background: color-mix(in srgb, var(--kc) 12%, transparent);
}
.d-meta { font-family: var(--mono); font-size: 11.5px; color: var(--ink-dim); margin: 4px 0; }
.d-value { font-family: var(--mono); font-size: 12.5px; color: var(--strong-ink); margin: 6px 0; word-break: break-all; }
.d-bits code { word-break: break-all; }
.d-note { color: var(--ink-dim); margin-top: 6px; max-width: 60ch; overflow-wrap: anywhere; }

/* --- meta.json page --- */
.metajson { font-family: var(--mono); font-size: 13px; line-height: 1.8; white-space: pre; }
.jno { color: var(--ink-dim); margin-right: 14px; user-select: none; }
.jline { border-radius: 4px; padding: 0 6px; }
.jline.has-note { cursor: pointer; }
.jline.has-note:hover { background: var(--panel-2); }
.jline.active { background: var(--panel-2); box-shadow: inset 2px 0 0 var(--torch); }

/* --- primitives page --- */
.prim { max-width: 76ch; margin-bottom: 8px; }
.enc { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin: 10px 0 26px; }
.enc label { font-family: var(--mono); font-size: 12.5px; color: var(--ink-dim); margin-right: 14px; }
.enc input {
  background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 5px;
  font-family: var(--mono); font-size: 13.5px; padding: 6px 9px; width: 200px;
}
.enc input:focus { outline: 2px solid var(--torch); border-color: transparent; }
.enc-out { margin-top: 12px; font-family: var(--mono); font-size: 13px; }
.obyte {
  display: inline-block; background: var(--bg); border: 1px solid var(--line); border-radius: 5px;
  padding: 5px 8px; margin: 2px 6px 2px 0; letter-spacing: 0.05em;
}
.obyte .cont { color: var(--torch); font-weight: 700; }
.obyte .ohex { color: var(--ink-dim); margin-left: 8px; }
.obits { display: inline-block; background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 5px 9px; letter-spacing: 0.08em; word-break: break-all; }
.obits b { color: var(--torch); }
.obits .dim { color: var(--ink-dim); }
.olabel { color: var(--ink-dim); font-size: 11.5px; margin-top: 6px; }
.btable { border-collapse: collapse; font-size: 13.5px; margin: 8px 0; }
.btable th, .btable td { border: 1px solid var(--line); padding: 4px 12px; text-align: left; }
.btable th { color: var(--ink-dim); font-weight: 600; }

/* focus visibility */
a:focus-visible, button:focus-visible, .hexgrid:focus-visible { outline: 2px solid var(--torch); outline-offset: 2px; }

/* responsive */
@media (max-width: 1080px) {
  .lens { grid-template-columns: minmax(0, 1fr); }
  .lens-hex { max-height: 380px; }
}
@media (max-width: 800px) {
  /* The map already wraps at every width; a phone just needs the longest
     section names clamped so one of them can't drag a row past the viewport
     (they ellipse instead, with the full name still on the title tooltip). */
  .seg { min-width: 84px; max-width: 47%; height: 32px; }
  /* minmax(0, 1fr), not bare 1fr: a plain 1fr track still grows to fit its
     item's min-content (e.g. the section-map's un-wrappable segment labels,
     or the nav's un-wrappable directory paths), which silently widens the
     whole page past the viewport. minmax(0, ...) caps that floor at 0. */
  body { grid-template-columns: minmax(0, 1fr); }
  #nav { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  /* #app normally centers via max-width + margin: 0 auto, which sizes it to
     content (fit-content) rather than the viewport -- fine on desktop where
     content is narrower than the cap, but on mobile the same overflowing
     content just drags #app wider than the screen instead of being
     clamped. Pin it to the track's full, already-viewport-safe width. */
  #app { padding: 22px 18px 60px; width: 100%; max-width: none; margin: 0; }
  .hero h1, .pagehead h1 { font-size: 30px; }
  /* Fewer bytes fit per screenful at phone widths; shrinking the hex cells
     a bit keeps the horizontal scroll (unavoidable for a 16-byte hex dump)
     shorter rather than forcing it on desktop-sized cells. */
  .hexgrid { font-size: 11.5px; }
  .byte { width: 20px; }
}
@media (max-width: 480px) {
  #app { padding: 18px 14px 48px; }
  .hero h1, .pagehead h1 { font-size: 25px; }
  .hexgrid { font-size: 10.5px; }
  .byte { width: 18px; }
  .ascii { margin-left: 8px; }
}
