:root {
  --bg: #0d0f12;
  --bar: rgba(16, 18, 22, 0.82);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f2f3f5;
  --muted: #a3a8b3;
  --accent: #29d3ff;
  --ok: #3ddc84;
  --warn: #ffb020;
  --bad: #ff4d5e;
  --tb-h: 76px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden;
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }
button, select, input, .button { font: inherit; color: inherit; }

#stage { position: fixed; inset: 0; overflow: hidden; background: #000; touch-action: none; }
#cam, #still { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform-origin: 0 0; }
#art { position: absolute; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; will-change: transform; }
#art.hidden, #art.strobe-off { visibility: hidden; }
#layers, #guides { position: absolute; inset: 0; width: 100%; height: 100%; }
.layer { position: absolute; inset: 0; width: 100%; height: 100%; }
.layer img { width: 100%; height: 100%; display: block; }
.layer.color { -webkit-mask-size: 100% 100%; mask-size: 100% 100%; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat; }
#debug { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#handles { position: absolute; inset: 0; pointer-events: none; }
.handle { position: absolute; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%;
  border: 2px solid var(--accent); background: rgba(41, 211, 255, 0.12); pointer-events: auto; touch-action: none; }
.handle::after { content: ""; position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: var(--accent); }
.handle.active { background: rgba(41, 211, 255, 0.3); }
#loupe { position: absolute; width: 200px; height: 200px; border-radius: 50%; border: 3px solid var(--accent);
  pointer-events: none; box-shadow: 0 6px 24px rgba(0,0,0,.6); }

#status { position: fixed; top: calc(10px + var(--safe-t)); left: 12px; display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 20px; background: var(--bar); border: 1px solid var(--line); font-size: 14px; z-index: 5;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
#status .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
#status.ok .dot { background: var(--ok); }
#status.warn .dot { background: var(--warn); }
#status.bad .dot { background: var(--bad); }
#zoomChip { position: fixed; top: calc(10px + var(--safe-t)); right: 12px; z-index: 5; padding: 7px 12px; border-radius: 20px;
  background: var(--bar); border: 1px solid var(--accent); color: var(--accent); font-size: 14px; }
#hint { position: fixed; top: calc(52px + var(--safe-t)); left: 50%; transform: translateX(-50%); padding: 8px 14px; border-radius: 10px;
  background: var(--bar); border: 1px solid var(--line); z-index: 5; font-size: 14px; max-width: 90vw; text-align: center; }

#toolbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 6px; justify-content: safe center; align-items: stretch; overflow-x: auto;
  padding: 8px 10px calc(8px + var(--safe-b)); background: var(--bar); border-top: 1px solid var(--line); z-index: 6;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.tb { min-width: 74px; height: 60px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,0.05);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 0 10px; }
.tb b { font-size: 15px; font-weight: 600; }
.tb span { font-size: 12px; color: var(--muted); }
.tb.on { border-color: var(--accent); background: rgba(41, 211, 255, 0.14); }
.tb.on span { color: var(--accent); }
.tb:active { transform: scale(0.97); }
.stepper { display: flex; gap: 4px; }
.tb.arrow { min-width: 48px; font-size: 28px; }
.tb.layername { min-width: 150px; max-width: 220px; }
.tb.layername b { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* portrait iPads (mini 744 px, Pro 11 834 px) */
@media (max-width: 900px) {
  #toolbar { gap: 5px; padding-left: 6px; padding-right: 6px; }
  .tb { min-width: 58px; padding: 0 6px; }
  .tb.arrow { min-width: 40px; }
  .tb.layername { min-width: 110px; max-width: 150px; }
  .tb.layername b { max-width: 130px; }
}

#placebar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tb-h) + 14px + var(--safe-b)); display: flex; gap: 6px;
  align-items: center; padding: 8px; border-radius: 14px; background: var(--bar); border: 1px solid var(--line); z-index: 6; flex-wrap: wrap; justify-content: center; max-width: 96vw; }
.pb { height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,0.05); display: inline-flex; align-items: center; gap: 6px; }
.pb.on { border-color: var(--accent); color: var(--accent); }
.primary { background: var(--accent) !important; color: #00151c !important; border-color: var(--accent) !important; font-weight: 600; }
.readout { color: var(--muted); font-size: 13px; padding: 0 6px; font-variant-numeric: tabular-nums; }

#panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(400px, 92vw); background: rgba(16, 18, 22, 0.96); border-left: 1px solid var(--line);
  z-index: 8; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: calc(10px + var(--safe-t)) 16px calc(24px + var(--safe-b));
  -webkit-user-select: text; user-select: text; }
#panel header { display: flex; align-items: center; justify-content: space-between; }
#panel h2 { font-size: 18px; margin: 4px 0; }
#panel h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
#panel section { border-top: 1px solid var(--line); }
#panel button, #panel .button, #panel select { min-height: 40px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line); background: rgba(255,255,255,0.06); text-decoration: none; display: inline-flex; align-items: center; }
#panel select { width: 100%; background: #1b1e24; }
#panel input[type=number] { width: 72px; min-height: 36px; border-radius: 8px; border: 1px solid var(--line); background: #1b1e24; padding: 0 8px; }
#panel input[type=color] { width: 44px; height: 32px; border: none; background: none; padding: 0; vertical-align: middle; }
#panel input[type=range] { width: 100%; }
.close { border: none !important; background: none !important; font-size: 20px; }
.danger { color: var(--bad); }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.chk { display: inline-flex; align-items: center; gap: 6px; }
.chk input { width: 20px; height: 20px; }
.small { font-size: 13px; color: var(--muted); }
.howto { padding-left: 18px; }
.howto li { margin: 4px 0; }

.layer-row { display: grid; grid-template-columns: 40px 1fr auto; gap: 6px 8px; align-items: center; padding: 8px; margin: 6px 0;
  border: 1px solid var(--line); border-radius: 10px; }
.layer-row.current { border-color: var(--accent); }
.layer-row .thumb { width: 40px; height: 30px; object-fit: contain; background: #f4f1ea; border-radius: 4px; }
.layer-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.layer-row .ctrls { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.layer-row .ctrls input[type=range] { flex: 1; min-width: 120px; }
.layer-row button { min-height: 34px !important; padding: 0 10px !important; }
.layer-row .vis.off { opacity: .45; }

.sheet { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: radial-gradient(ellipse at center, #1a1f27, #0b0d10); text-align: center; padding: 24px; }
.sheet h1 { margin: 0; font-size: 34px; }
.sheet p { max-width: 460px; margin: 0; color: var(--muted); }
.big { min-width: 260px; height: 56px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255,255,255,0.06); font-size: 17px; }
[hidden] { display: none !important; }
