/* ============================================================
   PixelTriks — forge.css
   Modern, responsive image-editor shell. One layout, component-
   responsive: desktop = left tools / right panel; mobile = bottom
   tool bar + summonable bottom-sheet panel.
   ============================================================ */

:root {
  /* surfaces */
  --bg:        #0e0f13;
  --bg-2:      #15171d;
  --surface:   #1a1d24;
  --surface-2: #22262f;
  --line:      #2c313b;
  --line-soft: #23272f;
  /* ink */
  --ink:       #e9ecf2;
  --ink-2:     #aeb6c4;
  --ink-3:     #79808d;
  /* brand */
  --accent:    #e8a33d;
  --accent-2:  #f4b860;
  --accent-ink:#1a1206;
  --ai:        #8a7bff;
  --ai-2:      #a99bff;
  --danger:    #e5634d;
  --ok:        #5bbf7a;
  /* metrics */
  --bar-h:     clamp(48px, 6vh, 56px);
  --rail-w:    clamp(72px, 6.5vw, 84px);
  --panel-w:   clamp(280px, 24vw, 340px);
  --r:         12px;
  --r-sm:      8px;
  --shadow:    0 8px 30px rgba(0,0,0,.45);
  --shadow-sm: 0 2px 10px rgba(0,0,0,.3);
  --font:      "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:#eef0f4; --bg-2:#e7eaef; --surface:#fff; --surface-2:#f3f5f8;
    --line:#d6dae1; --line-soft:#e4e7ec;
    --ink:#1c2128; --ink-2:#4a5260; --ink-3:#828b98;
    --accent-ink:#fff; --shadow:0 8px 30px rgba(20,30,50,.16);
    --ai:#6a52f0; --ai-2:#5540d6;   /* the dark-theme lavenders wash out on light */
  }
}
:root[data-theme="light"] {
  --bg:#eef0f4; --bg-2:#e7eaef; --surface:#fff; --surface-2:#f3f5f8;
  --line:#d6dae1; --line-soft:#e4e7ec;
  --ink:#1c2128; --ink-2:#4a5260; --ink-3:#828b98;
  --accent-ink:#fff; --shadow:0 8px 30px rgba(20,30,50,.16);
  --ai:#6a52f0; --ai-2:#5540d6;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font);
  background: var(--bg); color: var(--ink);
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-size: clamp(13px, 1.4vw, 14.5px);
  display: flex; flex-direction: column;
  /* crisp, legible type */
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11", "ss01";
  letter-spacing: -0.006em;
}
svg { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------- buttons ---------------------------- */
button { font-family: inherit; color: inherit; cursor: pointer; border: 0;
  background: none; font-size: inherit; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; border-radius: var(--r-sm);
  color: var(--ink-2); transition: .15s background, .15s color;
}
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:disabled { opacity: .32; pointer-events: none; }
.icon-btn.danger:hover { color: var(--danger); }

.text-btn {
  padding: .5em 1em; border-radius: 999px; font-weight: 600;
  color: var(--ink); background: var(--surface-2);
  transition: .15s transform, .15s background, .15s box-shadow;
  white-space: nowrap;
}
.text-btn:hover { background: var(--line); }
.text-btn:active { transform: translateY(1px); }
.text-btn.ghost { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.text-btn.ghost:hover { background: var(--surface-2); }
.text-btn.primary { background: var(--accent); color: var(--accent-ink); }
.text-btn.primary:hover { background: var(--accent-2); }
.text-btn.lg { padding: .7em 1.3em; font-size: 1.05em; }
.text-btn.wide { flex: 1; text-align: center; }
.text-btn.ai-btn { color: var(--ai-2); background: color-mix(in srgb, var(--ai) 14%, transparent); }
.text-btn.ai-btn:hover { background: color-mix(in srgb, var(--ai) 26%, transparent); }

/* ---------------------------- top bar ---------------------------- */
#topbar {
  height: var(--bar-h); flex: 0 0 auto;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: .5rem; padding: 0 .6rem;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
  z-index: 30;
}
.tb-group { display: flex; align-items: center; gap: .35rem; }
.tb-left  { justify-self: start; }
.tb-center{ justify-self: center; }
.tb-right { justify-self: end; }
.brand { display: flex; align-items: center; gap: .4rem; font-weight: 800;
  letter-spacing: .2px; margin: 0 .3rem; }
.brand-mark { color: var(--accent); font-size: 1.1em; }
.menu-btn { display: none; }

.zoom-pill { display: flex; align-items: center; background: var(--surface);
  border-radius: 999px; box-shadow: inset 0 0 0 1px var(--line); }
.zoom-label { min-width: 4ch; padding: .35em .2em; font-variant-numeric: tabular-nums;
  font-weight: 600; color: var(--ink-2); font-size: .92em; }
.zoom-label:hover { color: var(--ink); }

/* ------------------------- tool option bar ----------------------- */
#optbar {
  flex: 0 0 auto; min-height: 42px;
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  padding: .35rem .8rem; background: var(--surface);
  border-bottom: 1px solid var(--line-soft); z-index: 20;
}
#optbar .opt { display: flex; align-items: center; gap: .45rem; color: var(--ink-2); font-size: .9em; }
#optbar input[type=range] { width: clamp(70px, 14vw, 130px); }
#optbar .seg { display: flex; background: var(--bg-2); border-radius: var(--r-sm);
  box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
