/* styles.css — one stylesheet, no framework, no build step.
 *
 * ── Theming ───────────────────────────────────────────────────────────────────
 * Three states, and the third is why this looks the way it does:
 *   System  → NO data-theme attribute, so prefers-color-scheme decides.
 *   Light   → :root[data-theme="light"]
 *   Dark    → :root[data-theme="dark"]
 * An explicit choice must beat the media query in BOTH directions, which a
 * single `@media (prefers-color-scheme: light) { :root {…} }` block cannot do —
 * hence `:root:not([data-theme])` on the media rule and a separate attribute
 * rule per theme. The light values appear twice on purpose; plain CSS has no
 * way to share them, and duplicating six lines beats adding a build step.
 * `theme-boot.js` stamps the attribute before first paint so there is no flash.
 *
 * EVERY colour lives here. If you find yourself writing a hex value further
 * down, add a token instead — a hardcoded colour is a bug in one of the themes.
 * Alpha-only values (#0006 shadows, ::backdrop) are fine, they work in both.
 */
:root {
  color-scheme: dark;
  --bg: #0f1115; --panel: #161a21; --panel2: #1c212a; --panel3: #232a35;
  --line: #262c37; --line2: #38414f;
  --fg: #e7e9ee; --muted: #8c94a5; --faint: #6b7484;
  --accent: #5b8cff; --accent-fg: #ffffff; --accent-soft: #1d2740;
  --ok: #3fbf7f; --warn: #e0a33c; --danger: #e0555f;
  --ok-bg: #12291d; --warn-bg: #3a2d10; --danger-bg: #3a1519;
  --ok-fg: #8ee0b4; --warn-fg: #ffd98a; --danger-fg: #ffc2c6;
  --sel: #2a3a63;
  --shadow: 0 10px 30px #00000080;
  /* syntax */
  --sx-comment: #6b7484; --sx-punct: #9aa3b2; --sx-tag: #ff7b90;
  --sx-attr: #d6a860;   --sx-str: #7fd39a;   --sx-num: #d59bff;
  --sx-kw: #79a8ff;     --sx-fn: #7fdcf0;    --sx-var: #e7e9ee;
  --sx-sel: #ffb86c;    --sx-prop: #8fd0ff;  --sx-imp: #ff9d5c;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* Light values — kept identical in the two rules below. Change both. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: #f5f6f8; --panel: #ffffff; --panel2: #eef1f5; --panel3: #e3e8ef;
    --line: #dbe0e8; --line2: #c2cad6;
    --fg: #14171c; --muted: #5c6675; --faint: #8b95a3;
    --accent: #2f6bdc; --accent-fg: #ffffff; --accent-soft: #e4ecfd;
    --ok: #17804d; --warn: #9a6612; --danger: #c22f3c;
    --ok-bg: #e3f6ec; --warn-bg: #fdf2dc; --danger-bg: #fdeaec;
    --ok-fg: #0f5f39; --warn-fg: #7a5210; --danger-fg: #94232e;
    --sel: #cfe0ff;
    --shadow: 0 8px 24px #0000001f;
    --sx-comment: #7a8493; --sx-punct: #5c6675; --sx-tag: #b3245c;
    --sx-attr: #8a5a00;   --sx-str: #12704a;   --sx-num: #7a29b8;
    --sx-kw: #1f52b3;     --sx-fn: #0d6c86;    --sx-var: #14171c;
    --sx-sel: #a5490b;    --sx-prop: #14568a;  --sx-imp: #a5490b;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6f8; --panel: #ffffff; --panel2: #eef1f5; --panel3: #e3e8ef;
  --line: #dbe0e8; --line2: #c2cad6;
  --fg: #14171c; --muted: #5c6675; --faint: #8b95a3;
  --accent: #2f6bdc; --accent-fg: #ffffff; --accent-soft: #e4ecfd;
  --ok: #17804d; --warn: #9a6612; --danger: #c22f3c;
  --ok-bg: #e3f6ec; --warn-bg: #fdf2dc; --danger-bg: #fdeaec;
  --ok-fg: #0f5f39; --warn-fg: #7a5210; --danger-fg: #94232e;
  --sel: #cfe0ff;
  --shadow: 0 8px 24px #0000001f;
  --sx-comment: #7a8493; --sx-punct: #5c6675; --sx-tag: #b3245c;
  --sx-attr: #8a5a00;   --sx-str: #12704a;   --sx-num: #7a29b8;
  --sx-kw: #1f52b3;     --sx-fn: #0d6c86;    --sx-var: #14171c;
  --sx-sel: #a5490b;    --sx-prop: #14568a;  --sx-imp: #a5490b;
}
:root[data-theme="dark"] { color-scheme: dark; }  /* :root defaults are dark */

