:root {
  --bg: #1e1e2e;
  --surface: #181825;
  --surface2: #11111b;
  --text: #cdd6f4;
  --subtext: #a6adc8;
  --muted: #6c7086;
  --blue: #89b4fa;
  --green: #a6e3a1;
  --red: #f38ba8;
  --yellow: #f9e2af;
  --mauve: #cba6f7;
  --peach: #fab387;
  --teal: #94e2d5;
  --border: #313244;
  --highlight: rgba(137, 180, 250, 0.15);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  /* Belt-and-braces: never let a stray wide element open up a page-level
     horizontal scrollbar. Wide tables get their own internal scrolling. */
  overflow-x: hidden;
}

/* Top bar is hidden on desktop; the sidebar shows its own h1 in-place. */
.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 10;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.topbar h1 {
  color: var(--blue);
  font-size: 1em;
  margin: 0;
}
.nav-toggle {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 1.1em;
  padding: 6px 10px;
  border-radius: 4px;
  font-weight: 400;
}

#app {
  display: grid;
  grid-template-columns: 220px 1fr;
  height: 100vh;
}

nav.side {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  overflow-y: auto;
}
nav.side h1 {
  color: var(--blue);
  font-size: 1.0em;
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
nav.side .group {
  color: var(--muted);
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 16px 16px 4px;
}
nav.side a {
  display: block;
  padding: 8px 16px;
  color: var(--subtext);
  text-decoration: none;
  border-left: 3px solid transparent;
}
nav.side a:hover { background: var(--highlight); color: var(--text); }
nav.side a.active {
  color: var(--blue);
  border-left-color: var(--blue);
  background: var(--highlight);
}

/* Sidebar disk widget — auto-polled free-space chips with red
   highlight when any mount drops under the 10 GB low_free threshold,
   plus one-click cleanup buttons for the recurring offenders. */
.disk-widget {
  margin-top: 24px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.disk-widget-title {
  color: var(--muted);
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}
.disk-row { margin-bottom: 6px; }
.disk-row-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.78em;
  color: var(--subtext);
  margin-bottom: 2px;
}
.disk-row .disk-label { color: var(--text); }
.disk-row .disk-free { color: var(--subtext); }
.disk-row.low .disk-label,
.disk-row.low .disk-free { color: var(--red); font-weight: 600; }
.disk-bar {
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
}
.disk-bar-used {
  height: 100%;
  background: var(--subtext);
  transition: width 0.3s ease;
}
.disk-row.low .disk-bar-used { background: var(--red); }
.disk-cleanups { margin-top: 10px; }
.disk-cleanups-head {
  color: var(--muted);
  font-size: 0.7em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}
.disk-clean-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  text-align: left;
  background: var(--surface2);
  color: var(--subtext);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  margin-bottom: 4px;
  cursor: pointer;
  font-size: 0.75em;
  font-family: inherit;
}
.disk-clean-btn:hover {
  background: var(--highlight);
  color: var(--text);
  border-color: var(--subtext);
}
.disk-clean-btn .disk-clean-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 6px;
}
.disk-clean-btn .disk-clean-size {
  color: var(--muted);
  flex-shrink: 0;
}
.disk-clean-btn[data-busy="1"] {
  opacity: 0.6;
  cursor: progress;
}
/* Scan-discovered cargo targets get a subtle accent so they read as
   distinct from the always-present static actions. */
.disk-clean-btn.scanned {
  border-left: 2px solid var(--accent, var(--subtext));
}
.disk-scan { margin-top: 10px; }
.disk-offender {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72em;
  color: var(--subtext);
  padding: 2px 0;
}
.disk-offender-path {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 6px;
}
.disk-offender-size {
  color: var(--muted);
  flex-shrink: 0;
}
.disk-status {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.7em;
  font-style: italic;
  word-break: break-word;
}
.disk-empty {
  color: var(--muted);
  font-size: 0.78em;
}

main {
  padding: 16px 24px;
  overflow-y: auto;
  /* Allow the main grid cell to shrink below its content's natural width so
     wide tables/grids inside don't force horizontal page overflow. */
  min-width: 0;
}
main h2 {
  color: var(--mauve);
  font-size: 1.1em;
  margin-bottom: 16px;
}
main h3 {
  color: var(--blue);
  font-size: 0.95em;
  margin: 16px 0 8px;
}