#optbar .seg button { padding: .35em .7em; color: var(--ink-3); font-weight: 600; }
#optbar .seg button.on { background: var(--accent); color: var(--accent-ink); }

/* ---------------------------- stage ------------------------------ */
#stage { flex: 1 1 auto; display: flex; min-height: 0; position: relative; }

/* tool rail */
#toolrail {
  flex: 0 0 var(--rail-w); display: flex; flex-direction: column;
  align-items: stretch; gap: 3px; padding: 6px 6px;
  background: var(--bg-2); border-right: 1px solid var(--line);
  overflow-y: auto; z-index: 15;
}
.tool {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  width: 100%; min-height: 50px; padding: 6px 2px;
  border-radius: 10px; color: var(--ink-2); cursor: pointer;
  transition: .14s background, .14s color;
}
.tool:hover { background: var(--surface-2); color: var(--ink); }
.tool.on { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent-2);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent); }
.tool svg { width: 23px; height: 23px; }
.tlabel { font-size: 10.5px; line-height: 1; font-weight: 600; letter-spacing: .2px; color: var(--ink-3); }
.tool:hover .tlabel { color: var(--ink-2); }
.tool.on .tlabel { color: var(--accent-2); }
.rail-sep { width: 70%; height: 1px; background: var(--line); margin: 5px auto; flex: 0 0 auto; }
.color-tool { gap: 4px; }
.color-chip { width: 26px; height: 26px; border-radius: 7px; overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--line), 0 1px 3px rgba(0,0,0,.3); position: relative; }
.color-chip input[type=color] { position: absolute; inset: -4px; width: calc(100% + 8px);
  height: calc(100% + 8px); border: 0; padding: 0; background: none; cursor: pointer; }

/* viewport */
#viewport {
  flex: 1 1 auto; position: relative; overflow: hidden;
  background:
    radial-gradient(120% 120% at 50% 0%, var(--bg-2), var(--bg));
  touch-action: none; min-width: 0;
}
#view-canvas { position: absolute; top: 0; left: 0; }

/* empty state */
#empty-state { position: absolute; inset: 0; display: grid; place-items: center;
  padding: 2rem; z-index: 5; }
.empty-card { text-align: center; max-width: 560px; animation: pop .4s ease; }
.empty-mark { font-size: 3rem; color: var(--accent); filter: drop-shadow(0 4px 16px color-mix(in srgb,var(--accent) 40%, transparent)); }
.empty-card h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); margin: .3rem 0 .2rem; }
.empty-card p { color: var(--ink-2); margin: .2rem 0 1.2rem; line-height: 1.5; }
.empty-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }
.empty-hint { font-size: .85em; color: var(--ink-3); margin-top: 1rem; }