* { box-sizing: border-box; }
/* Background on html too: the app pane is height-limited, so on a short phone
   the document ends above the fold and the browser paints its own canvas below
   body without this. */
html { background: var(--bg); min-height: 100%; }
body {
  margin: 0; min-height: 100svh; background: var(--bg); color: var(--fg);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
/* Themed chrome: scrollbars, selection and focus rings all follow the tokens,
   otherwise light mode gets dark scrollbars and vice versa. */
* { scrollbar-color: var(--line2) transparent; scrollbar-width: thin; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }
::selection { background: var(--sel); color: var(--fg); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1.05rem; }
.mono, code, pre { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: .86rem; } .xs { font-size: .76rem; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; }
.row.gap { gap: .5rem; } .row.end { justify-content: flex-end; }
.hidden { display: none !important; }
.err { color: var(--danger); min-height: 1.2em; font-size: .86rem; }

/* ── theme control (top bar + login) ──────────────────────────────────────── */
.themectl { display: inline-flex; flex: none; gap: 1px; padding: 2px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; }
.themebtn { border: none; background: none; border-radius: 999px; cursor: pointer;
  padding: .18rem .42rem; font-size: .84rem; line-height: 1.2; color: var(--muted);
  min-height: 0; transition: background .12s, color .12s; }
.themebtn:hover { color: var(--fg); background: var(--panel3); border: none; }
.themebtn.on { background: var(--accent); color: var(--accent-fg); }
.loginbar { position: absolute; top: .75rem; right: .75rem; z-index: 2; }

/* boot */
.booting { display: grid; place-items: center; height: 100vh; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.fatal { display: grid; place-items: center; height: 100vh; color: var(--muted); padding: 2rem; text-align: center; }

/* buttons */
button, .ghost { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--fg); padding: .5rem .85rem; transition: .12s; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
button.danger { background: var(--danger); border-color: var(--danger); color: var(--accent-fg); }
button.ghost { background: transparent; }
button.sm { padding: .32rem .6rem; font-size: .86rem; }
button.xs { padding: .15rem .45rem; font-size: .75rem; }
button.big { padding: .7rem 1rem; width: 100%; font-size: 1rem; }
input, textarea, select {
  font: inherit; width: 100%; background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
label { display: block; margin: 0 0 .75rem; font-size: .85rem; color: var(--muted); }
label input { margin-top: .25rem; color: var(--fg); }

/* ── header ───────────────────────────────────────────────────────────────
   Mobile-first two-row bar: row 1 is brand + budget + account, row 2 is the
   site breadcrumb across the full width (it is the longest, most variable
   item, and squeezing it onto row 1 is what overflows a phone). From 768px
   everything sits on one row. Nothing here relies on a fixed width. */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .6rem;
  padding: .5rem .75rem; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; text-decoration: none; color: var(--fg); flex: none; }
.top > button:last-child { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb { order: 5; flex: 1 1 100%; display: flex; align-items: center; gap: .4rem;
  min-width: 0; padding-top: .1rem; border-top: 1px solid var(--line); }
.crumb b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.crumb button { flex: none; }
@media (min-width: 768px) {
  .top { flex-wrap: nowrap; gap: .75rem; padding: .6rem 1rem; }
  .crumb { order: 0; flex: 0 1 auto; padding-top: 0; border-top: none; }
  .crumb b { max-width: 34vw; }
  .top > button:last-child { max-width: none; }
}
.budget { display: flex; align-items: center; gap: .4rem; font-size: .78rem; color: var(--muted); flex: none; }
.budget .bar { width: 56px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
@media (min-width: 768px) { .budget .bar { width: 70px; } }
.budget .bar i { display: block; height: 100%; background: var(--ok); }
.budget.warn .bar i { background: var(--warn); } .budget.danger .bar i { background: var(--danger); }

.banner { padding: .6rem 1rem; background: var(--panel2); border-bottom: 1px solid var(--line); font-size: .88rem; }
.banner.warn { background: var(--warn-bg); color: var(--warn-fg); }
.banner.danger { background: var(--danger-bg); color: var(--danger-fg); }

.wrap { padding: 1rem; max-width: 1500px; margin: 0 auto; }
.hero { margin: 1rem 0 1.25rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.card.pad { padding: 1rem; margin-bottom: 1rem; }

/* login */
.centered { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
.login { width: min(420px, 100%); padding: 1.75rem; }
.login h1 { font-size: 1.55rem; }
.login .sub { color: var(--muted); margin: 0 0 1.25rem; }
.login input { margin-bottom: .6rem; }
.login .hint { font-size: .86rem; color: var(--muted); margin: .8rem 0 0; }
.login .fine { font-size: .74rem; color: var(--muted); margin: 1rem 0 0; opacity: .75; }

/* site grid */
.sitegrid { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.site { padding: 1rem; cursor: pointer; transition: .12s; }
.site:hover { border-color: var(--accent); transform: translateY(-1px); }
.site.off { opacity: .55; }
.newsite { display: grid; place-items: center; gap: .25rem; min-height: 118px; color: var(--muted);
  border-style: dashed; background: transparent; }
.newsite .plus { font-size: 1.6rem; }
.chip { display: inline-flex; align-items: center; gap: .25rem; padding: .1rem .45rem; border-radius: 999px;
  background: var(--panel2); border: 1px solid var(--line); font-size: .74rem; }
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.chip.warn { color: var(--warn); } .chip.danger { color: var(--danger); }
.chip.del { color: var(--danger); text-decoration: line-through; }
.chip.pending { opacity: .6; }
.chip .x { background: none; border: none; padding: 0 0 0 .2rem; color: inherit; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin: .35rem 0; }

/* tabs */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tab { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0;
  padding: .55rem .85rem; color: var(--muted); }
.tab.active { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }

/* ── build pane ───────────────────────────────────────────────────────────
   Mobile-first. Base = ONE column at a time, chosen by the .paneswitch
   segmented control. 768px+ = AI beside a switchable code/preview slot.
   1200px+ = all three at once and the switch disappears. Column visibility is
   driven entirely by [data-show] + media queries, so there is no JS layout
   logic to fall out of sync with the CSS. */
.paneswitch { display: flex; gap: .25rem; margin-bottom: .6rem; background: var(--panel);
  border: 1px solid var(--line); border-radius: 999px; padding: .2rem; }
.paneswitch button { flex: 1; border: none; background: none; border-radius: 999px;
  padding: .4rem .5rem; font-size: .85rem; color: var(--muted); }
.paneswitch button.on { background: var(--accent); color: var(--accent-fg); font-weight: 600; }

.pane-build { display: grid; gap: .6rem; grid-template-columns: 1fr;
  height: calc(100svh - 210px); min-height: 400px; }
.col { display: flex; flex-direction: column; min-width: 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
/* one pane at a time on phones */
.pane-build[data-show="ai"]   .files, .pane-build[data-show="ai"]   .prev,
.pane-build[data-show="code"] .ai,    .pane-build[data-show="code"] .prev,
.pane-build[data-show="prev"] .ai,    .pane-build[data-show="prev"] .files { display: none; }
.colhead { display: flex; align-items: center; gap: .5rem; padding: .45rem .7rem; font-size: .8rem;
  font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); background: var(--panel2); }
.colhead.sub { font-weight: 400; justify-content: space-between; }
.colhead > .ghost, .colhead > a { margin-left: auto; }
.colhead > .ghost + .ghost { margin-left: 0; }

.filelist { max-height: 26%; overflow: auto; padding: .3rem; }
.file { display: flex; width: 100%; gap: .5rem; background: none; border: none; border-radius: 6px;
  padding: .28rem .45rem; text-align: left; font-size: .84rem; }
.file:hover { background: var(--panel2); }
.file.active { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.file .name { flex: 1; font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .sz { color: var(--muted); font-size: .72rem; }
.file.binary .name { opacity: .7; }
/* ── code editor ──────────────────────────────────────────────────────────
   A transparent <textarea> sits exactly on top of a highlighted <pre>. The two
   layers MUST agree on every metric — font, size, line-height, padding,
   tab-size, and the wrapping mode — or the caret drifts away from the text.
   Change one, change both. (See public/js/codeedit.js.) */
.codehost { flex: 1; min-height: 0; display: flex; }
.codewrap { position: relative; flex: 1; min-height: 0; background: var(--bg); }
.codelayer, .codeinput {
  position: absolute; inset: 0; margin: 0; padding: .6rem .7rem;
  font-family: var(--mono); font-size: 13px; line-height: 1.6;
  tab-size: 2; -moz-tab-size: 2; letter-spacing: 0;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: normal;
  border: 0; border-radius: 0; overflow: auto;
}
/* 16px on phones: anything smaller makes iOS zoom in on focus. Both layers
   move together so alignment is preserved. */
@media (max-width: 640px) { .codelayer, .codeinput { font-size: 16px; } }
.codelayer { pointer-events: none; color: var(--fg); background: transparent; z-index: 0; }
.codehl { font: inherit; background: none; padding: 0; }
.codeinput {
  z-index: 1; resize: none; background: transparent;
  color: transparent; -webkit-text-fill-color: transparent;
  caret-color: var(--accent);
}
.codeinput::placeholder { color: var(--muted); -webkit-text-fill-color: var(--muted); }
.codeinput:disabled { cursor: not-allowed; }

/* Prism tokens, mapped onto the theme so they recolour with it. */
.codehl .token.comment, .codehl .token.prolog, .codehl .token.cdata { color: var(--sx-comment); font-style: italic; }
.codehl .token.doctype { color: var(--sx-comment); }
.codehl .token.punctuation { color: var(--sx-punct); }
.codehl .token.tag, .codehl .token.deleted { color: var(--sx-tag); }
.codehl .token.attr-name, .codehl .token.builtin, .codehl .token.symbol { color: var(--sx-attr); }
.codehl .token.string, .codehl .token.attr-value, .codehl .token.char,
.codehl .token.inserted, .codehl .token.url { color: var(--sx-str); }
.codehl .token.number, .codehl .token.boolean, .codehl .token.constant,
.codehl .token.entity, .codehl .token.regex { color: var(--sx-num); }
.codehl .token.keyword, .codehl .token.atrule, .codehl .token.rule { color: var(--sx-kw); font-weight: 600; }
.codehl .token.function, .codehl .token.class-name, .codehl .token.method { color: var(--sx-fn); }
.codehl .token.selector { color: var(--sx-sel); }
.codehl .token.property { color: var(--sx-prop); }
.codehl .token.operator { color: var(--sx-punct); }
.codehl .token.variable, .codehl .token.parameter { color: var(--sx-var); }
.codehl .token.important { color: var(--sx-imp); font-weight: 700; }
.codehl .token.bold { font-weight: 700; }
.codehl .token.italic { font-style: italic; }
.codehl .token.namespace { opacity: .7; }
.savestate { font-size: .72rem; color: var(--muted); }
.savestate.dirty { color: var(--warn); } .savestate.saved { color: var(--ok); }

.commitbar { display: flex; align-items: center; gap: .5rem; padding: .5rem .6rem;
  border-top: 1px solid var(--line); background: var(--panel2); }
.commitbar b { font-size: .8rem; white-space: nowrap; }
.commitbar input { flex: 1; font-size: .82rem; padding: .35rem .5rem; }
.commitbar .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: none; }

/* The iframe shows the user's own page, which sets its own background; this
   only covers the moment before it loads, so use our surface, not white. */
#preview { flex: 1; border: none; background: var(--panel); }

/* ai panel */
.ailog { flex: 1; overflow: auto; padding: .7rem; display: flex; flex-direction: column; gap: .6rem; }
.msg { padding: .5rem .7rem; border-radius: 10px; font-size: .88rem; max-width: 100%; }
.msg.you { background: color-mix(in srgb, var(--accent) 18%, transparent); align-self: flex-end;
  max-width: 88%; white-space: pre-wrap; }
.msg.ai { background: var(--panel2); border: 1px solid var(--line); }
.msg.ai p { margin: .3rem 0 0; }
.msg.err { background: var(--danger-bg); color: var(--danger-fg); }
.msg.live { border-color: var(--accent); }
.streaming::after { content: '▍'; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.reason summary { cursor: pointer; font-size: .78rem; color: var(--muted); }
.thoughts { margin: .4rem 0 0; padding: .45rem .55rem; background: var(--bg); border-radius: 6px;
  font-size: .74rem; line-height: 1.45; color: var(--muted); white-space: pre-wrap;
  max-height: 190px; overflow: auto; }
.costline { font-size: .7rem; color: var(--muted); margin-top: .4rem; }
.aibox { border-top: 1px solid var(--line); padding: .5rem; background: var(--panel2); }
.aiprompt { resize: none; font-size: .88rem; margin-bottom: .4rem; }
.attachrow { display: flex; flex-wrap: wrap; gap: .3rem; }
.attachrow:not(:empty) { margin-bottom: .4rem; }

/* versions */
.vhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; }
.vlist { display: flex; flex-direction: column; gap: .5rem; }
.vrow { display: flex; align-items: center; gap: .8rem; padding: .65rem .8rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.vrow.live { border-color: var(--ok); }
.vn { font-family: var(--mono); font-weight: 700; color: var(--muted); min-width: 3rem; }
.vmain { flex: 1; min-width: 0; }

/* media */
.drop { display: grid; place-items: center; gap: .25rem; padding: 2rem; margin: 1rem 0;
  border: 2px dashed var(--line); border-radius: var(--radius); cursor: pointer; }
.drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.assetgrid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.asset { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.asset img { width: 100%; height: 110px; object-fit: cover; display: block; background: var(--panel2); }
.asset .noimg { display: grid; place-items: center; height: 110px; color: var(--muted); background: var(--panel2); }
.asset figcaption { padding: .4rem .5rem; display: flex; flex-direction: column; gap: .15rem; }
.asset figcaption code { overflow: hidden; text-overflow: ellipsis; }

/* settings */
.kv { display: grid; grid-template-columns: 8rem 1fr; gap: .4rem 1rem; margin: 0; font-size: .9rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }

/* modal + toasts */
.modal { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  color: var(--fg); padding: 1.25rem; width: min(420px, 92vw); }
.modal::backdrop { background: #0009; }
#toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 100; }
.toast { padding: .6rem .9rem; border-radius: 8px; background: var(--panel2); border: 1px solid var(--line);
  font-size: .88rem; box-shadow: var(--shadow); animation: in .18s ease-out; max-width: 340px; }
.toast.error { border-color: var(--danger); color: var(--danger-fg); }
.toast.ok { border-color: var(--ok); }
.toast.out { opacity: 0; transition: .3s; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }

/* ── responsive tiers ─────────────────────────────────────────────────────
   Nothing above this point assumes a wide screen; each tier only adds. */

/* Small phones: give the code editor room by shrinking chrome. */
@media (max-width: 420px) {
  .wrap { padding: .6rem; }
  .top { gap: .5rem; padding: .5rem .6rem; }
  .budget .bar { width: 44px; }
  .crumb b { max-width: 32vw; }
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; padding: .5rem .6rem; }
  .commitbar { flex-wrap: wrap; }
  .commitbar input { flex: 1 1 100%; order: 3; }
  .kv { grid-template-columns: 1fr; gap: .1rem .5rem; }
  .kv dt { margin-top: .5rem; }
}

/* Tablet: AI panel beside a switchable code/preview slot. */
@media (min-width: 768px) {
  .pane-build { grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.35fr);
    height: calc(100svh - 200px); }
  .paneswitch { max-width: 360px; margin-left: auto; }
  .paneswitch [data-pane="ai"] { display: none; }        /* always visible here */
  .pane-build[data-show="ai"] .ai,
  .pane-build[data-show="ai"] .files { display: flex; }
  .pane-build[data-show="ai"] .prev { display: none; }
  .pane-build[data-show="code"] .ai { display: flex; }
  .pane-build[data-show="prev"] .ai { display: flex; }
}

/* Desktop: all three columns, no switching. */
@media (min-width: 1200px) {
  .pane-build { grid-template-columns: minmax(290px, 1fr) minmax(320px, 1.1fr) minmax(340px, 1.25fr);
    height: calc(100svh - 175px); }
  .paneswitch { display: none; }
  .pane-build .ai, .pane-build .files, .pane-build .prev { display: flex !important; }
}

/* Touch devices: bigger hit targets, and no hover-only affordances. */
@media (hover: none) {
  button, .file { min-height: 38px; }
  .file { align-items: center; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* account menu (anchored popover, clamped to the viewport) */
.menu { position: fixed; z-index: 60; min-width: 200px; max-width: min(280px, calc(100vw - 16px));
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; }
.menu-head { padding: .6rem .8rem; border-bottom: 1px solid var(--line); }
.menu-head b { display: block; overflow-wrap: anywhere; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: none;
  border-radius: 0; padding: .65rem .8rem; font-size: .9rem; }
.menu-item:hover { background: var(--panel2); }
/* background:none is required — the global `button.danger` rule paints a solid
   red fill, which combined with red text made this item an unreadable red block. */
.menu-item.danger { background: none; color: var(--danger); border-top: 1px solid var(--line); }
.menu-item.danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.top .account { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* history tab — mobile-first: cards stack, nothing relies on width */
.hhead { margin-bottom: 1rem; }
.hlist { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1rem; }
.hcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem; }
.hcard.live { border-color: var(--accent); }
.hmeta { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.hprompt { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 .5rem;
  padding: .5rem .65rem; background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-radius: 8px; font-size: .92rem; }
.hanswer { margin: .5rem 0 0; font-size: .92rem; }
.thoughts.tall { max-height: 340px; }

/* site card: title + inline edit button */
.sitetop { display: flex; align-items: flex-start; gap: .5rem; }
.sitetop h3 { flex: 1; min-width: 0; margin: 0 0 .25rem; overflow-wrap: anywhere; }
.sitetop .edit { flex: none; opacity: .55; }
.site:hover .sitetop .edit, .sitetop .edit:focus-visible { opacity: 1; }
@media (hover: none) { .sitetop .edit { opacity: 1; } }   /* no hover on touch */
.slugstatus { margin: .2rem 0 0; font-size: .78rem; min-height: 1.1em; color: var(--muted); }
.slugstatus.ok { color: var(--ok); }
.slugstatus.bad { color: var(--danger); }

/* "open in new tab" links on a site card */
.row.wrap { flex-wrap: wrap; row-gap: .3rem; }
.openlink { font-size: .78rem; text-decoration: none; white-space: nowrap;
  padding: .1rem .4rem; border: 1px solid var(--line); border-radius: 999px; }
.openlink:hover { border-color: var(--accent); text-decoration: underline; }
.openlink.muted { color: var(--muted); }
@media (hover: none) { .openlink { padding: .3rem .55rem; } }  /* bigger tap target */

/* publishing state block on a site card */
.pubstate { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .45rem; margin: .45rem 0 .5rem; }
.pubstate .chip { font-weight: 600; }
