/* =====================================================================
   ARC — AI Portal.  Brand system mirrored from arc-squared.com:
   gold (#c8a35a) rationed as the single accent on a near-black neutral
   base, system geometric sans, tight radii, flat low-alpha surfaces,
   crisp 1px edges, letter-spaced uppercase micro-labels, no glow / no
   gradient text.  (See RESEARCH.md.)
   ===================================================================== */

:root {
  /* neutral base — depth via surface lightness, not shadow */
  --bg:        #000000;
  --bg-elev:   #0a0a0a;
  --panel:     #111213;
  --panel-2:   #1a1c1e;
  --line:      #262626;
  --line-2:    #333537;

  /* text ramp — off-white → neutral greys (WCAG ≥ 4.5:1) */
  --text:   #f4f4f5;
  --text-2: #a1a1aa;
  --muted:  #71717a;

  /* single accent — brand gold */
  --gold-deep:   #7d5620;
  --gold:        #c8a35a;
  --gold-bright: #d4af70;
  --gold-light:  #eacfa6;
  --on-gold:     #171003;

  --gold-a08: rgb(200 163 90 / .08);
  --gold-a14: rgb(200 163 90 / .14);
  --gold-a40: rgb(200 163 90 / .40);

  /* brand blue — carried from the Arc-Squared "A" mark; used softly as ambient glow */
  --blue-edge: #1e3a8a;
  --blue-core: #60a5fa;
  --blue-a04:  rgb(96 165 250 / .04);
  --blue-a06:  rgb(96 165 250 / .06);
  --blue-a10:  rgb(96 165 250 / .10);
  --blue-glow: rgb(96 165 250 / .38);

  --danger: #e5675f;
  --ok:     #5cba7d;

  /* engineered / tight radii */
  --r-sm: 6px;
  --r:    8px;
  --r-lg: 12px;
  --radius: var(--r);

  font-size: 15px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
*::selection { background: var(--gold-a40); color: #fff; }
[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100vh;
  height: 100dvh;        /* mobile: exclude the browser chrome so the top bar is never cut off */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* thin, unobtrusive scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; }

/* ---------- top bar ---------- */
.topbar {
  position: relative;              /* anchor for the centred tool tabs */
  display: flex;
  align-items: center;
  /* geometry is shared with .site-header so the wordmark never shifts
     when you move between the portal and the public pages */
  gap: 14px;
  padding: 12px 24px;
  min-height: 62px;
  flex-shrink: 0;
  /* faint blue glow at the top-left, tying in the Arc-Squared mark */
  background:
    radial-gradient(130% 320% at 0% 0%, var(--blue-a06), transparent 42%),
    var(--bg-elev);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; }
/* Arc-Squared "A·ai" portal mark */
.brand-logo {
  height: 34px; width: auto; display: block;   /* enough for the gold "ai" to read */
}
.brand-logo.lg { height: 50px; }
.brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: var(--gold);
  color: var(--on-gold);
  font-size: 18px;
  border-radius: var(--r-sm);
}
.brand-name {
  font-weight: 600;
  font-size: .82rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--text);
}
.brand-sub { font-size: .68rem; color: var(--muted); letter-spacing: .14em; text-transform: uppercase; }

/* Tool tabs are pinned to the true centre of the header and never shift as the
   left or right groups change width. */
.tabs {
  position: absolute; left: 50%; transform: translateX(-50%);
  display: flex; gap: 2px;
  background: var(--panel); padding: 3px;
  border-radius: var(--r); border: 1px solid var(--line);
  z-index: 1;
}
.top-actions { margin-left: auto; }
.tab {
  border: 0; background: transparent; color: var(--text-2);
  padding: 8px 16px; border-radius: var(--r-sm); cursor: pointer;
  font-size: .82rem; font-weight: 500; letter-spacing: .01em;
  transition: color .15s, background .15s;
}
.tab.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.tab.active::after {
  content: ""; display: block; height: 2px; margin: 6px -4px -6px;
  background: var(--gold); border-radius: 2px;
}
.tab:hover:not(.active) { color: var(--text); }

.top-actions { display: flex; align-items: center; gap: 10px; }
.key-status { color: var(--danger); font-size: 12px; }
.key-status.ok { color: var(--gold); }
.icon-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--text-2);
  width: 34px; height: 34px; border-radius: var(--r-sm); cursor: pointer; font-size: 15px;
  transition: color .15s, border-color .15s, background .15s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--line-2); }

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