/* intent-first launcher — lead with outcomes, not "open a file" */
.intent-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin: 1.3rem 0 1rem; }
.intent { display: flex; flex-direction: column; align-items: flex-start; gap: .1rem; padding: .85rem .8rem;
  background: var(--surface); border-radius: var(--r); box-shadow: inset 0 0 0 1px var(--line); text-align: left; }
.intent:hover { background: var(--surface-2); transform: translateY(-2px); box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--accent); }
.intent .in-ic { font-size: 1.5rem; margin-bottom: .25rem; line-height: 1; }
.intent b { font-size: .92em; font-weight: 600; }
.intent small { color: var(--ink-3); font-size: .76em; }
@media (max-width: 560px) { .intent-grid { grid-template-columns: repeat(2, 1fr); } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* touch companion (mobile only; shown via media query) */
#touch-companion { position: absolute; left: 12px; bottom: 12px; display: none;
  flex-direction: column; gap: .3rem; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px); border: 1px solid var(--line); border-radius: 999px;
  padding: .3rem; box-shadow: var(--shadow-sm); z-index: 12; }

/* ---------------------------- panel ------------------------------ */
#panel {
  flex: 0 0 var(--panel-w); display: flex; flex-direction: column;
  background: var(--bg-2); border-left: 1px solid var(--line);
  z-index: 18;
}
.panel-grip { display: none; }
.panel-tabs { display: flex; padding: .4rem .5rem 0; gap: .2rem; border-bottom: 1px solid var(--line); }
.ptab { flex: 1; padding: .6em .4em; font-weight: 600; color: var(--ink-3);
  border-radius: var(--r-sm) var(--r-sm) 0 0; border-bottom: 2px solid transparent; }
.ptab:hover { color: var(--ink-2); }
.ptab.on { color: var(--ink); border-bottom-color: var(--accent); }
.panel-body { flex: 1; overflow-y: auto; padding: .85rem; }
.ptab-pane { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.panel-h { font-size: .72rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--ink-3); margin: 1.1rem 0 .55rem; font-weight: 700; }
.panel-h.first { margin-top: .1rem; }


/* adjust sliders */
.adj-group { margin-top: 1rem; display: flex; flex-direction: column; gap: .15rem; }
.slider { padding: .25rem 0; }
.slider-top { display: flex; justify-content: space-between; align-items: center;
  font-size: .9em; color: var(--ink-2); margin-bottom: .15rem; }
.slider-top b { color: var(--ink); font-weight: 600; }
.slider-top .val { font-variant-numeric: tabular-nums; color: var(--ink-3); cursor: pointer; }
.slider-top .val.changed { color: var(--accent-2); }
input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px;
  background: var(--line); border-radius: 99px; outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: pointer;
  border: 2px solid var(--bg-2); transition: .1s transform; }
input[type=range]::-webkit-slider-thumb:active { transform: scale(1.18); }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%;
  background: var(--ink); border: 2px solid var(--bg-2); cursor: pointer; }

.adj-row { display: flex; gap: .5rem; margin-top: .9rem; }

/* filter presets */
.filter-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.filter-chip { aspect-ratio: 1; border-radius: var(--r-sm); background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; position: relative;
  display: grid; place-items: end center; padding: .25rem; }
.filter-chip canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.filter-chip span { position: relative; font-size: .72em; font-weight: 600;
  background: rgba(0,0,0,.45); padding: .1em .5em; border-radius: 99px; backdrop-filter: blur(2px); }
.filter-chip:hover { box-shadow: inset 0 0 0 1px var(--accent); }

/* layers */
.layer-toolbar { display: flex; gap: .25rem; margin-bottom: .6rem; }
.layer-props { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .7rem; }
.mini { font-size: .82em; color: var(--ink-3); display: flex; flex-direction: column; gap: .25rem; }
.mini select { background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: .4em; font-size: 1.05em; }
.layer-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .3rem; }
.layer-item { display: flex; align-items: center; gap: .5rem; padding: .4rem; border-radius: var(--r-sm);
  background: var(--surface); box-shadow: inset 0 0 0 1px transparent; cursor: pointer; }
