/* ============================== tokens ============================== */
:root {
  --ink: #1c1526;
  --ink-soft: #4a4358;
  --muted: #837c94;
  --paper: #f8f6fb;
  --surface: #ffffff;
  --surface-2: #fbf9fd;
  --line: #e6e1ee;
  --line-strong: #d8d1e6;
  --accent: #311081;
  --accent-2: #4b1fb0;
  --accent-soft: #efe7fb;
  --on-accent: #ffffff;
  --signal-bound: #1f8f5c;
  --signal-bound-soft: #e4f6ec;
  --signal-static: #b8720a;
  --signal-static-soft: #fbeed9;
  --danger: #c23a3a;
  --danger-soft: #fbe7e7;
  --shadow: rgba(43, 21, 82, 0.14);
  --card-front-a: #3c1596;
  --card-front-b: #1c0a52;
  --card-back: #f4f1fa;

  --font-display: 'Archivo', system-ui, sans-serif;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
}

a.brand { text-decoration: none; color: inherit; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f1eef8;
    --ink-soft: #cabfe0;
    --muted: #9a8fb5;
    --paper: #14101d;
    --surface: #1b1628;
    --surface-2: #100c18;
    --line: #2c2440;
    --line-strong: #3a3050;
    --accent: #b195f5;
    --accent-2: #c7aefa;
    --accent-soft: rgba(177, 149, 245, 0.16);
    --on-accent: #1b1130;
    --signal-bound: #4fce97;
    --signal-bound-soft: rgba(79, 206, 151, 0.14);
    --signal-static: #eab355;
    --signal-static-soft: rgba(234, 179, 85, 0.14);
    --danger: #ef7272;
    --danger-soft: rgba(239, 114, 114, 0.14);
    --shadow: rgba(0, 0, 0, 0.5);
    --card-front-a: #4a1cb8;
    --card-front-b: #180a44;
    --card-back: #201a30;
  }
}
:root[data-theme="dark"] {
  --ink: #f1eef8;
  --ink-soft: #cabfe0;
  --muted: #9a8fb5;
  --paper: #14101d;
  --surface: #1b1628;
  --surface-2: #100c18;
  --line: #2c2440;
  --line-strong: #3a3050;
  --accent: #b195f5;
  --accent-2: #c7aefa;
  --accent-soft: rgba(177, 149, 245, 0.16);
  --on-accent: #1b1130;
  --signal-bound: #4fce97;
  --signal-bound-soft: rgba(79, 206, 151, 0.14);
  --signal-static: #eab355;
  --signal-static-soft: rgba(234, 179, 85, 0.14);
  --danger: #ef7272;
  --danger-soft: rgba(239, 114, 114, 0.14);
  --shadow: rgba(0, 0, 0, 0.5);
  --card-front-a: #4a1cb8;
  --card-front-b: #180a44;
  --card-back: #201a30;
}

/* ============================== base ============================== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
::selection { background: var(--accent-soft); color: var(--accent); }
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.scroll-x { overflow-x: auto; }

/* ============================== shell ============================== */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 640px;
  min-width: 1120px;
  overflow: auto;
}

/* ---------- topbar ---------- */
.topbar {
  flex: 0 0 auto;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: center; gap: 9px; padding-right: 14px; border-right: 1px solid var(--line); }
.brand-mark {
  width: 26px; height: 20px; border-radius: 5px;
  background: linear-gradient(155deg, var(--accent) 0%, var(--accent-2) 100%);
  display: flex; align-items: center; justify-content: center;
  color: var(--on-accent); font-family: var(--font-display); font-weight: 800; font-size: 12px;
  flex-shrink: 0;
  transform: skewX(-8deg);
}
.brand-mark span { display: inline-block; transform: skewX(8deg); }
.brand-word { font-family: var(--font-display); font-weight: 700; font-size: 14.5px; letter-spacing: -0.01em; white-space: nowrap; }