input[type="text"], textarea, select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.9em;
  border-radius: 4px;
  outline: none;
}
input[type="text"]:focus, textarea:focus, select:focus { border-color: var(--blue); }

button {
  background: var(--blue);
  color: var(--bg);
  border: none;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 0.85em;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.subtle {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 400;
}
button.subtle:hover { border-color: var(--blue); color: var(--blue); }

.row { display: flex; gap: 8px; align-items: center; }
.row > input[type="text"], .row > select { flex: 1; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
  /* Let panels participate in shrinkable grid/flex parents without forcing
     horizontal overflow from wide inner content. */
  min-width: 0;
  /* Wide tables (training/checkpoints/evals/RL) overflow the panel; the
     panel scrolls horizontally instead of pushing the page. Tables remain
     `display: table` so `width: 100%` actually stretches them to fill the
     panel when content fits. */
  overflow-x: auto;
}

.log {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 0.85em;
  white-space: pre-wrap;
  overflow-y: auto;
  min-height: 200px;
  max-height: 50vh;
  color: var(--subtext);
}
.log .ok { color: var(--green); }
.log .err { color: var(--red); }
.log .cmd { color: var(--blue); }
.log .meta { color: var(--muted); font-size: 0.8em; }

.tree {
  font-size: 0.85em;
  white-space: pre;
  color: var(--text);
  background: var(--surface2);
  border-radius: 4px;
  padding: 8px 12px;
  overflow-x: auto;
}

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; font-size: 0.85em; }
.kv .k { color: var(--muted); }
.kv .v { color: var(--text); }