.layer-item.on { box-shadow: inset 0 0 0 1px var(--accent); background: var(--surface-2); }
.layer-thumb { width: 36px; height: 36px; border-radius: 6px; flex: 0 0 auto;
  background-image: linear-gradient(45deg,#2a2e36 25%,transparent 25%,transparent 75%,#2a2e36 75%),
    linear-gradient(45deg,#2a2e36 25%,#1d2028 25%,#1d2028 75%,#2a2e36 75%);
  background-size: 12px 12px; background-position: 0 0, 6px 6px;
  box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
.layer-thumb canvas { width: 100%; height: 100%; object-fit: contain; }
.layer-name { flex: 1; font-size: .88em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-vis { color: var(--ink-3); }
.layer-vis.off { opacity: .35; }

/* pro grid */
.pro-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.pro-btn { padding: .7em; background: var(--surface); border-radius: var(--r-sm);
  box-shadow: inset 0 0 0 1px var(--line); font-weight: 600; font-size: .9em; text-align: left; }
.pro-btn:hover { background: var(--surface-2); }

/* mobile panel toggle (hidden on desktop) */
#panel-toggle { display: none; }

/* toast (engine's GF.util.toast toggles #toast.show) */
#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(10px);
  background: var(--surface); color: var(--ink); padding: .6em 1.1em; border-radius: 999px;
  box-shadow: var(--shadow), inset 0 0 0 1px var(--line); font-size: .9em; z-index: 60;
  opacity: 0; pointer-events: none; max-width: 80vw; text-align: center;
  transition: opacity .2s ease, transform .2s ease; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* document dimensions readout */
.dims { font-size: .82em; color: var(--ink-3); font-variant-numeric: tabular-nums; padding: 0 .3rem; }

/* generic modal */
.fs-modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center;
  z-index: 80; padding: 1rem; animation: fade .2s ease; backdrop-filter: blur(3px); }
.fs-modal .card { background: var(--surface); border-radius: var(--r); padding: 1.3rem;
  width: min(420px, 100%); box-shadow: var(--shadow), inset 0 0 0 1px var(--line); animation: pop .25s ease; }
.fs-modal h2 { margin: 0 0 .3rem; font-size: 1.2rem; }
.fs-modal .sub { color: var(--ink-2); font-size: .9em; margin: 0 0 1rem; }
.fs-modal label { display: flex; flex-direction: column; gap: .3rem; font-size: .85em; color: var(--ink-2); margin-bottom: .8rem; }
.fs-modal input, .fs-modal select, .fs-modal textarea {
  background: var(--bg-2); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: .55em; font-size: 1.05em; font-family: inherit; }
.fs-modal textarea { resize: vertical; min-height: 64px; }
.fs-modal .row { display: flex; gap: .6rem; }
.fs-modal .row > * { flex: 1; }
.fs-modal menu { display: flex; gap: .5rem; justify-content: flex-end; margin: 1.1rem 0 0; padding: 0; }
.size-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: .5rem; margin-bottom: .8rem; }
.size-card { padding: .7em .4em; text-align: center; background: var(--bg-2); border-radius: var(--r-sm);
  box-shadow: inset 0 0 0 1px var(--line); font-size: .82em; font-weight: 600; }
.size-card.on { box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent-2); }
.size-card small { display: block; color: var(--ink-3); font-weight: 400; }


/* ---------------------- accessibility ---------------------- */
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; border-radius: 4px; }
.tool:focus-visible, .icon-btn:focus-visible { outline-offset: -2px; }
.tool[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent-2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* ---------------------- command palette (⌘K) ---------------------- */
.palette-trigger { display: flex; align-items: center; gap: .5rem; padding: .4em .7em;
  background: var(--surface); border-radius: 999px; box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink-3); transition: .15s background, .15s color; }
