/* "Glass cockpit" style, after the mesh_viewer theme (mesh_tools/mesh_viewer/src/ui/theme.cpp)
   and fkimmerle.de: black panels, 1px gray borders, no rounding, dense, one monospace font.
   Color only with meaning: cyan = action / focus, green = value / readout,
   yellow = keyboard focus / alert. Accounts get their own colors (magenta, amber, ...). */

@font-face {
  font-family: "Ioskeley Mono";
  src: url("fonts/ioskeley-mono-regular.woff2") format("woff2");
  font-display: swap;
  /* Not for arrows (U+2190-21FF), the ellipsis (U+2026) and geometric shapes
     (U+25A0-25FF): this font draws them two cells wide on a one-cell advance, so
     they run into the next character. Those come from the fallback monospace. */
  unicode-range: U+0020-007E, U+00A0-017F, U+2010-2025, U+2027-203A, U+20AC, U+2122, U+2212, U+2500-259F;
}

:root {
  color-scheme: dark;
  --black: #080808;
  --bg-dim: #0d0d0d;
  --gray-dark: #1f1f1f;
  --gray-mid: #404040;
  --gray-light: #666666;
  --tab: #4d4d4d;
  --text: #ffffff;
  --dim: #808080;          /* on black only (5.1:1); on gray panels use --dim-on-panel */
  --dim-on-panel: #999999;  /* 5.8:1 on --gray-dark */
  --action: #00ffff;
  --action-dim: #005959;
  --action-mid: #008085;
  --action-trans: rgba(0, 255, 255, 0.3);
  --toggle-on: #00616b;
  --value: #00ff00;
  --alert: #ffff00;
  --error: #ff7366;
  --link: #8cbfff;

  --mono: "Ioskeley Mono", ui-monospace, "DejaVu Sans Mono", Menlo, Consolas, monospace;
  --hud-h: 124px;
}

* { box-sizing: border-box; }
html { scrollbar-color: var(--gray-mid) var(--black); }
body {
  margin: 0;
  background: var(--black);
  color: var(--text);
  font: 13px/1.4 var(--mono);
  font-synthesis: none;
}
::selection { background: var(--action-trans); }
:focus-visible { outline: 2px solid var(--alert); outline-offset: 0; }
[hidden] { display: none !important; }
h1, h2, h3 { font-weight: normal; font-size: inherit; margin: 0; }

button {
  font: inherit; color: var(--text);
  background: var(--gray-dark); border: 1px solid var(--gray-mid); border-radius: 0;
  padding: 1px 0.8ch; cursor: pointer; white-space: nowrap;
}
button:hover { background: var(--action-dim); }
button:active { background: var(--action-mid); }
button[aria-pressed="true"] { background: var(--toggle-on); }
button[aria-pressed="true"]:hover { background: var(--action-mid); }
button[aria-pressed="false"], button .dim { color: var(--dim-on-panel); }
button:disabled { color: var(--gray-light); background: var(--black); cursor: default; }

.dim { color: var(--dim); }
.val { color: var(--value); }
.key { color: var(--action); }
.sw { display: inline-block; width: 8px; height: 8px; background: var(--c); margin-right: 0.6ch; vertical-align: 0; }
button[aria-pressed="false"] .sw { opacity: 0.35; }

/* Tab like a docked ImGui window: gray, cyan overline. */
.tab {
  display: inline-block; padding: 3px 1ch 1px; background: var(--tab);
  box-shadow: inset 0 3px 0 var(--action); white-space: nowrap;
}

/* ---------- menu bar ---------- */
.menubar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: stretch;
  background: var(--black); border-bottom: 1px solid var(--gray-mid);
}
.menubar > *, .menubar .filters > * { padding: 4px 1ch; border-right: 1px solid var(--gray-mid); display: flex; align-items: center; gap: 0.6ch; }
/* TYPE + CAROUSEL: part of the single row on wide screens, their own swipeable row on phones */
.menubar .filters { display: contents; }
.menubar h1 { letter-spacing: 0.12em; text-transform: uppercase; }
.menubar .lbl { color: var(--dim); margin-right: 0.4ch; }
.hud-head .stat { color: var(--dim); }
/* user menu, far right */
.usermenu { margin-left: auto; border-left: 1px solid var(--gray-mid); border-right: 0 !important; padding: 0 !important; position: relative; }
#menu-btn { border: 0; height: 100%; padding: 4px 1ch; background: var(--black); }
#menu-btn:hover, #menu-btn[aria-expanded="true"] { background: var(--action-dim); }
.um-panel {
  position: absolute; z-index: 40; right: -1px; top: calc(100% + 1px); min-width: 22ch;
  display: flex; flex-direction: column; background: var(--black); border: 1px solid var(--action);
  box-shadow: 0 0 0 1px var(--black), 0 12px 40px rgba(0,0,0,.7);
}
.um-panel button { border: 0; border-bottom: 1px solid var(--gray-dark); background: var(--black); text-align: left; padding: 4px 1ch; width: 100%; }
.um-panel button:hover { background: var(--action-dim); }
.um-panel form { margin: 0; }
.menubar form { margin: 0; }
.menubar .group { flex-wrap: wrap; }