/* main site nav inside the portal header — only "Portal" stays visible here */
.portal-nav { display: flex; gap: 2px; flex-shrink: 0; }
.portal-nav a {
  color: var(--muted); text-decoration: none;
  font-size: .78rem; font-weight: 500;
  padding: 7px 11px; border-radius: var(--r-sm);
  transition: color .15s, background .15s;
}
.portal-nav a:hover { color: var(--text); background: var(--panel); }
.portal-nav a.active { color: var(--gold-bright); background: var(--panel); }
.portal-nav a.nav-portal {
  background: var(--gold); color: var(--on-gold); font-weight: 600;
  font-size: .8rem; padding: 8px 16px; border-radius: var(--r);
}
.portal-nav a.nav-portal:hover,
.portal-nav a.nav-portal.active { background: var(--gold-bright); color: var(--on-gold); }

/* Entering the portal: the three links have folded away, so the burger fades
   up in their place and Portal eases back from where they were. */
@keyframes burgerIn {
  from { opacity: 0; transform: translateX(10px) rotate(-45deg); }
  to   { opacity: 1; transform: none; }
}
@keyframes portalSettle {
  from { opacity: 0; transform: translateX(180px); }
  to   { opacity: 1; transform: none; }
}
/* only when arriving from the public site, not on a portal refresh */
.nav-animate .portal-nav a.nav-portal { animation: portalSettle .52s cubic-bezier(.22, 1, .36, 1) both; }
.nav-animate .site-menu { animation: burgerIn .4s cubic-bezier(.22, 1, .36, 1) .18s both; }

/* the collapsed Home / Subscription / Contact menu */
.site-menu { position: relative; flex-shrink: 0; }
.site-burger {
  width: 32px; height: 32px; display: grid; place-items: center;
  border: 1px solid var(--line-2); background: var(--panel); color: var(--text-2);
  border-radius: var(--r-sm); cursor: pointer; font-size: 14px;
  transition: color .15s, border-color .15s, background .15s, transform .18s;
}
.site-burger:hover { color: var(--text); border-color: var(--gold-a40); }
.site-burger.open { color: var(--gold-bright); border-color: var(--gold); transform: rotate(90deg); }
.site-drop {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 70;
  min-width: 176px;
  background: var(--panel); border: 1px solid var(--line-2);
  border-radius: var(--r); padding: 6px;
  box-shadow: 0 12px 34px rgb(0 0 0 / .6);
  display: flex; flex-direction: column; gap: 2px;
  animation: dropIn .18s ease both;
}
@keyframes dropIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.site-drop a {
  color: var(--text-2); text-decoration: none;
  font-size: .84rem; padding: 10px 12px; border-radius: var(--r-sm);
  transition: color .15s, background .15s;
}
.site-drop a:hover { color: var(--text); background: var(--panel-2); }

/* site links live inside the mobile drawer instead */
.drawer-site { display: none; }

/* hamburger + backdrop live only on mobile */
.nav-toggle { display: none; font-size: 17px; }
.nav-backdrop { display: none; }

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

.sidebar {
  width: 324px; min-width: 324px;
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  padding: 18px;
  overflow-y: auto;
  /* generous gap so each panel reads as its own block with the background
     showing between, rather than one continuous column */
  display: flex; flex-direction: column; gap: 20px;
}
.sidebar > .primary-btn,
.sidebar > .ghost-btn { margin-top: -6px; }   /* action sits closer to its panel */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
/* the tab wrappers are plain containers — space their children the same way */
#clayControls, #materialControls, #commentControls, #aidControls, #narrativeControls {
  display: flex; flex-direction: column; gap: 20px;
}
.panel h3 {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--text-2); font-weight: 600;
}
.hint { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); }
.panel h3 .hint { font-size: .92em; }

textarea, input[type="text"], input[type="password"], input[type="number"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--text);
  padding: 9px 11px;
  font: inherit;
  font-size: .88rem;
  resize: vertical;
  transition: border-color .15s, box-shadow .15s;
}
textarea::placeholder, input::placeholder { color: var(--muted); }
textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-a14);
}

