:root {
  --bg: #0e1015;
  --panel: #161920;
  --raised: #1d212b;
  --line: #272c38;
  --text: #e8ebf2;
  --muted: #8d95a8;
  --accent: #6ea8fe;
  --accent-dim: #2a3c5c;
  --danger: #ff8a8a;
  --radius: 7px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------------------------------------------------------------- header */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.logo { font-size: 17px; font-weight: 650; letter-spacing: .01em; }
.tag { color: var(--muted); font-size: 12px; }

.lang { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }

.head-right { display: flex; align-items: center; gap: 12px; }

.rail-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 5px 11px;
  font-size: 12px;
}
.rail-btn:hover { color: var(--text); }
.rail-btn.on { background: var(--accent-dim); border-color: #3c5580; color: #dbe7ff; }

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

/* Two collapsible rails around a single vertical column: the schema and its
   settings on top, the generated data underneath at full width. Reading down
   the page matches the order of the work. */
#shell {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 1px;
  background: var(--line);
  min-height: calc(100vh - 53px);
  align-items: stretch;
}

#palette {
  background: var(--panel);
  padding: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 53px);
  position: sticky;
  top: 0;
  width: 232px;
}
/* The palette is track 1 and main is track 2, pinned. Without pinning, hiding
   the palette (display:none) lets main flow back into the auto-sized first
   track — it collapses to its content width and leaves the right half of the
   page empty. Pinning main to track 2 keeps it full-width either way. */
#palette { grid-column: 1; }
#palette[hidden] { display: none; }

main {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--line);
  min-width: 0;
}

main > section {
  background: var(--panel);
  padding: 16px 20px;
  min-width: 0;
}

#preview-pane { flex: 1; }

h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
}

.pane-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.pane-tools { display: flex; align-items: center; gap: 10px; }
.pane-tools .hint { margin: 0; }

.toggle { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.toggle button {
  border: none;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  padding: 4px 10px;
}
.toggle button:hover { color: var(--text); background: var(--raised); }
.toggle button.on { background: var(--accent-dim); color: #dbe7ff; }

/* ---------------------------------------------------------------- controls */

input, select, button {
  font: inherit;
  color: inherit;
  background: #0f1218;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 9px;
}

input:hover, select:hover { border-color: #333a49; }

input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

button { cursor: pointer; }
button:hover { border-color: var(--accent); }

button.primary {
  background: var(--accent-dim);
  border-color: #3c5580;
  color: #dbe7ff;
  font-weight: 600;
}
button.primary:hover { background: #33507f; border-color: var(--accent); }

button.icon {
  background: none;
  border: none;
  color: var(--muted);
  padding: 2px 6px;
  line-height: 1;
  font-size: 15px;
  border-radius: 5px;
}
button.icon:hover { color: var(--text); background: var(--raised); }

/* ---------------------------------------------------------------- palette */

#search { width: 100%; margin-bottom: 8px; }

.legend {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  margin: 0 0 10px;
  font-size: 11px;
  color: var(--muted);
}
.legend .dot { margin-left: 4px; }
.legend .dot:first-child { margin-left: 0; }

.group-name {
  margin: 12px 0 3px;
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: #6e768a;
}

.type {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 4px 7px;
  border-radius: 5px;
}
.type:hover { background: var(--raised); border-color: transparent; }

.dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 7px;
  background: #39404f;
  vertical-align: middle;
}
.type.localized .dot, .dot.on { background: var(--accent); }

.palette-hint { margin: 10px 0 12px; font-size: 11px; line-height: 1.45; }

/* Collapsed category groups. The full catalog stays reachable without being
   the first thing anyone sees. */
#types details { border-top: 1px solid var(--line); }
#types details > summary {
  list-style: none;
  cursor: pointer;
  padding: 7px 4px;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6e768a;
  user-select: none;
}
#types details > summary::-webkit-details-marker { display: none; }
#types details > summary::before {
  content: '›';
  display: inline-block;
  width: 12px;
  color: #4d5566;
  transition: transform .12s ease;
}
#types details[open] > summary::before { transform: rotate(90deg); }
#types details > summary:hover { color: var(--text); }
#types details[open] > summary { color: var(--text); }
#types details > .type { padding-left: 18px; }

/* ---------------------------------------------------------------- builder */

.settings {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.settings label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); }
.settings { align-items: flex-end; }
.settings input, .settings select { width: 132px; }
.settings-actions { display: flex; gap: 8px; margin-left: auto; }
.settings .seed input { width: 96px; border-color: var(--accent-dim); }
.seed-row { display: flex; gap: 4px; align-items: center; }

.hint { color: var(--muted); font-size: 12px; margin: 6px 0 14px; max-width: 62ch; }

#fields { width: 100%; border-collapse: collapse; }
#fields th {
  text-align: left;
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6e768a;
  padding: 0 6px 6px 0;
}
#fields td { padding: 3px 6px 3px 0; vertical-align: middle; }
#fields td:last-child, #fields th:last-child { padding-right: 0; width: 1%; }
#fields input, #fields select { width: 100%; }
#fields td.order { width: 1%; white-space: nowrap; }
#fields td.opts-cell { width: 1%; white-space: nowrap; }

