/* =========================================================================
   KOREKTOR · PELCRA brand
   Tokens copied from the PELCRA brand sheet v1.0 (tmp/brand_sheet.html).
   ========================================================================= */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  /* ---- Core brand ---------------------------------------------------- */
  --pelcra-blue:  #0244B0;
  --pelcra-sky:   #21B3F4;
  --pelcra-navy:  #162044;
  --pelcra-mid:   #1077CF;
  --pelcra-ice:   #F1F9FF;
  --pelcra-ink:   #202020;
  --pelcra-grid:  #C8C8C8;
  --pelcra-gradient:        radial-gradient(100% 100% at 100% 0%, #21B3F4 0%, #0244B0 84%);
  --pelcra-gradient-linear: linear-gradient(135deg, #0244B0 40%, #21B3F4 140%);
  --pelcra-rule:            linear-gradient(90deg, #0244B0, #21B3F4);

  /* ---- Neutrals ------------------------------------------------------ */
  --gray-0:  #FFFFFF;
  --gray-5:  #FBFBFB;
  --gray-10: #F2F2F2;
  --gray-20: #D9D9D9;
  --gray-30: #A8A8A8;
  --gray-50: #6C6C6C;
  --gray-70: #454444;
  --gray-90: #171717;

  /* ---- Status -------------------------------------------------------- */
  --status-error:   #A63429;
  --status-success: #20861E;
  --status-warning: #A86400;
  --status-info:    #1077CF;

  /* ---- Semantic roles (light) --------------------------------------- */
  --bg:            #FFFFFF;
  --surface:       #FFFFFF;
  --surface-alt:   #F1F9FF;
  --surface-muted: #F2F2F2;
  --text:          #202020;
  --text-body:     #454444;
  --text-muted:    #6C6C6C;
  --text-on-brand: #FFFFFF;
  --line:          #D9D9D9;
  --line-strong:   #A8A8A8;
  --accent:        #0244B0;
  --accent-hover:  #162044;
  --accent-ink:    #FFFFFF;   /* text on a filled accent */
  --focus:         #21B3F4;

  /* ---- App-specific -------------------------------------------------- */
  --out-bg:        #162044;   /* active output panel: deep surface */
  --out-bar:       #0E1530;
  --out-text:      #FFFFFF;
  --out-muted:     #9AA3BC;
  --out-label:     #21B3F4;
  --chip-bg:       #F1F9FF;
  --chip-text:     #0244B0;
  --del-text:      #A63429;
  --del-bg:        rgba(166, 52, 41, .10);
  --add-text:      #0244B0;
  --add-bg:        #F1F9FF;
  --add-text-out:  #7FD3FA;   /* corrected words on navy */
  --add-bg-out:    rgba(33, 179, 244, .18);
  --backdrop:      rgba(22, 32, 68, .45);
  --wave:          #D9D9D9;

  /* ---- Typography ---------------------------------------------------- */
  --font-brand:   Syne, "Helvetica Neue", Arial, sans-serif;
  --font-body:    Roboto, "Helvetica Neue", Arial, sans-serif;

  --fs-h1: 52px;  --lh-h1: 60px;
  --fs-h3: 27px;  --lh-h3: 32px;
  --fs-h4: 22px;  --lh-h4: 26px;
  --fs-lead: 20px; --lh-lead: 32px;
  --fs-body: 16px; --lh-body: 24px;
  --fs-label: 16px; --lh-label: 21px;
  --fs-small: 14px; --lh-small: 22px;
  --fs-micro: 12px; --lh-micro: 20px;

  /* ---- Space (8-pt grid) --------------------------------------------- */
  --space-1: 4px;  --space-2: 8px;  --space-3: 16px; --space-4: 24px;
  --space-5: 32px; --space-6: 40px; --space-7: 64px; --space-8: 80px;

  /* ---- Shape, depth, motion ----------------------------------------- */
  --radius-0: 0;
  --radius-1: 4px;
  --radius-2: 8px;
  --border:   2px;
  --hairline: 1px;
  --shadow-1: 0 2px 4px rgba(0, 0, 0, 0.08);
  --shadow-2: 0 9px 32px rgba(0, 0, 0, 0.12);
  --shadow-3: 0 32px 74px rgba(0, 0, 0, 0.08);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur:  300ms;

  --container: 1240px;
  color-scheme: light;
}

/* ---- Dark mode: only when chosen with the toggle (light is the default) */
:root[data-theme="dark"] {
  --bg: #0E1530; --surface: #162044; --surface-alt: #1B2752; --surface-muted: #1B2752;
  --text: #FFFFFF; --text-body: #F2F2F2; --text-muted: #9AA3BC; --line: #2A3768; --line-strong: #3B4A85;
  --accent: #21B3F4; --accent-hover: #5CC8F7; --accent-ink: #0E1530; --focus: #5CC8F7;
  --out-bg: #0A1026; --out-bar: #070B1C;
  --chip-bg: rgba(33, 179, 244, .15); --chip-text: #5CC8F7;
  --del-text: #FF8A7F; --del-bg: rgba(255, 138, 127, .14);
  --add-text: #7FD3FA; --add-bg: rgba(33, 179, 244, .18);
  --backdrop: rgba(5, 8, 20, .65); --wave: #3B4A85;
  --shadow-1: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 9px 32px rgba(0, 0, 0, 0.4);
  --shadow-3: 0 32px 74px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

/* ---------- base ---------- */
html, body { margin: 0; }
body {
  font-variant-numeric: tabular-nums;
  background: var(--bg);
  color: var(--text-body);
  font: 400 var(--fs-body)/var(--lh-body) var(--font-body);
  -webkit-font-smoothing: antialiased;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
button, textarea, input { font: inherit; color: inherit; }
h1, h2, p { margin: 0; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
code { font-family: var(--font-body); font-weight: 500; }

.ic {
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: square;
  stroke-linejoin: miter;
}
.ic-fill { fill: currentColor; stroke: none; }

.wrap {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding-inline: var(--space-5);
}

.app { display: flex; flex-direction: column; min-height: 100vh; overflow-x: clip; }

.p-rule { height: 4px; margin: 0; border: 0; background: var(--pelcra-rule); }
.p-eyebrow {
  font: 600 var(--fs-label)/var(--lh-label) var(--font-brand);
  letter-spacing: -0.01em;
  color: var(--accent);
}

/* ---------- app bar ---------- */
.appbar { border-bottom: var(--hairline) solid var(--line); background: var(--bg); }
.appbar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding-top: var(--space-3);
  padding-bottom: var(--space-3);
}
.brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.logo { display: block; line-height: 0; }
.logo svg { display: block; height: 24px; width: auto; }
.logo-dark { display: none; }
:root[data-theme="dark"] .logo-light { display: none; }
:root[data-theme="dark"] .logo-dark { display: block; }
.brand-sep { width: 1px; height: 32px; background: var(--line); }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-tagline {
  font: 600 15px/20px var(--font-brand);
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
}
.header-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; margin-left: auto; }
.badge {
  display: inline-block;
  min-width: 22px;
  padding: 0 6px;
  border-radius: var(--radius-1);
  background: var(--chip-bg);
  color: var(--chip-text);
  font: 600 12px/20px var(--font-brand);
  text-align: center;
}

/* ---------- hero (the view's single gradient field) ---------- */
.hero {
  position: relative;
  overflow: hidden;
  background: var(--pelcra-gradient);
  color: #fff;
}
/* Signal lines sit to the right of the text column (which ends ~130px right
   of centre) and fade in from the left, so they never run behind the copy. */
.lines {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  left: max(calc(50% + 12px), 640px);
  background: url("brand/lines.svg") left center / cover no-repeat;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 240px);
  mask-image: linear-gradient(90deg, transparent 0, #000 240px);
  pointer-events: none;
}
.hero-inner { position: relative; padding-top: var(--space-4); padding-bottom: var(--space-4); padding-right: 120px; }
.hero .p-eyebrow { color: #fff; opacity: .85; margin-bottom: var(--space-1); font-size: 14px; line-height: 20px; }
.hero h1 {
  font: 600 40px/44px var(--font-brand);
  letter-spacing: -0.02em;
  color: #fff;
  margin: 0 0 var(--space-1);
}
.hero-lead { max-width: 720px; font: 400 16px/24px var(--font-body); color: rgba(255, 255, 255, .92); }
.cutout {
  position: absolute;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, 24px);
  grid-template-rows: repeat(2, 24px);
}
.cutout i { background: var(--bg); }
.cutout i.x { background: transparent; }

/* ---------- main ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding-top: var(--space-6);
  padding-bottom: var(--space-8);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 8px 16px;
  font: 600 15px/20px var(--font-brand);
  letter-spacing: -0.01em;
  background: transparent;
  color: var(--accent);
  border: var(--border) solid var(--accent);
  border-radius: var(--radius-0);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.btn:hover:not(:disabled), .btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-icon { width: 44px; padding: 0; }

.btn-ghost { border-color: transparent; color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-alt); border-color: transparent; color: var(--accent); }

/* Primary call-to-action: filled blue, carries the ↗ arrow */
.p-button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 56px;
  padding: 14px 28px;
  border: var(--border) solid var(--accent);
  border-radius: var(--radius-0);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  font: 600 18px/24px var(--font-brand);
  letter-spacing: -0.01em;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.p-button::after { content: "↗"; font-family: var(--font-body); font-weight: 400; }
.p-button:hover:not(:disabled) { background: transparent; color: var(--accent); }
.p-button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- sections ---------- */
.section-title { margin: 0; }
.section-head { display: flex; align-items: baseline; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-3); }
.section-desc { font: 400 var(--fs-small)/var(--lh-small) var(--font-body); color: var(--text-muted); }
.prompt-buttons { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.prompt-buttons .btn { color: var(--text); border-color: var(--line-strong); border-width: 1px; padding: 9px 16px; }
.prompt-buttons .btn:hover:not(:disabled) { background: var(--surface-alt); border-color: var(--accent); color: var(--accent); }
.prompt-buttons .btn[aria-pressed="true"],
.prompt-buttons .btn[aria-pressed="true"]:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.num { font: 500 12px/1 var(--font-body); opacity: .65; }

/* model switch + Cenzura toggle */
.model-row { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin-bottom: var(--space-4); }
.model-switch .btn { font-weight: 600; }
.prompt-desc { margin-bottom: var(--space-3); }
.toggle { display: inline-flex; align-items: center; gap: var(--space-2); margin-top: var(--space-3); cursor: pointer; font: 400 var(--fs-small)/var(--lh-small) var(--font-body); color: var(--text); }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-box { width: 18px; height: 18px; flex: none; border: var(--hairline) solid var(--line-strong); background: var(--surface); display: inline-grid; place-items: center; }
.toggle input:checked + .toggle-box { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .toggle-box::after { content: ""; width: 8px; height: 4px; border: 2px solid var(--accent-ink); border-top: 0; border-right: 0; transform: translateY(-1px) rotate(-45deg); }
.toggle input:focus-visible + .toggle-box { outline: 2px solid var(--focus); outline-offset: 2px; }
.toggle-sub { color: var(--text-muted); margin-left: var(--space-1); }
.run-hint { margin: 0; font: 400 var(--fs-small)/var(--lh-small) var(--font-body); color: var(--status-warning); text-align: center; max-width: 560px; }
.gap { display: inline-block; padding: 0 6px; border: var(--hairline) dashed currentColor; font: 500 11px/16px var(--font-body); letter-spacing: .04em; text-transform: uppercase; opacity: .75; vertical-align: 1px; }

.collapsible {
  max-height: 900px;
  opacity: 1;
  visibility: visible;
  transition: max-height .45s var(--ease), opacity var(--dur) var(--ease), visibility 0s;
}
.collapsible.collapsed {
  max-height: 0;
  opacity: 0;
  visibility: hidden;
  overflow: hidden;
  transition: max-height .45s var(--ease), opacity var(--dur) var(--ease), visibility 0s .45s;
}
.prompt-section.collapsed { margin-bottom: calc(-1 * var(--space-5)); }

/* ---------- locked row ---------- */
.locked { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 6px 10px;
  border: 0;
  border-radius: var(--radius-1);
  background: var(--chip-bg);
  color: var(--chip-text);
  font: 600 13px/18px var(--font-brand);
  max-width: 100%;
}
.chip b { font: 400 13px/18px var(--font-body); color: var(--text-body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-solid { background: var(--accent); color: var(--accent-ink); }
.chip-play { min-height: 44px; gap: var(--space-2); cursor: pointer; transition: box-shadow var(--dur) var(--ease); }
.chip-play:hover:not(:disabled) { background: var(--chip-bg); color: var(--chip-text); box-shadow: inset 0 0 0 2px var(--accent); }
.chip-play > span { display: inline-flex; }

/* ---------- stage ---------- */
.stage {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: var(--space-6);
  row-gap: var(--space-5);
  transition: column-gap .45s var(--ease);
}
.app:not([data-phase="idle"]) .stage { column-gap: 112px; }
.col { position: relative; z-index: 1; display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.col-input { gap: 0; }
.col-input > * + * { margin-top: var(--space-3); }
.col-input > .collapsed { margin-top: 0; }

.energy {
  position: absolute;
  left: -56px; right: -56px; top: -120px; bottom: -220px;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
.energy canvas { display: block; width: 100%; height: 100%; }

/* ---------- windows ---------- */
.window {
  border: var(--hairline) solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.window:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow-1); }
.win-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: 8px 14px;
  background: var(--surface-alt);
  border-bottom: var(--hairline) solid var(--line);
  font: 600 14px/20px var(--font-brand);
  letter-spacing: -0.01em;
  color: var(--text);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.win-title .hint { font: 400 13px/18px var(--font-body); color: var(--text-muted); letter-spacing: 0; }
.count { font: 400 12px/18px var(--font-body); color: var(--text-muted); letter-spacing: 0; }

textarea {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0;
  resize: vertical;
  background: transparent;
  padding: 12px 14px;
}
textarea:focus { outline: none; }
textarea::placeholder { color: var(--text-muted); opacity: 1; }
.ctx { font: 400 14px/1.6 var(--font-body); color: var(--text-body); }
.frag { font: 400 16px/1.8 var(--font-body); color: var(--text); }
.frag-view {
  font: 400 16px/1.8 var(--font-body);
  color: var(--text);
  padding: 12px 14px;
  min-height: 220px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.w-del {
  color: var(--del-text);
  background: var(--del-bg);
  text-decoration: line-through 2px;
  padding: 0 2px;
}
.w-add {
  color: var(--add-text);
  background: var(--add-bg);
  font-weight: 500;
  padding: 0 3px;
}
/* Same number in another form (99 <-> dziewięćdziesiąt dziewięć): not an error. */
.w-num {
  text-decoration: underline dotted 2px;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 4px;
}
.app:not([data-phase="idle"]) .window-out .w-num { text-decoration-color: var(--out-muted); }

/* ---------- audio ---------- */
.dropzone {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 88px;
  padding: 14px 20px;
  border: var(--hairline) dashed var(--line-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.dropzone .ic { color: var(--accent); }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--surface-alt); }
.dropzone.drag { border-style: solid; }
.dropzone:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.dropzone .label { font: 600 15px/20px var(--font-brand); }
.dropzone .sub { font: 400 13px/18px var(--font-body); color: var(--text-muted); margin-top: 4px; }
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.player {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 12px;
  border: var(--hairline) solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
.player > .btn-play { background: var(--accent); color: var(--accent-ink); }
.player > .btn-play:hover:not(:disabled) { background: transparent; color: var(--accent); }
.player > .btn-remove { border-color: transparent; color: var(--text-muted); }
.player > .btn-remove:hover:not(:disabled) { background: var(--surface-alt); color: var(--accent); border-color: transparent; }
.player-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.player-meta { display: flex; justify-content: space-between; gap: 10px; font: 400 12px/18px var(--font-body); color: var(--text-muted); }
.player-name { font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wave { display: flex; align-items: center; gap: 2px; height: 36px; }
.wave i { flex: 1; min-width: 2px; background: var(--wave); transition: background 120ms linear; }
.wave i.on { background: var(--accent); }

/* ---------- output ---------- */
.window-out .out-body {
  min-height: 480px;
  padding: 18px 20px;
  font: 400 16px/1.8 var(--font-body);
  color: var(--text);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  overflow-wrap: anywhere;
}
.app:not([data-phase="idle"]) .window-out {
  border-color: var(--out-bg);
  border-top: 0;
  box-shadow: var(--shadow-2);
}
.app:not([data-phase="idle"]) .window-out::before {
  content: "";
  display: block;
  height: 4px;
  background: var(--pelcra-rule);
}
.app:not([data-phase="idle"]) .window-out .out-body { background: var(--out-bg); color: var(--out-text); min-height: 300px; }
.app:not([data-phase="idle"]) .window-out .win-title { background: var(--out-bar); color: var(--out-text); border-bottom-color: rgba(255, 255, 255, .12); }
.app:not([data-phase="idle"]) .window-out .w-add { color: var(--add-text-out); background: var(--add-bg-out); }

.empty {
  min-height: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-3);
}
.empty .ic { color: var(--line-strong); }
.empty-title { font: 600 18px/24px var(--font-brand); letter-spacing: -0.01em; color: var(--text); }
.empty p { font: 400 var(--fs-small)/var(--lh-small) var(--font-body); color: var(--text-muted); max-width: 320px; }
.cursor {
  display: inline-block;
  width: .55em;
  height: 1.05em;
  background: var(--pelcra-sky);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: blink 1s var(--ease) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.warm { font: 600 16px/24px var(--font-brand); color: var(--out-text); }
.dots::after { content: ""; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.warm-hint { font: 400 13px/20px var(--font-body); color: var(--out-muted); margin-top: 10px; }
.turn + .turn, .para + .para, .turn + .para, .para + .turn, .meta + * { margin-top: var(--space-3); }
.label { display: block; font: 600 12px/18px var(--font-brand); letter-spacing: .02em; color: var(--out-label); margin-bottom: 2px; }
.meta { font: 500 13px/20px var(--font-body); letter-spacing: .02em; color: var(--out-muted); }
.dash { color: var(--out-muted); }
.out-error { font-family: var(--font-body); }
.out-error .label { color: #FF8A7F; }
.out-foot {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: 10px 20px;
  background: var(--out-bar);
  color: var(--out-muted);
  border-top: 1px solid rgba(255, 255, 255, .12);
  font: 400 12px/18px var(--font-body);
}

/* ---------- controls ---------- */
.controls {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}
.control-row { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-2); }
.progress { width: 100%; max-width: 640px; }
.progress-label { display: flex; justify-content: space-between; font: 600 15px/20px var(--font-brand); color: var(--text); margin-bottom: var(--space-2); }
.progress-label #progPct { font: 400 13px/20px var(--font-body); color: var(--text-muted); }
.cells {
  display: grid;
  grid-template-columns: repeat(32, 1fr);
  gap: 3px;
  height: 20px;
}
.cells i { background: var(--surface-muted); transition: background 160ms var(--ease); }
.cells i.on { background: var(--accent); }
.cells i.on:has(+ i:not(.on)) { background: var(--pelcra-sky); }
.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-4);
  font: 400 13px/20px var(--font-body);
  color: var(--text-muted);
}
.legend > span { display: inline-flex; align-items: center; gap: var(--space-2); }

/* ---------- footer ---------- */
.ft { background: var(--pelcra-navy); color: rgba(255, 255, 255, .8); font: 400 13px/20px var(--font-body); }
.ft-inner { display: flex; justify-content: space-between; flex-wrap: wrap; gap: var(--space-2); padding-top: var(--space-4); padding-bottom: var(--space-4); }

/* ---------- drawer / modal (floating panels) ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--backdrop);
}
.bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 12px 10px 24px;
  background: var(--surface);
  border-bottom: var(--hairline) solid var(--line);
  position: sticky;
  top: 0;
  z-index: 1;
}
.bar h2 { font: 600 18px/24px var(--font-brand); letter-spacing: -0.01em; color: var(--text); }

.drawer {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 21;
  width: min(1240px, 100vw);
  max-height: 72vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: var(--radius-2) var(--radius-2) 0 0;
  box-shadow: var(--shadow-3), var(--shadow-2);
  transform: translate(-50%, 105%);
  visibility: hidden;
  transition: transform .35s var(--ease), visibility 0s .35s;
}
.drawer::before { content: ""; display: block; height: 4px; background: var(--pelcra-rule); }
.drawer.open { transform: translate(-50%, 0); visibility: visible; transition: transform .35s var(--ease), visibility 0s; }
.template-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
  padding: var(--space-4);
}

/* Tiles used by templates and history runs */
.card, .run {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: var(--space-2);
  text-align: left;
  min-height: 170px;
  padding: 16px 18px;
  background: var(--surface);
  color: var(--text-body);
  border: 0;
  border-top: var(--border) solid transparent;
  box-shadow: var(--shadow-1);
  font: 400 14px/22px var(--font-body);
  letter-spacing: 0;
}
.card:hover:not(:disabled), .run:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text-body);
  border-top-color: var(--accent);
  box-shadow: var(--shadow-2);
}
.card-top, .run-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font: 600 13px/18px var(--font-brand);
  color: var(--accent);
}
.tag {
  padding: 2px 8px;
  border-radius: var(--radius-1);
  background: var(--accent);
  color: var(--accent-ink);
  font: 600 11px/16px var(--font-brand);
}
.card-title { font: 600 16px/22px var(--font-brand); letter-spacing: -0.01em; color: var(--text); }
.card-meta { font: 400 12px/18px var(--font-body); color: var(--text-muted); }
.card-preview, .run-preview { font: 400 13px/20px var(--font-body); color: var(--text-body); }
.grid-empty { grid-column: 1 / -1; font: 400 14px/22px var(--font-body); color: var(--text-muted); padding: 12px 0; }

.modal {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 21;
  transform: translate(-50%, -50%);
  width: min(640px, calc(100vw - 32px));
  max-height: min(72vh, 640px);
  overflow-y: auto;
  background: var(--bg);
  border-radius: var(--radius-2);
  box-shadow: var(--shadow-3), var(--shadow-2);
}
.modal::before { content: ""; display: block; height: 4px; background: var(--pelcra-rule); }
.history-list { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-4); }
.run { min-height: 0; gap: 4px; }
.run-sub { font: 600 16px/22px var(--font-brand); letter-spacing: -0.01em; color: var(--text); }

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .stage, .app:not([data-phase="idle"]) .stage { grid-template-columns: minmax(0, 1fr); column-gap: 0; }
  .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
  .lines { left: 50%; opacity: .45; -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 60%); mask-image: linear-gradient(90deg, transparent 0, #000 60%); }
  .hero h1 { font-size: 32px; line-height: 36px; }
  .hero-lead { font-size: 15px; line-height: 22px; }
  .cutout { grid-template-columns: repeat(3, 16px); grid-template-rows: repeat(2, 16px); }
  .hero-inner { padding-top: var(--space-3); padding-bottom: var(--space-5); padding-right: var(--space-3); }
}
@media (max-width: 560px) {
  .wrap { padding-inline: var(--space-3); }
  .main { padding-top: var(--space-5); padding-bottom: var(--space-7); }
  .template-grid { grid-template-columns: minmax(0, 1fr); padding: var(--space-3); }
  .p-button { font-size: 16px; padding: 12px 20px; }
  .brand-sep, .brand-text { display: none; }
  .header-actions .btn-ghost:not(.btn-icon) { padding: 8px 10px; }
  .history-list { padding: var(--space-3); }
}
@media (max-width: 420px) {
  .header-actions .btn-label { display: none; }
  .appbar-inner { flex-wrap: nowrap; gap: var(--space-2); }
  .header-actions { gap: 0; flex-wrap: nowrap; }
  .header-actions .btn-icon { width: 40px; }
  .header-actions .btn-ghost:not(.btn-icon) { padding: 8px; }
  .logo svg { height: 18px; }
  .brand { gap: var(--space-2); }
}
@media (prefers-reduced-motion: reduce) {
  .cursor, .dots::after { animation: none; }
  .energy { display: none; }
  *, *::before, *::after { transition-duration: 0s !important; }
}

/* ---------- signed-in navigation ---------- */
.app-nav { display: inline-flex; align-items: center; gap: var(--space-1); flex-wrap: wrap; }
.nav-link {
  display: inline-flex; align-items: center; min-height: 40px; padding: 8px 12px;
  font: 600 15px/20px var(--font-brand); color: var(--text); text-decoration: none; border-bottom: 2px solid transparent;
}
.nav-link:hover { color: var(--accent); }
.nav-link[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.nav-user { font: 400 13px/20px var(--font-body); color: var(--text-muted); padding: 0 var(--space-1) 0 var(--space-2); border-left: 1px solid var(--line); margin-left: var(--space-1); }
.nav-logout { min-height: 40px; }
.out-foot a { color: inherit; }
.ft a { color: inherit; }

/* ---------- account / admin / docs pages ---------- */
.page-main { padding-top: var(--space-6); padding-bottom: var(--space-7); flex: 1; }
.page-head { margin-bottom: var(--space-4); }
.page-title { margin: 0; font: 600 var(--fs-h3)/var(--lh-h3) var(--font-brand); color: var(--text); }
.page-lead { margin: var(--space-1) 0 0; color: var(--text-muted); }
.app:has(.page-main) { min-height: 100vh; display: flex; flex-direction: column; }
img.logo-light, img.logo-dark { height: 24px; width: auto; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: flex; flex-direction: column; }
.login-main { flex: 1; display: grid; place-items: center; padding: var(--space-5) var(--space-3); }
.login-card {
  width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: var(--space-3);
  border: var(--hairline) solid var(--line); background: var(--surface); padding: var(--space-5);
}
.login-card h1 { margin: var(--space-2) 0 0; font: 600 var(--fs-h3)/var(--lh-h3) var(--font-brand); color: var(--text); }
.login-logo { height: 24px; width: auto; align-self: flex-start; }
.login-lead { margin: 0; color: var(--text-muted); font-size: var(--fs-small); line-height: var(--lh-small); }
.login-field { display: flex; flex-direction: column; gap: 6px; font: 500 13px/18px var(--font-body); color: var(--text-muted); }
.login-field input {
  min-height: 44px; padding: 10px 12px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font: 400 16px/22px var(--font-body); border-radius: 0;
}
.login-field input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.login-error { margin: 0; color: var(--status-error); font-size: var(--fs-small); }
.login-card .p-button { justify-content: center; }
.login-foot { margin: 0; font-size: 13px; color: var(--text-muted); }
.login-foot a { color: var(--accent); }
@media (max-width: 768px) {
  .nav-user { display: none; }
  .nav-link { padding: 8px; }
}
/* With the signed-in nav, the tool page's header has no room for the tagline. */
@media (max-width: 1480px) {
  .appbar:has(.app-nav a) .brand-sep,
  .appbar:has(.app-nav a) .brand-text { display: none; }
}
.run-hint.info { color: var(--text-muted); }

/* ---------- model & output style (01, 02) ---------- */
.prompt-section { display: flex; flex-direction: column; gap: var(--space-5); }
.setting-block + .setting-block { padding-top: var(--space-5); border-top: var(--hairline) solid var(--line); }
.setting-block .section-head { align-items: center; gap: var(--space-2); }
.style-grid { display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: center; gap: var(--space-3) var(--space-4); }
.style-label { font: 600 13px/18px var(--font-brand); color: var(--text-muted); letter-spacing: .01em; }
.style-checks { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-5); }
.style-checks .toggle { margin-top: 0; }
.toggle-wrap { display: inline-flex; align-items: center; gap: 6px; }
.toggle-wrap[hidden] { display: none; }
.prompt-desc { margin: var(--space-3) 0 0; max-width: 72ch; }
.prompt-buttons .btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- (i) tooltips ---------- */
.info {
  appearance: none; display: inline-grid; place-items: center; width: 18px; height: 18px; padding: 0; margin: 0 0 0 6px;
  border: var(--hairline) solid var(--line-strong); border-radius: 50%; background: transparent; color: var(--text-muted);
  font: 600 11px/1 var(--font-body); cursor: help; vertical-align: 1px;
}
.info:hover, .info:focus-visible { border-color: var(--accent); color: var(--accent); }
.info:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.tip {
  position: fixed; z-index: 1000; max-width: 300px; padding: 8px 12px; pointer-events: none;
  background: var(--pelcra-navy); color: #fff; box-shadow: var(--shadow-2);
  font: 400 13px/19px var(--font-body);
}
:root[data-theme="dark"] .tip { background: #F2F2F2; color: #162044; }

/* ---------- input / output columns ---------- */
.stage { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
.col-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-height: 36px; }
.col-input > .col-head + * { margin-top: var(--space-3); }
.btn-small { min-height: 36px; padding: 6px 10px; font-size: 14px; }
.btn-small .badge { margin-left: 2px; }
.p-button.no-arrow::after { content: none; }
@media (max-width: 820px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
  .style-grid { grid-template-columns: minmax(0, 1fr); gap: var(--space-2); }
  .style-label { margin-top: var(--space-2); }
}
/* Narrow screens: logo on one row, navigation on the next. */
@media (max-width: 600px) {
  .appbar-inner { flex-wrap: wrap; row-gap: var(--space-1); }
  .header-actions { width: 100%; margin-left: 0; flex-wrap: nowrap; }
  .app-nav { flex: 1; flex-wrap: nowrap; min-width: 0; }
  .nav-logout { margin-left: auto; padding: 8px; }
}
