:root {
  --bg: #f6f6f8; --surface: #ffffff; --surface-2: #efeff3; --line: #e2e2e8;
  --text: #17171b; --muted: #6c6c75; --accent: #3a6df0; --accent-ink: #fff;
  --danger: #d93f3f; --radius: 12px; --shadow: 0 8px 30px rgba(20, 20, 30, .10);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214; --surface: #1b1c20; --surface-2: #25262b; --line: #2f3036;
    --text: #ececf1; --muted: #9a9aa5; --accent: #6b93ff; --accent-ink: #0b0d12;
    --shadow: 0 8px 30px rgba(0, 0, 0, .45);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button, input, select { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
a { color: var(--accent); }
kbd { font: 12px var(--font); padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--surface); }

#app {
  height: 100dvh; display: grid;
  grid-template: "top top" auto "tools main" minmax(0, 1fr) / 136px minmax(0, 1fr);
}
#app.empty { grid-template: "top" auto "main" minmax(0, 1fr) / minmax(0, 1fr); }
#app.empty .needs-doc { display: none !important; }

/* Top bar */
.topbar { grid-area: top; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: -.01em; color: var(--text); text-decoration: none; font-size: 15px; }
.top-actions { display: flex; align-items: center; gap: 4px; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.zoom-label { min-width: 46px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }

button { cursor: pointer; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 12px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: background .12s, border-color .12s, opacity .12s; -webkit-tap-highlight-color: transparent; }
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: .38; cursor: default; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn { border-color: transparent; background: transparent; padding: 7px; }
.icon-btn .lbl { font-weight: 500; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
button.big { padding: 12px 22px; font-size: 16px; border-radius: 12px; }
button.danger { color: var(--danger); }
button.on { background: var(--surface-2); border-color: var(--accent); }
button.primary.on { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }

/* Tool rail */
.tools { grid-area: tools; display: grid; grid-template-columns: 1fr 1fr; align-content: start; gap: 2px; padding: 6px; border-right: 1px solid var(--line); background: var(--surface); overflow-y: auto; scrollbar-width: thin; }
.tools button { flex-direction: column; gap: 2px; border: 0; background: transparent; padding: 6px 1px 5px; font-size: 10.5px; line-height: 1.15; color: var(--muted); border-radius: 9px; min-width: 0; }
.tools button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tools button svg { width: 20px; height: 20px; }
.tgroup { grid-column: 1 / -1; font-size: 9.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); opacity: .7; padding: 8px 4px 2px; }
.tgroup:first-child { padding-top: 2px; }
.tgroup.sep-only { padding: 4px 0 0; border-top: 1px solid var(--line); margin-top: 6px; }
.color-well { grid-column: 1 / -1; position: relative; height: 62px; margin: 10px 6px 4px; }
.color-well .well { position: absolute; width: 34px; height: 34px; padding: 0; border-radius: 8px; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line), 0 1px 3px rgba(0,0,0,.2); }
.color-well .fg { left: 8px; top: 2px; z-index: 2; }
.color-well .bg { left: 30px; top: 22px; z-index: 1; box-shadow: 0 0 0 1px #8888, 0 1px 3px rgba(0,0,0,.2); }
.color-well .mini { position: absolute; right: 8px; top: 0; padding: 3px; border: 0; background: transparent; color: var(--muted); }
.color-well .mini svg { width: 16px; height: 16px; }
.color-well .reset { top: 34px; width: 16px; height: 16px; padding: 0; right: 10px; background: linear-gradient(135deg, #000 50%, #fff 50%); border: 1px solid var(--line); border-radius: 3px; }
.color-well input[type=color] { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.row-center { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.pick-out { display: flex; align-items: center; gap: 10px; }
.pick-chip { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); }
.grad-preview { height: 28px; border-radius: 8px; border: 1px solid var(--line); }
.lock-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.lock-row button { flex-direction: column; gap: 2px; padding: 6px 2px; font-size: 11px; }
.lock-row button svg { width: 16px; height: 16px; }
.lname .lock-ico { margin-left: 4px; font-size: 11px; }
.anchor-grid { display: grid; grid-template-columns: repeat(3, 30px); gap: 4px; }
.anchor-grid button { width: 30px; height: 30px; padding: 0; border-radius: 6px; }
.anchor-grid button.on { background: var(--accent); border-color: var(--accent); }
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); padding: 18px 20px; width: min(380px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { margin: 0 0 12px; font-size: 16px; }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; }
dialog input[type=number] { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.tools button.active { background: var(--surface-2); color: var(--accent); }
.tools button:hover { color: var(--text); }

/* Workspace */
.workspace { grid-area: main; position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; min-height: 0; min-width: 0; }
#app.empty .workspace { grid-template-columns: 1fr; }
.stage-wrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; touch-action: none; }
#app.empty .stage-wrap { display: none; }
#stage { position: absolute; inset: 0; display: block; }
.stage-wrap.pan { cursor: grab; }
.stage-wrap.panning { cursor: grabbing; }
.stage-wrap.crosshair { cursor: crosshair; }
.stage-wrap.brush { cursor: none; }
.stage-wrap.dragover::after { content: "Drop to open"; position: absolute; inset: 12px; border: 2px dashed var(--accent); border-radius: 16px; display: grid; place-items: center; font-size: 18px; font-weight: 600; color: var(--accent); background: color-mix(in srgb, var(--bg) 70%, transparent); }

/* Panel */
.panel { width: 300px; border-left: 1px solid var(--line); background: var(--surface); padding: 14px 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.panel:empty { display: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel h2 { margin: 0; font-size: 15px; font-weight: 650; }
.panel .x { border: 0; background: transparent; font-size: 22px; line-height: 1; padding: 2px 8px; color: var(--muted); }
.panel label { display: flex; flex-direction: column; gap: 6px; font-weight: 550; font-size: 13px; }
.panel label output { float: right; font-weight: 450; color: var(--muted); font-variant-numeric: tabular-nums; }
.panel .lab { display: flex; justify-content: space-between; }
.panel input[type="text"], .panel input[type="number"], .panel textarea, .panel select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-weight: 400; }
.panel textarea { resize: vertical; min-height: 64px; font: inherit; }
.panel input[type="range"] { width: 100%; accent-color: var(--accent); margin: 2px 0; }
.panel input[type="color"] { width: 38px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); cursor: pointer; }
.panel .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel .grow { flex: 1; }
.panel .meta { margin: 0; color: var(--muted); font-size: 13px; }
.panel .note { margin: 0; color: var(--muted); font-size: 12px; }
.panel .hint { margin: 0; color: var(--muted); font-size: 13px; }
.panel .sub { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 4px 0 -6px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { padding: 6px 10px; font-size: 13px; font-weight: 500; }
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.swatch { width: 28px; height: 28px; padding: 0; border-radius: 50%; border: 2px solid var(--line); }
.swatch.on { outline: 2px solid var(--accent); outline-offset: 1px; }
.swatch.transparent { background: repeating-conic-gradient(#ccc 0 25%, #fff 0 50%) 0 0 / 10px 10px; }
.checkbox { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 500 !important; }
.looks-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.looks-grid button { flex-direction: column; padding: 4px 4px 6px; gap: 4px; font-size: 12px; border-radius: 10px; }
.looks-grid canvas { width: 100%; aspect-ratio: 1; border-radius: 7px; display: block; object-fit: cover; }
.progress { height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.progress.indeterminate > i { width: 35%; animation: indet 1.1s ease-in-out infinite; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }

/* Layers */
.layers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow-y: auto; }
.layers li { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 8px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--bg); user-select: none; }
.layers li.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
.layers li.hidden-layer .lthumb, .layers li.hidden-layer .linfo { opacity: .45; }
.layers li:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.lthumb { width: 44px; height: 44px; object-fit: contain; border-radius: 6px; flex: none; background: repeating-conic-gradient(#d9d9de 0 25%, #fff 0 50%) 0 0 / 8px 8px; border: 1px solid var(--line); }
.linfo { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lname { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lsub { font-size: 11px; color: var(--muted); }
.layers .eye { padding: 6px; color: var(--muted); }
.layer-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.layer-actions button { padding: 7px 4px; font-size: 12px; font-weight: 500; }
.layer-note { margin: -6px 0 0; font-size: 12px; color: var(--accent); font-weight: 550; }

/* Welcome */
.welcome { grid-column: 1 / -1; overflow-y: auto; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 20px; gap: 26px; }
#app:not(.empty) .welcome { display: none; }
.drop { max-width: 560px; width: 100%; text-align: center; padding: 40px 28px; border: 2px dashed var(--line); border-radius: 22px; background: var(--surface); transition: border-color .15s, background .15s; }
.drop.dragover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.drop h1 { font-size: clamp(24px, 4vw, 32px); letter-spacing: -.02em; margin: 14px 0 8px; line-height: 1.15; }
.drop h1 em { font-style: normal; color: var(--accent); }
.drop p { color: var(--muted); margin: 0 auto 20px; max-width: 440px; }
.drop p strong { color: var(--text); font-weight: 600; }
.drop .hint { margin: 14px 0 0; font-size: 13px; }
.features { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 260px)); gap: 10px 24px; color: var(--muted); font-size: 13px; }
.features b { color: var(--text); font-weight: 600; }
.foot { color: var(--muted); font-size: 12px; margin: 0; }
.show-touch { display: none; }
@media (hover: none) { .show-touch { display: inline; } .hide-touch { display: none; } }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100vw - 32px); box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Phones */
@media (max-width: 760px) {
  #app { grid-template: "top" auto "main" minmax(0, 1fr) "tools" auto / minmax(0, 1fr); }
  .hide-sm { display: none !important; }
  .icon-btn .lbl { display: none; }
  .tools { flex-direction: row; border-right: 0; border-top: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; padding: 6px 6px max(6px, env(safe-area-inset-bottom)); scrollbar-width: none; }
  .tools { display: flex; }
  .tools button { flex: 0 0 64px; min-width: 64px; }
  .brand span { display: none; }
  .top-actions { gap: 0; }
  .top-actions .icon-btn { padding: 6px; }
  .tgroup { display: none; }
  .color-well { flex: none; width: 76px; height: 52px; margin: 0 4px; }
  .color-well .well { width: 28px; height: 28px; }
  .color-well .bg { left: 26px; top: 18px; }
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .panel { width: auto; max-height: 46dvh; border-left: 0; border-top: 1px solid var(--line); padding: 12px 14px 14px; gap: 12px; box-shadow: 0 -8px 24px rgba(0,0,0,.06); }
  .features { grid-template-columns: 1fr; }
  .drop { padding: 30px 18px; }
  .toast { bottom: 96px; }
}
.panel .row button.grow { white-space: nowrap; font-size: 13px; padding-left: 8px; padding-right: 8px; }
.layer-actions.two { grid-template-columns: 1fr 1fr; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ======================================================================== */
/* Photoshop-style layout: menu bar, icon tool column, right-hand docks      */
/* ======================================================================== */
#app { grid-template: "menu menu menu" auto "tools main side" minmax(0, 1fr) / 50px minmax(0, 1fr) 300px; }
#app.empty { grid-template: "menu" auto "main" minmax(0, 1fr) / minmax(0, 1fr); }
.workspace { grid-template-columns: minmax(0, 1fr); }

.menubar { grid-area: menu; display: flex; align-items: center; gap: 4px; padding: 4px 8px; padding-top: max(4px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--surface); min-height: 44px; }
.menubar .brand { margin-right: 6px; font-size: 14px; }
.menus { display: flex; gap: 1px; flex: 1; min-width: 0; }
.menu-btn { border: 0; background: transparent; padding: 5px 9px; border-radius: 6px; font-size: 13px; font-weight: 500; }
.menu-btn:hover, .menu-btn.open { background: var(--surface-2); }
.menu-toggle { display: none; }
.menu-pop { position: fixed; z-index: 60; list-style: none; margin: 0; padding: 5px; min-width: 230px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.menu-pop button, .menu-sheet button { width: 100%; justify-content: space-between; border: 0; background: transparent; padding: 7px 10px; border-radius: 6px; font-size: 13px; text-align: left; }
.menu-pop button:hover:not(:disabled), .menu-pop button:focus-visible, .menu-sheet button:hover:not(:disabled) { background: var(--accent); color: var(--accent-ink); outline: none; }
.menu-pop kbd, .menu-sheet kbd { border: 0; background: none; color: inherit; opacity: .6; font-size: 12px; padding: 0; }
.msep { height: 1px; background: var(--line); margin: 4px 6px; }
.menu-sheet { position: fixed; z-index: 60; left: 8px; right: 8px; top: 52px; max-height: calc(100dvh - 70px); overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 6px 10px 10px; }
.menu-sheet h3 { margin: 10px 4px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.menu-sheet ul { list-style: none; margin: 0; padding: 0; }

/* Left tool column: icons only, names in tooltips */
.tools { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; grid-template-columns: none; }
.tools button { width: 40px; height: 38px; padding: 0; border-radius: 8px; }
.tools button span { display: none; }
.tools button svg { width: 20px; height: 20px; }
.tools .tsep { width: 26px; height: 1px; background: var(--line); margin: 4px 0; flex: none; }
/* Tool groups (several tools on one button): corner mark, right-click or long-press flyout */
.tools button { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.tools button.group { position: relative; }
.tools button.group::after { content: ""; position: absolute; right: 3px; bottom: 3px; border: 3px solid transparent; border-right-color: currentColor; border-bottom-color: currentColor; opacity: .55; }
.menu-pop.tool-flyout { min-width: 180px; }
.tool-flyout button > span { display: flex; align-items: center; gap: 9px; }
.tool-flyout svg { width: 18px; height: 18px; }
.tool-flyout button.on:not(:hover):not(:focus-visible) { color: var(--accent); }
.color-well { width: 42px; height: 50px; margin: 10px 0 4px; flex: none; }
.color-well .well { width: 24px; height: 24px; border-radius: 5px; }
.color-well .fg { left: 0; top: 0; }
.color-well .bg { left: 14px; top: 14px; }
.color-well .mini { right: -4px; top: -4px; }
.color-well .reset { top: auto; bottom: 0; right: auto; left: 0; width: 12px; height: 12px; }

/* Right sidebar: tool options on top, then History, then Layers, with drag
   handles between them (history.js). The tool options take what's left. */
.side { grid-area: side; display: flex; flex-direction: column; min-height: 0; overflow: hidden; border-left: 1px solid var(--line); background: var(--surface); }
.side-tabs { display: none; }
.side .panel { width: auto; border: 0; box-shadow: none; }
.side .props { flex: 1 1 0; min-height: 90px; overflow-y: auto; padding: 12px 14px 16px; }
.side .props:empty::before { content: "Choose a tool on the left."; color: var(--muted); font-size: 13px; }
.side .history-dock, .side .layers-dock { flex: 0 1 auto; padding: 0; display: flex; flex-direction: column; gap: 0; overflow: hidden; }
.side .history-dock { height: 24%; min-height: 64px; }
.side .layers-dock { height: 40%; min-height: 184px; }
/* Drag handles: a 1px line with a wider invisible grab area and a grip on hover */
.split { flex: none; position: relative; z-index: 2; height: 9px; margin: -4px 0; cursor: row-resize; touch-action: none; outline: none; }
.split::before { content: ""; position: absolute; left: 0; right: 0; top: calc(50% - .5px); height: 1px; background: var(--line); transition: background .12s; }
.split::after { content: ""; position: absolute; left: calc(50% - 16px); top: calc(50% - 2.5px); width: 32px; height: 5px; border-radius: 3px; background: var(--muted); opacity: 0; transition: opacity .12s; }
.split:hover::before, .split.dragging::before, .split:focus-visible::before { background: var(--accent); }
.split:hover::after, .split.dragging::after, .split:focus-visible::after { opacity: .7; }
@media (pointer: coarse) { .split { height: 17px; margin: -8px 0; } .split::after { opacity: .35; } }
/* History */
.history-panel { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.history { list-style: none; margin: 0; padding: 2px 8px 8px; flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; scrollbar-width: thin; }
.history .hrow { width: 100%; justify-content: flex-start; gap: 8px; border: 0; background: transparent; padding: 4px 8px; border-radius: 6px; font-size: 13px; text-align: left; }
.history .hrow.current { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
.history .hrow.future { opacity: .45; }
.history .hrow.future:hover { opacity: .75; }
.history .hlabel { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .hsub { flex: 0 1 auto; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 400; color: var(--muted); }
.history .trimmed { padding: 3px 8px; font-size: 11px; font-style: italic; color: var(--muted); }
.layers-panel { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.dock-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 4px; }
.dock-head h2, .panel-head h2 { font-size: 12px !important; font-weight: 700 !important; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0; }
.layer-props { display: flex; gap: 8px; align-items: center; padding: 4px 12px; }
.layer-props select { flex: 1; min-width: 0; padding: 5px 6px !important; font-size: 12px; }
.layer-props .op { flex-direction: row !important; align-items: center; gap: 4px !important; font-size: 12px !important; font-weight: 500 !important; flex: 1.3; }
.layer-props .op input { flex: 1; min-width: 40px; }
.layer-props .op output { float: none !important; min-width: 32px; text-align: right; font-size: 12px; }
.lock-row { display: flex !important; align-items: center; gap: 2px !important; padding: 0 12px 4px; grid-template-columns: none !important; }
.lock-row .lock-label { font-size: 12px; color: var(--muted); margin-right: 4px; }
.lock-row .icon-btn { padding: 4px; border-radius: 6px; color: var(--muted); }
.lock-row .icon-btn svg { width: 16px; height: 16px; }
.lock-row .icon-btn.on { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.layers-panel .layers { flex: 1; min-height: 0; max-height: none; overflow-y: auto; padding: 2px 8px; gap: 2px; }
.layers li { padding: 3px 6px 3px 2px; gap: 6px; border-radius: 8px; }
.layers .lthumb { width: 34px; height: 34px; }
.layers .lock-ico svg { width: 13px; height: 13px; color: var(--muted); }
.layer-bar { display: flex; justify-content: space-between; padding: 4px 8px; border-top: 1px solid var(--line); }
.layer-bar .icon-btn { padding: 6px; color: var(--muted); }
.layer-bar .icon-btn:hover { color: var(--text); }
.layer-bar .icon-btn svg { width: 18px; height: 18px; }
.keys { border-collapse: collapse; width: 100%; font-size: 13px; }
.keys td { padding: 5px 4px; border-bottom: 1px solid var(--line); }
.keys td:last-child { text-align: right; }

@media (max-width: 760px) {
  #app { grid-template: "menu" auto "main" minmax(0, 1fr) "side" auto "tools" auto / minmax(0, 1fr); }
  .menus { display: none; }
  .menu-toggle { display: inline-flex; order: -1; }
  .menubar .brand { display: none; }
  .top-actions { margin-left: auto; }
  .tools { flex-direction: row; align-items: center; overflow-x: auto; padding: 4px 6px max(4px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); border-right: 0; }
  .tools button { flex: 0 0 52px; width: 52px; height: 48px; flex-direction: column; gap: 2px; }
  .tools button span { display: block; font-size: 10px; }
  .tools .tsep { width: 1px; height: 28px; margin: 0 4px; }
  .color-well { width: 46px; height: 40px; margin: 0 6px; }
  .side { border-left: 0; border-top: 1px solid var(--line); max-height: 44dvh; box-shadow: 0 -8px 24px rgba(0,0,0,.06); }
  .side-tabs { display: flex; gap: 4px; padding: 6px 10px 0; }
  .side-tabs button { flex: 1; padding: 6px; font-size: 13px; border-radius: 8px; }
  .side-tabs button.on { background: var(--surface-2); border-color: var(--accent); }
  .side .dock { height: auto !important; max-height: none; border-top: 0; flex: 1 1 auto; }
  .side .split { display: none; }
  .side:not([data-tab="props"]) .props, .side:not([data-tab="history"]) .history-dock, .side:not([data-tab="layers"]) .layers-dock { display: none; }
  .side .layers-dock, .side .history-dock { min-height: 0; }
  .history .hrow { padding: 7px 10px; }
}
.color-well .mini { right: -2px; top: -2px; padding: 1px; }
.color-well .mini svg { width: 13px; height: 13px; }
.color-well { height: 54px; }
.color-well .fg { top: 8px; left: 2px; }
.color-well .bg { top: 22px; left: 16px; }
.color-well .mini { right: 0; top: 0; }
.color-well .reset { left: 0; bottom: 0; }

/* Metadata dialog */
dialog.wide { width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); padding: 16px 18px; }
.md-head { display: flex; justify-content: space-between; align-items: center; }
.md-head h2 { margin: 0; }
dialog .x { border: 0; background: transparent; font-size: 22px; padding: 2px 8px; color: var(--muted); }
dialog .meta { margin: 4px 0 10px; color: var(--muted); font-size: 13px; }
dialog .note { color: var(--muted); font-size: 12px; margin: 6px 0; }
.md-alert { background: color-mix(in srgb, #ff9500 14%, var(--surface)); border: 1px solid color-mix(in srgb, #ff9500 50%, var(--line)); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 13px; }
.md-presets { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.md-presets button { padding: 5px 10px; font-size: 13px; }
.md-list { display: flex; flex-direction: column; gap: 6px; max-height: 50dvh; overflow-y: auto; }
.md-group { border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.md-group.private summary b { color: var(--text); }
.md-group summary { display: flex; align-items: center; gap: 8px; padding: 8px 10px; cursor: pointer; flex-wrap: wrap; }
.md-group summary .md-hint { flex-basis: 100%; padding-left: 26px; font-size: 12px; color: var(--muted); }
.md-row { display: grid; grid-template-columns: 18px minmax(110px, 38%) 1fr auto; gap: 8px; align-items: center; padding: 5px 10px 5px 10px; border-top: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.md-name { color: var(--muted); }
.md-val { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.md-thumb { height: 40px; border-radius: 4px; border: 1px solid var(--line); }
.md-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.meta-link { margin: 0; }
button.link { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 4px; text-decoration: underline; text-underline-offset: 3px; }
.panel .field { display: flex; flex-direction: column; gap: 6px; font-weight: 550; font-size: 13px; }
.panel .num { display: inline-flex; align-items: center; gap: 4px; font-weight: 450; color: var(--muted); }
.panel .num input[type="number"] { width: 72px; padding: 3px 6px; border-radius: 8px; color: var(--text); }
/* Exact-value field next to every slider (ui.js numField) */
.panel .lab { align-items: center; gap: 8px; min-height: 24px; }
.panel .num input.numf[type="number"] { width: 54px; padding: 2px 6px; border-radius: 7px; font: inherit; font-size: 12px; font-weight: 450; text-align: right; font-variant-numeric: tabular-nums; -moz-appearance: textfield; appearance: textfield; }
.panel .num input.numf::-webkit-inner-spin-button, .panel .num input.numf::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.panel .num input.numf:focus { border-color: var(--accent); outline: none; }
.layer-props .op { flex: 2; }
.layer-props .op .num { flex: none; font-size: 12px; }
.layer-props .op .num input.numf[type="number"] { flex: none; width: 44px; min-width: 0; padding: 2px 4px; }
/* iOS zooms the page into inputs under 16px; keep the fields at 16px on touch screens. */
@media (pointer: coarse) { .panel .num input.numf[type="number"] { font-size: 16px; width: 60px; padding: 2px 5px; } .layer-props .op .num input.numf[type="number"] { width: 50px; } }