.palette-trigger:hover { background: var(--surface-2); color: var(--ink-2); }
.palette-trigger svg { width: 16px; height: 16px; }
.kbd { font: 600 .72em/1 ui-monospace, monospace; color: var(--ink-2); background: var(--bg);
  padding: .25em .45em; border-radius: 5px; box-shadow: inset 0 0 0 1px var(--line); white-space: nowrap; }

.cmdk { position: fixed; inset: 0; z-index: 90; display: flex; justify-content: center;
  align-items: flex-start; padding: 12vh 1rem 1rem; background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px); animation: fade .15s ease; }
.cmdk-box { width: min(620px, 100%); background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow), inset 0 0 0 1px var(--line); overflow: hidden;
  animation: cmdkin .18s cubic-bezier(.32,.72,0,1); }
@keyframes cmdkin { from { opacity: 0; transform: translateY(-8px) scale(.98); } }
.cmdk-top { display: flex; align-items: center; gap: .6rem; padding: .9rem 1rem; border-bottom: 1px solid var(--line); }
.cmdk-ico { width: 18px; height: 18px; color: var(--ink-3); flex: 0 0 auto; }
.cmdk-input { flex: 1; background: none; border: 0; outline: none; color: var(--ink);
  font-size: 1.05rem; font-family: inherit; }
.cmdk-list { list-style: none; margin: 0; padding: .4rem; max-height: 46vh; overflow-y: auto; }
.cmdk-item { display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; border-radius: 9px; cursor: pointer; }
.cmdk-item.on { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.cmdk-grp { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3);
  min-width: 64px; flex: 0 0 auto; }
.cmdk-label { flex: 1; font-size: .95em; }
.cmdk-item.on .cmdk-label { color: var(--ink); }
.cmdk-empty { padding: 1.4rem; text-align: center; color: var(--ink-3); }
.cmdk-foot { display: flex; gap: 1.1rem; padding: .55rem 1rem; border-top: 1px solid var(--line);
  font-size: .76em; color: var(--ink-3); }
.cmdk-foot span { display: flex; align-items: center; gap: .35rem; }

/* ---------------------- histogram ---------------------- */
.histogram { width: 100%; height: 56px; display: block; margin: .2rem 0 .9rem;
  background: var(--bg-2); border-radius: var(--r-sm); box-shadow: inset 0 0 0 1px var(--line); }

/* ---------------------- crop overlay ---------------------- */
#crop-overlay { position: absolute; inset: 0; z-index: 8; cursor: default;
  background: rgba(0,0,0,.42); touch-action: none; }
.crop-rect { position: absolute; box-shadow: 0 0 0 9999px rgba(0,0,0,.42); cursor: move;
  outline: 1px solid rgba(255,255,255,.9);
  background-image:
    linear-gradient(rgba(255,255,255,.35) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.35) 1px, transparent 1px);
  background-size: 100% 33.33%, 100% 33.33%, 33.33% 100%, 33.33% 100%;
  background-position: 0 33.33%, 0 66.66%, 33.33% 0, 66.66% 0;
  background-repeat: no-repeat; }