/* ---------- timeline ---------- */
#timeline { padding: 6px 8px calc(var(--hud-h) + 40px); }
.year {
  display: flex; align-items: baseline; gap: 2ch; flex-wrap: wrap;
  margin: 22px 0 6px; padding-top: 4px; border-top: 1px solid var(--gray-mid);
}
.year:first-child { margin-top: 6px; }
.year h2 { font-size: 26px; line-height: 1; letter-spacing: 0.04em; }
.counts { display: flex; gap: 1.5ch; flex-wrap: wrap; color: var(--dim); }
.counts b { font-weight: normal; color: var(--c, var(--value)); }

.month {
  border: 1px solid var(--gray-mid); margin-bottom: 6px;
  background: linear-gradient(var(--gray-mid), var(--gray-mid)) 0 21px / 100% 1px no-repeat, var(--black);
}
.month-head { display: flex; align-items: flex-start; gap: 2ch; height: 22px; }
.month-head .tab { height: 21px; }
.month-head .counts { padding-top: 3px; }
.grid {
  display: grid; gap: 4px; padding: 6px;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
}
.tile {
  position: relative; display: block; aspect-ratio: 1; padding: 0; overflow: hidden;
  border: 1px solid var(--gray-mid); background: var(--gray-dark);
}
.tile:hover { border-color: var(--action); background: var(--gray-dark); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .acc { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--c); }
.tile .tag, .tile .cnt {
  position: absolute; top: 3px; padding: 0 0.5ch; font-size: 11px; line-height: 15px;
  background: rgba(8, 8, 8, 0.8); border: 1px solid var(--gray-mid); color: var(--text);
}
.tile .tag { left: 3px; text-transform: uppercase; }
.tile .cnt { right: 3px; }
.tile .none { display: grid; place-items: center; height: 100%; color: var(--dim); }
.tile.here { border-color: var(--value); }
/* split carousels: a band along the top joins the tiles of one carousel,
   reaching across the grid gap; neighbouring carousels alternate white / gray */
.grid { --gap: 4px; }
.tile.grp { overflow: visible; }
.tile.grp img { overflow: hidden; }
.tile .band { position: absolute; z-index: 1; top: -1px; left: -1px; right: -1px; height: 4px; background: var(--band); }
.tile.grp:not(.grp-last) .band { right: calc(-1px - var(--gap) - 1px); }
.tile.grp-a { --band: var(--text); }
.tile.grp-b { --band: var(--dim); }
.tile.grp .cnt { top: 6px; }
.tile.grp .tag { top: 6px; }
.empty { padding: 60px 1ch; color: var(--dim); text-align: center; }
.empty code { color: var(--action); }

/* ---------- HUD: the time tape ---------- */
.hud {
  position: fixed; z-index: 30; left: 50%; bottom: 10px; transform: translateX(-50%);
  width: min(1180px, calc(100vw - 20px)); height: var(--hud-h);
  display: flex; flex-direction: column;
  background: rgba(8, 8, 8, 0.78); backdrop-filter: blur(10px) saturate(1.2);
  border: 1px solid var(--gray-mid); box-shadow: 0 0 0 1px var(--black), 0 8px 30px rgba(0, 0, 0, 0.6);
}
.hud-head {
  display: flex; align-items: stretch; height: 22px; flex: none;
  border-bottom: 1px solid var(--gray-mid);
}
.hud-head > * {
  display: flex; align-items: center; gap: 0.6ch; padding: 0 1ch; border-right: 1px solid var(--gray-mid);
  white-space: nowrap; flex: none;            /* readouts never wrap or shrink */
}
.hud-head .tab { padding-top: 2px; }
.hud-head .rng { margin-left: auto; border-left: 1px solid var(--gray-mid); gap: 0; padding: 0; border-right: 0; }
.hud-head .rng button { border: 0; border-left: 1px solid var(--gray-mid); height: 100%; }
.hud-head .hint { color: var(--dim); flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; display: block; line-height: 21px; }
.hud-head .stat { display: block; line-height: 21px; }   /* one line of text, not flex items */
.hud-head #hud-hover:empty { display: none; }
@media (max-width: 1100px) { .hud-head .hint { display: none; } }
#tape { flex: 1; display: block; width: 100%; min-height: 0; cursor: grab; touch-action: none; }
#tape.drag { cursor: grabbing; }

