/* PhotoForge AI — mobile-first styles
   Theming: follows the system by default; Settings can force light/dark via
   <html data-theme="light|dark">. */

:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --radius-s: 10px;
  --radius: 16px;
  --radius-l: 22px;
  --gap: 12px;
  --tabbar-h: 58px;
  --topbar-h: 52px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --accent-1: #6a4cff;
  --accent-2: #c13fd0;
  --accent-3: #ff9f43;
  --accent-grad: linear-gradient(120deg, var(--accent-1), var(--accent-2) 60%, var(--accent-3));

  /* light tokens */
  --bg: #f4f4f7;
  --bg-elev: #ffffff;
  --bg-sunken: #eaeaef;
  --line: rgba(20, 20, 40, 0.09);
  --line-strong: rgba(20, 20, 40, 0.18);
  --text: #111118;
  --text-2: #55556a;
  --text-3: #8a8a9c;
  --accent: #5b3df5;
  --accent-soft: rgba(91, 61, 245, 0.12);
  --ok: #138a4c;
  --ok-soft: rgba(19, 138, 76, 0.12);
  --warn: #a8640a;
  --warn-soft: rgba(230, 150, 20, 0.15);
  --err: #c62a3a;
  --err-soft: rgba(198, 42, 58, 0.12);
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(20,20,60,.08);
  --glass: rgba(255, 255, 255, 0.78);
  --checker-a: #e6e6ec;
  --checker-b: #f6f6f9;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b10;
    --bg-elev: #16161e;
    --bg-sunken: #0f0f15;
    --line: rgba(255, 255, 255, 0.08);
    --line-strong: rgba(255, 255, 255, 0.16);
    --text: #f3f3f7;
    --text-2: #a9a9bb;
    --text-3: #6f6f82;
    --accent: #8f7aff;
    --accent-soft: rgba(143, 122, 255, 0.16);
    --ok: #3ddc84;
    --ok-soft: rgba(61, 220, 132, 0.14);
    --warn: #ffb648;
    --warn-soft: rgba(255, 182, 72, 0.14);
    --err: #ff5d6c;
    --err-soft: rgba(255, 93, 108, 0.14);
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
    --glass: rgba(18, 18, 26, 0.78);
    --checker-a: #1d1d26;
    --checker-b: #262631;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0b10;
  --bg-elev: #16161e;
  --bg-sunken: #0f0f15;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f3f3f7;
  --text-2: #a9a9bb;
  --text-3: #6f6f82;
  --accent: #8f7aff;
  --accent-soft: rgba(143, 122, 255, 0.16);
  --ok: #3ddc84;
  --ok-soft: rgba(61, 220, 132, 0.14);
  --warn: #ffb648;
  --warn-soft: rgba(255, 182, 72, 0.14);
  --err: #ff5d6c;
  --err-soft: rgba(255, 93, 108, 0.14);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  --glass: rgba(18, 18, 26, 0.78);
  --checker-a: #1d1d26;
  --checker-b: #262631;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, a, label, .tab { touch-action: manipulation; }
img, canvas { display: block; max-width: 100%; }
[hidden] { display: none !important; }
.noscript { padding: 24px; text-align: center; }