.crop-h { position: absolute; width: 14px; height: 14px; background: #fff; border-radius: 3px;
  box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.crop-h.nw { left: -7px; top: -7px; cursor: nwse-resize; }
.crop-h.ne { right: -7px; top: -7px; cursor: nesw-resize; }
.crop-h.sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.crop-h.se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.crop-h.n { left: 50%; top: -7px; transform: translateX(-50%); cursor: ns-resize; }
.crop-h.s { left: 50%; bottom: -7px; transform: translateX(-50%); cursor: ns-resize; }
.crop-h.e { right: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.crop-h.w { left: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

/* ---------------------- history panel ---------------------- */
.history-list { list-style: none; margin: 0 0 .4rem; padding: 0; display: flex; flex-direction: column;
  gap: 2px; max-height: 220px; overflow-y: auto; }
.hist-item { padding: .4rem .55rem; border-radius: 6px; font-size: .85em; color: var(--ink-2);
  cursor: pointer; display: flex; align-items: center; gap: .4rem; }
.hist-item:hover { background: var(--surface-2); color: var(--ink); }
.hist-item.on { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--ink); font-weight: 600; }
.hist-item.on::before { content: "▸"; color: var(--accent-2); }
.hist-item.base { color: var(--ink-3); font-style: italic; }
.hist-item.future { color: var(--ink-3); opacity: .55; }

/* ------------- first-run coach mark (wand) ------------- */
#coach { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 11;
  width: min(300px, 90%); animation: pop .25s ease; pointer-events: none; }   /* click-through */
.coach-card { background: color-mix(in srgb, var(--surface) 96%, transparent); backdrop-filter: blur(12px);
  border: 1px solid var(--accent); border-radius: 14px; padding: .85rem .9rem; box-shadow: var(--shadow);
  text-align: left; pointer-events: none; }
#coach .text-btn { pointer-events: auto; }   /* only the dismiss button is interactive */
.coach-card b { display: block; margin-bottom: .3rem; font-size: .95em; }
.coach-card p { margin: 0 0 .7rem; font-size: .84em; color: var(--ink-2); line-height: 1.45; }
.text-btn.sm { padding: .35em .9em; font-size: .85em; }

/* ------------- contextual selection OUTCOME bar (intent-first) ------------- */
#sel-bar { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 9;
  width: min(320px, 92%); padding: .5rem;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(12px); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); animation: pop .18s ease; }
#sel-bar.floating { bottom: auto; }   /* desktop: JS sets left/top at the selection */