.pill {
  display: inline-block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.75em;
  color: var(--subtext);
  margin-right: 4px;
}
.pill.ok { color: var(--green); border-color: var(--green); }
.pill.err { color: var(--red); border-color: var(--red); }
.pill.warn { color: var(--peach, #fab387); border-color: var(--peach, #fab387); }
.pill.badtool { color: var(--mauve, #cba6f7); border-color: var(--mauve, #cba6f7); }
.pill.run {
  color: var(--yellow); border-color: var(--yellow);
  animation: rl-pulse 1.5s ease-in-out infinite;
}
@keyframes rl-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

/* Tables stretch to fill their parent (panel) with `width: 100%`. When
   content overflows, the parent panel's `overflow-x: auto` provides the
   scroll — keeping tables as `display: table` preserves the natural
   stretch-to-fill behavior of table layout. */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85em;
}
th, td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  /* Keep cells on a single line; horizontal scroll handles the overflow.
     This also makes long paths in <code> cells readable instead of wrapping
     into vertical ribbons. */
  white-space: nowrap;
}
/* `<code>` cells inside tables still soft-wrap if they hold a single token
   longer than the viewport — better than freezing the scroll axis. */
td code, td a code { word-break: normal; }
th { color: var(--muted); font-weight: 400; }
tr:hover td { background: var(--highlight); }

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* RL live panel — tighter, monospace numbers, no row hover noise. */
.rl-tbl { font-size: 0.82em; }
.rl-tbl td.num, .rl-tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.rl-tbl tbody tr:hover td { background: transparent; }
.rl-tbl tfoot td { border-top: 1px solid var(--border); padding-top: 4px; }

/* Session summary strip — eight named stats in a responsive grid. */
.rl-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px 14px;
  margin-bottom: 10px;
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.rl-stat-k {
  font-size: 0.72em;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}
.rl-stat-v {
  font-size: 0.95em;
  font-variant-numeric: tabular-nums;
}
.rl-laststep {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px 12px;
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85em;
}
.rl-laststep-fields { display: flex; flex-wrap: wrap; gap: 4px; }
.rl-trained-tasks { margin-top: 4px; }
.rl-trained-tasks > summary {
  cursor: pointer;
  color: var(--muted);
  user-select: none;
}
.rl-trained-tasks > summary:hover { color: var(--text); }
.rl-trained-tasks-tbl {
  width: 100%;
  margin-top: 4px;
  border-collapse: collapse;
  font-size: 0.82em;
  font-variant-numeric: tabular-nums;
}
.rl-trained-tasks-tbl th,
.rl-trained-tasks-tbl td {
  padding: 2px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.rl-trained-tasks-tbl th {
  font-weight: 600;
  font-size: 0.92em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.rl-trained-tasks-tbl tr.muted { color: var(--muted); }
.rl-trained-tasks-tbl code { font-size: 0.95em; }

/* Training process bars: two side-by-side progress meters above the
   stats strip — one for time-to-next-step, one for overall-dataset
   progress. Stacks on narrow widths so the strip stays readable. */
.rl-progress-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
@media (max-width: 720px) {
  .rl-progress-row { grid-template-columns: 1fr; }
}
.rl-progress {
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.rl-progress-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 0.85em;
  font-variant-numeric: tabular-nums;
}
.rl-progress-label {
  font-size: 0.72em;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.rl-progress-count { white-space: nowrap; }
.rl-progress-track {
  position: relative;
  height: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.rl-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--mauve));
  transition: width 0.5s ease;
}
.rl-progress-step .rl-progress-fill {
  background: linear-gradient(90deg, var(--teal), var(--blue));
}
.rl-progress-overall .rl-progress-fill {
  background: linear-gradient(90deg, var(--mauve), var(--peach));
}
.rl-progress-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.rl-progress-foot-cell {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.1;
}
.rl-progress-foot-cell:last-child {
  align-items: flex-end;
}
.rl-progress-foot-cell:nth-child(2) {
  align-items: center;
  flex: 1;
}
.rl-progress-foot-k {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.65em;
  letter-spacing: 0.05em;
}
.rl-progress-foot-v {
  font-size: 0.85em;
}

/* Training-row inspector — mirrors inspect_training_row.py's ANSI scheme. */
.tok-content { background: rgba(166, 227, 161, 0.25); color: var(--green); }
.tok-sep     { background: rgba(249, 226, 175, 0.20); color: var(--yellow); }
.tok-special { background: rgba(243, 139, 168, 0.25); color: var(--red); }
.tok-unsup   { color: var(--muted); }
.tok-content, .tok-sep, .tok-special { border-radius: 2px; padding: 0 1px; }

button.subtle.active {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--highlight);
}

/* Modal overlay used by the per-checkpoint Eval form (and any future
   transient dialog). Click outside the card or the × to dismiss.
   The card itself caps at 88vh and scrolls internally so the close button
   stays reachable on short viewports. */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 17, 27, 0.7);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 12px;
  /* Honor mobile safe-area insets so the card never lands under a notch. */
  padding-top: max(6vh, env(safe-area-inset-top));
  padding-bottom: max(6vh, env(safe-area-inset-bottom));
  z-index: 100;
  overflow-y: auto;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
  width: min(640px, 100%);
  max-width: 100%;
  /* Cap card height + scroll internally so wide eval/download tables don't
     push the close button off-screen. */
  max-height: calc(100vh - 12vh);
  overflow: auto;
  /* Anchor children in a column so a future sticky header/footer is possible
     without affecting current single-block layouts. */
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.modal-card h3 { margin: 0; color: var(--mauve); }
/* Tables inside modals (download progress, eval params) get their own scroll
   so the surrounding card's controls stay aligned. */
.modal-card table { max-width: 100%; }
/* The k/v summary at the top of modals shouldn't keep the 160px first column
   on narrow phones — it pushes the value <input> off-canvas. */
.modal-card .kv { grid-template-columns: minmax(120px, 160px) 1fr; }

/* Rollout-trace viewer: a roomy overlay built specifically for replaying
   a single RL rollout. Wider + taller than the generic modal-card so the
   bubble transcript has space to breathe. Backdrop click dismisses. */
.rl-trace-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 17, 27, 0.75);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 4vh 4vw;
  padding-top: max(4vh, env(safe-area-inset-top));
  padding-bottom: max(4vh, env(safe-area-inset-bottom));
  z-index: 110;
}
.rl-trace-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  width: min(1100px, 100%);
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  min-height: 0;
}

/* Eval params form — labels in muted, inputs flex. The first column is
   capped on the high side so labels don't crowd the value column on
   narrow desktop windows or in a modal. */
