/* ============================================================
   Mivie design system — plan §6.1 / §12.
   Work mode: near-white, ink, one deep-blue accent.
   Roleplay mode: near-black, parchment text, character accents.
   Flat colors, sharp corners, hairline dividers, no gradients.
   ============================================================ */

:root {
  --bar-h: 64px;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}

/* ---------- Work mode palette ---------- */
body.mode-work, body.auth, body.landing {
  --bg: #FAFAF9;
  --panel: #FFFFFF;
  --ink: #111111;
  --ink-soft: #55555f;
  --ink-faint: #9a9aa2;
  --line: #E7E7E4;
  --accent: #1D4ED8;
  --accent-ink: #FFFFFF;
  --danger: #B91C1C;
  --ok: #15803D;
  --warn: #B45309;
  --chip: #F1F1EE;
  --user-bubble: #EEF2FF;
  font-family: var(--font-sans);
}

/* ---------- Roleplay mode palette ---------- */
body.mode-roleplay {
  --bg: #0B0B0F;
  --panel: #131318;
  --ink: #EDE6D8;
  --ink-soft: #B7AE9C;
  --ink-faint: #6E6759;
  --line: #26262E;
  --accent: #C9A227;
  --accent-ink: #14120A;
  --danger: #E5484D;
  --ok: #4CC38A;
  --warn: #E5A00D;
  --chip: #1D1D24;
  --user-bubble: #1E1E28;
  font-family: var(--font-sans);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- primitives ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 8px 16px;
  border-radius: 2px;
  font-weight: 500;
  white-space: normal;
}
.btn:hover { border-color: var(--ink-faint); }
.btn.solid { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.solid:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--chip); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }

.field { display: block; margin-bottom: 14px; }
.field label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 2px;
  background: var(--panel);
}
.field input:focus, .field textarea:focus { border-color: var(--accent); outline: none; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 2px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 2px;
  background: var(--chip); border: 1px solid var(--line);
  font-size: 12px; color: var(--ink-soft);
}
.chip.accent { color: var(--accent); border-color: var(--accent); background: transparent; }
.hairline { border: none; border-top: 1px solid var(--line); margin: 0; }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
.err { color: var(--danger); font-size: 13px; }
.ok { color: var(--ok); }
.mono { font-family: var(--font-mono); font-size: 12.5px; }

/* ---------- landing bar (§5.1) ---------- */
.bar {
  position: sticky; top: 0; z-index: 50;
  height: var(--bar-h);
  display: flex; align-items: center; gap: 28px;
  padding: 0 28px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.bar.scrolled { background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(10px); }
.wordmark { font-weight: 700; font-size: 18px; letter-spacing: -0.02em; color: var(--ink); }
.bar nav { display: flex; gap: 22px; margin: 0 auto; }
.bar nav a { color: var(--ink-soft); font-size: 13.5px; }
.bar nav a:hover { color: var(--ink); }
.bar .right { display: flex; gap: 10px; align-items: center; }

/* ---------- auth pages (§5.1/§5.2) ---------- */
.auth-wrap { max-width: 420px; margin: 10vh auto 0; padding: 0 20px; }
.auth-wrap h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
.auth-wrap .sub { color: var(--ink-soft); margin-bottom: 26px; }
.auth-wrap .alt { text-align: center; margin-top: 18px; color: var(--ink-soft); font-size: 13px; }
.strength { height: 4px; background: var(--line); margin-top: 6px; border-radius: 1px; overflow: hidden; }
.strength > div { height: 100%; width: 0; background: var(--danger); transition: width .15s, background .15s; }

/* mfa segmented input */
.mfa-row { display: flex; gap: 8px; justify-content: center; margin: 22px 0; }
.mfa-row input {
  width: 44px; height: 52px; text-align: center; font-size: 20px;
  border: 1px solid var(--line); border-radius: 2px; background: var(--panel);
}

/* ---------- app shell (§12.2) ---------- */
/* min-width: 0 defeats CSS Grid's default min-width:auto floor — without it,
   a single long-text child (e.g. a full-sentence button label) can force the
   implicit column, and every ancestor up to .shell, wider than the viewport. */
.shell { display: grid; grid-template-rows: var(--bar-h) 1fr; height: 100vh; min-width: 0; }
.shell > * { min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--bg);
}
/* flex items default to min-width:auto (sized to their content's intrinsic
   width) — the chat-title <input> in particular has a wide UA-default
   intrinsic size that ignores its own max-width unless this is overridden,
   which on narrow viewports blows out the whole row (and the shell's grid
   track, and the page's layout viewport) instead of just truncating. */