/* ---------- Layout ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--topbar-h) + var(--safe-t));
  padding: var(--safe-t) calc(16px + var(--safe-r)) 0 calc(16px + var(--safe-l));
  display: flex; align-items: center; justify-content: space-between;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.01em; }
.brand-mark { border-radius: 8px; }
.brand-name { font-size: 17px; }
.brand-ai { background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.count-pill {
  font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
  padding: 4px 10px; border-radius: 999px; background: var(--bg-sunken); color: var(--text-2);
  border: 1px solid var(--line);
}

.views {
  flex: 1;
  padding: 16px calc(16px + var(--safe-r)) calc(var(--tabbar-h) + var(--safe-b) + 24px) calc(16px + var(--safe-l));
  width: 100%; max-width: 760px; margin: 0 auto;
}
.view { animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--text-3); font-size: 10.5px; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--accent); }

/* ---------- Typography ---------- */
.h1 { font-size: 28px; font-weight: 750; letter-spacing: -0.02em; margin: 4px 0 4px; }
.lede { color: var(--text-2); margin: 0 0 16px; font-size: 15px; }
.h2 { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin: 22px 4px 8px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.tiny { font-size: 12px; color: var(--text-3); }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.card + .card { margin-top: var(--gap); }
.card-title { font-weight: 650; margin: 0 0 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.divider { height: 1px; background: var(--line); margin: 12px 0; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--line-strong); background: var(--bg-elev); color: var(--text);
  min-height: 44px; padding: 0 16px; border-radius: 12px; font-weight: 600; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  transition: transform .08s ease, opacity .15s, background .15s;
  user-select: none; -webkit-user-select: none; white-space: nowrap; text-decoration: none;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent-grad); color: #fff; border-color: transparent; box-shadow: 0 6px 18px rgba(106, 76, 255, .3); }
.btn.primary:disabled { box-shadow: none; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.danger { color: var(--err); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.icon { width: 44px; padding: 0; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Segmented control */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bg-sunken); border-radius: 12px; padding: 3px; gap: 3px; border: 1px solid var(--line); }
.seg button {
  appearance: none; border: 0; background: transparent; min-height: 36px; border-radius: 9px;
  font-weight: 600; font-size: 14px; color: var(--text-2); cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }

/* Chips */
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.chip {
  appearance: none; text-align: left; border: 1px solid var(--line); background: var(--bg-sunken);
  border-radius: 12px; padding: 10px 12px; cursor: pointer; min-height: 56px;
}
.chip strong { display: block; font-size: 14px; }
.chip span { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }

/* Inputs */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--bg-sunken); font-size: 16px; /* >=16px avoids iOS zoom */
}
textarea.input { resize: vertical; min-height: 88px; line-height: 1.4; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.dims { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: end; }
.lock-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.slider { display: grid; grid-template-columns: 96px 1fr 44px; align-items: center; gap: 10px; min-height: 40px; }
.slider label { font-size: 14px; color: var(--text-2); }
.slider output { font-size: 13px; text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }
input[type="color"] { width: 44px; height: 44px; border: 1px solid var(--line-strong); border-radius: 12px; padding: 4px; background: var(--bg-sunken); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---------- Banners / notices ---------- */
.notice { border-radius: var(--radius); padding: 12px 14px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); }
.notice svg { flex: none; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; margin-top: 1px; }
.notice.info { background: var(--accent-soft); color: var(--text); }
.notice.warn { background: var(--warn-soft); }
.notice.err { background: var(--err-soft); }
.notice.ok { background: var(--ok-soft); }
.notice a { color: var(--accent); font-weight: 600; }
.notice + .notice, .notice + .card, .card + .notice { margin-top: var(--gap); }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 999px; background: var(--bg-sunken); color: var(--text-2); }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); background: var(--ok-soft); }
.pill.warn { color: var(--warn); background: var(--warn-soft); }
.pill.err { color: var(--err); background: var(--err-soft); }