.eval-params-form .kv {
  grid-template-columns: minmax(140px, 220px) 1fr;
}
.eval-params-form .kv .v {
  /* Lets the input shrink rather than push the column wider. */
  min-width: 0;
}
.eval-params-form .kv .v input[type="text"],
.eval-params-form .kv .v input[type="number"] {
  max-width: 100%;
}
.eval-params-form .kv .v input[type="checkbox"] {
  transform: scale(1.1);
  vertical-align: middle;
}
.eval-params-form details { margin-bottom: 8px; }
.eval-params-form summary:hover { color: var(--text); }

/* Datasets rows-table: expandable long cells. `min()` keeps the cell from
   hogging the whole viewport on phones (where the table self-scrolls) while
   still giving comfortable 520px on desktop. */
#ins_tbl td {
  vertical-align: top;
  max-width: min(520px, 70vw);
  /* Inspector cells hold soft-wrappable JSON previews; the global td nowrap
     would otherwise force horizontal overflow even for short rows. */
  white-space: normal;
}
#ins_tbl code { word-break: break-word; white-space: pre-wrap; }
.cell-expand { cursor: pointer; }
.cell-expand summary {
  list-style: none;
  cursor: pointer;
}
.cell-expand summary::-webkit-details-marker { display: none; }
.cell-expand summary::before {
  content: "▸ ";
  color: var(--blue);
}
.cell-expand[open] summary::before { content: "▾ "; }
.cell-expand pre {
  margin-top: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px;
  max-height: 60vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.85em;
  color: var(--text);
}

/* ------------------------------------------------------------------ tablet */
/* Wide screens (>720) keep the sidebar but at landscape-tablet sizes the
   inline two-column dashboards (home, lib) feel cramped. Collapse those
   specifically before phones kick in. */