.topbar .title { min-width: 0; }
.topbar .seg, .topbar .hamburger { flex-shrink: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 2px; overflow: hidden; }
.seg button { padding: 6px 18px; border: 0; background: transparent; color: var(--ink-soft); }
.seg button.on { background: var(--ink); color: var(--bg); }
body.mode-roleplay .seg button.on { background: var(--accent); color: var(--accent-ink); }

.topbar .title { font-weight: 600; border: 1px solid transparent; padding: 4px 8px; background: transparent; border-radius: 2px; max-width: 300px; }
.topbar .title:hover, .topbar .title:focus { border-color: var(--line); outline: none; background: var(--panel); }
.topbar .spacer { flex: 1; }

.main { display: grid; grid-template-columns: 240px 1fr auto; min-height: 0; }
.main.no-left { grid-template-columns: 0 1fr auto; }
.main.no-right { grid-template-columns: 240px 1fr 0; }
.main.no-left.no-right { grid-template-columns: 0 1fr 0; }

.rail { border-right: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 12px 8px; }
/* fixed + hidden by default so it never participates in the .main grid's
   column auto-placement (a grid child normally consumes a track even when
   empty) — only shown, as an overlay, on narrow viewports. */
.rail-backdrop { display: none; position: fixed; inset: var(--bar-h) 0 0 0; background: rgb(0 0 0 / 40%); z-index: 40; }
.rail-backdrop.show { display: block; }
.rail h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); margin: 14px 8px 6px; }
.rail .item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: 2px; cursor: pointer; color: var(--ink-soft);
  font-size: 13.5px; border: none; background: none; width: 100%; text-align: left;
}
.rail .item:hover { background: var(--chip); color: var(--ink); }
.rail .item.on { background: var(--chip); color: var(--ink); font-weight: 600; }

.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 22px clamp(16px, 8%, 120px); }
.composer { border-top: 1px solid var(--line); padding: 12px clamp(16px, 8%, 120px); background: var(--bg); }
.composer .box { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 2px;
  background: var(--panel); padding: 10px 12px; max-height: 180px; min-height: 42px;
}
.composer .hint { font-size: 11.5px; color: var(--ink-faint); margin-top: 6px; display: flex; gap: 14px; }

/* avatars — deterministic gradient+initials tile, or a real <img> once one exists */
.avatar { display: inline-flex; align-items: center; justify-content: center; overflow: hidden; flex: none; user-select: none; }

