/* Schreibwerkstatt on the terminal theme.
 *
 * Every upstream rule is scoped to .sw (stated in app.css:1), and nearly every
 * colour goes through a custom property, so remapping those properties recolours
 * the whole widget without touching the vendored stylesheet.
 *
 * Served by the plugin at /schreibwerkstatt/theme.css, after app.css.
 */

/* app.css declares its palette three times: on `.sw`, on `:root[data-theme="dark"]
 * .sw`, and on `:root:not([data-theme="light"]) .sw` inside a
 * prefers-color-scheme: dark query. The latter two have specificity (0,3,0), so the
 * override repeats the same selector list to win against each of them. The host
 * never sets data-theme and is always dark, which is why the plain `.sw` case
 * matters too: without it a visitor whose OS prefers light would get upstream's
 * off-white paper palette on a black page. */
:root .sw,
:root[data-theme="dark"] .sw,
:root:not([data-theme="light"]) .sw {
  --paper: var(--terminal-bg);
  --card: var(--terminal-section);
  --soft: var(--terminal-header);
  --ink: var(--terminal-text);
  --muted: var(--terminal-dim);
  --rule: var(--terminal-border);

  /* The three ACF modes: AI, hybrid, human. */
  --ai: var(--terminal-info);
  --hy: var(--terminal-warning);
  --hu: var(--terminal-error);
  --ok: var(--terminal-highlight);

  /* The adventure console, one shade below the page so it still reads as a
   * terminal inside a terminal. */
  --con-bg: #000000;
  --con-fg: var(--terminal-text);
  --con-dim: var(--terminal-dim);
  --con-room: var(--terminal-highlight);
  --con-err: var(--terminal-error);
  --con-ok: var(--terminal-highlight);
  --con-warn: var(--terminal-warning);

  /* JetBrains Mono is already vendored site-wide (static/vendor/jetbrains-mono.css),
   * so the widget's Archivo/Newsreader/IBM Plex stacks collapse onto it and no
   * Google Fonts request is needed. build_config passes load_fonts=False to keep
   * upstream's <link> out of the head as well. */
  --serif: 'JetBrains Mono', 'Courier New', monospace;
  --sans: 'JetBrains Mono', 'Courier New', monospace;
  --mono: 'JetBrains Mono', 'Courier New', monospace;

  color-scheme: dark;
}

/* ── Host stylesheet bleed ───────────────────────────────────────────────────
 * base.html loads Bootstrap. Its Reboot styles bare elements, and its grid
 * claims the very generic class name .row — which this widget uses for its own
 * button groups. Upstream's .sw rules never set the properties below, so
 * Bootstrap wins them by default. Scope them back to the widget's own intent. */

/* Reboot: legend { float:left; width:100%; font-size:calc(1.275rem + .3vw) }.
 * Floating takes the legend out of the fieldset's own legend rendering, so
 * inside .typegrid's grid it becomes an ordinary grid item and eats the first
 * Textsorte card's cell — pushing the last card onto a second row. */
.sw fieldset > legend {
  float: none;
  width: auto;
  grid-column: 1 / -1;
  font-size: inherit;
  line-height: inherit;
}

/* Bootstrap's grid: .row gets negative gutter margins and .row > * is stretched
 * to the full line with gutter padding, so every button in one of the widget's
 * button rows rendered full-width and stacked. */
.sw .row {
  margin: 0;
}

.sw .row > * {
  width: auto;
  max-width: none;
  padding-left: 0;
  padding-right: 0;
  margin-top: 0;
}

/* The widget sits inside .terminal-main, which already pads the page. With
 * ui.show_header off, header.top's .brand half is empty, so its padding would
 * leave a dead gap above the project bar. */
.sw .wrap {
  padding-left: 0;
  padding-right: 0;
  padding-top: 0;
}

.sw header.top {
  padding-top: 0;
}

.sw .brand:empty {
  display: none;
}

/* button.primary fills with var(--ink), which is now terminal green; its label
 * needs a dark foreground to stay legible. */
.sw button.primary {
  color: var(--terminal-bg);
}

/* The mode badges (AI-led / Hybrid / Human-led) are inline-block, but a badge
 * that lands as a direct grid child gets blockified and stretches to the column
 * width — as the consistency-check heading's AI-led badge does. Upstream's muted
 * slate blue hides that; a saturated terminal blue turns it into a slab. Keep the
 * badge content-sized wherever it lands. */
.sw .mode {
  width: fit-content;
  justify-self: start;
  align-self: start;
}

/* Three literals in app.css sit outside the custom properties and would keep
 * their light-theme assumptions. */
.sw .ix::after {
  /* Index-card punch hole: an inset light-on-paper shadow, invisible on black. */
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.6);
}

.sw .con-form {
  /* Console input divider, originally a translucent white hairline. */
  border-top-color: var(--terminal-border);
}

.sw .modal {
  /* Modal backdrop, originally a near-black wash with a green cast. */
  background: rgba(0, 0, 0, 0.72);
}

/* The widget keeps its own px scale (15px base, 16-18px for the serif writing
 * surfaces) rather than the site's 12px: it is a long-form writing tool, and the
 * host's html { font-size: 90% } does not touch px values. Only the app's own
 * oversized display heading is pulled back toward the site's scale, for the case
 * where ui.show_header is ever turned back on. */
.sw .brand h1 {
  font-size: clamp(20px, 2.4vw, 28px);
}