.peek {
  position: absolute; bottom: calc(100% + 6px); z-index: 31; pointer-events: auto;
  background: var(--black); border: 1px solid var(--action); padding: 4px;
  display: flex; flex-direction: column; gap: 4px; transform: translateX(-50%);
  max-width: calc(100vw - 20px);
}
.peek-row { display: flex; gap: 4px; }
.peek-row button { padding: 0; width: 64px; height: 64px; border: 1px solid var(--gray-mid); position: relative; overflow: hidden; }
.peek-row button:hover { border-color: var(--action); }
.peek-row img { width: 100%; height: 100%; object-fit: cover; display: block; }
.peek-row .acc { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--c); }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, 0.95);
  display: grid; grid-template-columns: minmax(0, 1fr) 380px;
}
.lb-stage { position: relative; display: grid; place-items: center; padding: 12px; min-width: 0; min-height: 0; }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: calc(100vh - 24px); display: block; border: 1px solid var(--gray-mid); background: #000; }
.lb-step { position: absolute; top: 50%; transform: translateY(-50%); width: 30px; height: 56px; background: rgba(8, 8, 8, 0.7); }
.lb-step.prev { left: 12px; } .lb-step.next { right: 12px; }
.lb-dots { position: absolute; bottom: 18px; display: flex; gap: 3px; }
.lb-dots span { width: 14px; height: 3px; background: var(--gray-mid); }
.lb-dots span.on { background: var(--action); }