.dropzone {
  border: 1px dashed var(--line-2);
  border-radius: var(--r-lg);
  padding: 20px 12px;
  text-align: center;
  color: var(--muted);
  font-size: .84rem;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  transition: border-color .15s, background .15s, color .15s;
  position: relative;
}
.dropzone:hover, .dropzone.drag { border-color: var(--gold); background: var(--gold-a08); color: var(--text-2); }
.dropzone u { text-decoration-color: var(--gold); text-underline-offset: 2px; color: var(--text); }
.dz-icon { font-size: 22px; color: var(--gold); }
.dz-prompt { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.dropzone.has-img { padding: 0; border-style: solid; border-color: var(--line-2); overflow: hidden; }
.dropzone.has-img img { display: block; width: 100%; border-radius: var(--r); }
.dz-replace {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgb(0 0 0 / .74);
  color: var(--text); font-size: .7rem;
  padding: 5px; text-align: center;
  opacity: 0; transition: opacity .15s;
}
.dropzone.has-img:hover .dz-replace, .dropzone.has-img.drag .dz-replace { opacity: 1; }
.file-meta { font-size: .76rem; color: var(--muted); }
.file-meta:empty { display: none; }

.primary-btn {
  border: 0; cursor: pointer;
  background: var(--gold);
  color: var(--on-gold); font-weight: 600; font-size: .9rem;
  letter-spacing: .02em;
  padding: 12px 14px; border-radius: var(--r);
  box-shadow: 0 1px 2px rgb(0 0 0 / .4);
  transition: background .15s, transform .05s;
}
.primary-btn:hover:not(:disabled) { background: var(--gold-bright); }
.primary-btn:active:not(:disabled) { transform: translateY(1px); }
.primary-btn:disabled { opacity: .4; cursor: not-allowed; }
.primary-btn.sm { padding: 8px 14px; font-size: .82rem; border-radius: var(--r-sm); box-shadow: none; }

.ghost-btn {
  border: 1px solid var(--line-2); background: transparent; color: var(--text-2);
  padding: 8px 13px; border-radius: var(--r); cursor: pointer; font-size: .83rem;
  transition: color .15s, border-color .15s, background .15s;
}
.ghost-btn:hover:not(:disabled) { background: var(--panel-2); border-color: var(--gold-a40); color: var(--text); }
.ghost-btn:disabled { opacity: .38; cursor: not-allowed; }
.ghost-btn.sm { padding: 6px 10px; font-size: .78rem; }
.ghost-btn.danger { color: var(--danger); border-color: rgb(229 103 95 / .4); }
.ghost-btn.danger:hover:not(:disabled) { background: rgb(229 103 95 / .1); border-color: var(--danger); color: var(--danger); }

/* ---------- references ---------- */
.ref-list { display: flex; flex-direction: column; gap: 8px; }
.ref-item {
  display: flex; gap: 9px; align-items: center;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); padding: 7px;
}
.ref-item img { width: 44px; height: 44px; object-fit: cover; border-radius: var(--r-sm); }
.ref-item input { flex: 1; padding: 6px 8px; font-size: .8rem; }
.ref-item .x, .pin-ref-thumb .x {
  border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; padding: 4px;
}
.ref-item .x:hover, .pin-ref-thumb .x:hover { color: var(--danger); }

/* ---------- pins ---------- */
.pin-list { display: flex; flex-direction: column; gap: 8px; }
.empty-note { color: var(--muted); font-size: .82rem; padding: 6px 2px; line-height: 1.5; }
.pin-item {
  display: flex; gap: 9px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); padding: 9px;
  cursor: pointer; transition: border-color .15s;
}
.pin-item:hover { border-color: var(--gold-a40); }
.pin-item .pin-num {
  width: 22px; height: 22px; min-width: 22px;
  border-radius: 50%; background: var(--gold); color: var(--on-gold);
  display: grid; place-items: center; font-size: .76rem; font-weight: 700;
}
.pin-item .pin-body { flex: 1; min-width: 0; }
.pin-item .pin-note { font-size: .84rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pin-item .pin-note.placeholder { color: var(--muted); font-style: italic; }
.pin-item .pin-refflag { font-size: .7rem; color: var(--gold-bright); margin-top: 3px; }
.pin-item img.pin-thumb { width: 38px; height: 38px; object-fit: cover; border-radius: var(--r-sm); }

.pin-layer { position: absolute; inset: 0; pointer-events: none; }
.pin-dot {
  position: absolute;
  width: 26px; height: 26px;
  transform: translate(-50%, -50%);
  border-radius: 50% 50% 50% 3px;
  background: var(--gold);
  color: var(--on-gold);
  display: grid; place-items: center;
  font-size: .76rem; font-weight: 700;
  border: 2px solid rgb(255 255 255 / .25);
  box-shadow: 0 2px 8px rgb(0 0 0 / .55);
  cursor: pointer;
  pointer-events: auto;
}
.pin-dot.active { background: var(--gold-bright); outline: 2px solid rgb(255 255 255 / .5); }

.pin-pop {
  position: fixed; z-index: 60;
  width: 272px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  box-shadow: 0 12px 36px rgb(0 0 0 / .65);
  padding: 12px;
  display: flex; flex-direction: column; gap: 9px;
}
.pin-pop-head { font-size: .7rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--gold-bright); }
.pin-pop-actions { display: flex; justify-content: space-between; }
.pin-pop-ref { display: flex; align-items: center; gap: 8px; }
.pin-ref-thumb { position: relative; display: flex; align-items: center; gap: 4px; }
.pin-ref-thumb img { width: 40px; height: 40px; object-fit: cover; border-radius: var(--r-sm); }

