:root {
  --paper:       #FBF9F3;
  --paper-2:     #F4E8CC;
  --paper-3:     #EFE0BA;
  --frolla:      #E8C896;
  --frolla-dk:   #D4A574;
  --crust:       #B68A5A;
  --cocoa:       #8B6F47;
  --cocoa-dk:    #5C4033;
  --ink:         #3E2E22;
  --ink-soft:    #6B5847;
  --ink-faded:   #8C7860;
  --burgundy:    #8B3A2E;
  --basil:       #6B8E5F;
  --line:        #D9C9A8;
  --line-soft:   #E8DDC4;
  --shadow:      0 2px 6px rgba(92,64,51,.08);
  --shadow-md:   0 8px 24px rgba(92,64,51,.12);
  --heading:     'Playfair Display', Georgia, serif;
  --body:        'Inter', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--body);
  color: var(--ink);
  background: var(--paper);
  font-size: 14px;
  line-height: 1.5;
  display: flex; flex-direction: column;
  background-image:
    radial-gradient(ellipse at 12% 8%, rgba(184,138,90,.06) 0%, transparent 40%),
    radial-gradient(ellipse at 88% 92%, rgba(184,138,90,.05) 0%, transparent 45%);
}

/* ────────────────────────────────────────
   TOPBAR
─────────────────────────────────────── */
.topbar {
  height: 76px;
  background: var(--paper-2);
  border-bottom: 1.5px solid var(--line);
  padding: 0 1.25rem;
  display: flex; align-items: center; gap: 1.5rem;
  flex-shrink: 0;
  z-index: 50;
}
.brand {
  display: flex; align-items: center; gap: .55rem;
  text-decoration: none; color: var(--ink);
  padding-right: 1.5rem;
  border-right: 1px solid var(--line);
  height: 100%; padding-top: 8px; padding-bottom: 8px;
}
.brand img { height: 72px; width: auto; object-fit: contain; }
.sectnav { display:flex; gap:.4rem; margin-left:.6rem; }
.sectnav a { text-decoration:none; color:var(--ink-soft); padding:.55rem 1.25rem; border-radius:10px; font-size:1.15rem; font-weight:600; font-family:var(--body); }
.sectnav a:hover { background:rgba(232,200,150,.4); color:var(--ink); }
.sectnav a.active { color:var(--ink); font-weight:600; background:var(--paper); box-shadow:var(--shadow); }
.topbar-spacer { flex: 1; }


/* ────────────────────────────────────────
   TOPBAR: language dropdown (globe icon)
─────────────────────────────────────── */
.lang-dropdown { position: relative; }
.lang-dropdown-trigger {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink-soft); cursor: pointer;
  transition: all .15s;
}
.lang-dropdown-trigger:hover { border-color: var(--cocoa); color: var(--ink); }
.lang-dropdown.open .lang-dropdown-trigger { border-color: var(--cocoa); color: var(--ink); background: var(--frolla); }
.lang-dropdown-menu {
  display: none;
  position: absolute; top: calc(100% + 10px); right: 0;
  min-width: 108px;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow-md);
  padding: 5px; z-index: 40;
  flex-direction: column; gap: 2px;
  animation: langMenuIn .14s ease-out;
}
.lang-dropdown-menu::before {
  content: '';
  position: absolute; top: -5px; right: 11px;
  width: 10px; height: 10px;
  background: var(--paper);
  border-left: 1px solid var(--line); border-top: 1px solid var(--line);
  transform: rotate(45deg);
  border-radius: 2px 0 0 0;
}
.lang-dropdown.open .lang-dropdown-menu { display: flex; }
@keyframes langMenuIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.lang-dropdown-opt {
  display: flex; align-items: center; justify-content: space-between;
  padding: .5rem .7rem;
  border-radius: 8px;
  font-family: var(--body); font-size: .85rem; font-weight: 600;
  color: var(--ink-soft); cursor: pointer;
  transition: background .12s, color .12s;
}
.lang-dropdown-opt:hover { background: var(--paper-2); color: var(--ink); }
.lang-dropdown-opt.sel { background: var(--frolla); color: var(--ink); }
.lang-dropdown-opt.sel::after {
  content: '✓'; color: var(--cocoa-dk); font-size: .78rem; margin-left: .5rem;
}

/* ────────────────────────────────────────
   TOPBAR: account icon link
─────────────────────────────────────── */
.account-icon-link {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink-soft); cursor: pointer;
  text-decoration: none;
  transition: all .15s;
}
.account-icon-link:hover { border-color: var(--cocoa); color: var(--ink); background: var(--frolla); }

/* ────────────────────────────────────────
   MAIN LAYOUT
─────────────────────────────────────── */
.main {
  flex: 1;
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 0;
}

/* ────────────────────────────────────────
   SIDEBAR
─────────────────────────────────────── */
.sidebar {
  background: var(--paper-2);
  border-right: 1.5px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0;
}
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.1rem 1rem;
}
.sidebar-scroll::-webkit-scrollbar { width: 8px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 4px;
}
.sidebar-scroll::-webkit-scrollbar-thumb:hover { background: var(--frolla-dk); }