.lb-info {
  border-left: 1px solid var(--gray-mid); background: var(--black);
  display: flex; flex-direction: column; min-height: 0;
}
.lb-info .head { display: flex; border-bottom: 1px solid var(--gray-mid); height: 22px; flex: none; }
.lb-info .head .tab { height: 21px; }
.lb-info .head .tab { margin-right: auto; }
.lb-info .head button { border: 0; border-left: 1px solid var(--gray-mid); }
.lb-body { overflow-y: auto; padding: 8px 1ch; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.kv { display: grid; grid-template-columns: 9ch 1fr; gap: 2px 1ch; margin: 0; }
.kv dt { color: var(--dim); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.who { display: flex; align-items: center; gap: 1ch; }
.who img, .who .av { width: 40px; height: 40px; border: 1px solid var(--c); object-fit: cover; flex: none; }
.who .av { display: grid; place-items: center; background: var(--gray-dark); color: var(--c); font-size: 18px; }
.who .name { color: var(--c); }
.section-title { color: var(--dim); border-bottom: 1px solid var(--gray-dark); padding-bottom: 2px; }
.caption { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.lb-nav { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--gray-mid); flex: none; }
.lb-nav button { border: 0; padding: 6px; }
.lb-nav button + button { border-left: 1px solid var(--gray-mid); }
.keys { color: var(--dim); padding: 4px 1ch 6px; flex: none; }

/* ---------- login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(340px, 100%); border: 1px solid var(--gray-mid); background: var(--black); }
.login .head { border-bottom: 1px solid var(--gray-mid); height: 22px; }
.login .head .tab { height: 21px; }
.login .body { padding: 10px 1ch 12px; display: flex; flex-direction: column; gap: 8px; }
.login label { color: var(--dim); }
.login input {
  font: inherit; color: var(--text); background: var(--gray-dark);
  border: 1px solid var(--gray-mid); border-radius: 0; padding: 4px 0.8ch; caret-color: var(--action);
}
.login input:hover { background: var(--action-dim); }
.login input:focus { outline: 0; border-color: var(--action); background: var(--gray-dark); }
.login button { padding: 4px; }
.login .stack { display: flex; flex-direction: column; gap: 8px; }
.login p { margin: 0; }
.error { color: var(--error); margin: 0; }

/* ---------- account picker ---------- */
.picker { position: relative; padding: 0 !important; }
#acct-btn { border: 0; height: 100%; padding: 4px 1ch; background: var(--black); display: flex; align-items: center; gap: 0.5ch; }
#acct-btn:hover, #acct-btn[aria-expanded="true"] { background: var(--action-dim); }
#acct-btn .sw { margin: 0; }
.pk-panel {
  position: absolute; z-index: 40; top: calc(100% + 1px); left: -1px; width: min(460px, calc(100vw - 16px));
  background: var(--black); border: 1px solid var(--action); box-shadow: 0 0 0 1px var(--black), 0 12px 40px rgba(0,0,0,.7);
  display: flex; flex-direction: column; max-height: min(70vh, 640px);
}
.pk-head { display: flex; border-bottom: 1px solid var(--gray-mid); }
.pk-head input { flex: 1; min-width: 0; border: 0; background: var(--gray-dark); }
.pk-head button { border: 0; border-left: 1px solid var(--gray-mid); }
.pk-list { overflow-y: auto; padding: 4px 0; }
.pk-person, .pk-acct { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 0 1ch; padding: 1px 1ch; }
.pk-person { margin-top: 6px; border-top: 1px solid var(--gray-dark); padding-top: 4px; }
.pk-person:first-child { margin-top: 0; border-top: 0; }
.pk-person .pk-name { text-transform: uppercase; letter-spacing: 0.06em; }
.pk-acct { padding-left: 3ch; grid-template-columns: 1fr auto auto; }
.pk-toggle { border: 0; background: none; text-align: left; padding: 1px 0.5ch; }
.pk-toggle:hover { background: var(--action-dim); }
.pk-toggle[aria-pressed="true"], .pk-toggle[aria-pressed="mixed"] { background: none; color: var(--text); }
.pk-toggle[aria-pressed="false"] { color: var(--dim); }
.pk-only { padding: 0 0.6ch; font-size: 11px; visibility: hidden; }
.pk-person:hover .pk-only, .pk-acct:hover .pk-only { visibility: visible; }
.pk-foot { border-top: 1px solid var(--gray-mid); padding: 3px 1ch; font-size: 11px; }
.pk-none { padding: 8px 1ch; margin: 0; }

/* ---------- panels (upload, my accounts, admin) ---------- */
.overlay { position: fixed; inset: 0; z-index: 110; background: rgba(0,0,0,.8); display: grid; place-items: start center; padding: 6vh 10px 10px; overflow-y: auto; }
.sheet { width: min(820px, 100%); border: 1px solid var(--gray-mid); background: var(--black); box-shadow: 0 0 0 1px var(--black); }
.sheet .head { display: flex; height: 22px; border-bottom: 1px solid var(--gray-mid); }
.sheet .head .tab { height: 21px; margin-right: auto; }
.sheet .head button { border: 0; border-left: 1px solid var(--gray-mid); }
.sheet-body { padding: 8px 1ch 14px; display: flex; flex-direction: column; gap: 8px; }
.sheet-body p { margin: 0; }
.sheet-body .section-title { margin-top: 10px; }
.steps { margin: 0; padding-left: 3ch; display: flex; flex-direction: column; gap: 4px; color: var(--dim); }
.steps b { font-weight: normal; color: var(--text); }
.steps b.val { color: var(--value); }
.sheet input:not([type="checkbox"]):not([type="radio"]) {
  font: inherit; color: var(--text); background: var(--gray-dark); border: 1px solid var(--gray-mid);
  border-radius: 0; padding: 2px 0.8ch; caret-color: var(--action);
}
.sheet input:focus { outline: 0; border-color: var(--action); }
.sheet input[type="number"] { width: 7ch; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--toggle-on); margin: 0 0.6ch 0 0; vertical-align: -1px; }
input[type="file"] { color: var(--dim); }
input[type="file"]::file-selector-button { font: inherit; color: var(--text); background: var(--gray-dark); border: 1px solid var(--gray-mid); padding: 2px 1ch; margin-right: 1ch; cursor: pointer; }
input[type="file"]::file-selector-button:hover { background: var(--action-dim); }
.form-grid { display: grid; grid-template-columns: 16ch 1fr; gap: 3px 1ch; align-items: baseline; }
.form-col { display: flex; flex-direction: column; gap: 4px; max-width: 40ch; }
.check { white-space: nowrap; cursor: pointer; }
.people { display: flex; flex-wrap: wrap; gap: 3px 2ch; padding-left: 17ch; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 1ch; }
.actions input { flex: 1; min-width: 16ch; }
.bar { height: 6px; border: 1px solid var(--gray-mid); background: var(--black); }
.bar > div { height: 100%; width: 0; background: var(--value); }
.warn { color: var(--alert); }
button.danger:hover { background: #5a1f1a; }
.toast {
  position: fixed; z-index: 140; top: 44px; left: 50%; transform: translateX(-50%); max-width: calc(100vw - 20px);
  background: rgba(8, 8, 8, 0.9); backdrop-filter: blur(10px); border: 1px solid var(--action);
  padding: 4px 1.2ch; color: var(--text); box-shadow: 0 8px 30px rgba(0,0,0,.6);
}
.ask-overlay { z-index: 130; place-items: center; padding: 10px; }
.sheet.ask { width: min(460px, 100%); border-color: var(--action); }
.ask #ask-text { color: var(--text); }
.ask input { width: 100%; }
button.danger-on { background: #5a1f1a; }
button.danger-on:hover { background: #7a2a22; }
.tbl { border-collapse: collapse; width: 100%; }
.tbl th { text-align: left; font-weight: normal; color: var(--dim); background: var(--gray-dark); padding: 1px 1ch; }
.tbl td { padding: 1px 1ch; border-top: 1px solid #262626; }
.tbl td:last-child { text-align: right; }
.tbl .row-person td { border-top: 1px solid var(--gray-mid); padding-top: 4px; }
.acct-card { border: 1px solid var(--gray-mid); padding: 0 1ch 8px; display: flex; flex-direction: column; gap: 8px; }
.linkish { font: inherit; }

/* ---------- help page ---------- */
.navlink { color: var(--text); text-decoration: none; }
a.navlink:hover { background: var(--action-dim); }
.doc { max-width: 860px; margin: 0 auto; padding: 10px 8px 40px; display: flex; flex-direction: column; gap: 8px; }
.docpanel {
  border: 1px solid var(--gray-mid); padding: 0 1ch 10px;
  background: linear-gradient(var(--gray-mid), var(--gray-mid)) 0 21px / 100% 1px no-repeat, var(--black);
  display: flex; flex-direction: column; gap: 8px;
}
.docpanel h2.tab { margin-left: -1ch; align-self: flex-start; height: 22px; font-size: inherit; }
.docpanel p { margin: 0; }
.doc code { color: var(--action); }
.doc a { color: var(--link); }
.kv-wide { grid-template-columns: 11ch 1fr; gap: 6px 1ch; }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  :root { --hud-h: 112px; }
  /* row 1: name | ACCT ▾ | user ▾ — row 2: filters, swipe sideways instead of wrapping */
  .menubar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; }
  .menubar h1, .menubar .picker, .menubar .usermenu { grid-row: 1; }
  .menubar .usermenu { grid-column: 3; margin-left: 0; }
  .menubar .picker { border-right: 0; }
  .menubar .filters {
    display: flex; grid-column: 1 / -1; grid-row: 2; padding: 0; border-right: 0;
    border-top: 1px solid var(--gray-mid); overflow-x: auto; scrollbar-width: none;
  }
  .menubar .filters::-webkit-scrollbar { display: none; }
  .menubar .filters.more { mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); }
  .menubar .filters > * { flex: none; flex-wrap: nowrap; white-space: nowrap; }
  .hud { bottom: 0; width: 100vw; border-left: 0; border-right: 0; }
  .hud-head .hint, .hud-head .stat { display: none; }
  .hud-head > * { padding: 0 0.6ch; }
  .hud-head .rng button { padding: 0 0.6ch; }
  #timeline { padding: 4px 2px calc(var(--hud-h) + 24px); }
  .grid { grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 2px; --gap: 2px; }
  .lightbox { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .lb-stage { padding: 0; }
  .lb-stage img, .lb-stage video { max-height: 62vh; border: 0; }
  .lb-info { border-left: 0; border-top: 1px solid var(--gray-mid); }
  .keys { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .dim, .form-grid span:not(.check) { padding-left: 3ch; margin-bottom: 4px; }
  .people { padding-left: 3ch; }
  .overlay { padding: 0; }
  .pk-panel { position: fixed; top: 32px; left: 8px; }
  .pk-only { visibility: visible; }
}