/* messages */
.msg { margin-bottom: 18px; max-width: 860px; display: flex; gap: 10px; align-items: flex-start; }
.msg .avatar { margin-top: 2px; }
.msg .col { min-width: 0; flex: 1; }
.msg.user { flex-direction: row-reverse; margin-left: auto; }
.msg.user .col { display: flex; flex-direction: column; align-items: flex-end; }
.msg .who { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-faint); margin-bottom: 4px; display: flex; gap: 10px; align-items: center; }
.msg.user .body { background: var(--user-bubble); border: 1px solid var(--line); padding: 10px 14px; border-radius: 2px; display: inline-block; }
.msg .body { white-space: normal; overflow-wrap: anywhere; }
.msg .body pre { background: var(--chip); border: 1px solid var(--line); padding: 12px; overflow-x: auto; border-radius: 2px; }
.msg .body code { font-family: var(--font-mono); font-size: 12.5px; }
.msg .body p:first-child { margin-top: 0; } .msg .body p:last-child { margin-bottom: 0; }
.msg .body table { border-collapse: collapse; } .msg .body th, .msg .body td { border: 1px solid var(--line); padding: 4px 10px; }
.msg .acts { display: flex; gap: 8px; margin-top: 6px; opacity: 0; transition: opacity .12s; }
.msg:hover .acts { opacity: 1; }
.msg .acts button { font-size: 11.5px; color: var(--ink-faint); background: none; border: none; padding: 2px 4px; }
.msg .acts button:hover { color: var(--ink); }
.msg.err-b .body { border: 1px solid var(--danger); color: var(--danger); padding: 10px 14px; border-radius: 2px; }
.cursor-blink::after { content: "▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* right panel: canvas / stage */
.side { width: 460px; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.side .head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.side .content { flex: 1; overflow: auto; padding: 14px; }
.side textarea.editor { width: 100%; height: 55%; min-height: 220px; font-family: var(--font-mono); font-size: 12.5px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); padding: 10px; border-radius: 2px; resize: vertical; }
.side pre.out { background: var(--bg); border: 1px solid var(--line); padding: 10px; font-size: 12px; overflow: auto; max-height: 30%; }

/* stage (roleplay) */
.stage-sprite { width: 100%; max-height: 300px; object-fit: contain; background: var(--chip); border: 1px solid var(--line); }
.meter { margin: 10px 0; }
.meter .lbl { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .06em; }
.meter .track { height: 5px; background: var(--chip); border: 1px solid var(--line); margin-top: 4px; }
.meter .fill { height: 100%; background: var(--accent); transition: width .4s; }
.floater { position: absolute; font-size: 12px; color: var(--ok); animation: rise 1.2s forwards; }
@keyframes rise { to { transform: translateY(-24px); opacity: 0; } }

/* model selector dropdown (§12.3) */
.dropdown { position: relative; display: inline-block; }
.menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 60;
  min-width: min(380px, calc(100vw - 24px)); max-height: 420px; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 2px;
  box-shadow: 0 8px 30px rgb(0 0 0 / 12%); display: none;
}
.menu.open { display: block; }
/* chips near the right edge: anchor the menu there so it never overflows */
.dropdown.right .menu { left: auto; right: 0; }
.menu .row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.menu .row:hover { background: var(--chip); }
.menu .row .name { font-weight: 600; font-size: 13px; }
.menu .row .meta { font-size: 11.5px; color: var(--ink-faint); }
.menu .row .price { margin-left: auto; font-size: 11.5px; color: var(--ink-soft); font-family: var(--font-mono); }
.badge { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding: 1px 6px; border: 1px solid var(--accent); color: var(--accent); border-radius: 2px; }

/* omnibar (§6.8) */
.omni-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 40%); z-index: 90; display: flex; justify-content: center; padding-top: 14vh; }
.omni { width: min(640px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 4px; height: fit-content; overflow: hidden; }
.omni input { width: 100%; border: 0; padding: 15px 16px; font-size: 15px; background: transparent; color: var(--ink); }
.omni .list { max-height: 340px; overflow: auto; border-top: 1px solid var(--line); }
.omni .opt { padding: 9px 16px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; }
.omni .opt.sel, .omni .opt:hover { background: var(--chip); }

/* timeline steps (§6.6) */
.timeline { border: 1px solid var(--line); border-radius: 2px; margin: 10px 0; background: var(--panel); }
.tstep { display: flex; gap: 10px; align-items: flex-start; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.tstep:last-child { border-bottom: none; }
.tstep .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; background: var(--ink-faint); flex: none; }
.tstep.ok .dot { background: var(--ok); }
.tstep.error .dot { background: var(--danger); }
.tstep.pending .dot { background: var(--warn); animation: blink 1s steps(2) infinite; }
.tstep details { flex: 1; min-width: 0; }
.tstep summary { cursor: pointer; color: var(--ink); }
.tstep pre { margin: 6px 0 0; font-size: 11.5px; background: var(--chip); padding: 8px; overflow: auto; }

/* checklist widget */
.checklist { list-style: none; margin: 8px 0; padding: 0; }
.checklist li { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.checklist .box { width: 14px; height: 14px; border: 1px solid var(--line); display: inline-block; }
.checklist li.done .box { background: var(--ok); border-color: var(--ok); }
.checklist li.done span { text-decoration: line-through; color: var(--ink-faint); }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 45%); z-index: 80; display: flex; align-items: center; justify-content: center; }
.modal { width: min(520px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 22px; max-height: 86vh; overflow: auto; }
.modal h3 { margin: 0 0 12px; }

/* toast */
#toasts { position: fixed; bottom: 18px; right: 18px; z-index: 120; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 2px; font-size: 13px; animation: slidein .18s; }
@keyframes slidein { from { transform: translateX(12px); opacity: 0; } }

/* tables */
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.grid th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); }