.sel-head { display: flex; align-items: center; gap: .4rem; padding: .1rem .3rem .5rem; }
.sel-count { flex: 1; font-size: .74em; font-weight: 600; color: var(--ink-3);
  font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.sel-more-btn { font-size: .76em; font-weight: 700; color: var(--ink-2); padding: .25em .6em; border-radius: 999px; }
.sel-more-btn:hover { background: var(--surface-2); color: var(--ink); }
.sel-x { color: var(--ink-3); width: 22px; height: 22px; border-radius: 999px; font-size: .82em; display: grid; place-items: center; }
.sel-x:hover { background: var(--surface-2); color: var(--ink); }

.sel-outs { display: flex; flex-direction: column; gap: .25rem; }
.sel-out { display: flex; align-items: center; gap: .55rem; padding: .5rem .55rem; border-radius: 11px;
  text-align: left; color: var(--ink); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.sel-out:hover { background: var(--surface-2); box-shadow: inset 0 0 0 1.5px var(--accent); }
.sel-out.ai:hover { box-shadow: inset 0 0 0 1.5px var(--ai-2); }
.so-ic { font-size: 1.1rem; width: 1.7rem; text-align: center; flex: 0 0 auto; }
.so-tx { display: flex; flex-direction: column; line-height: 1.22; min-width: 0; }
.so-tx b { font-weight: 600; font-size: .92em; }
.so-tx small { color: var(--ink-3); font-size: .75em; }
.sel-out.ai .so-tx b { color: var(--ai-2); }

.sel-more { grid-template-columns: 1fr 1fr; gap: .25rem; margin-top: .5rem;
  padding-top: .5rem; border-top: 1px solid var(--line-soft); }
.sel-more:not([hidden]) { display: grid; }
.sel-more button { padding: .45em .5em; border-radius: 8px; font-size: .8em; font-weight: 600;
  color: var(--ink-2); text-align: left; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.sel-more button:hover { background: var(--surface-2); color: var(--ink); }

/* ---------------------- tool guides ---------------------- */
.guide-btn { font-weight: 800; color: var(--ink-3); box-shadow: inset 0 0 0 1px var(--line); }
.guide-btn:hover { color: var(--accent-2); }
.tool-guide { font-size: .92em; line-height: 1.5; color: var(--ink-2); max-height: 62vh; overflow-y: auto; }
.tool-guide .g-lead { color: var(--ink); margin: 0 0 .8rem; }
.tool-guide h4 { margin: .9rem 0 .35rem; font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); }
.tool-guide ul { margin: .2rem 0; padding-left: 1.1rem; display: flex; flex-direction: column; gap: .35rem; }
.tool-guide b { color: var(--ink); }
.pro-btn.dis { opacity: .4; pointer-events: none; }

/* ---------------------- cheat sheet + checkboxes ---------------------- */
.cheat { display: flex; flex-direction: column; gap: .1rem; }
.cheat-row { display: flex; justify-content: space-between; align-items: center; padding: .45rem .2rem;
  border-bottom: 1px solid var(--line-soft); font-size: .92em; }
.cheat-row span:first-child { color: var(--ink-2); }
.ck { flex-direction: row !important; align-items: center; gap: .5rem !important; cursor: pointer; }
.ck input { width: auto; }

/* ---------------------- micro-interactions / polish ---------------------- */
.text-btn, .tool, .icon-btn, .pro-btn, .filter-chip, .palette-trigger {
  transition: background .15s ease, color .15s ease, box-shadow .15s ease, transform .08s ease; }
.text-btn:active, .icon-btn:active, .tool:active, .pro-btn:active, .filter-chip:active { transform: scale(.96); }
.text-btn.primary { box-shadow: 0 1px 0 color-mix(in srgb, var(--accent) 50%, #000), var(--shadow-sm); }
.text-btn.primary:active { box-shadow: 0 1px 0 color-mix(in srgb, var(--accent) 50%, #000); }
#topbar, #panel, #toolrail { transition: background .25s ease; }

/* ===================================================================
   RESPONSIVE — phones & narrow tablets
   =================================================================== */
@media (max-width: 880px) {
  .menu-btn { display: inline-grid; }
  .brand-name { display: none; }
  #topbar { grid-template-columns: auto 1fr auto; padding: 0 .35rem; }
  .tb-group { gap: .2rem; }
  .tb-center { gap: .15rem; }
  /* keep the top bar inside the viewport: Open/New/Save live in the ☰ menu,
     zoom is pinch + the touch companion's Fit */
  #btn-open, #doc-dims, .zoom-pill { display: none; }
  .tb-right .text-btn { padding: .45em .7em; }

  /* tool rail -> bottom bar */
  #toolrail {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    flex-direction: row; align-items: stretch; flex: 0 0 auto; height: 62px;
    border-right: 0; border-top: 1px solid var(--line);
    padding: 4px .3rem; gap: 2px; overflow-x: auto; overflow-y: hidden;
    justify-content: flex-start;
    padding-bottom: calc(4px + env(safe-area-inset-bottom));
  }
  #toolrail .tool { width: auto; min-width: 56px; min-height: auto; flex: 0 0 auto; padding: 4px 8px; }
  .rail-sep { width: 1px; height: auto; margin: 4px 3px; align-self: stretch; }
  .color-tool { flex: 0 0 auto; }
  #stage { padding-bottom: 62px; }

  /* panel -> bottom sheet */
  #panel {
    position: fixed; left: 0; right: 0; bottom: 0;
    height: min(72vh, 540px); flex: none;
    border-left: 0; border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
    transform: translateY(calc(100% + 60px));
    transition: transform .28s cubic-bezier(.32,.72,0,1);
  }
  #panel.open { transform: translateY(0); }
  .panel-grip { display: block; width: 38px; height: 4px; border-radius: 99px;
    background: var(--line); margin: .5rem auto .1rem; }
  .panel-body { padding-bottom: calc(58px + env(safe-area-inset-bottom)); }

  /* mobile panel toggle FAB */
  #panel-toggle {
    display: flex; align-items: center; gap: .4rem;
    position: fixed; right: 12px; bottom: calc(58px + env(safe-area-inset-bottom) + 12px);
    padding: .6em 1em; background: var(--accent); color: var(--accent-ink);
    border-radius: 999px; font-weight: 700; box-shadow: var(--shadow); z-index: 25;
  }
  body.sheet-open #panel-toggle { display: none; }
  #touch-companion { display: flex; }
  #sel-bar { bottom: calc(62px + env(safe-area-inset-bottom) + 10px); left: 50%;
    transform: translateX(-50%); width: min(360px, 94%); }
}

/* ------------- no-document state: quiet the chrome until work exists -------------
   The scene (3D) pane stays live — a 3D scene can start before any document. */
body.no-doc #panel .ptab-pane:not([data-pane="scene"]) { opacity: .45; pointer-events: none; }
body.no-doc[data-mode="image"] #optbar { display: none; }
body.no-doc #histogram { display: none; }
body.no-doc #touch-companion { display: none; }

/* ============================= 3D WORKSPACE ============================= */
/* WebGL host overlays the 2D canvas; visible only while body[data-mode="3d"] */
#scene3d-host { position: absolute; inset: 0; display: none; background: transparent; }
body[data-mode="3d"] #scene3d-host { display: block; }
#scene3d-host canvas { width: 100%; height: 100%; display: block; touch-action: none; }
body[data-mode="3d"] #empty-state, body[data-mode="3d"] #sel-bar { display: none; }

.s3-row { display: flex; gap: .4rem; align-items: center; margin: .35rem 0; flex-wrap: wrap; }
.s3-row .text-btn { flex: 1; white-space: nowrap; }
.s3-prims { margin-bottom: .4rem; }
/* collapsible groups (shape catalog, advanced maps) */
.s3-group { margin: .2rem 0; }
.s3-group summary { cursor: pointer; font-size: .68em; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 700; padding: .3rem 0; user-select: none; }
.s3-group summary:hover { color: var(--ink-2); }
.s3-group[open] summary { margin-bottom: .25rem; }
.s3-count { opacity: .55; font-weight: 600; margin-left: .25rem; }
.s3-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .35rem; }
.s3-num { display: grid; gap: .15rem; font-size: .72em; color: var(--ink-3); font-weight: 600; }
.s3-num input { width: 100%; min-width: 0; padding: .3em .35em; border-radius: 7px;
  border: 1px solid var(--line); background: transparent; color: var(--ink); font: inherit; font-size: .95em; }
.s3-status { font-size: .78em; color: var(--ink-3); margin: .5rem 0 0; }
/* label row with a right-aligned value — matches the Adjust tab's slider rhythm */
.s3-top { display: flex; justify-content: space-between; align-items: baseline; }
.s3-val { color: var(--ink-3); font-weight: 600; font-variant-numeric: tabular-nums; }
/* export hub sections */
.m-sec { font-size: .68em; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 700; margin: .9rem 0 .4rem; }
.m-sec:first-child { margin-top: 0; }
.m-actions .text-btn { flex: 1; }

/* AI dialog "Advanced" disclosure */
.ai-adv summary { cursor: pointer; color: var(--ink-3); font-size: .85em; font-weight: 600; margin: .2rem 0; }
.ai-adv[open] summary { margin-bottom: .5rem; }
@media (max-width: 880px) {
  /* keep the 3D options bar to one tidy row on phones */
  .s3-hint, #s3-publish-ob { display: none; }
}
#s3-objects { margin-top: .4rem; }
#s3-objects .layer-item { cursor: pointer; }

/* Poly Haven picker */
.ph-search { width: 100%; margin: .5rem 0; padding: .5em .7em; border-radius: 8px;
  border: 1px solid var(--line); background: transparent; color: var(--ink); font: inherit; }
.ph-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem;
  max-height: 46vh; overflow: auto; padding: .2rem; }
.ph-card { display: grid; gap: .25rem; padding: .3rem; border-radius: 10px; background: transparent;
  border: 1px solid var(--line); cursor: pointer; color: var(--ink-2); font-size: .72em; }
.ph-card:hover { border-color: var(--accent); color: var(--ink); }
.ph-card img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 7px; }
.ph-card span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