@media (max-width: 960px) {
  /* Inline grids defined via style="grid-template-columns: …" lose their
     fixed left columns at tablet sizes. Captures lib_view (380px 1fr) and
     home_view (1fr 1fr) without touching CSS in the JS templates. */
  main [style*="grid-template-columns: 380px 1fr"],
  main [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

/* ------------------------------------------------------------------ phones */
/* Phones / small tablets: collapsible drawer nav, stacked form rows,
   horizontally scrollable tables, larger tap targets.

   Breakpoint at 720px so portrait tablets still get the side rail; below
   that the layout flips to single-column with a top bar. */
@media (max-width: 720px) {
  body { font-size: 13px; }
  .topbar { display: flex; }
  #app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }
  /* Off-canvas drawer; slides in when .open is set. */
  nav.side {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 240px;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    padding-top: calc(16px + env(safe-area-inset-top));
    box-shadow: 0 0 18px rgba(0, 0, 0, 0.5);
  }
  nav.side.open { transform: translateX(0); }
  nav.side h1 { display: none; }  /* the topbar shows the title instead */

  main {
    padding: 12px;
    overflow-y: visible;
  }
  main h2 { font-size: 1em; margin-bottom: 12px; }
  main h3 { font-size: 0.9em; }

  /* Form rows stack so inputs aren't crammed side-by-side. !important is
     unfortunately required because many input rows carry inline
     `style="flex: 0 0 NNNpx"` that would otherwise pin the input to a
     fixed width and overflow narrow viewports. */
  .row {
    flex-wrap: wrap;
    gap: 6px;
  }
  .row > input[type="text"],
  .row > input[type="number"],
  .row > input[type="password"],
  .row > select,
  .row > textarea {
    flex: 1 1 100% !important;
    min-width: 0 !important;
    /* Some inline styles also pin width: drop those at phone sizes so
       inputs (e.g. interactive_view's `flex: 0 0 200px`) actually expand. */
    width: 100%;
  }
  /* Stand-alone <input style="width:NNNpx"> outside a .row (datasets train
     pane) should still respect their inline width since they're meant to
     pack into a flex-wrap row. No override here. */

  /* Tighter panel padding so phones aren't all chrome. */
  .panel { padding: 10px; }

  /* Buttons get a beefier hit area. */
  button {
    padding: 8px 14px;
    font-size: 0.95em;
  }
  .nav-toggle { padding: 8px 12px; }

  /* The kv grid loses its fixed left column. Specificity bump via .panel
     wraps the eval-params-form override that desktop sets to 220px. */
  .kv,
  .eval-params-form .kv,
  .modal-card .kv {
    grid-template-columns: 1fr;
  }
  .kv .k { color: var(--muted); }

  /* The log pane and the tree blocks shouldn't blow past the viewport. */
  .log, .tree, .cell-expand pre {
    max-height: 50vh;
    font-size: 12px;
  }

  /* Modals: tighten padding so phones aren't wasting half their viewport
     on overlay padding, and let cards fill the available space. */
  .modal-overlay {
    padding: 4vh 8px;
    padding-top: max(2vh, env(safe-area-inset-top));
    padding-bottom: max(2vh, env(safe-area-inset-bottom));
  }
  .modal-card {
    padding: 12px 14px;
    max-height: calc(100vh - 4vh);
  }
  .rl-trace-overlay {
    padding: 2vh 6px;
    padding-top: max(2vh, env(safe-area-inset-top));
    padding-bottom: max(2vh, env(safe-area-inset-bottom));
  }
  .rl-trace-modal { padding: 12px; }
}

/* ── RL live-params subsection ──────────────────────────────────────
   Hot-reloadable config knobs. Each chip wraps one key's widget +
   Apply button. Class color-coding matches the trainer's reload
   classification so an operator can spot at a glance whether an edit
   will land immediately vs at the next group boundary.
*/
.rl-params-chips {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.rl-param-chip {
  display: flex; flex-direction: column; gap: 4px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 0.85em;
}
.rl-param-key { display: flex; gap: 6px; align-items: baseline; }
.rl-param-key code { font-size: 0.92em; }
.rl-param-row { display: flex; gap: 6px; align-items: center; }
.rl-param-class {
  font-size: 0.7em;
  padding: 1px 6px;
  border-radius: 8px;
  color: var(--muted);
  border: 1px solid var(--border);
  background: var(--surface2);
}
.rl-param-class-immediate    { color: #2a8;  border-color: #2a830; }
.rl-param-class-next_rollout { color: #4ad;  border-color: #4ad30; }
.rl-param-class-next_group   { color: #d9a;  border-color: #d9a30; }
.rl-param-class-via_setter   { color: #8b8;  border-color: #8b830; }
.rl-param-class-startup_only { color: #888;  border-color: var(--border); }
.rl-param-apply.err { color: #d33; border-color: #d33; }
.rl-params-raw {
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.rl-params-raw textarea {
  width: 100%; box-sizing: border-box;
  font: 12px/1.4 var(--mono, monospace);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 6px 8px;
}
.rl-params-error {
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid #d33; color: #d33;
  border-radius: 4px; font-size: 0.85em;
}
.rl-params-log { width: 100%; font-size: 0.82em; }
.rl-params-log td {
  padding: 2px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.rl-params-log td.rl-params-log-ts {
  color: var(--muted); font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ----------------------------------------------------------- narrow phones */
/* Tighter packing for very small phones (iPhone SE-class). */
@media (max-width: 400px) {
  main { padding: 8px; }
  .panel { padding: 8px; margin-bottom: 8px; }
  table th, table td { padding: 4px 8px; }
  /* Eval params form's first column would still claim ~140px otherwise;
     stack on truly narrow screens. */
  .eval-params-form .kv { grid-template-columns: 1fr; }
  .modal-card { padding: 10px 12px; }
}

/* --------------------------------------------------------------------------
   Self-play view: KPIs, tabs, library/citation/proposals tables, spawn tree.
   -------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 12px;
}
.card h2 { margin-top: 0; }

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  margin: 8px 0;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
}
.kpi-label { color: var(--muted); font-size: 0.8em; }
.kpi-value { font-size: 1.1em; font-weight: 600; margin-top: 2px; }
.kpi-sub { color: var(--muted); font-size: 0.78em; margin-top: 2px; }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.tab {
  background: transparent;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 0.9em;
  color: var(--muted);
}
.tab.active {
  background: var(--surface);
  color: var(--text);
  border-bottom: 1px solid var(--surface);
  margin-bottom: -1px;
}
.tab-panel { padding: 8px 0; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85em;
}
.data-table th, .data-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.data-table th { color: var(--muted); font-weight: 500; }

.tier-pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  color: white;
  font-size: 0.78em;
}

.chart-host {
  margin-bottom: 12px;
  min-height: 200px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  align-items: end;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85em;
  color: var(--muted);
}
.form-grid label input, .form-grid label select { font-size: 0.9em; }
.form-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.muted { color: var(--muted); }
.error { color: var(--red, #c33); }

