/* tokenteger — ransom-note design.
   Layout: full-height app frame (topbar / workspace / statusbar); the grid
   scrolls inside #viewport with an address gutter per row and a VS Code-style
   minimap rail on the right. Square corners everywhere.
   Token pieces are drawn as straight "scraps" in shades of one gold family —
   the shade steps (plus a hairline border and a gap) mark where each token
   starts and stops. Cell text is the raw digits only, so browser find (Ctrl+F)
   matches numbers like "10000"; commas and piece boundaries are CSS-only. */
:root {
  color-scheme: light;
  --page: #f3efe6;
  --surface: #fbf8f1;
  --text-primary: #171512;
  --text-secondary: #57534a;
  --text-muted: #8d8779;
  --hairline: #e0dacb;
  --baseline: #beb6a1;
  --border: rgba(23, 21, 18, 0.2);
  --chip-bg: #ece6d7;
  --accent: #c8322b;
  --gold: #f5c400;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --font-ui: var(--font-mono);
  --shadow-tooltip: 0 4px 14px rgba(23, 21, 18, 0.18);
  --gutter-w: 84px;
  --rail-w: 108px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font-ui);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- top bar ---------- */
.topbar {
  flex: none;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--baseline);
}
.topbar-inner {
  margin: 0 auto;
  width: 100%;
  padding: 8px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 28px;
}
.brand { margin-right: auto; }
.logo {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0;
}
.logo-accent {
  background: var(--text-primary);
  color: #fff;
  padding: 0 5px;
  display: inline-block;
}
.logo-rest {
  background: var(--gold);
  color: var(--text-primary);
  padding: 0 4px;
  display: inline-block;
}
.tagline {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 18px;
}
.control { display: flex; flex-direction: column; gap: 4px; }
.control-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
select, #jump-input {
  font: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--baseline);
  border-radius: 0;
  padding: 5px 8px;
}
#jump-input {
  font-family: var(--font-mono);
  font-size: 12px;
  width: 110px;
}
#jump-input::placeholder { color: var(--text-muted); }
select:focus-visible, #jump-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- workspace: scrolling grid + minimap rail ---------- */
#workspace {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
}
#viewport {
  flex: 1 1 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  position: relative;
}
.status {
  position: absolute;
  z-index: 5;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--baseline);
  box-shadow: var(--shadow-tooltip);
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}

#grid {
  position: relative;
  margin: 0 auto;
  padding: 0 12px;
}
#cells { position: absolute; left: 12px; right: 12px; top: 0; }
.row {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: stretch;
}
.row:hover { z-index: 3; }

/* address gutter — the row's first number, hex-editor style; commas are
   CSS-generated so the text content stays raw digits for browser find */
.row-label .g + .g::before { content: ","; }
.row-label {
  flex: none;
  width: var(--gutter-w);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 10px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  user-select: none;
  border-right: 1px solid var(--hairline);
  margin-right: 6px;
}

.cell {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--cell-font, 11px);
  font-variant-numeric: tabular-nums;
  margin: 1px;
  cursor: default;
  overflow: hidden;
  white-space: nowrap;
}
.cell:hover { background: var(--chip-bg); }
.cell.pending { color: var(--text-muted); }
.cell.flash { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- token pieces ----------
   Two alternating shades of the same gold plus a 2px gap — enough to make
   every token's start and stop unambiguous without visual noise. */
.tp {
  padding: 1px 3px;
  margin: 0 1px;
  font-weight: 600;
  color: var(--text-primary);
}
.tp:nth-child(odd) { background: #f2ca1d; }
.tp:nth-child(even) { background: #d9a900; }

/* ---------- minimap rail (VS Code-style document overview) ---------- */
#rail {
  flex: none;
  width: var(--rail-w);
  position: relative;
  background: var(--surface);
  border-left: 1px solid var(--hairline);
  cursor: pointer;
  user-select: none;
  touch-action: none;
}
#minimap { display: block; width: 100%; height: 100%; }
#minimap-view {
  position: absolute;
  left: 0;
  right: 0;
  border: 1px solid color-mix(in srgb, var(--text-primary) 55%, transparent);
  background: color-mix(in srgb, var(--text-primary) 14%, transparent);
  pointer-events: none;
  min-height: 12px;
}
#rail:hover #minimap-view {
  background: color-mix(in srgb, var(--text-primary) 22%, transparent);
}

@media (max-width: 760px) {
  #rail { display: none; }
  .row-label { display: none; }
}

/* ---------- hovercard (anchored to the hovered cell) ---------- */
.tooltip {
  position: fixed;
  z-index: 20;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--baseline);
  box-shadow: var(--shadow-tooltip);
  padding: 9px 11px;
  pointer-events: none;
  border-top: 3px solid var(--gold);
}
.tooltip.above {
  border-top-width: 1px;
  border-bottom: 3px solid var(--gold);
}
.tooltip-number {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-bottom: 7px;
}
.tooltip-tokens { display: flex; flex-wrap: wrap; gap: 4px; }
.token-chip {
  padding: 2px 7px;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: pre;
}
.tooltip-count {
  margin-top: 7px;
  font-size: 12px;
  color: var(--text-secondary);
}