.opts-button {
  font: inherit; font-size: 12px; color: var(--muted);
  background: transparent; border: 1px dashed #3a4055; border-radius: 6px;
  padding: 5px 12px; cursor: pointer; white-space: nowrap;
}
.opts-button:hover { border-color: #566; color: #cfd6e6; }
.opts-button.has-options { border-style: solid; border-color: #4b7bec; color: #9fb8ff; }

/* Column settings dialog. */
#colSettings {
  border: 1px solid #2a3040; border-radius: 12px; padding: 0;
  background: #161a24; color: inherit; min-width: 320px; max-width: 420px;
}
#colSettings::backdrop { background: rgba(6, 8, 14, .6); }
#colSettings header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid #232838;
}
#colSettings h2 { margin: 0; font-size: 14px; font-weight: 600; }
#colSettingsBody { padding: 12px 16px; display: grid; gap: 10px; }
#colSettings footer { padding: 12px 16px; border-top: 1px solid #232838; text-align: right; }
.setting { display: grid; grid-template-columns: 1fr 150px; align-items: center; gap: 12px; }
.setting > span { font-size: 13px; color: var(--muted); }
.setting input, .setting select { width: 100%; }

#add { margin-top: 10px; }

/* Generate button: the spinner takes up its space even when idle, so the label
   does not jump sideways the moment the run starts. */
#generate { display: inline-flex; align-items: center; gap: 7px; }
#generate .spinner {
  width: 12px; height: 12px; flex: none;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%;
  opacity: 0;
}
#generate.busy .spinner { opacity: .8; animation: spin .7s linear infinite; }
#generate:disabled { opacity: .7; cursor: progress; }

@keyframes spin { to { transform: rotate(360deg); } }

/* Someone who set prefers-reduced-motion asked not to be spun at. The button
   still reads "Generating…" and stays disabled, so nothing is lost. */
@media (prefers-reduced-motion: reduce) {
  #generate.busy .spinner { animation: none; }
}

.gen-status { margin-top: 8px; color: #9fb8ff; }

/* ---------------------------------------------------------------- preview */

#error {
  background: #2a1618;
  border: 1px solid #5a2a2e;
  color: var(--danger);
  padding: 9px 11px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  font-size: 13px;
}

/* Stacked layout: one record per block, fields down the page. Readable at any
   width, and it does not lose the right-hand columns off the edge. */
.record {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: #0f1218;
}
.record-head {
  padding: 5px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6e768a;
}
.record dl { margin: 0; padding: 6px 12px 8px; }
.record dl > div {
  display: grid;
  grid-template-columns: minmax(90px, 30%) 1fr;
  gap: 10px;
  padding: 3px 0;
  border-bottom: 1px solid #1b1f28;
}
.record dl > div:last-child { border-bottom: none; }
.record dt { color: var(--muted); font-size: 12px; }
.record dd {
  margin: 0;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.table-scroll { overflow-x: auto; }
table.rows { border-collapse: collapse; width: 100%; font-size: 12px; }
table.rows th, table.rows td {
  border-bottom: 1px solid var(--line);
  padding: 5px 9px;
  text-align: left;
  white-space: nowrap;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.rows th {
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--panel);
}
table.rows tr:hover td { background: var(--raised); }

pre.yaml {
  background: #0f1218;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  overflow: auto;
  font-size: 12px;
}

/* ---------------------------------------------------------------- toast */

#toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--raised);
  border: 1px solid var(--accent-dim);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .45);
}

/* ---------------------------------------------------------------- narrow

   Three breakpoints, each for a real failure rather than a round number:
   1100px is where the palette stops fitting beside the work area, 900px is
   where the schema table's five columns start truncating their inputs, and
   620px is a phone. Below 900px the table becomes stacked cards, because a
   horizontally scrolling table of form controls cannot be filled in with a
   thumb. */

@media (max-width: 1100px) {
  /* Collapse to one column: the palette stops being a sticky sidebar and sits
     above the work area. Both children share the single track. */
  #shell { grid-template-columns: 1fr; }
  #palette { grid-column: 1; width: auto; position: static; max-height: 42vh; }
  main { grid-column: 1; }
  main > section { max-height: none; }
}

@media (max-width: 900px) {
  header { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .settings { flex-wrap: wrap; }
  .settings label { flex: 1 1 130px; }

  /* The schema table becomes one card per column. A five-column table of
     inputs at this width leaves every field too narrow to read. */
  #fields, #fields tbody, #fields tr, #fields td { display: block; width: 100%; }
  #fields thead { display: none; }
  #fields tr {
    border: 1px solid var(--line); border-radius: var(--radius);
    padding: 10px; margin-bottom: 10px; background: var(--panel);
    display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  }
  #fields td { padding: 0; }
  #fields td.order { grid-row: 1; grid-column: 2; width: auto; }
  #fields td:nth-child(2) { grid-row: 1; grid-column: 1; }
  #fields td:nth-child(3) { grid-row: 2; grid-column: 1 / -1; }
  #fields td.opts-cell { grid-row: 3; grid-column: 1; width: auto; }
  #fields td:last-child { grid-row: 3; grid-column: 2; text-align: right; }
  .opts-button { width: 100%; }
}

@media (max-width: 620px) {
  header { padding: 8px 12px; }
  .tag { display: none; }               /* the tagline is the first thing to go */
  main > section { padding: 12px; }
  .settings label { flex: 1 1 100%; }
  .settings input, .settings select { width: 100%; }
  /* Stop pinning the actions to the right once things wrap — let them sit on
     their own full-width row so the buttons stay finger-sized. */
  .settings-actions { margin-left: 0; width: 100%; flex-wrap: wrap; }
  #colSettings { min-width: 0; width: calc(100vw - 24px); }
  .setting { grid-template-columns: 1fr; gap: 4px; }
  #preview table { font-size: 11px; }
}

/* A wide table must scroll inside its own pane, never the page. */
#preview { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Static build only. */
.wasm-note {
  padding: 7px 20px;
  background: #16233a;
  border-bottom: 1px solid #26334d;
  color: #9fb8ff;
  font-size: 12px;
}
.wasm-note a { color: #cfe0ff; }