.sec {
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px dashed var(--line);
}
.sec:last-of-type { border-bottom: none; margin-bottom: .5rem; }
.sec-title {
  font-family: var(--heading);
  font-size: 1.2rem; font-weight: 600;
  color: var(--ink);
  margin-bottom: .55rem;
  display: flex; align-items: center; justify-content: space-between;
}
.sec-title .help {
  font-size: .7rem; color: var(--ink-faded); cursor: help;
  background: var(--paper); border: 1px solid var(--line);
  width: 16px; height: 16px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--body); font-weight: 700;
}
.sec-desc {
  font-size: .82rem; line-height: 1.45;
  color: var(--ink);
  background: var(--frolla);
  border: 1px solid var(--line);
  border-left: 3px solid var(--cocoa);
  border-radius: 8px;
  padding: .5rem .65rem;
  margin-bottom: .7rem;
}

/* Tabs Describe / Upload */
.input-tabs {
  display: flex; gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 3px;
  margin-bottom: .55rem;
}
.input-tab {
  flex: 1;
  padding: .35rem .5rem;
  border: none; background: transparent;
  font-family: var(--body); font-size: .78rem; font-weight: 600;
  color: var(--ink-faded); cursor: pointer;
  border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  transition: all .15s;
}
.input-tab.active {
  background: var(--frolla); color: var(--ink);
}