/* landing hero (§12.1) */
.hero { max-width: 1040px; margin: 0 auto; padding: 90px 28px 60px; }
.hero h1 { font-size: clamp(30px, 4.4vw, 52px); line-height: 1.08; letter-spacing: -0.03em; margin: 0 0 16px; max-width: 720px; }
.hero p.lede { font-size: 17px; color: var(--ink-soft); max-width: 560px; margin: 0 0 26px; }
.hero .ctas { display: flex; gap: 12px; }
.frame { border: 1px solid var(--line); background: var(--panel); border-radius: 4px; margin-top: 54px; padding: 18px; }
.section { max-width: 1040px; margin: 0 auto; padding: 56px 28px; border-top: 1px solid var(--line); }
.section h2 { font-size: 22px; letter-spacing: -0.01em; }
.cols3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; }
@media (max-width: 800px) { .cols3 { grid-template-columns: 1fr; } .bar nav { display: none; } }

/* inline tool-call pill (§7 escalation, standard in Work chat) */
.tool-step { display: flex; align-items: center; gap: 8px; padding: 6px 10px; margin: 4px 0; border: 1px solid var(--line); border-radius: 2px; background: var(--chip); font-size: 12px; color: var(--ink-soft); cursor: pointer; }
.tool-step .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-faint); flex: none; }
.tool-step.pending .dot { background: var(--warn); animation: blink 1s steps(2) infinite; }
.tool-step.ok .dot { background: var(--ok); }
.tool-step.error .dot { background: var(--danger); }
.tool-step .label { flex: 1; font-family: var(--font-mono); font-size: 11.5px; }
.tool-step .detail { display: none; margin-top: 8px; }
.tool-step.open .detail { display: block; }
.tool-step pre { margin: 0; font-size: 11px; background: var(--bg); padding: 8px; border-radius: 2px; overflow: auto; max-height: 220px; }
.tool-step-wrap { margin-bottom: 6px; }

/* wizard / stepper (character creation, §9.1) */
.wizard-modal .modal { width: min(780px, 94vw); }
.wizard { display: flex; gap: 18px; min-height: 380px; max-height: 68vh; }
.wizard .steps { width: 172px; flex: none; overflow-y: auto; padding-right: 12px; border-right: 1px solid var(--line); }
.wizard .steps .step { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 2px; border: none; background: none; color: var(--ink-soft); font-size: 12.5px; cursor: pointer; margin-bottom: 2px; }
.wizard .steps .step:hover { background: var(--chip); }
.wizard .steps .step.on { background: var(--chip); color: var(--ink); font-weight: 600; }
.wizard .steps .step .n { display: inline-block; width: 16px; color: var(--ink-faint); }
.wizard .panel { flex: 1; min-width: 0; overflow-y: auto; padding-right: 4px; }
.wizard .panel h4 { margin: 0 0 4px; font-size: 15px; }
.wizard .panel .hint { color: var(--ink-soft); font-size: 12.5px; margin: 0 0 16px; }
.wizard .footer { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.wizard .footer .save-state { font-size: 11.5px; color: var(--ink-faint); }

/* chip / tag input (aliases, catchphrases, jargon, forbidden words, genre tags) */
.chipfield { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; border: 1px solid var(--line); border-radius: 2px; background: var(--panel); min-height: 38px; }
.chipfield .tag { display: inline-flex; align-items: center; gap: 4px; background: var(--chip); border: 1px solid var(--line); padding: 2px 4px 2px 9px; border-radius: 12px; font-size: 12px; }
.chipfield .tag button { border: none; background: none; cursor: pointer; color: var(--ink-faint); font-size: 14px; line-height: 1; padding: 2px 6px; }
.chipfield .tag button:hover { color: var(--danger); }
.chipfield input { border: none; outline: none; flex: 1; min-width: 90px; background: transparent; padding: 4px; color: var(--ink); }

/* trait sliders (§9.1.4) */
.slider-row { margin-bottom: 18px; }
.slider-row .ends { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .05em; }
.slider-row input[type=range] { width: 100%; margin: 6px 0; accent-color: var(--accent); }
.slider-row .preview { font-size: 12px; color: var(--ink-soft); font-style: italic; min-height: 16px; }

/* MBTI grid */
.mbti-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 4px; }
.mbti-grid button { padding: 9px 4px; border: 1px solid var(--line); background: var(--panel); border-radius: 2px; font-size: 12.5px; font-family: var(--font-mono); cursor: pointer; }
.mbti-grid button:hover { border-color: var(--ink-faint); }
.mbti-grid button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
body.mode-roleplay .mbti-grid button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* secrets rows */
.secret-row { border: 1px solid var(--line); border-radius: 2px; padding: 10px; margin-bottom: 10px; }
.secret-row textarea { width: 100%; border: 1px solid var(--line); border-radius: 2px; padding: 8px; margin-bottom: 8px; background: var(--panel); color: var(--ink); }
.secret-row .row-foot { display: flex; align-items: center; gap: 10px; }
.secret-row .row-foot label { font-size: 11px; color: var(--ink-soft); white-space: nowrap; }
.secret-row .row-foot input[type=range] { flex: 1; accent-color: var(--accent); }