/* ---------- viewer ---------- */
.viewer-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.viewer-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
  gap: 12px; flex-wrap: wrap;
}
.vt-left { font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.vt-right { display: flex; gap: 8px; flex-wrap: wrap; }
.ghost-btn.on { border-color: var(--gold); color: var(--gold-bright); background: var(--gold-a08); }

.viewer {
  flex: 1;
  position: relative;
  display: grid; place-items: center;
  overflow: hidden;
  background:
    radial-gradient(ellipse 80% 65% at 50% 28%, var(--blue-a04), transparent 60%),
    radial-gradient(ellipse at center, #0d0e10 0%, var(--bg) 78%);
  min-height: 0;
}
.viewer-empty { text-align: center; color: var(--muted); }
.ve-icon { font-size: 42px; margin-bottom: 10px; opacity: .4; }
.ve-logo { height: 62px; width: auto; display: block; margin: 0 auto 14px; opacity: .5; }
.viewer-empty p { font-size: .86rem; letter-spacing: .02em; }

.img-stage { position: relative; max-width: 96%; max-height: 94%; }
.img-stage img { display: block; max-width: 100%; max-height: calc(100vh - 250px); border-radius: 2px; }
.img-stage.pinnable { cursor: crosshair; }

.compare-top { position: absolute; inset: 0; overflow: hidden; }
.compare-top img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; max-width: none !important; max-height: none !important; }
.compare-handle {
  position: absolute; top: 0; bottom: 0;
  width: 2px; background: var(--gold);
  cursor: ew-resize;
}
.compare-handle::after {
  content: "◂ ▸";
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--gold); color: var(--on-gold);
  font-size: 10px; padding: 5px 6px; border-radius: 20px; white-space: nowrap;
}
.compare-label {
  position: absolute; top: 10px;
  background: rgb(0 0 0 / .7); color: var(--text);
  font-size: .68rem; padding: 4px 9px; border-radius: var(--r-sm);
  letter-spacing: .1em; text-transform: uppercase;
  pointer-events: none;
}
.compare-label.before { left: 10px; }
.compare-label.after { right: 10px; }

/* ---------- processing ---------- */
.processing {
  position: absolute; inset: 0;
  background: rgb(0 0 0 / .74);
  backdrop-filter: blur(3px);
  display: grid; place-items: center; place-content: center; gap: 16px;
  z-index: 40;
}
.spinner {
  width: 40px; height: 40px;
  border: 2px solid var(--line-2);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.processing-text { color: var(--text-2); font-size: .86rem; letter-spacing: .04em; }

/* ---------- version strip ---------- */
.version-strip {
  display: flex; gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg-elev);
  overflow-x: auto;
  min-height: 88px;
}
.version-strip:empty::after {
  content: "Versions appear here as you process changes";
  color: var(--muted); font-size: .78rem; align-self: center; letter-spacing: .02em;
}
.version-thumb {
  position: relative;
  min-width: 96px; width: 96px; height: 64px;
  border-radius: var(--r-sm); overflow: hidden;
  border: 1px solid var(--line-2);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color .15s;
}
.version-thumb:hover { border-color: var(--gold-a40); }
.version-thumb img { width: 100%; height: 100%; object-fit: cover; }
.version-thumb.current { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.version-thumb .vlabel {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgb(0 0 0 / .74); color: var(--text);
  font-size: .62rem; padding: 2px 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 80;
  background: rgb(0 0 0 / .72);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
}
.modal {
  width: 424px; max-width: 92vw;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  padding: 22px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 60px rgb(0 0 0 / .6);
}
.modal h2 { font-size: 1rem; font-weight: 600; letter-spacing: .01em; }
.modal label { display: flex; flex-direction: column; gap: 6px; font-size: .78rem; color: var(--text-2); }
.modal select, .modal textarea, .modal input {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--r); padding: 9px 11px; font: inherit; font-size: .88rem;
}
.modal textarea { resize: vertical; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: .76rem; }
.cfg-sep { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
#cfgComfyBlock { display: flex; flex-direction: column; gap: 14px; }
#cfgComfyStatus.ok { color: var(--ok); }
#cfgComfyStatus.bad { color: var(--danger); }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 4px; }

/* ---------- examples button / field help ---------- */
.examples-btn {
  align-self: stretch;
  border-color: var(--gold-a40);
  color: var(--gold-bright);
  font-weight: 500;
}
.examples-btn:hover:not(:disabled) { background: var(--gold-a08); border-color: var(--gold); color: var(--gold-bright); }

.field-head {
  display: flex; align-items: center; gap: 7px;
  font-size: .68rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--text-2); font-weight: 600;
}
.info-btn {
  width: 16px; height: 16px; flex-shrink: 0;
  border: 1px solid var(--line-2); background: transparent; color: var(--muted);
  border-radius: 50%; cursor: pointer;
  font-size: 10px; font-weight: 700; font-style: italic;
  line-height: 1; display: grid; place-items: center;
  text-transform: none; letter-spacing: 0;
  transition: color .15s, border-color .15s;
}
.info-btn:hover { color: var(--gold-bright); border-color: var(--gold); }