.ai-textarea {
  width: 100%; min-height: 75px;
  padding: .6rem .75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--body); font-style: italic;
  font-size: .9rem;
  background: var(--paper);
  color: var(--ink);
  resize: vertical;
  line-height: 1.6;
}
.ai-textarea:focus { outline: none; border-color: var(--cocoa); background: #FBF5E5; }
.ai-textarea::placeholder { color: var(--ink-faded); }

.upload-zone {
  width: 100%; padding: 1.1rem .75rem;
  border: 1.5px dashed var(--line);
  border-radius: 6px;
  background: var(--paper);
  display: none; flex-direction: column;
  align-items: center; gap: .35rem; cursor: pointer;
  transition: all .15s; text-align: center;
}
.upload-zone.active { display: flex; }
.upload-zone:hover { border-color: var(--cocoa); background: #FBF5E5; }
.upload-zone.drag-over {
  border-color: var(--burgundy); background: rgba(139,58,46,.06);
  border-style: solid;
}
.upload-zone .icon { font-size: 1.5rem; filter: sepia(.2); }
.upload-zone .main-txt {
  font-family: var(--heading); font-size: 1.05rem; font-weight: 600;
  color: var(--ink);
}
.upload-zone .sub-txt {
  font-size: .73rem; color: var(--ink-faded); font-style: italic;
}
.upload-preview {
  display: none; padding: .55rem; background: var(--paper);
  border: 1px solid var(--line); border-radius: 6px;
  align-items: center; gap: .55rem;
}
.upload-preview.active { display: flex; }
.upload-preview img {
  width: 40px; height: 40px; object-fit: contain;
  border: 1px solid var(--line); border-radius: 4px; background: white;
}
.upload-preview .name {
  flex: 1; font-size: .78rem; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.upload-preview .remove {
  font-size: 1rem; color: var(--ink-faded);
  background: none; border: none; cursor: pointer; padding: 0 .2rem;
}
.upload-preview .remove:hover { color: var(--burgundy); }
.upload-preview .recrop {
  font-size: .9rem; color: var(--ink-faded);
  background: none; border: none; cursor: pointer; padding: 0 .2rem;
}
.upload-preview .recrop:hover { color: var(--cocoa-dk); }
.upload-instr {
  display: none;
  width: 100%;
  margin-top: .45rem;
  padding: .5rem .65rem;
  font-family: var(--body); font-size: .8rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line); border-radius: 6px;
}
.upload-instr.active { display: block; }
.upload-instr:focus { outline: none; border-color: var(--cocoa); background: #FBF5E5; }
.upload-instr::placeholder { color: var(--ink-faded); font-style: italic; }

.chips {
  display: flex; flex-wrap: wrap; gap: .25rem;
  margin-top: .5rem;
}
.chip {
  font-family: var(--body);
  font-size: .95rem;
  padding: .05rem .55rem;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { background: var(--frolla); border-color: var(--cocoa); color: var(--ink); }

/* PARAM ROWS */
.row {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; padding: .3rem 0;
}
.row-label {
  font-family: var(--body); font-size: .83rem;
  color: var(--ink); flex: 1;
}
.row-label small {
  display: block; font-style: italic;
  color: var(--ink-faded); font-size: .72rem;
  margin-top: 1px;
}

.num-input {
  display: flex; align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  overflow: hidden;
  flex-shrink: 0;
}
.num-input button {
  width: 22px; height: 28px;
  background: transparent; border: none;
  color: var(--cocoa); cursor: pointer;
  font-size: 1rem; font-weight: 700;
  font-family: var(--body);
  transition: background .15s;
}
.num-input button:hover { background: var(--frolla); color: var(--ink); }
.num-input input {
  width: 50px; height: 28px;
  border: none; background: transparent;
  text-align: center;
  font-family: var(--body);
  font-size: .85rem; font-weight: 600;
  color: var(--ink);
  outline: none;
  -moz-appearance: textfield;
}
.num-input input::-webkit-outer-spin-button,
.num-input input::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}
.num-val {
  display: inline-flex; align-items: center;
  justify-content: center;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  min-width: 50px;
  height: 28px;
}
.num-val input {
  width: 32px; height: 28px;
  border: none; background: transparent;
  text-align: right;
  font-family: var(--body);
  font-size: .85rem; font-weight: 600;
  color: var(--ink);
  outline: none;
  padding: 0 0 0 4px;
  -moz-appearance: textfield;
  line-height: 28px;
}
.num-val .unit {
  font-size: .65rem; color: var(--ink-faded);
  font-style: italic; pointer-events: none;
  padding-right: 4px;
  padding-left: 2px;
  line-height: 28px;
  transform: translateY(1px);
}

.sel {
  height: 28px; padding: 0 1.6rem 0 .65rem;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--paper);
  font-family: var(--body); font-size: .82rem; font-weight: 600;
  color: var(--ink); cursor: pointer;
  outline: none;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238B6F47'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .55rem center;
  transition: border-color .15s, background-color .15s, box-shadow .15s;
}
.sel:hover { border-color: var(--cocoa); background-color: #FBF5E5; }
.sel:focus { border-color: var(--cocoa); box-shadow: 0 0 0 2px rgba(139,111,71,.1); }

/* Custom select dropdown */
.csel {
  position: relative;
  flex-shrink: 0;
}
.csel-trigger {
  height: 28px; padding: 0 1.4rem 0 .65rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  font-family: var(--body); font-size: .82rem; font-weight: 600;
  color: var(--ink); cursor: pointer;
  display: inline-grid; align-items: center;
  grid-template-columns: 1fr auto;
  transition: border-color .15s, background-color .15s;
  white-space: nowrap;
}
.csel-text, .csel-sizer {
  grid-column: 1; grid-row: 1;
}
.csel-sizer {
  visibility: hidden; pointer-events: none;
}
.csel-trigger:hover { border-color: var(--cocoa); background-color: #FBF5E5; }
.csel.open .csel-trigger { border-color: var(--cocoa); background-color: #FBF5E5; }
.csel-arrow {
  position: absolute; right: .55rem; top: 50%; transform: translateY(-50%);
  width: 0; height: 0;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid var(--cocoa);
  transition: transform .2s;
}
.csel.open .csel-arrow { transform: translateY(-50%) rotate(180deg); }
.csel-menu {
  position: absolute; top: calc(100% + 4px); left: 0;
  min-width: 100%; max-height: 180px; overflow-y: auto;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 4px;
  z-index: 40;
  display: none;
}
.csel.open .csel-menu { display: block; }
.csel-opt {
  padding: .4rem .7rem;
  border-radius: 8px;
  font-family: var(--body); font-size: .8rem;
  color: var(--ink); cursor: pointer;
  transition: background .12s;
  white-space: nowrap;
}
.csel-opt:hover { background: var(--frolla); }

.collapsable {
  max-height: 600px; overflow: hidden;
  transition: max-height .25s ease, opacity .25s, margin .25s;
}
.collapsable.collapsed {
  max-height: 0; opacity: 0; margin: 0;
}

.gen-btn {
  width: 100%;
  padding: .65rem 1rem;
  background: var(--ink); color: var(--paper);
  border: none; border-radius: 99px;
  font-family: var(--heading);
  font-size: 1.3rem; font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  transition: all .2s;
  box-shadow: 0 3px 10px rgba(62,46,34,.18);
}
.gen-btn:hover:not(:disabled) {
  background: var(--cocoa-dk);
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(62,46,34,.25);
}
.gen-btn:active:not(:disabled) { transform: scale(.98); }
.gen-btn:disabled {
  background: var(--ink-faded);
  cursor: not-allowed;
}
.adv-toggle { display:flex; align-items:center; gap:.4rem; cursor:pointer; color:var(--cocoa); font-weight:600; font-family:var(--heading); font-size:1.2rem; padding:.4rem 0; margin:.2rem 0 .6rem; padding-top:.7rem; user-select:none; }
.adv-toggle .adv-car { transition:transform .2s; }
.adv-toggle.open .adv-car { transform:rotate(180deg); }
.adv-sec { display:none; }
.adv-sec.open { display:block; }
.gen-hint {
  font-family: var(--body); font-style: italic;
  font-size: .73rem; color: var(--ink-faded);
  text-align: center; margin-top: .35rem;
}

/* ────────────────────────────────────────
   STAGE (preview area)
─────────────────────────────────────── */
.stage {
  position: relative;
  background:
    repeating-linear-gradient(90deg, rgba(150,120,80,.05) 0 1px, transparent 1px 24px),
    radial-gradient(circle at center, #FCFBF6 0%, #F1EADC 100%);
  display: flex; flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* decorative blotch */
.stage::before {
  content: ''; position: absolute;
  top: 8%; right: 12%;
  width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(184,138,90,.07) 0%, transparent 65%);
  border-radius: 50%; pointer-events: none;
}
.stage::after {
  content: ''; position: absolute;
  bottom: 12%; left: 8%;
  width: 220px; height: 220px;
  background: radial-gradient(circle, rgba(139,58,46,.04) 0%, transparent 65%);
  border-radius: 50%; pointer-events: none;
}

/* ────────────────────────────────────────
   MOBILE: hamburger menu
─────────────────────────────────────── */
.hamburger {
  display: none;
  background: none; border: none; cursor: pointer;
  width: 36px; height: 36px;
  flex-direction: column; align-items: center; justify-content: center; gap: 5px;
}
.hamburger span {
  display: block; width: 20px; height: 2px;
  background: var(--ink); border-radius: 2px;
  transition: all .2s;
}
.hamburger.open span:nth-child(1) { transform: rotate(45deg) translate(2.5px, 2.5px); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: rotate(-45deg) translate(2.5px, -2.5px); }

.mobile-menu {
  display: none;
  position: fixed; top: 56px; left: 0; right: 0;
  background: var(--paper-2); border-bottom: 1.5px solid var(--line);
  padding: .8rem 1rem;
  z-index: 100;
  flex-direction: column; gap: .4rem;
  box-shadow: var(--shadow-md);
}
.mobile-menu.open { display: flex; }
.mobile-menu a {
  text-decoration: none; color: var(--ink-soft); padding: .6rem .8rem;
  border-radius: 8px; font-size: 1rem; font-weight: 600;
}
.mobile-menu a.active { background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }

/* ────────────────────────────────────────
   THING TO MAKE: mode dropdown with 3D render icons (sidebar)
─────────────────────────────────────── */
.mode-dropdown {
  display: block;
  position: relative;
}
.mode-dropdown-trigger {
  display: flex; align-items: center; gap: .6rem;
  width: 100%;
  padding: .45rem .7rem;
  background: var(--paper); border: 1.5px solid var(--frolla-dk);
  border-radius: 10px; cursor: pointer;
  font-family: var(--body); font-size: .9rem; font-weight: 600;
  color: var(--ink);
}
.mode-dropdown-trigger .mode-lbl { flex: 1; }
.mode-dropdown-trigger .csel-arrow {
  position: static; transform: none;
  margin-left: .3rem;
}
.mode-dropdown.open .mode-dropdown-trigger .csel-arrow { transform: rotate(180deg); }
.mode-ico {
  width: 44px; height: 44px;
  object-fit: contain;
  border-radius: 8px;
  background: white;
  border: 1px solid var(--line);
}
.mode-dropdown-menu {
  display: none;
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow-md);
  padding: 4px; z-index: 40;
  max-height: 60vh; overflow-y: auto;
}
.mode-dropdown.open .mode-dropdown-menu { display: block; }
.mode-dropdown-menu .mode-opt {
  display: flex; align-items: center; gap: .65rem;
  padding: .4rem .6rem;
  border-radius: 8px;
  font-size: .9rem;
}
.mode-dropdown-menu .mode-opt.sel {
  background: var(--frolla);
  font-weight: 600;
}

/* ────────────────────────────────────────
   MOBILE: sidebar drawer
─────────────────────────────────────── */
.sidebar-toggle {
  display: none;
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  padding: .6rem 1.4rem;
  background: var(--ink); color: var(--paper);
  border: none; border-radius: 99px;
  font-family: var(--heading); font-size: 1rem; font-weight: 600;
  cursor: pointer; z-index: 60;
  box-shadow: 0 4px 16px rgba(62,46,34,.25);
}
.sidebar-toggle:active { transform: translateX(-50%) scale(.96); }

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(62,46,34,.4);
  z-index: 69;
}
.sidebar-backdrop.open { display: block; }

/* ────────────────────────────────────────
   MOBILE BREAKPOINT (820px)
─────────────────────────────────────── */
@media (max-width: 820px) {
  /* Topbar */
  .topbar { height: 56px; padding: 0 .8rem; gap: .6rem; }
  .brand { padding-right: .8rem; }
  .brand img { height: 44px; }
  .sectnav { display: none; }
  .topbar-spacer { flex: 1; }
  .hamburger { display: flex; }

  /* Main layout: stage only, sidebar is drawer */
  .main { grid-template-columns: 1fr; grid-template-rows: 1fr; }

  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0;
    max-height: 75vh; height: auto;
    border-right: none;
    border-top: 1.5px solid var(--line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(62,46,34,.15);
    z-index: 70;
    transform: translateY(100%);
    transition: transform .3s ease;
  }
  .sidebar.open { transform: translateY(0); }
  .sidebar-toggle { display: block; }

  /* Stage */
  .stage { min-height: 0; }
  .canvas { padding: 1rem; }
  .canvas-idle h2 { font-size: 1.8rem; }
  .canvas-idle p { font-size: .9rem; }
  .canvas-idle .ornament { font-size: 1.8rem; }

  /* Result actions */
  .result-actions { bottom: .6rem; }
  .stage-preview-card { max-width: calc(100% - 5.5rem); }
  .stage-3d-controls { right: .5rem; }
}

/* ────────────────────────────────────────
   MOBILE BREAKPOINT (480px) — small phones
─────────────────────────────────────── */
@media (max-width: 480px) {
  .topbar { height: 50px; padding: 0 .6rem; gap: .4rem; }
  .brand img { height: 36px; }
  .canvas { padding: .6rem; }
  .canvas-idle h2 { font-size: 1.5rem; }
  .canvas-idle .hints { padding: .6rem .8rem; }
  .canvas-idle .hint { font-size: .78rem; }
  .btn-dl { font-size: .8rem; padding: .35rem .7rem; }
  .btn-new-image { font-size: .8rem; padding: .3rem .6rem; }
  .btn-ghost { font-size: .78rem; padding: .3rem .6rem; }
  .result-meta span { font-size: .65rem; padding: .1rem .4rem; }
  .gen-btn { font-size: 1.1rem; padding: .55rem .8rem; }
  .sidebar-toggle { font-size: .9rem; padding: .5rem 1.2rem; }
}

/* Used by lettering.html's own stage layout (.fstage/.stage-tools) */
.stage-title {
  font-family: var(--heading);
  font-size: 1.15rem; font-weight: 600;
  color: var(--ink);
}

/* ────────────────────────────────────────
   STAGE: floating chrome (preview card, view tabs, 3D controls)
   Replaces the old full-width stage-toolbar — the stage is now borderless,
   with small floating pieces of UI over the canvas.
─────────────────────────────────────── */
.stage-preview-card {
  position: absolute; top: .9rem; left: .9rem;
  z-index: 6;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .6rem .85rem;
  box-shadow: var(--shadow-md);
  max-width: 240px;
}
.stage-preview-title {
  font-family: var(--heading);
  font-size: .95rem; font-weight: 600;
  color: var(--ink);
  margin-bottom: .3rem;
}
.stage-preview-meta {
  display: flex; flex-wrap: wrap; gap: .3rem;
}
.stage-preview-meta span {
  font-family: var(--body);
  font-size: .68rem;
  background: var(--paper-2);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  padding: .1rem .5rem;
  border-radius: 99px;
}

.view-tabs {
  position: absolute; top: .9rem; right: .9rem;
  z-index: 6;
  display: flex; gap: .2rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 3px;
  box-shadow: var(--shadow-md);
}
.view-tab {
  padding: .3rem .85rem;
  background: transparent;
  border: none;
  border-radius: 99px;
  font-family: var(--body);
  font-size: .78rem; font-weight: 600;
  color: var(--ink-faded);
  cursor: pointer;
  transition: all .15s;
}
.view-tab:hover { color: var(--ink); }
.view-tab.active {
  background: var(--cocoa); color: var(--paper);
}

.stage-3d-controls {
  position: absolute; top: 50%; right: .9rem;
  transform: translateY(-50%);
  z-index: 6;
  display: flex; flex-direction: column; gap: .5rem;
}
.stage-3d-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 50%;
  font-family: var(--body); font-size: 1.1rem; font-weight: 700;
  color: var(--ink-soft); cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: all .15s;
}
.stage-3d-btn:hover { border-color: var(--cocoa); color: var(--ink); background: var(--frolla); }

.canvas {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
  position: relative;
  min-height: 0;
}

/* Drag overlay global */
.drop-overlay {
  position: absolute; inset: 0;
  background: rgba(250,243,226,.95);
  backdrop-filter: blur(4px);
  border: 3px dashed var(--burgundy);
  border-radius: 8px;
  margin: 1rem;
  display: none;
  align-items: center; justify-content: center;
  z-index: 30;
  pointer-events: none;
}
.drop-overlay.active { display: flex; }
.drop-inner {
  text-align: center;
  pointer-events: none;
}
.drop-inner .ico {
  font-size: 3.5rem;
  filter: sepia(.3);
  margin-bottom: .8rem;
}
.drop-inner h3 {
  font-family: var(--heading);
  font-size: 1.8rem; color: var(--ink);
  margin-bottom: .3rem;
}
.drop-inner p {
  font-style: italic; color: var(--ink-soft);
}

/* Crop overlay (raster uploads pass through here before the pipeline) */
.crop-overlay {
  position: fixed; inset: 0;
  background: rgba(62,46,34,.55);
  display: none;
  align-items: center; justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.crop-overlay.active { display: flex; }
/* desktop: center over the CANVAS (stage), not the whole window — the
   340px sidebar sits on the left */
@media (min-width: 821px) {
  .crop-overlay { padding-left: calc(340px + 1rem); }
}
.crop-box {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--frolla-dk);
  border-radius: 10px;
  padding: 1.2rem 1.5rem 1.4rem;
  width: min(100%, 900px);
  max-height: 94vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(62,46,34,.35);
}
.crop-close {
  position: absolute;
  top: .6rem; right: .8rem;
  font-size: 1.6rem; line-height: 1;
  color: var(--ink-faded);
  background: none; border: none;
  cursor: pointer;
  padding: .2rem .4rem;
  z-index: 2;
}
.crop-close:hover { color: var(--burgundy); }
.crop-head h3 {
  font-family: var(--heading);
  font-size: 1.65rem; color: var(--ink);
  margin-bottom: .15rem;
}
.crop-head p {
  font-style: italic; color: var(--ink-soft);
  font-size: .92rem; margin-bottom: .8rem;
}
.crop-tools {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  margin-bottom: .7rem; flex-wrap: wrap;
}
.crop-tool {
  font-family: var(--body);
  font-size: .88rem;
  padding: .45rem .95rem;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
}
.crop-tool:hover { border-color: var(--frolla-dk); color: var(--ink); }
.crop-tool.active {
  background: var(--frolla); border-color: var(--frolla-dk); color: var(--ink);
}
.crop-tool:disabled { opacity: .55; cursor: wait; }
.crop-stage {
  position: relative;
  display: block;
  margin: 0 auto;              /* centered in the box (width pinned by JS) */
  line-height: 0;
  user-select: none;
  touch-action: none;          /* pointer events handle the dragging */
  background: white;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: auto;              /* zoomed image (mouse wheel) pans via scroll */
}
.crop-stage img {
  max-width: min(88vw, 840px);
  /* as tall as the screen allows while keeping toolbar + AI row + actions
     in view (~370px of chrome inside the 94vh box) */
  max-height: max(320px, calc(94vh - 370px));
  display: block;
  pointer-events: none;
}
.crop-rect {
  position: absolute;
  border: 2px dashed var(--burgundy);
  box-shadow: 0 0 0 9999px rgba(251,249,243,.72);  /* dims everything outside */
  cursor: move;
  display: none;                    /* selection is a tool: click to arm */
}
.crop-overlay.armed .crop-rect { display: block; }
.crop-handle {
  position: absolute;
  width: 14px; height: 14px;
  background: var(--burgundy);
  border: 2px solid var(--paper);
  border-radius: 50%;
}
.crop-handle[data-h="nw"] { top: -8px;  left: -8px;  cursor: nwse-resize; }
.crop-handle[data-h="ne"] { top: -8px;  right: -8px; cursor: nesw-resize; }
.crop-handle[data-h="sw"] { bottom: -8px; left: -8px;  cursor: nesw-resize; }
.crop-handle[data-h="se"] { bottom: -8px; right: -8px; cursor: nwse-resize; }
/* source line-art thumbnail in the result view */
.src-thumb {
  position: absolute; left: 12px; bottom: 12px;
  width: 68px; height: 68px;
  background: white;
  border: 1px solid var(--frolla-dk);
  border-radius: 8px;
  padding: 4px;
  cursor: zoom-in;
  z-index: 5;
  box-shadow: 0 2px 10px rgba(62,46,34,.12);
  transition: width .18s ease, height .18s ease;
}
.src-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.src-thumb.big {
  width: min(52vh, 380px); height: min(52vh, 380px);
  cursor: zoom-out;
}
@media (max-width: 820px) {
  .src-thumb { width: 56px; height: 56px; bottom: 70px; }  /* clear of the Parameters toggle */
  .src-thumb.big { width: min(70vw, 320px); height: min(70vw, 320px); }
}

.crop-instr-row {
  margin-top: .8rem;
  padding: .65rem .85rem;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.crop-instr-label {
  display: block;
  font-family: var(--heading);
  font-size: 1.05rem; font-weight: 600;
  color: var(--ink);
  margin-bottom: .4rem;
}
.crop-instr {
  display: block;
  width: 100%;
  padding: .65rem .8rem;
  font-family: var(--body); font-size: .95rem;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line); border-radius: 6px;
}
.crop-instr:focus { outline: none; border-color: var(--cocoa); background: #FBF5E5; }
.crop-instr::placeholder { color: var(--ink-faded); font-style: italic; }
.crop-instr-hint {
  margin-top: .4rem;
  font-size: .78rem; font-style: italic;
  color: var(--ink-faded);
}
.crop-actions {
  display: flex; justify-content: flex-end; gap: .5rem;
  margin-top: .9rem;
}
.crop-btn {
  font-family: var(--heading);
  font-size: .95rem;
  padding: .45rem 1.1rem;
  border-radius: 6px;
  cursor: pointer;
}
.crop-btn.ghost {
  background: none; color: var(--ink-soft);
  border: 1px solid var(--line);
}
.crop-btn.ghost:hover { color: var(--ink); border-color: var(--frolla-dk); }
.crop-btn.primary {
  background: var(--cocoa); color: var(--paper);
  border: 1px solid var(--cocoa-dk);
}
.crop-btn.primary:hover { background: var(--cocoa-dk); }

@media (max-width: 820px) {
  .crop-box { padding: .8rem; width: 96vw; }
  .crop-stage img { max-width: 88vw; max-height: 46vh; }
  .crop-handle { width: 18px; height: 18px; }  /* bigger touch targets */
  .crop-handle[data-h="nw"] { top: -10px;  left: -10px; }
  .crop-handle[data-h="ne"] { top: -10px;  right: -10px; }
  .crop-handle[data-h="sw"] { bottom: -10px; left: -10px; }
  .crop-handle[data-h="se"] { bottom: -10px; right: -10px; }
}

/* idle state */
.canvas-idle {
  text-align: center; max-width: 560px; width: 100%;
  margin-bottom: 2%;
}
/* hero input: the primary input lives here, centered on the canvas */
.hero-input {
  margin-top: 1.3rem;
  text-align: left;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.1rem 1.1rem 1rem;
  box-shadow: 0 6px 24px rgba(62,46,34,.08);
}
.hero-input .gen-btn { margin-top: .9rem; }
@media (max-width: 820px) {
  .canvas-idle { max-width: 100%; }
  .hero-input { padding: .85rem .85rem .8rem; }
}
.canvas-idle .ornament {
  font-family: var(--heading);
  font-size: 2.4rem; color: var(--burgundy);
  font-style: italic;
  margin-bottom: .3rem;
  transform: rotate(-2deg);
  display: inline-block;
}
.canvas-idle h2 {
  font-family: var(--heading);
  font-size: 2.6rem; font-weight: 700;
  color: var(--ink);
  line-height: 1.05;
  margin-bottom: 1rem;
}
.canvas-idle h2 .accent {
  color: var(--burgundy); font-style: italic;
}
.canvas-idle p {
  font-family: var(--body); font-style: italic;
  font-size: 1rem; color: var(--ink-soft);
  margin-bottom: 1.5rem;
  max-width: 380px; margin-left: auto; margin-right: auto;
}
.canvas-idle .hints {
  display: inline-flex; flex-direction: column; gap: .4rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .8rem 1.1rem;
  text-align: left;
}
.canvas-idle .hint {
  font-family: var(--body); font-size: .85rem;
  color: var(--ink-soft);
  display: flex; align-items: center; gap: .55rem;
}
.canvas-idle .hint .badge {
  font-family: var(--body);
  font-size: 0.75rem; color: var(--burgundy);
  background: var(--frolla);
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}

/* loading state */
.canvas-loading {
  display: none; flex-direction: column;
  align-items: center; justify-content: center; gap: .6rem;
}
.cookie-loader {
  display: flex; flex-direction: column; align-items: center;
}
.cookie-loader .cookie-wrapper {
  backface-visibility: hidden;
  perspective: 1000px;
  transform: translate3d(0,0,0);
  animation: cookieBounce 1s infinite forwards;
}
.cookie-loader .cookie-spin {
  width: 110px; height: 110px;
  outline: .5rem solid transparent;
  transform-origin: 50% 50%;
  animation: cookieRoll 2s cubic-bezier(1,0,.4,1) infinite;
}
.cookie-loader .cookie-shadow {
  width: 64px; height: 7px;
  margin: 10px auto 0;
  background: var(--ink);
  border-radius: 100%;
  opacity: .2;
  animation: cookieShadow 1s infinite;
}
.loading-step {
  font-family: var(--body); font-style: italic;
  font-size: .9rem; color: var(--ink-soft);
  min-height: 1.4em;
  transition: opacity .2s;
}

/* result state */
.canvas-result {
  display: none;
  position: absolute; inset: 0;
}


.viewer3d {
  display: none;
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 30%, #fffdf8, #f0e5d3);
  overflow: hidden;
  cursor: grab;
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20'%3E%3Ccircle cx='10' cy='10' r='7' fill='none' stroke='%239a9a9a' stroke-width='1.5'/%3E%3Ccircle cx='10' cy='10' r='2' fill='%239a9a9a'/%3E%3C/svg%3E") 10 10, grab;
}
.viewer3d.active { display: block; }
.viewer3d:active {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20'%3E%3Ccircle cx='10' cy='10' r='7' fill='none' stroke='%236b6b6b' stroke-width='1.5'/%3E%3Ccircle cx='10' cy='10' r='2' fill='%236b6b6b'/%3E%3C/svg%3E") 10 10, grabbing;
}
.btn-new-image {
  padding: .35rem .8rem;
  background: var(--paper);
  border: 1.5px solid var(--cocoa);
  border-radius: 99px;
  font-family: var(--heading);
  font-size: .9rem; font-weight: 600;
  color: var(--cocoa-dk);
  cursor: pointer;
  transition: all .2s;
  display: inline-flex; align-items: center; gap: .3rem;
}
.btn-new-image:hover {
  background: var(--frolla);
  color: var(--ink);
  transform: translateY(-1px);
}
.btn-new-image:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-new-image.dirty {
  background: var(--burgundy);
  color: var(--paper);
  border-color: var(--burgundy);
}
.live-pill {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center;
  opacity: 0;
  transition: opacity .2s;
  z-index: 5;
  pointer-events: none;
}
.live-pill.active { opacity: 1; }
.live-pill .cookie-wrapper {
  backface-visibility: hidden;
  perspective: 1000px;
  transform: translate3d(0,0,0);
  animation: cookieBounce 1s infinite forwards;
}
.live-pill .cookie-spin {
  width: 56px; height: 56px;
  outline: .5rem solid transparent;
  transform-origin: 50% 50%;
  animation: cookieRoll 2s cubic-bezier(1,0,.4,1) infinite;
}
.live-pill .cookie-shadow {
  width: 36px; height: 5px;
  margin: 6px auto 0;
  background: var(--ink);
  border-radius: 100%;
  opacity: .2;
  animation: cookieShadow 1s infinite;
}
.live-pill .live-text {
  font-family: var(--body); font-style: italic;
  font-size: .75rem; color: var(--ink-soft);
  margin-top: .4rem;
}
@keyframes cookieRoll { 100% { transform: rotate(360deg); } }
@keyframes cookieBounce { 50% { transform: translate3d(0,-8%,0); } }
@keyframes cookieShadow { 50% { opacity: .12; transform: scale(.9); } }

.result-svg-wrap {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper);
}
.result-svg-wrap svg { max-width: 80%; max-height: 80%; }
.result-meta {
  position: absolute; top: .6rem; left: .6rem; right: .6rem;
  display: flex; gap: .4rem; flex-wrap: wrap; align-items: center;
  z-index: 5; pointer-events: none;
}
.result-meta span {
  font-family: var(--body);
  font-size: .72rem;
  background: rgba(251,249,243,.85);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  padding: .12rem .55rem;
  border-radius: 99px;
}
.result-actions {
  position: absolute; bottom: 1.1rem; left: 50%; transform: translateX(-50%);
  display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; justify-content: center;
  z-index: 5;
}
.btn-dl {
  padding: .4rem .9rem;
  background: var(--ink); color: var(--paper);
  border: none; border-radius: 99px;
  font-family: var(--heading);
  font-size: .9rem; font-weight: 600;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: .35rem;
  transition: all .2s;
  text-decoration: none;
}
.btn-dl:hover { background: var(--cocoa-dk); transform: translateY(-1px); }
.btn-ghost {
  padding: .35rem .8rem;
  background: transparent;
  border: 1.5px solid var(--line);
  border-radius: 99px;
  font-family: var(--heading);
  font-size: .85rem; font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
}
.btn-ghost:hover { border-color: var(--cocoa); color: var(--ink); }

/* Status bar at the bottom of stage */
.stage-status {
  height: 32px;
  background: var(--paper-2);
  border-top: 1px solid var(--line);
  padding: 0 1rem;
  display: flex; align-items: center; gap: 1.5rem;
  font-family: var(--body); font-style: italic;
  font-size: .78rem; color: var(--ink-faded);
  flex-shrink: 0;
}
.stage-status .item {
  display: inline-flex; align-items: center; gap: .35rem;
}
.stage-status .item strong {
  font-style: normal; color: var(--ink); font-weight: 600;
}
.stage-status .spacer { flex: 1; }
.stage-status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--basil);
  box-shadow: 0 0 6px rgba(107,142,95,.5);
}



/* ────────────────────────────────────────
   FOCUS-VISIBLE (keyboard accessibility)
─────────────────────────────────────── */
.chip:focus-visible,
.mode-dropdown-trigger:focus-visible,
.view-tab:focus-visible,
.input-tab:focus-visible,
.csel-trigger:focus-visible,
.btn-dl:focus-visible,
.btn-ghost:focus-visible,
.btn-new-image:focus-visible,
.gen-btn:focus-visible,
.num-input button:focus-visible {
  outline: 2px solid var(--cocoa);
  outline-offset: 2px;
}

/* Save to library button */
.btn-save {
  padding: .4rem .9rem;
  background: var(--basil); color: var(--paper);
  border: none; border-radius: 99px;
  font-family: var(--heading);
  font-size: .9rem; font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.btn-save:hover:not(:disabled) { background: #5a7a4f; transform: translateY(-1px); }
.btn-save:disabled { opacity: .7; cursor: default; }
.btn-save.saved { background: var(--basil); opacity: .85; }