/* ---------- Dropzone / empty ---------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  gap: 10px; padding: 36px 20px; border-radius: var(--radius-l);
  border: 1.5px dashed var(--line-strong); background: var(--bg-elev); cursor: pointer;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .dz-icon { width: 64px; height: 64px; border-radius: 20px; background: var(--accent-grad); display: grid; place-items: center; box-shadow: 0 10px 30px rgba(106,76,255,.35); }
.dropzone .dz-icon svg { width: 30px; height: 30px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; }
.dropzone strong { font-size: 18px; }

/* ---------- Photo grid ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0; }
.toolbar .spacer { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.tile {
  position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--bg-sunken);
  border: 2px solid transparent; cursor: pointer; padding: 0; appearance: none;
}
.tile img { width: 100%; height: 100%; object-fit: cover; }
.tile img:not([src]) { visibility: hidden; }
.tile.selected { border-color: var(--accent); }
.tile.selected img { transform: scale(0.94); border-radius: 8px; transition: transform .12s; }
.tile .check {
  position: absolute; top: 6px; left: 6px; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0,0,0,.25); display: grid; place-items: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.tile.selected .check { background: var(--accent); border-color: #fff; }
.tile .check svg { width: 14px; height: 14px; stroke: #fff; fill: none; stroke-width: 3; opacity: 0; }
.tile.selected .check svg { opacity: 1; }
.tile .remove {
  position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.5); color: #fff; display: grid; place-items: center; cursor: pointer;
}
.tile .remove svg { width: 14px; height: 14px; stroke: #fff; stroke-width: 2.5; fill: none; }
.tile .badge {
  position: absolute; left: 6px; right: 6px; bottom: 6px; font-size: 11px; font-weight: 650;
  padding: 3px 7px; border-radius: 8px; background: rgba(0,0,0,.6); color: #fff; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.badge.s-processing, .badge.s-queued { background: rgba(106,76,255,.85); }
.badge.s-done { background: rgba(19,138,76,.88); }
.badge.s-error { background: rgba(198,42,58,.9); }
.badge.s-cancelled { background: rgba(120,120,130,.85); }
.tile .spinner { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.25); }

.spin { width: 22px; height: 22px; border: 2.5px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* Filmstrip */
.filmstrip { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; }
.filmstrip button {
  flex: none; width: 60px; height: 60px; border-radius: 12px; overflow: hidden; padding: 0; border: 2px solid transparent;
  background: var(--bg-sunken); position: relative; cursor: pointer; scroll-snap-align: start;
}
.filmstrip button img { width: 100%; height: 100%; object-fit: cover; }
.filmstrip button[aria-current="true"] { border-color: var(--accent); }
.filmstrip .dot { position: absolute; right: 4px; bottom: 4px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid #fff; }
.dot.s-done { background: var(--ok); } .dot.s-error { background: var(--err); } .dot.s-processing, .dot.s-queued { background: var(--accent); }

/* ---------- Preview stage ---------- */
.stage {
  position: relative; border-radius: var(--radius); overflow: hidden; display: grid; place-items: center;
  background-color: var(--checker-b);
  background-image: linear-gradient(45deg, var(--checker-a) 25%, transparent 25%, transparent 75%, var(--checker-a) 75%),
                    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%, transparent 75%, var(--checker-a) 75%);
  background-size: 20px 20px; background-position: 0 0, 10px 10px;
  border: 1px solid var(--line); min-height: 220px; max-height: 56vh; padding: 12px;
}
.stage canvas, .stage img.preview { max-height: calc(56vh - 24px); width: auto; max-width: 100%; height: auto; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.stage .draggable { cursor: grab; touch-action: none; }
.stage .stage-meta {
  position: absolute; left: 10px; bottom: 10px; font-size: 12px; font-weight: 600; padding: 4px 8px; border-radius: 8px;
  background: rgba(0,0,0,.6); color: #fff; font-variant-numeric: tabular-nums;
}
.stage .stage-hint { position: absolute; right: 10px; bottom: 10px; font-size: 12px; padding: 4px 8px; border-radius: 8px; background: rgba(0,0,0,.6); color: #fff; }
.stage .empty { color: var(--text-3); text-align: center; padding: 24px; }
.stage .loading { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.18); }

/* Compare slider (before/after) */
.compare { position: relative; width: 100%; aspect-ratio: var(--ratio, 1); max-height: 56vh; border-radius: var(--radius); overflow: hidden; background: var(--bg-sunken); touch-action: pan-y; user-select: none; -webkit-user-select: none; border: 1px solid var(--line); }
.compare > .layer { position: absolute; inset: 0; }
.compare > .layer img { width: 100%; height: 100%; object-fit: contain; }
.compare > .after { clip-path: inset(0 0 0 var(--pos, 50%)); }
.compare .handle { position: absolute; top: 0; bottom: 0; left: var(--pos, 50%); width: 2px; background: #fff; transform: translateX(-1px); box-shadow: 0 0 6px rgba(0,0,0,.5); pointer-events: none; }
.compare .knob { position: absolute; top: 50%; left: 50%; width: 36px; height: 36px; border-radius: 50%; background: #fff; transform: translate(-50%, -50%); box-shadow: 0 2px 10px rgba(0,0,0,.4); display: grid; place-items: center; }
.compare .knob svg { width: 18px; height: 18px; stroke: #222; stroke-width: 2.5; fill: none; }
.compare .tag { position: absolute; top: 10px; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 4px 8px; border-radius: 8px; background: rgba(0,0,0,.6); color: #fff; }
.compare .tag.l { left: 10px; } .compare .tag.r { right: 10px; }
.compare input[type="range"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: ew-resize; margin: 0; }

.placeholder-art {
  width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; padding: 20px;
  color: #fff;
  background:
    repeating-linear-gradient(-45deg, rgba(255,255,255,.06) 0 12px, transparent 12px 24px),
    linear-gradient(140deg, rgba(91,61,245,.85), rgba(193,63,208,.8) 60%, rgba(255,159,67,.8));
}
.placeholder-art strong { font-size: 14px; letter-spacing: .08em; text-transform: uppercase; }
.placeholder-art span { font-size: 13px; opacity: .9; max-width: 260px; }

/* Crop position grid */
.posgrid { display: grid; grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(3, 40px); gap: 4px; }
.posgrid button { border: 1px solid var(--line-strong); background: var(--bg-sunken); border-radius: 8px; cursor: pointer; position: relative; }
.posgrid button::after { content: ""; position: absolute; inset: 14px; border-radius: 50%; background: var(--text-3); }
.posgrid button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.posgrid button[aria-pressed="true"]::after { background: var(--accent); }

/* Style gallery */
.styles { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 10px; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; }
.style-card {
  flex: none; width: 118px; border-radius: 14px; overflow: hidden; border: 2px solid transparent; background: var(--bg-elev);
  padding: 0; text-align: left; cursor: pointer; scroll-snap-align: start; box-shadow: var(--shadow);
}
.style-card .art { height: 84px; position: relative; }
.style-card .art .emoji { position: absolute; right: 8px; bottom: 6px; font-size: 22px; filter: drop-shadow(0 2px 4px rgba(0,0,0,.4)); }
.style-card .meta { padding: 8px 10px 10px; }
.style-card strong { font-size: 13px; display: block; }
.style-card span { font-size: 11px; color: var(--text-3); display: block; line-height: 1.25; margin-top: 2px; }
.style-card[aria-pressed="true"] { border-color: var(--accent); }

/* Progress */
.progress { height: 8px; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; border: 1px solid var(--line); }
.progress > div { height: 100%; width: 0; background: var(--accent-grad); transition: width .25s ease; }

/* Results list */
.results { display: flex; flex-direction: column; gap: 8px; }
.result { display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; align-items: center; padding: 8px; border-radius: 14px; background: var(--bg-sunken); border: 1px solid var(--line); }
.result img { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--bg); }
.result .name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result .sub { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.result .sub.err { color: var(--err); white-space: normal; }
.result .actions { display: flex; gap: 6px; }

/* Estimate */
.estimate { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.estimate div { background: var(--bg-sunken); border-radius: 12px; padding: 10px; text-align: center; border: 1px solid var(--line); }
.estimate b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.estimate span { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }

/* Settings lists */
.list { border-radius: var(--radius); overflow: hidden; background: var(--bg-elev); border: 1px solid var(--line); box-shadow: var(--shadow); }
.list > .item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; min-height: 52px; }
.list > .item + .item { border-top: 1px solid var(--line); }
.list .item .k { font-weight: 550; }
.list .item .v { color: var(--text-2); font-size: 14px; text-align: right; overflow-wrap: anywhere; }
.list .item select.input { width: auto; min-width: 130px; }
.list .item.col { flex-direction: column; align-items: stretch; }
ul.plain { margin: 0; padding-left: 18px; color: var(--text-2); font-size: 14px; }
ul.plain li + li { margin-top: 6px; }

/* Details (collapsible sections) */
details.section { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
details.section + details.section { margin-top: var(--gap); }
details.section > summary { list-style: none; cursor: pointer; padding: 14px; font-weight: 650; display: flex; align-items: center; justify-content: space-between; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::after { content: ""; width: 9px; height: 9px; border-right: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3); transform: rotate(45deg); transition: transform .15s; margin-right: 4px; }
details.section[open] > summary::after { transform: rotate(-135deg); }
details.section > .body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 12px; }
summary .sum-val { margin-left: auto; margin-right: 12px; font-weight: 500; font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* Toasts */
.toast-host { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); z-index: 50; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto; max-width: 520px; width: fit-content; padding: 10px 14px; border-radius: 14px; font-size: 14px; font-weight: 550;
  background: #1c1c26; color: #fff; box-shadow: 0 10px 30px rgba(0,0,0,.35); animation: toastIn .2s ease-out;
  display: flex; gap: 10px; align-items: center;
}
.toast.err { background: #8a1f2b; }
.toast.ok { background: #145c37; }
.toast button { background: transparent; border: 0; color: #c9bfff; font-weight: 700; cursor: pointer; padding: 4px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Edit preview overlays */
.canvas-wrap { position: relative; display: inline-block; line-height: 0; max-width: 100%; border-radius: 2px; overflow: hidden; }
.circle-guide { position: absolute; inset: 0; border-radius: 50%; border: 2px dashed rgba(255,255,255,.9); box-shadow: 0 0 0 9999px rgba(0,0,0,.45); pointer-events: none; }
.stage .stage-ai { position: absolute; left: 10px; top: 10px; right: 10px; font-size: 12px; font-weight: 600; padding: 5px 9px; border-radius: 8px; background: rgba(91,61,245,.85); color: #fff; width: fit-content; max-width: calc(100% - 20px); }

/* Category tabs (scrollable pills) */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 8px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; appearance: none; border: 1px solid var(--line-strong); background: var(--bg-sunken); color: var(--text-2); border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 600; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