.help-modal { width: 520px; max-width: 94vw; max-height: 84vh; }
.help-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.help-head .icon-btn { width: 28px; height: 28px; font-size: 12px; flex-shrink: 0; }
.help-body { overflow-y: auto; font-size: .86rem; line-height: 1.6; color: var(--text-2); }
.help-lead { color: var(--text); margin-bottom: 14px; }
.help-body h4 {
  font-size: .66rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--gold-bright); font-weight: 600; margin: 16px 0 7px;
}
.help-body ul { padding-left: 18px; display: flex; flex-direction: column; gap: 5px; }
.help-body li { padding-left: 2px; }
.help-body b { color: var(--text); font-weight: 600; }
.help-ex li {
  list-style: none; margin-left: -18px;
  background: var(--bg); border: 1px solid var(--line);
  border-left: 2px solid var(--gold-a40);
  border-radius: var(--r-sm); padding: 7px 10px;
  color: var(--text); font-style: italic;
}
.help-note { margin-top: 12px; color: var(--muted); font-size: .82rem; }

/* ---------- crop modal ---------- */
.crop-modal { width: 760px; max-width: 94vw; }
.crop-note { font-size: .8rem; color: var(--muted); line-height: 1.55; }
.crop-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line-2); background: var(--bg); color: var(--text-2);
  border-radius: 20px; padding: 5px 13px; font-size: .78rem; cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.chip:hover { border-color: var(--gold-a40); color: var(--text); }
.chip.sel { border-color: var(--gold); color: var(--gold-bright); background: var(--gold-a08); }
.chip .sub { color: var(--muted); font-size: .68rem; margin-left: 5px; }
.crop-stage {
  position: relative; background: #000;
  display: grid; place-items: center;
  border-radius: var(--r); overflow: hidden;
  user-select: none;
}
.crop-stage img { max-width: 100%; max-height: 52vh; display: block; }
.crop-rect {
  position: absolute;
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 9999px rgb(0 0 0 / .6);
  cursor: move;
  touch-action: none;
}
.crop-zoom { display: flex; align-items: center; gap: 10px; font-size: .78rem; color: var(--muted); }
.crop-zoom input[type="range"] { flex: 1; }
.crop-res { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .78rem; color: var(--muted); }
.res-chips { display: flex; gap: 6px; }
.crop-info { margin-left: auto; color: var(--gold-bright); font-size: .76rem; }

/* range inputs — gold accent */
input[type="range"] { accent-color: var(--gold); }

/* ---------- brush ---------- */
.brush-toggle { display: flex; align-items: center; gap: 8px; font-size: .84rem; cursor: pointer; color: var(--text-2); }
.brush-toggle input { width: 15px; height: 15px; accent-color: var(--gold); }
.brush-tools { display: flex; flex-direction: column; gap: 9px; margin-top: 4px; }
.brush-btns { display: flex; gap: 6px; }
.brush-btns .ghost-btn.on { border-color: var(--gold); color: var(--gold-bright); background: var(--gold-a08); }
.mask-layer { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 20; touch-action: none; opacity: .5; }
.img-stage.brushing { cursor: crosshair; }

/* ---------- A-id tab ---------- */
.aid-inputs { display: flex; gap: 9px; }
.aid-input { flex: 1; }
.dropzone.sm { padding: 12px 6px; min-height: 76px; font-size: .76rem; }
.dropzone.sm.has-img { padding: 0; border-style: solid; }
.dropzone.sm img { display: block; width: 100%; border-radius: var(--r-sm); }
.dz-mini { display: flex; flex-direction: column; gap: 4px; align-items: center; color: var(--muted); }
.dz-mini .dz-icon { font-size: 17px; }

