:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --ink: #20272e;
  --ink-soft: #6a7078;
  --line: #e6e2da;
  --line-strong: #d4cec3;
  --topbar: #23282d;
  --accent: #2f3843;          /* graphite — primary actions */
  --accent-2: #212932;
  --hi: #9c8560;              /* warm stone highlight (pins, active) */
  --hi-soft: #efe7d8;
  --ok: #3f7d5a;             /* rendered / ready */
  --drawer-w: 420px;
  --shadow: 0 1px 2px rgba(30,40,50,.06), 0 14px 34px rgba(30,40,50,.10);
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Manrope", system-ui, sans-serif; color: var(--ink);
  background: var(--bg); -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
img { max-width: 100%; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--surface);
  position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 16px; }
.brand-logo { height: 38px; width: auto; display: block; }
.brand-text { padding-left: 16px; border-left: 1px solid var(--line-strong); }
.brand-title { font-family: "Fraunces", serif; font-weight: 600; font-size: 16px; color: var(--ink); letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--ink-soft); margin-top: 1px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.ai-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700;
  padding: 6px 11px; border-radius: 999px; background: var(--hi); color: #2a1f0c;
}
.ai-pill i { width: 14px; height: 14px; }

/* ---------- Main layout (full-width stage) ---------- */
.stage-layout { max-width: 1120px; margin: 0 auto; padding: 22px 22px 60px; }
.stage-hint { font-size: 13px; color: var(--ink-soft); margin: 0 0 14px; line-height: 1.5; }
.stage-hint strong { color: var(--ink); font-weight: 700; }
.stage-canvas-wrap {
  position: relative; border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); background: #ece8e1;
  height: clamp(380px, 74vh, 780px); display: grid; place-items: center;
}
/* frame is sized by JS to the *displayed* image rect, so portrait fits the same
   height (pillar-boxed) instead of stretching the stage — and pins line up. */
.stage-frame { position: relative; line-height: 0; max-width: 100%; max-height: 100%; }
#stage { display: block; width: 100%; height: 100%; object-fit: cover; }
.stage-fs {
  position: absolute; top: 12px; right: 12px; z-index: 4; width: 38px; height: 38px;
  display: grid; place-items: center; border: none; border-radius: 10px; cursor: pointer;
  background: rgba(24,22,19,.55); color: #fff;
}
.stage-fs:hover { background: rgba(24,22,19,.78); }
.stage-fs i { width: 18px; height: 18px; }

.gen-overlay {
  position: absolute; inset: 0; display: grid; place-items: center; gap: 14px; z-index: 12;
  background: rgba(24,22,19,.62); color: #fff; font-size: 14px; font-weight: 600;
  grid-auto-flow: row; align-content: center; text-align: center; padding: 24px;
}
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 3px solid rgba(255,255,255,.25); border-top-color: #fff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Pins (teardrop; outline -> filled with the stone) ---------- */
.hotspot-layer { position: absolute; inset: 0; pointer-events: none; }
.hotspot { position: absolute; transform: translate(-50%, -100%); pointer-events: auto; border: none; background: none; padding: 0; cursor: pointer; z-index: 3; filter: drop-shadow(0 3px 5px rgba(0,0,0,.42)); }
/* inverted-water-drop marker (tip points at the surface); small until a stone is
   assigned, then it grows and fills with the swatch. two outlines: white (outer,
   box-shadow) + gold (inner, the border). */
.pin {
  width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: rgba(255,255,255,.55); border: 2px solid var(--hi); box-shadow: 0 0 0 2px #fff;
  display: grid; place-items: center; transition: width .16s, height .16s, background .16s;
}
.pin-inner { width: 16px; height: 16px; border-radius: 50%; background: var(--hi); transform: rotate(45deg); transition: width .16s, height .16s; }
.hotspot:hover .pin { background: rgba(255,255,255,.9); }
.hotspot.filled .pin { width: 54px; height: 54px; background: rgba(255,255,255,.5); }
/* larger pin -> 50%-white padding frame; swatch keeps the same brown (gold) frame as the rim */
.hotspot.filled .pin-inner { width: 40px; height: 40px; border: 2px solid var(--hi); background-size: cover; background-position: center; }
.hotspot.active .pin { box-shadow: 0 0 0 2px #fff, 0 0 0 6px var(--hi-soft); }
.pin-label {
  position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%);
  font-size: 11px; font-weight: 700; color: #fff; white-space: nowrap; letter-spacing: .01em;
  background: rgba(24,22,19,.82); padding: 4px 9px; border-radius: 999px; opacity: 0; transition: opacity .12s; pointer-events: none;
}
.hotspot:hover .pin-label { opacity: 1; }
.hotspot.active .pin-label { opacity: 0; }
.hotspot.placing { cursor: grab; touch-action: none; }
.hotspot.placing:active { cursor: grabbing; }
.hotspot.placing .pin-label { opacity: 1; }