/* Avatar Studio (§9.2) */
.studio-preview { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 14px; }
.studio-preview .portrait { width: 156px; height: 156px; border-radius: 4px; overflow: hidden; border: 1px solid var(--line); background: var(--chip); flex: none; display: flex; align-items: center; justify-content: center; font-size: 44px; font-family: serif; color: var(--ink-faint); }
.studio-preview .portrait img { width: 100%; height: 100%; object-fit: cover; }
.studio-preview .actions { display: flex; flex-direction: column; gap: 8px; flex: 1; padding-top: 4px; }

/* skeleton loading shimmer */
.skel { background: linear-gradient(90deg, var(--chip) 25%, var(--line) 37%, var(--chip) 63%); background-size: 400% 100%; animation: skel 1.4s ease infinite; border-radius: 2px; }
@keyframes skel { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* mode switch crossfade (§6.1) */
#main.fade-out, .topbar.fade-out { opacity: 0; transition: opacity 150ms ease; }
#main, .topbar { transition: opacity 150ms ease; }

/* onboarding */
.onboard-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0 20px; }
.onboard-tiles .tile { border: 1px solid var(--line); border-radius: 2px; padding: 16px; cursor: pointer; text-align: left; background: var(--panel); }
.onboard-tiles .tile:hover { border-color: var(--ink-faint); }
.onboard-tiles .tile h4 { margin: 0 0 6px; font-size: 14px; }
.onboard-tiles .tile p { margin: 0; font-size: 12px; color: var(--ink-soft); }

/* hamburger (mobile only) */
.hamburger { display: none; }

.hidden { display: none !important; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- responsive pass (mobile / narrow viewports) ---------- */
@media (max-width: 880px) {
  .hamburger { display: inline-flex !important; }
  /* rail/side become fixed overlays (display:none by default), leaving
     .center as .main's only real grid item — drop the grid so it isn't
     auto-placed into a 0-width track instead of filling the pane. */
  .main { display: block; position: relative; }
  .center { height: 100%; }
  .rail { display: none; position: fixed; top: var(--bar-h); left: 0; bottom: 0; width: min(84vw, 320px); z-index: 45; box-shadow: 2px 0 24px rgb(0 0 0 / 20%); }
  .rail.mobile-open { display: flex; flex-direction: column; }
  .side { position: fixed; top: var(--bar-h); right: 0; bottom: 0; width: min(94vw, 440px); z-index: 45; box-shadow: -2px 0 24px rgb(0 0 0 / 20%); }
  /* Narrow screens can't fit every chip on one row legibly — keep only
     primary navigation (rail, mode, title, canvas/stage, account) and move
     the rest behind the omnibar / settings rather than shrinking everything
     to illegible slivers. */
  .topbar { padding: 0 10px; gap: 6px; }
  .topbar .title { max-width: 120px; }
  .topbar .wordmark, .topbar #tools-toggle, .topbar #model-dd, .topbar #credits-chip, .topbar #omni-open { display: none; }
  .topbar #user-chip { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }
  .seg button { padding: 6px 10px; }
  .messages { padding: 14px 10px; }
  .composer { padding: 10px; }
  .composer .hint { flex-wrap: wrap; row-gap: 4px; }
  .msg { max-width: 100%; }
  .wizard { flex-direction: column; max-height: 62vh; }
  .wizard .steps { width: 100%; border-right: none; border-bottom: 1px solid var(--line); padding-right: 0; padding-bottom: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
  .wizard .steps .step { width: auto; }
  .onboard-tiles { grid-template-columns: 1fr; }
}