.aid-highlight {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 16;
  transition: opacity .12s ease;
}
.aid-color.locating { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.aid-detect { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.aid-detect input[type="range"] { flex: 1; }
.aid-color-list { display: flex; flex-direction: column; gap: 9px; }
.aid-color {
  display: flex; gap: 9px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); padding: 8px;
}
.aid-swatch {
  width: 30px; height: 30px; min-width: 30px;
  border-radius: var(--r-sm); border: 1px solid rgb(255 255 255 / .2);
}
.aid-color-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.aid-hex { font-size: .7rem; color: var(--muted); font-family: ui-monospace, monospace; display: flex; justify-content: space-between; }
.aid-hex .aid-loc { color: var(--gold-bright); }
.aid-color-body textarea { min-height: 40px; font-size: .82rem; }
.aid-refthumbs { display: flex; gap: 5px; flex-wrap: wrap; }
.aid-refthumbs .aid-refthumb { position: relative; }
.aid-refthumbs img { width: 34px; height: 34px; object-fit: cover; border-radius: 5px; }
.aid-refthumbs .x {
  position: absolute; top: -5px; right: -5px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--danger); color: #fff; border: 0; cursor: pointer;
  font-size: 10px; line-height: 1; display: grid; place-items: center;
}
.aid-addref { align-self: flex-start; }

/* ---------- Narrative (people creator) ---------- */
.nr-field { display: flex; flex-direction: column; gap: 5px; font-size: .78rem; color: var(--text-2); }
.nr-field select, .round-bar select, .nr-card-head select {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--r-sm); padding: 7px 8px; font: inherit; font-size: .84rem;
}
.nr-box-layer { position: absolute; inset: 0; z-index: 18; }
.img-stage.boxing { cursor: crosshair; }
.nr-box {
  position: absolute; box-sizing: border-box;
  border: 2px solid var(--gold);
  background: var(--gold-a14);
  pointer-events: auto; cursor: pointer;
}
.nr-box.sel { border-color: var(--gold-bright); background: rgb(212 175 112 / .22); box-shadow: 0 0 0 1px var(--gold-bright); }
.nr-box .nr-box-num {
  position: absolute; top: -11px; left: -11px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--gold); color: var(--on-gold);
  display: grid; place-items: center; font-size: .72rem; font-weight: 700;
}
.nr-box .nr-box-x {
  position: absolute; top: -10px; right: -10px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--danger); color: #fff; border: 0; cursor: pointer;
  font-size: 10px; display: grid; place-items: center;
}

.nr-box-list { display: flex; flex-direction: column; gap: 9px; }
.nr-box-card {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); padding: 9px;
  display: flex; flex-direction: column; gap: 7px;
}
.nr-box-card.sel { border-color: var(--gold); }
.nr-card-head { display: flex; align-items: center; gap: 8px; }
.nr-card-head .nr-num {
  width: 20px; height: 20px; min-width: 20px; border-radius: 50%;
  background: var(--gold); color: var(--on-gold); display: grid; place-items: center; font-size: .7rem; font-weight: 700;
}
.nr-card-head select { border-radius: var(--r-sm); padding: 3px 6px; font-size: .76rem; }
.nr-box-card textarea { min-height: 38px; font-size: .82rem; }
.nr-card-refrow { display: flex; align-items: center; gap: 8px; }
.nr-refthumb { position: relative; }
.nr-refthumb img { width: 34px; height: 34px; object-fit: cover; border-radius: 5px; }
.nr-refthumb .x { position: absolute; top: -5px; right: -5px; width: 15px; height: 15px; border-radius: 50%; background: var(--danger); color: #fff; border: 0; cursor: pointer; font-size: 9px; }
.nr-options { display: flex; gap: 6px; flex-wrap: wrap; }
.nr-option {
  width: 60px; height: 60px; border-radius: var(--r-sm); overflow: hidden;
  border: 1px solid var(--line-2); cursor: pointer; position: relative;
  transition: border-color .15s;
}
.nr-option:hover { border-color: var(--gold-a40); }
.nr-option.chosen { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.nr-woption { width: 84px; height: 52px; }
.nr-option img { width: 100%; height: 100%; object-fit: cover; }
.nr-option .dl { position: absolute; bottom: 0; right: 0; background: rgb(0 0 0 / .6); color: #fff; font-size: 9px; padding: 1px 4px; }
.nr-card-status { font-size: .72rem; color: var(--gold-bright); }

/* ---------- comment rounds ---------- */
.round-bar { display: flex; align-items: center; gap: 8px; }
.round-bar select { flex: 1; }
.round-bar label { font-size: .78rem; color: var(--text-2); display: flex; align-items: center; gap: 6px; flex: 1; }
.round-readonly {
  font-size: .64rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--on-gold); background: var(--gold-bright); padding: 2px 7px; border-radius: var(--r-sm);
}

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 90;
  background: var(--panel-2); border: 1px solid var(--line-2);
  color: var(--text);
  padding: 12px 18px; border-radius: var(--r);
  font-size: .86rem;
  box-shadow: 0 10px 34px rgb(0 0 0 / .55);
  max-width: 70vw;
}
.toast.error { border-color: var(--danger); color: #f0b6b2; }
.toast.ok { border-color: var(--gold); }

/* ---------- credits pill ---------- */
.credits-pill {
  position: fixed; left: 16px; bottom: 16px; z-index: 55;
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line-2);
  color: var(--text); cursor: pointer;
  padding: 9px 15px; border-radius: 22px;
  font: inherit; font-size: .8rem; font-weight: 500;
  box-shadow: 0 6px 20px rgb(0 0 0 / .5);
  transition: border-color .15s, background .15s;
}
.credits-pill:hover { border-color: var(--gold); background: var(--panel-2); }
.cp-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); flex-shrink: 0; }
.credits-balance {
  font-size: 2.4rem; font-weight: 300; color: var(--text); letter-spacing: -.02em;
  display: flex; align-items: baseline; gap: 10px;
}
.credits-balance small { font-size: .78rem; color: var(--muted); font-weight: 400; letter-spacing: .04em; }