/* ---------- Callout (click-only, one at a time) ---------- */
.callout {
  position: absolute; width: 216px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 28px 66px rgba(14,18,22,.46), 0 10px 26px rgba(14,18,22,.30);
  padding: 14px; z-index: 9; transform: translate(-50%, -100%); pointer-events: auto;
}
.callout.below { transform: translate(-50%, 0); }
.callout::after { content: ""; position: absolute; left: var(--tail, 50%); transform: translateX(-50%); width: 0; height: 0; border-left: 9px solid transparent; border-right: 9px solid transparent; }
.callout:not(.below)::after { bottom: -9px; border-top: 9px solid var(--surface); }
.callout.below::after { top: -9px; border-bottom: 9px solid var(--surface); }
.co-kicker { font-size: 10px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--hi); line-height: 1; margin-bottom: 6px; }
.co-title { font-family: "Fraunces", serif; font-size: 18px; font-weight: 600; line-height: 1.15; margin: 0 0 12px; }
.co-preview { width: 100%; height: 92px; border-radius: 9px; border: 1px solid var(--line); background-size: cover; background-position: center; }
.co-name { font-size: 14px; font-weight: 600; line-height: 1.2; margin-top: 10px; }
.co-coll { font-size: 11.5px; color: var(--ink-soft); margin-top: 5px; }
.co-empty { font-size: 12.5px; color: var(--ink-soft); line-height: 1.45; }
.co-actions { display: flex; gap: 7px; margin-top: 12px; }
.co-btn { flex: 1; min-width: 0; white-space: nowrap; font: inherit; font-weight: 600; font-size: 12.5px; padding: 8px; border-radius: 9px; cursor: pointer; border: 1px solid var(--accent); background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.co-btn:hover { background: var(--accent-2); }
.co-btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.co-btn.ghost:hover { background: var(--bg); }
.co-btn i { width: 14px; height: 14px; }

/* ---------- Scene switch + actions ---------- */
.stage-foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
.scene-switch { display: flex; gap: 10px; }
.scene-chip { position: relative; width: 84px; height: 56px; border-radius: 10px; overflow: hidden; border: 2px solid transparent; cursor: pointer; padding: 0; background: var(--line); opacity: .55; transition: border-color .15s, transform .15s, opacity .15s, box-shadow .15s; }
.scene-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.scene-chip:hover { transform: translateY(-2px); opacity: 1; }
.scene-chip.active { border-color: var(--hi); opacity: 1; box-shadow: 0 0 0 2px var(--hi-soft), var(--shadow); }
.scene-chip .sc-name { position: absolute; inset: auto 0 0 0; font-size: 10px; font-weight: 600; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.72)); padding: 10px 5px 3px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.foot-actions { display: flex; gap: 10px; }
.btn { display: inline-flex; align-items: center; gap: 7px; font: inherit; font-weight: 600; font-size: 14px; padding: 10px 18px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; transition: .15s; }
.btn i { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.primary:disabled { background: var(--line-strong); color: var(--ink-soft); cursor: not-allowed; }
.btn.ghost { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn.ghost:hover { background: var(--bg); }
.btn.ghost:disabled { color: var(--ink-soft); cursor: not-allowed; opacity: .6; }
#genCount { font-weight: 700; }

/* ---------- Catalog: mid-edge handle ---------- */
.drawer-handle {
  position: fixed; top: 50%; right: 0; transform: translateY(-50%); z-index: 55;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  padding: 16px 9px; border-radius: 12px 0 0 12px; box-shadow: -5px 0 18px rgba(30,40,50,.22);
  transition: right .28s cubic-bezier(.4,0,.2,1), background .15s;
}
.drawer-handle:hover { background: var(--accent-2); }
.drawer-handle i { width: 18px; height: 18px; }
.handle-label { writing-mode: vertical-rl; text-orientation: mixed; font-size: 12px; font-weight: 700; letter-spacing: .08em; }
body.drawer-open .drawer-handle { right: min(var(--drawer-w), 94vw); }

/* ---------- Catalog drawer ---------- */
.drawer-scrim { position: fixed; inset: 0; background: rgba(24,28,32,.34); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: var(--drawer-w); max-width: 94vw;
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: -14px 0 44px rgba(30,40,50,.16);
  z-index: 50; display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .28s cubic-bezier(.4,0,.2,1);
}
.drawer[aria-hidden="false"] { transform: translateX(0); }
.panel-kicker { font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--hi); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 8px; }
.drawer-title { font-family: "Fraunces", serif; font-size: 22px; font-weight: 600; margin-top: 2px; }
.assign-bar { margin: 0 20px 10px; padding: 8px 12px; background: var(--hi-soft); border-radius: 9px; font-size: 12.5px; color: #6b4a12; }
.assign-bar strong { font-weight: 700; }
.dens-switch { display: flex; gap: 3px; padding: 3px; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; }
.dens-btn { width: 28px; height: 28px; font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer; border: none; background: none; color: var(--ink-soft); border-radius: 6px; transition: .12s; }
.dens-btn:hover { color: var(--ink); }
.dens-btn.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.drawer-tabs { display: flex; gap: 4px; padding: 0 20px 12px; }
.drawer-tab { flex: 1; font: inherit; font-weight: 600; font-size: 12.5px; padding: 9px 6px; cursor: pointer; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-soft); transition: .15s; position: relative; }
.drawer-tab:hover { color: var(--ink); }
.drawer-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.drawer-tab .tab-count { font-size: 10.5px; opacity: .7; margin-left: 5px; }
.drawer-search { display: flex; align-items: center; gap: 8px; margin: 0 20px 8px; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: 10px; }
.drawer-search i { width: 16px; height: 16px; color: var(--ink-soft); }
.drawer-search input { border: none; outline: none; font: inherit; font-size: 14px; background: none; width: 100%; color: var(--ink); }
.drawer-count { padding: 0 20px 8px; font-size: 12px; color: var(--ink-soft); }
.drawer-grid { flex: 1; overflow-y: auto; padding: 4px 20px 24px; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 172px; gap: 14px; align-content: start; }
.drawer-grid[data-cols="1"] { grid-template-columns: 1fr; grid-auto-rows: 264px; }
.drawer-grid[data-cols="2"] { grid-template-columns: 1fr 1fr; grid-auto-rows: 172px; }
.drawer-grid[data-cols="3"] { grid-template-columns: 1fr 1fr 1fr; grid-auto-rows: 146px; }
.cat-card { display: block; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); cursor: pointer; transition: border-color .15s, transform .15s, box-shadow .15s; position: relative; }
.cat-card:hover { transform: translateY(-2px); border-color: var(--line-strong); box-shadow: var(--shadow); }
.cat-card.selected { border-color: var(--hi); box-shadow: 0 0 0 2px var(--hi-soft); }
.cat-swatch { display: block; height: 118px; background-color: #ece8e1; background-repeat: no-repeat; background-size: 240%; background-position: center; }
.drawer-grid[data-cols="1"] .cat-swatch { height: 210px; background-size: 150%; }
.drawer-grid[data-cols="3"] .cat-swatch { height: 92px; }
.cat-meta { padding: 9px 11px 11px; }
.cat-name { font-size: 12.5px; font-weight: 600; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-code { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }
.cat-badge { position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.9); color: var(--ink-soft); box-shadow: 0 1px 3px rgba(0,0,0,.14); }
.cat-badge i { width: 13px; height: 13px; }
.cat-badge.ready { background: var(--ok); color: #fff; }

/* ---- Consumer default view: hide AI/generation affordances; q×5 reveals full (dev) view ---- */
.ai-pill { display: none; }
#generateBtn { display: none; }
.cat-badge:not(.ready) { display: none; }          /* keep only the green ticks on materials */
body.full-view .ai-pill { display: inline-flex; }
body.full-view #generateBtn { display: inline-flex; }
body.full-view .cat-badge:not(.ready) { display: grid; }
.drawer-empty { grid-column: 1 / -1; color: var(--ink-soft); font-size: 13px; padding: 24px 4px; line-height: 1.5; }

/* ---------- Fullscreen preview ---------- */
.fs-overlay { position: fixed; inset: 0; z-index: 80; background: rgba(16,15,13,.94); display: grid; place-items: center; padding: 32px; }
.fs-overlay img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; box-shadow: 0 24px 80px rgba(0,0,0,.5); }
.fs-close { position: absolute; top: 20px; right: 22px; width: 42px; height: 42px; border-radius: 50%; border: none; cursor: pointer; background: rgba(255,255,255,.14); color: #fff; display: grid; place-items: center; }
.fs-close:hover { background: rgba(255,255,255,.26); }
.fs-close i { width: 20px; height: 20px; }