.crumb { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.crumb b { color: var(--ink); font-weight: 600; }
.crumb .sep { opacity: 0.5; }

.side-tabs {
  display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px; padding: 3px; gap: 2px;
}
.side-tab {
  border: none; background: transparent; padding: 6px 16px; border-radius: 5px;
  font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.side-tab.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 2px var(--shadow); }
.side-tab:not(.active):hover { color: var(--ink-soft); }

.zoom-control {
  display: flex; align-items: center; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px; padding: 3px;
}
.icon-btn {
  width: 26px; height: 26px; border-radius: 5px; border: none; background: transparent;
  display: flex; align-items: center; justify-content: center; color: var(--ink-soft); cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn:disabled:hover { background: transparent; color: var(--ink-soft); }
.zoom-value { font-size: 12px; width: 42px; text-align: center; color: var(--ink-soft); }

.btn {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-size: 12.5px; font-weight: 600; padding: 7px 13px; border-radius: 7px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }

/* ---------- workspace ---------- */
.workspace { flex: 1 1 auto; display: flex; min-height: 0; }

/* rail */
.rail {
  flex: 0 0 60px; background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 6px;
}
.rail-btn {
  width: 44px; height: 44px; border-radius: 9px; border: none; background: transparent; color: var(--ink-soft);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer;
  font-size: 9.5px; font-weight: 600; letter-spacing: 0.01em;
  transition: background .15s ease, color .15s ease;
}
.rail-btn svg { width: 18px; height: 18px; }
.rail-btn:hover { background: var(--surface-2); color: var(--ink); }
.rail-btn.active { background: var(--accent-soft); color: var(--accent); }

/* left panel */
.panel {
  flex: 0 0 280px; background: var(--surface); border-right: 1px solid var(--line);
  overflow-y: auto; display: flex; flex-direction: column;
}
.panel-content { display: none; flex-direction: column; padding: 18px 16px 24px; gap: 18px; }
.panel-content.active { display: flex; }
.panel-title { font-family: var(--font-display); font-weight: 700; font-size: 14px; letter-spacing: -0.01em; }
.panel-sub { font-size: 12px; color: var(--muted); margin-top: -12px; }

.field-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  border: 1px solid transparent; cursor: pointer; text-align: left; background: none;
  transition: background .15s ease, border-color .15s ease;
}
.field-row:hover { background: var(--surface-2); }
.field-row.selected { background: var(--accent-soft); border-color: var(--accent); }
.field-type-icon {
  width: 28px; height: 28px; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--ink-soft);
}
.field-row.selected .field-type-icon { background: var(--surface); color: var(--accent); border-color: var(--accent); }
.field-type-icon svg { width: 14px; height: 14px; }
.field-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.field-name { font-size: 13px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field-bind { display: flex; align-items: center; gap: 5px; font-size: 10.5px; }
.bind-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.bind-dot.bound { background: var(--signal-bound); }
.bind-dot.unbound { background: var(--signal-static); }
.bind-label { color: var(--muted); font-family: var(--font-mono); }

.field-list { display: flex; flex-direction: column; gap: 2px; margin: 0 -6px; }

.add-field-btn {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  border: 1.5px dashed var(--line-strong); border-radius: 9px; padding: 10px; background: none;
  color: var(--muted); font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.add-field-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.template-card {
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.template-card:hover { border-color: var(--accent); }
.template-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.template-thumb {
  height: 62px; background: linear-gradient(135deg, var(--card-front-a), var(--card-front-b));
  position: relative;
}
.template-thumb::after {
  content: ''; position: absolute; inset: 0;
  background-image: repeating-linear-gradient(-45deg, rgba(255,255,255,.05) 0 6px, transparent 6px 12px);
}
.template-meta { padding: 8px 10px; display: flex; align-items: center; justify-content: space-between; background: var(--surface); }
.template-name { font-size: 12.5px; font-weight: 700; }
.template-tag {
  font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 2px 6px;
}
.template-grid { display: flex; flex-direction: column; gap: 10px; }
.state-heading { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 4px 0 -2px; }

.upload-slot {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 10px;
}
.upload-preview {
  height: 90px; border-radius: 7px; background: linear-gradient(135deg, var(--card-front-a), var(--card-front-b));
}
.upload-file { font-family: var(--font-mono); font-size: 11px; color: var(--ink-soft); word-break: break-all; }

.text-preset {
  border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; cursor: pointer; background: none; text-align: left;
  transition: border-color .15s ease, background .15s ease;
}
.text-preset:hover { border-color: var(--accent); background: var(--accent-soft); }
.text-preset-label { font-size: 10.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.text-preset-sample { font-family: var(--font-display); margin-top: 4px; }
.text-preset-sample.h1 { font-size: 20px; font-weight: 800; }
.text-preset-sample.h2 { font-size: 15px; font-weight: 700; }
.text-preset-sample.body { font-family: var(--font-ui); font-size: 13px; font-weight: 500; }
.text-preset-sample.fine { font-family: var(--font-ui); font-size: 11px; font-weight: 500; color: var(--muted); }

/* ---------- canvas area ---------- */
.canvas-area {
  flex: 1 1 auto; position: relative; overflow: auto; background: var(--surface-2);
  background-image: radial-gradient(circle, var(--line-strong) 1px, transparent 1px);
  background-size: 22px 22px;
  display: flex; align-items: center; justify-content: center; padding: 40px;
}
.sheet-meta {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px;
  box-shadow: 0 2px 6px var(--shadow);
}
.sheet-meta .dot { width: 4px; height: 4px; border-radius: 50%; background: var(--line-strong); }

.rig { display: grid; grid-template-columns: 26px auto; grid-template-rows: 26px auto; }
.ruler-corner { }
.ruler-x, .ruler-y { position: relative; color: var(--muted); }
.ruler-x { height: 26px; }
.ruler-y { width: 26px; }
.tick { position: absolute; font-family: var(--font-mono); font-size: 8.5px; color: var(--muted); }
.tick.x { top: 14px; transform: translateX(-50%); }
.tick.x::before { content: ''; position: absolute; left: 50%; bottom: 100%; width: 1px; height: 5px; background: var(--line-strong); }
.tick.y { left: 4px; transform: translateY(-50%); }
.tick.y::before { content: ''; position: absolute; top: 50%; right: -6px; height: 1px; width: 5px; background: var(--line-strong); }

.artboard-wrap { position: relative; }
.reg-mark { position: absolute; width: 16px; height: 16px; pointer-events: none; }
.reg-mark::before, .reg-mark::after { content: ''; position: absolute; background: var(--muted); opacity: 0.55; }
.reg-mark::before { left: 50%; top: 0; width: 1px; height: 100%; transform: translateX(-50%); }
.reg-mark::after { top: 50%; left: 0; height: 1px; width: 100%; transform: translateY(-50%); }
.reg-mark.tl { top: -24px; left: -24px; }
.reg-mark.tr { top: -24px; right: -24px; }
.reg-mark.bl { bottom: -24px; left: -24px; }
.reg-mark.br { bottom: -24px; right: -24px; }

.artboard {
  position: relative; width: 560px; height: 347.5px;
  border-radius: 8px; overflow: hidden;
  box-shadow: 0 1px 2px var(--shadow), 0 18px 40px -12px var(--shadow);
  transition: transform .18s ease;
  background: var(--card-back);
}
.artboard.front { background: linear-gradient(150deg, var(--card-front-a) 0%, var(--card-front-b) 100%); }
.artboard.front::before {
  content: '';
  position: absolute; inset: 0;
  background-image: radial-gradient(circle at 15% 20%, rgba(255,255,255,0.10), transparent 45%),
    repeating-linear-gradient(115deg, rgba(255,255,255,0.035) 0 2px, transparent 2px 26px);
}
.specimen {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none; z-index: 5; overflow: hidden;
}
.specimen span {
  font-family: var(--font-display); font-weight: 800; font-size: 30px; letter-spacing: 0.14em;
  color: rgba(255,255,255,0.16); transform: rotate(-11deg); white-space: nowrap;
}
.artboard.back .specimen span { color: rgba(28,21,38,0.10); }

.field-box {
  position: absolute; border: 1.5px solid transparent; border-radius: 3px; cursor: grab;
  display: flex; align-items: center; padding: 0 3px;
  transition: border-color .12s ease, background .12s ease;
}
.field-box:hover { border-color: rgba(255,255,255,0.5); }
.artboard.back .field-box:hover { border-color: var(--muted); }
.field-box.selected { border-color: var(--accent); background: rgba(177, 149, 245, 0.12); cursor: grabbing; }
.field-box.selected::before {
  content: attr(data-tab); position: absolute; top: -19px; left: -1.5px;
  background: var(--accent); color: var(--on-accent); font-size: 9px; font-weight: 700;
  padding: 2px 6px; border-radius: 4px 4px 4px 0; white-space: nowrap; font-family: var(--font-ui);
}
.handle {
  position: absolute; width: 7px; height: 7px; background: var(--accent); border: 1.5px solid var(--surface);
  border-radius: 2px; display: none;
}
.field-box.selected .handle { display: block; }
.handle.nw { top: -4px; left: -4px; cursor: nwse-resize; }
.handle.ne { top: -4px; right: -4px; cursor: nesw-resize; }
.handle.sw { bottom: -4px; left: -4px; cursor: nesw-resize; }
.handle.se { bottom: -4px; right: -4px; cursor: nwse-resize; }

.f-text { font-family: var(--font-ui); font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; }
.f-photo { width: 100%; height: 100%; border-radius: 3px; display: flex; align-items: center; justify-content: center; }
.f-photo svg { width: 46%; height: 46%; opacity: 0.85; }
.f-qr { width: 100%; height: 100%; border-radius: 2px; background: #fff; padding: 3px; }
.f-qr svg { width: 100%; height: 100%; }

/* mini sheet map */
.sheet-mini {
  position: absolute; left: 18px; bottom: 18px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; box-shadow: 0 2px 10px var(--shadow); width: 156px;
}
.sheet-mini-title { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 8px; }
.sheet-mini-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.sheet-mini-cell { aspect-ratio: 259.09 / 161.01; background: var(--surface-2); border: 1px solid var(--line); border-radius: 2px; }
.sheet-mini-cell.current { background: var(--accent-soft); border-color: var(--accent); }
.sheet-mini-caption { font-family: var(--font-mono); font-size: 9.5px; color: var(--muted); margin-top: 8px; display: flex; justify-content: space-between; }

/* ---------- inspector ---------- */
.inspector { flex: 0 0 300px; background: var(--surface); border-left: 1px solid var(--line); overflow-y: auto; }
.inspector-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%;
  padding: 40px 24px; text-align: center; gap: 10px; color: var(--muted);
}
.inspector-empty svg { width: 34px; height: 34px; opacity: 0.5; }
.inspector-empty p { font-size: 12.5px; margin: 0; line-height: 1.5; }

.insp-header { padding: 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.insp-icon {
  width: 32px; height: 32px; border-radius: 8px; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.insp-icon svg { width: 16px; height: 16px; }
.insp-title { flex: 1; min-width: 0; }
.insp-name { font-family: var(--font-display); font-weight: 700; font-size: 14.5px; }
.insp-type { font-size: 11px; color: var(--muted); text-transform: capitalize; }
.insp-delete {
  width: 30px; height: 30px; border-radius: 7px; border: none; background: none; color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: background .15s ease, color .15s ease;
}
.insp-delete svg { width: 15px; height: 15px; }
.insp-delete:hover { background: var(--danger-soft); color: var(--danger); }

.insp-section { padding: 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.insp-section-title { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.field-label { font-size: 12px; font-weight: 600; color: var(--ink-soft); display: block; margin-bottom: 6px; }
.input, .select {
  width: 100%; border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink);
  border-radius: 7px; padding: 8px 10px; font-size: 12.5px; font-family: var(--font-ui);
}
.input:focus, .select:focus, .stepper:focus-within { outline: none; border-color: var(--accent); background: var(--surface); }
.input.mono { font-family: var(--font-mono); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-4 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 10px; }

.stepper {
  display: flex; align-items: stretch; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--surface-2); overflow: hidden;
}
.stepper .unit-label { display: flex; align-items: center; padding: 0 4px 0 9px; font-size: 10.5px; color: var(--muted); font-weight: 600; }
.stepper input {
  border: none; background: none; width: 100%; padding: 8px 2px 8px 0; font-family: var(--font-mono); font-size: 12.5px;
  color: var(--ink); text-align: right;
}
.stepper input:focus { outline: none; }
.stepper-btns { display: flex; flex-direction: column; border-left: 1px solid var(--line-strong); }
.stepper-btns button {
  flex: 1; border: none; background: none; width: 20px; color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.stepper-btns button:first-child { border-bottom: 1px solid var(--line-strong); }
.stepper-btns button:hover { background: var(--accent-soft); color: var(--accent); }
.stepper-btns svg { width: 8px; height: 8px; }
.field-mini-label { font-size: 10px; color: var(--muted); margin-bottom: 4px; display: block; }

.swatch-row { display: flex; align-items: center; gap: 8px; }
.swatch { width: 32px; height: 32px; border-radius: 7px; border: 1px solid var(--line-strong); flex-shrink: 0; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; }
.toggle-row .field-label { margin: 0; }
.switch { width: 34px; height: 20px; border-radius: 999px; background: var(--line-strong); position: relative; cursor: pointer; border: none; flex-shrink: 0; transition: background .15s ease; }
.switch::after { content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); top: 2px; left: 2px; transition: transform .15s ease; box-shadow: 0 1px 2px var(--shadow); }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(14px); }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: var(--font-mono); font-size: 10.5px; background: var(--surface-2); border: 1px solid var(--line);
  color: var(--ink-soft); padding: 4px 8px; border-radius: 999px;
}

.status-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; padding: 6px 10px; border-radius: 999px; width: fit-content;
}
.status-pill.bound { background: var(--signal-bound-soft); color: var(--signal-bound); }
.status-pill.unbound { background: var(--signal-static-soft); color: var(--signal-static); }
.status-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pill b { font-family: var(--font-mono); font-weight: 600; }

/* toast */
.toast-wrap { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 999; }
.toast {
  background: var(--ink); color: var(--paper); font-size: 12.5px; font-weight: 600; padding: 11px 16px; border-radius: 9px;
  box-shadow: 0 8px 24px var(--shadow); display: flex; align-items: center; gap: 9px;
  animation: toast-in .22s cubic-bezier(.2,.8,.2,1);
}
:root[data-theme="dark"] .toast, @media (prefers-color-scheme: dark) { }
.toast svg { width: 14px; height: 14px; color: var(--signal-bound); flex-shrink: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

button:focus-visible, .field-row:focus-visible, .rail-btn:focus-visible, .side-tab:focus-visible, .template-card:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------- account chip ---------- */
.account-chip {
  position: relative; display: flex; align-items: center; gap: 8px;
  padding: 5px 11px 5px 5px; border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--surface); cursor: pointer;
}
.account-chip[hidden] { display: none; }
.account-avatar {
  width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
  font-family: var(--font-display); flex-shrink: 0;
}
.account-label { font-size: 12px; font-weight: 600; color: var(--ink-soft); max-width: 128px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-chevron { width: 12px; height: 12px; color: var(--muted); flex-shrink: 0; }
.account-dropdown {
  position: absolute; top: calc(100% + 10px); right: 0; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 10px 28px var(--shadow); padding: 8px; width: 210px; z-index: 20;
}
.account-dropdown[hidden] { display: none; }
.account-dropdown-meta { font-size: 11px; color: var(--muted); padding: 6px 8px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; line-height: 1.5; }
.account-dropdown-meta b { color: var(--ink-soft); }
.account-signout {
  width: 100%; text-align: left; background: none; border: none; padding: 8px; border-radius: 7px;
  font-size: 12.5px; font-weight: 600; color: var(--danger); cursor: pointer;
}
.account-signout:hover { background: var(--danger-soft); }

/* ---------- auth modal ---------- */
.auth-overlay {
  position: fixed; inset: 0; background: rgba(15, 9, 26, 0.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 200;
  opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
.auth-overlay.open { opacity: 1; pointer-events: auto; }
.auth-modal {
  background: var(--surface); border-radius: 16px; width: 392px; max-width: 92vw; padding: 26px 26px 22px;
  box-shadow: 0 24px 60px -12px var(--shadow), 0 0 0 1px var(--line); position: relative;
  transform: translateY(10px) scale(0.98); transition: transform .18s ease;
}
.auth-overlay.open .auth-modal { transform: translateY(0) scale(1); }
.auth-close {
  position: absolute; top: 14px; right: 14px; width: 28px; height: 28px; border-radius: 7px; border: none;
  background: none; color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s ease, color .15s ease;
}
.auth-close:hover { background: var(--surface-2); color: var(--ink); }
.auth-close svg { width: 15px; height: 15px; }
.auth-step[hidden] { display: none; }
.auth-icon {
  width: 42px; height: 42px; border-radius: 11px; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; margin-bottom: 16px;
}
.auth-icon svg { width: 21px; height: 21px; }
.auth-title { font-family: var(--font-display); font-weight: 700; font-size: 18.5px; letter-spacing: -0.01em; margin: 0 0 6px; text-wrap: balance; }
.auth-subtitle { font-size: 13px; color: var(--muted); line-height: 1.55; margin: 0 0 20px; }
.auth-subtitle b { color: var(--ink-soft); font-weight: 600; }

.google-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 10px;
  border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-size: 13.5px; font-weight: 600; cursor: pointer; transition: background .15s ease, box-shadow .15s ease;
}
.google-btn:hover { background: var(--surface-2); box-shadow: 0 1px 4px var(--shadow); }
.google-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.google-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.google-btn:disabled:hover { background: var(--surface); box-shadow: none; }
#googleBtnSlot .gsi-material-button { width: 100%; }

.auth-divider { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--muted); font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.phone-field { margin-bottom: 14px; }
.phone-input-row { display: flex; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--surface-2); overflow: hidden; transition: border-color .15s ease; }
.phone-input-row:focus-within { border-color: var(--accent); }
.phone-prefix {
  display: flex; align-items: center; padding: 0 10px; font-family: var(--font-mono); font-size: 12.5px;
  color: var(--ink-soft); border-right: 1px solid var(--line-strong); background: var(--surface); flex-shrink: 0;
}
.phone-input-row input { border: none; background: none; padding: 9px 10px; font-size: 13.5px; width: 100%; color: var(--ink); font-family: var(--font-mono); }
.phone-input-row input:focus { outline: none; }
.field-error { font-size: 11.5px; color: var(--danger); margin-top: 6px; display: none; }
.field-error.show { display: block; }

.auth-fineprint { font-size: 11px; color: var(--muted); text-align: center; margin: 16px 0 0; line-height: 1.5; }

.auth-back { display: flex; align-items: center; gap: 5px; background: none; border: none; color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer; padding: 0; margin-bottom: 14px; }
.auth-back:hover { color: var(--accent); }
.auth-back svg { width: 13px; height: 13px; }

.otp-boxes { display: flex; gap: 8px; margin-bottom: 16px; }
.otp-box {
  width: 100%; aspect-ratio: 1; text-align: center; font-family: var(--font-mono); font-size: 19px; font-weight: 500;
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface-2); color: var(--ink);
  transition: border-color .15s ease, background .15s ease;
}
.otp-box:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.otp-box.filled { border-color: var(--line-strong); background: var(--surface); }

.auth-resend { text-align: center; font-size: 12px; color: var(--muted); margin: 14px 0 0; }
.auth-resend button { background: none; border: none; color: var(--accent); font-weight: 700; cursor: pointer; padding: 0; font-size: 12px; font-family: inherit; }
.auth-resend button:disabled { color: var(--muted); cursor: default; }

.auth-spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: auth-spin .7s linear infinite; margin: 6px auto 18px; }
@keyframes auth-spin { to { transform: rotate(360deg); } }
.auth-loading { display: flex; flex-direction: column; align-items: center; padding: 8px 0 4px; }

.auth-success-icon {
  width: 50px; height: 50px; border-radius: 50%; background: var(--signal-bound-soft); color: var(--signal-bound);
  display: flex; align-items: center; justify-content: center; margin: 6px auto 16px;
}
.auth-success-icon svg { width: 24px; height: 24px; }
.auth-success-text { text-align: center; font-size: 13.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 4px; }