/* ---------- first-run tour ---------- */
.tour { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; }
.tour-backdrop {
  position: absolute; inset: 0; background: rgb(0 0 0 / .68);
  backdrop-filter: blur(3px);
  animation: tourFade .3s ease both;
}
.tour-card {
  position: relative;
  width: 460px; max-width: 100%;
  background: var(--panel); border: 1px solid var(--gold-a40);
  border-radius: var(--r-lg); padding: 28px 28px 24px;
  box-shadow: 0 24px 70px rgb(0 0 0 / .6);
  animation: tourIn .32s cubic-bezier(.22, 1, .36, 1) both;
}
.tour-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.tour-step {
  font-size: .64rem; text-transform: uppercase; letter-spacing: .14em;
  color: var(--gold-bright); font-weight: 700;
}
.tour-skip {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; font-size: .78rem; color: var(--muted);
  text-decoration: underline; text-underline-offset: 3px;
}
.tour-skip:hover { color: var(--text-2); }
.tour-title { font-size: 1.35rem; font-weight: 400; letter-spacing: -.01em; color: var(--text); margin-bottom: 10px; }
.tour-body { font-size: .95rem; line-height: 1.6; color: var(--text-2); margin-bottom: 22px; }
.tour-nav { display: flex; justify-content: flex-end; gap: 10px; }
@keyframes tourFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes tourIn   { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- AI transparency notice ---------- */
.ai-notice {
  position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 75;
  max-width: 720px; margin: 0 auto;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--gold-a40);
  border-radius: var(--r-lg); padding: 16px 20px;
  box-shadow: 0 12px 40px rgb(0 0 0 / .6);
}
.ai-notice-body { flex: 1; min-width: 240px; font-size: .85rem; line-height: 1.55; color: var(--text-2); }
.ai-notice-body b { color: var(--text); font-weight: 600; }
.ai-notice-link {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; color: var(--gold-bright); text-decoration: underline;
  text-underline-offset: 2px;
}
.ai-notice .primary-btn { flex-shrink: 0; }

/* ---------- login gate ---------- */
.login-body {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 24px;
  /* subtle blue wash up top (brand mark), faint warm gold below */
  background:
    radial-gradient(ellipse 72% 55% at 50% -8%, var(--blue-a10) 0%, transparent 68%),
    radial-gradient(ellipse 50% 40% at 50% 112%, rgb(200 163 90 / .05) 0%, transparent 70%),
    var(--bg);
}
.login-brand { display: flex; align-items: center; gap: 13px; }
.login-card {
  width: 360px; max-width: 100%;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  padding: 32px 28px;
  display: flex; flex-direction: column; gap: 18px;
  box-shadow: 0 24px 70px rgb(0 0 0 / .6);
}
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand .brand-mark { width: 40px; height: 40px; font-size: 21px; }
.login-title { font-size: .8rem; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; }
.login-sub { font-size: .82rem; color: var(--muted); line-height: 1.5; margin-top: -6px; }
.login-card label { font-size: .68rem; text-transform: uppercase; letter-spacing: .12em; color: var(--text-2); display: flex; flex-direction: column; gap: 7px; }
.login-error { color: var(--danger); font-size: .8rem; min-height: 1em; }
.login-foot { font-size: .72rem; color: var(--muted); text-align: center; letter-spacing: .04em; }
.login-alt { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 4px; }
.login-alt-toggle {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; font-size: .78rem; color: var(--muted);
  text-decoration: underline; text-underline-offset: 3px;
}
.login-alt-toggle:hover { color: var(--gold-bright); }

/* ---------- responsive / phone ---------- */
@media (max-width: 760px) {
  /* --- top bar: hamburger · brand · actions, one tidy row.
         Pinned so it can never scroll out of reach on a phone. --- */
  .topbar {
    gap: 10px; padding: 10px 12px;
    position: sticky; top: 0; z-index: 50;
    flex-shrink: 0;
  }
  .nav-toggle { display: grid; }
  .brand { flex: 1; min-width: 0; gap: 9px; }
  .brand-mark { width: 30px; height: 30px; font-size: 16px; }
  .brand-name { font-size: .66rem; letter-spacing: .1em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .top-actions { gap: 6px; }

  /* on a phone the site links live inside the drawer, not a second burger */
  .site-menu { display: none; }
  .portal-nav { display: none; }
  .drawer-site {
    display: flex; flex-direction: column; gap: 2px;
    margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line);
  }
  .drawer-site::before {
    content: "Site"; display: block;
    font-size: .64rem; text-transform: uppercase; letter-spacing: .14em;
    color: var(--muted); font-weight: 600; padding: 0 12px 10px;
  }
  .drawer-site a {
    color: var(--text-2); text-decoration: none;
    font-size: .95rem; padding: 12px; border-radius: var(--r);
  }
  .drawer-site a:hover { color: var(--text); background: var(--panel-2); }

  /* --- tabs become a left slide-in drawer (the hamburger menu) --- */
  .tabs {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 70;
    flex-direction: column; align-items: stretch;
    width: 80%; max-width: 300px;
    background: var(--bg-elev);
    border: 0; border-right: 1px solid var(--line-2);
    border-radius: 0;
    padding: 18px 14px;
    gap: 4px;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform .24s ease;
    box-shadow: 0 0 40px rgb(0 0 0 / .5);
  }
  .tabs::before {
    content: "Tools"; display: block;
    font-size: .64rem; text-transform: uppercase; letter-spacing: .14em;
    color: var(--muted); font-weight: 600;
    padding: 4px 12px 12px;
  }
  body.nav-open .tabs { transform: translateX(0); }
  .tab { text-align: left; padding: 14px 12px; font-size: .95rem; font-weight: 500; border-radius: var(--r); }
  .tab.active { background: var(--panel-2); color: var(--gold-bright); }
  .tab.active::after { display: none; }

  .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 65;
    background: rgb(0 0 0 / .6);
    opacity: 0; pointer-events: none; transition: opacity .24s ease;
  }
  body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }

  /* --- single-column, page scrolls as one --- */
  body { overflow: hidden; }
  .layout { flex-direction: column; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .sidebar {
    width: 100%; min-width: 0;
    border-right: 0; border-bottom: 1px solid var(--line);
    overflow: visible; padding: 14px;
  }
  .viewer-wrap { min-height: 0; }
  .viewer { min-height: 54vh; }
  .img-stage img { max-height: 64vh; }

  /* toolbar buttons stay on one swipeable row */
  .viewer-toolbar { flex-wrap: nowrap; gap: 8px; padding: 10px 12px; }
  .vt-left { flex-shrink: 0; }
  .vt-right { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .vt-right .ghost-btn { flex-shrink: 0; }

  /* comfortable touch targets */
  .primary-btn { padding: 14px; font-size: .95rem; }
  .ghost-btn { padding: 11px 14px; }
  .ghost-btn.sm { padding: 9px 12px; }
  .icon-btn { width: 38px; height: 38px; }

  /* --- roomier spacing so nothing sits on top of anything --- */
  .sidebar { gap: 18px; padding: 16px; }
  .panel { gap: 14px; padding: 16px; }

  /* button rows / chip rows / column groups get real breathing room */
  .brush-btns, .res-chips, .crop-chips, .nr-options, .aid-refthumbs { gap: 10px; }
  .brush-btns { flex-wrap: wrap; }
  .brush-btns .ghost-btn { flex: 1; min-width: 88px; }
  .vt-right { gap: 12px; }
  .aid-inputs { gap: 14px; }
  .crop-chips { gap: 8px 10px; }

  /* list rows a touch more padded */
  .ref-item, .pin-item, .aid-color, .nr-box-card { padding: 12px; }
  .pin-list, .ref-list, .aid-color-list, .nr-box-list { gap: 12px; }
  .nr-field, .round-bar { gap: 8px; }

  /* 16px inputs so iOS doesn't zoom on focus */
  textarea, input[type="text"], input[type="password"], input[type="number"],
  .modal select, .modal input, .modal textarea,
  .nr-field select, .round-bar select, select { font-size: 16px; }

  /* popovers / modals fit small screens */
  .pin-pop { width: calc(100vw - 28px); max-width: 300px; }
  .modal { padding: 18px; border-radius: var(--r-lg); }
  .aid-inputs { flex-direction: column; }
}

@media (min-width: 761px) {
  /* ensure drawer state never leaks onto desktop */
  body.nav-open .tabs { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
