:root {
  --bg: #f3f1ec;
  --stage: #e6e3db;
  --panel: #faf9f6;
  --ink: #1b1a17;
  --muted: #6b675f;
  --line: #dcd8ce;
  --line-strong: #bfbab0;
  --accent: #c9432c;
  --accent-ink: #ffffff;
  --chip-on: #1b1a17;
  --chip-on-ink: #faf9f6;
  --shadow: 0 1px 2px rgba(0,0,0,.08), 0 8px 24px rgba(0,0,0,.08);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --bar-h: 52px;
  --panel-w: 360px;
  --peek: 176px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --stage: #0d0d0c;
    --panel: #1b1b19;
    --ink: #ebe8e0;
    --muted: #8e8a81;
    --line: #2d2c29;
    --line-strong: #46443f;
    --accent: #e9573c;
    --accent-ink: #ffffff;
    --chip-on: #ebe8e0;
    --chip-on-ink: #151514;
    --shadow: 0 1px 2px rgba(0,0,0,.5), 0 8px 30px rgba(0,0,0,.45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  display: grid;
  grid-template-columns: 1fr var(--panel-w);
  grid-template-rows: calc(var(--bar-h) + var(--safe-t)) 1fr;
  grid-template-areas: "bar panel" "stage panel";
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.bar {
  grid-area: bar; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: var(--safe-t) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line); background: var(--bg); z-index: 3;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .01em; font-size: 15px; }
.mark {
  width: 18px; height: 18px; border-radius: 3px;
  background: repeating-conic-gradient(var(--ink) 0 25%, transparent 0 50%) 0 0 / 6px 6px;
  box-shadow: inset 0 0 0 1px var(--ink);
}
.actions { display: flex; gap: 6px; align-items: center; }
.btn {
  appearance: none; border: 1px solid var(--line-strong); background: transparent;
  min-height: 36px; padding: 0 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
  font-weight: 550; letter-spacing: .005em;
}
.btn:hover:not(:disabled) { border-color: var(--ink); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.06); border-color: var(--accent); }
.link { appearance: none; border: 0; background: none; padding: 6px 2px; cursor: pointer; color: var(--muted); font-size: 12.5px; font-weight: 550; }
.link:hover { color: var(--ink); }
.pp-only { display: none; }
body.pp .pp-only { display: inline-block; }
body.pp #btn-camera, body.pp #btn-video, body.pp #btn-open, body.pp #btn-petri, body.pp #btn-remix { display: none; }

/* ---------- stage ---------- */
.stage { grid-area: stage; position: relative; background: var(--stage); overflow: hidden; min-height: 0; }
.viewport { position: absolute; inset: 0; touch-action: none; cursor: grab; overflow: hidden; outline: none; }
.viewport.dragging { cursor: grabbing; }
.layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; box-shadow: var(--shadow); will-change: transform; }
.layer canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
.layer canvas#cv-after { image-rendering: pixelated; }
#cv-before { visibility: hidden; image-rendering: auto; }
.stage.show-before #cv-before { visibility: visible; }
.stage.show-before #cv-after { visibility: hidden; }
.stage.splitting #cv-before { visibility: visible; }
.stage.splitting #cv-after { clip-path: inset(0 0 0 var(--split, 50%)); }
.split { position: absolute; top: 0; bottom: 0; left: var(--split, 50%); width: 0; }
.split::before { content: ""; position: absolute; top: 0; bottom: 0; left: calc(-1px / var(--z, 1)); width: calc(2px / var(--z, 1)); background: var(--accent); }
.split-knob {
  position: absolute; top: 50%; left: 0; width: 40px; height: 40px; border-radius: 50%;
  transform: translate(-50%, -50%) scale(calc(1 / var(--z, 1)));
  background: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.3); cursor: ew-resize; touch-action: none;
}
.split-knob::before, .split-knob::after { content: ""; position: absolute; top: 50%; width: 0; height: 0; border: 6px solid transparent; margin-top: -6px; }
.split-knob::before { left: 6px; border-right-color: #fff; }
.split-knob::after { right: 6px; border-left-color: #fff; }

.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 4px; }
.empty-title { font-size: 22px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.empty-sub { margin: 0 0 14px; color: var(--muted); }
.empty-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.empty-actions .btn { min-height: 44px; padding: 0 18px; }

.hud { position: absolute; left: 12px; top: 10px; font: 11.5px/1 var(--mono); color: var(--muted); display: flex; gap: 10px; align-items: center; pointer-events: none; font-variant-numeric: tabular-nums; }
.hud span:first-child { background: color-mix(in srgb, var(--stage) 80%, transparent); padding: 5px 7px; border-radius: 5px; }
.busy { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); opacity: 0; transition: opacity .15s; }
.busy.on { opacity: 1; animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.viewtools { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 4px; background: color-mix(in srgb, var(--panel) 88%, transparent); border: 1px solid var(--line); border-radius: 10px; padding: 3px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.tool { appearance: none; border: 0; background: none; min-height: 34px; min-width: 40px; padding: 0 10px; border-radius: 7px; cursor: pointer; font-size: 12.5px; font-weight: 550; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.tool:hover { background: var(--line); }
.tool[aria-pressed="true"], .tool.on { background: var(--chip-on); color: var(--chip-on-ink); }
.drop-hint { position: absolute; inset: 12px; border: 2px dashed var(--accent); border-radius: 14px; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 18px; background: color-mix(in srgb, var(--stage) 70%, transparent); pointer-events: none; }
.toast { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 13px; max-width: calc(100% - 32px); box-shadow: var(--shadow); z-index: 5; }

/* camera */
.camera { position: absolute; inset: 0; background: #000; display: flex; align-items: center; justify-content: center; z-index: 2; }
#cv-live { max-width: 100%; max-height: 100%; image-rendering: pixelated; }
#cv-live.mirror { transform: scaleX(-1); }
.camera-note { position: absolute; top: 12px; left: 12px; right: 12px; margin: 0; text-align: center; color: #eee; font-size: 12.5px; text-shadow: 0 1px 2px #000; }
.camera-bar { position: absolute; left: 0; right: 0; bottom: 16px; display: flex; justify-content: center; align-items: center; gap: 28px; }
.camera-bar .btn { color: #fff; border-color: rgba(255,255,255,.5); background: rgba(0,0,0,.35); min-height: 44px; }
.shutter { width: 68px; height: 68px; border-radius: 50%; border: 4px solid #fff; background: var(--accent); cursor: pointer; box-shadow: 0 0 0 2px rgba(0,0,0,.3); }
.shutter:active { transform: scale(.94); }

/* petri: cellular-automaton camera */
.petri-stage { position: absolute; inset: 0; background: #000; display: flex; align-items: center; justify-content: center; z-index: 2; overflow: hidden; padding: 52px 0 96px; }
.petri-stage[data-mode=photo] { padding-bottom: 150px; }
#cv-petri { display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
#cv-petri.smooth { image-rendering: auto; }
#cv-remix { display: block; touch-action: none; cursor: crosshair; }
#cv-remix.dithered { image-rendering: pixelated; image-rendering: crisp-edges; }
.remix-stage[data-mode=photo] { padding-bottom: 96px; }
.petri-hud { position: absolute; left: 12px; top: 10px; margin: 0; font: 11.5px/1 var(--mono); color: #d8d4cc; background: rgba(0,0,0,.45); padding: 5px 7px; border-radius: 5px; font-variant-numeric: tabular-nums; pointer-events: none; }
.petri-transport { position: absolute; right: 12px; top: 8px; display: flex; gap: 2px; padding: 3px; border-radius: 10px; background: rgba(20,20,19,.62); border: 1px solid rgba(255,255,255,.14); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.petri-transport .tool { color: #eee; }
.petri-transport .tool:hover { background: rgba(255,255,255,.12); }
.petri-transport .tool[aria-pressed="true"] { background: #eee; color: #111; }
.petri-scrub { position: absolute; left: 16px; right: 16px; bottom: 96px; display: flex; align-items: center; gap: 10px; padding: 0 10px; border-radius: 10px; background: rgba(20,20,19,.62); border: 1px solid rgba(255,255,255,.14); color: #eee; }
.petri-scrub input[type=range]::-webkit-slider-runnable-track { background: rgba(255,255,255,.35); }
.petri-scrub input[type=range]::-moz-range-track { background: rgba(255,255,255,.35); }
.petri-scrub input[type=range]::-webkit-slider-thumb { background: #111; border-color: #eee; }
.petri-scrub input[type=range]::-moz-range-thumb { background: #111; border-color: #eee; }
.petri-scrub span { font: 12px var(--mono); min-width: 4.5ch; text-align: right; font-variant-numeric: tabular-nums; }
.petri-stage .shutter { background: #fff; box-shadow: 0 0 0 2px rgba(0,0,0,.3), inset 0 0 0 3px #000; }
.petri-stage .camera-bar .btn { min-width: 74px; }
.mode-tag { font-weight: 550; color: var(--muted); }
.mode-tag::before { content: "/"; margin-right: 8px; color: var(--line-strong); }
.petri-only, .petri-only-block, .remix-only, .remix-only-block { display: none; }
body.petri .petri-only, body.remix .remix-only { display: inline-block; }
body.petri .petri-only-block, body.remix .remix-only-block { display: block; }
body.petri #btn-open, body.petri #btn-camera, body.petri #btn-video, body.petri #btn-petri, body.petri #btn-remix, body.petri #btn-export,
body.remix #btn-open, body.remix #btn-camera, body.remix #btn-video, body.remix #btn-petri, body.remix #btn-remix, body.remix #btn-export { display: none; }
body.petri #controls, body.petri .panel-scroll > .group.presets, body.remix #controls, body.remix .panel-scroll > .group.presets { display: none; }
#petri-rec.rec-on, #remix-rec.rec-on { border-color: var(--accent); color: var(--accent); }
#petri-rec.rec-on::before, #remix-rec.rec-on::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 7px; vertical-align: 1px; animation: pulse .9s ease-in-out infinite; }
.text.mono { font-family: var(--mono); font-size: 13px; }
.text.bad { border-color: var(--accent); }

/* ---------- panel ---------- */
.panel { grid-area: panel; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; z-index: 4; }
.sheet-handle { display: none; }
.panel-scroll { overflow-y: auto; overscroll-behavior: contain; flex: 1; padding-bottom: calc(24px + var(--safe-b)); }
.group { padding: 14px 16px 12px; border-bottom: 1px solid var(--line); }
.group-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.group h2 { margin: 0; font-size: 11px; font-weight: 650; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.head-actions { display: flex; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  appearance: none; border: 1px solid var(--line-strong); background: transparent; border-radius: 7px;
  min-height: 34px; padding: 0 11px; cursor: pointer; font-size: 13px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { border-color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--chip-on); color: var(--chip-on-ink); border-color: var(--chip-on); }
.chip .x { opacity: .6; font-size: 15px; line-height: 1; padding-left: 2px; }
.chip .x:hover { opacity: 1; }
.chip.own { border-style: dashed; }
.chips.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); }
.chips.grid3 .chip { justify-content: center; padding: 0 6px; }
.chips.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); }
.chips.grid2 .chip { justify-content: center; padding: 0 6px; }

/* elementary rule editor: eight patterns, each a switch for its result */
.eca-bits { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin: 4px 0 8px; }
.eca-bit { appearance: none; border: 1px solid var(--line); background: transparent; border-radius: 7px; padding: 6px 0 5px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 44px; }
.eca-bit:hover { border-color: var(--line-strong); }
.eca-bit[aria-pressed="true"] { border-color: var(--ink); }
.eca-bit .pat, .eca-bit .out { display: flex; gap: 1px; }
.eca-bit i { width: 8px; height: 8px; box-shadow: inset 0 0 0 1px var(--line-strong); }
.eca-bit i.on { background: var(--ink); box-shadow: none; }
.eca-bit .out i.on { background: var(--accent); }
.eca-picks .chip { min-width: 44px; justify-content: center; font-family: var(--mono); font-size: 12.5px; }
.numrow .btn { min-width: 38px; padding: 0 10px; }

/* remix: the effect chain */
.head-note { font: 11.5px var(--mono); color: var(--muted); }
.fx-list { display: flex; flex-direction: column; gap: 6px; }
.fx-card { border: 1px solid var(--line); border-radius: 9px; }
.fx-card.open { border-color: var(--line-strong); }
.fx-card.off .fx-name { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line-strong); }
.fx-head { display: flex; align-items: center; gap: 2px; padding: 3px 4px 3px 2px; }
.fx-name { appearance: none; border: 0; background: none; flex: 1; text-align: left; min-height: 38px; padding: 0 8px; cursor: pointer; font-weight: 600; display: flex; align-items: center; gap: 9px; border-radius: 7px; }
.fx-name::after { content: ""; margin-left: auto; width: 6px; height: 6px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg) translateY(-2px); transition: transform .15s; }
.fx-name[aria-expanded="true"]::after { transform: rotate(-135deg) translateY(-1px); }
.fx-num { font: 11px var(--mono); color: var(--muted); width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--line-strong); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.fx-head .switch { margin: 0 6px; flex: none; }
.icon { appearance: none; border: 0; background: none; width: 34px; height: 34px; border-radius: 7px; cursor: pointer; font-size: 15px; color: var(--muted); flex: none; }
.icon:hover:not(:disabled) { background: var(--line); color: var(--ink); }
.icon:disabled { opacity: .3; cursor: default; }
.fx-body { padding: 2px 12px 12px; border-top: 1px solid var(--line); }
.fx-body .row { grid-template-columns: 80px 1fr 46px; }
.fx-body .row.wide { grid-template-columns: 80px 1fr; }
.fx-add { margin-top: 10px; }
.fx-add .field-label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.fx-add .chip { min-height: 32px; padding: 0 9px; font-size: 12.5px; }
.chip:disabled { opacity: .4; cursor: default; }

.row { display: grid; grid-template-columns: 92px 1fr 46px; align-items: center; gap: 10px; min-height: 38px; }
.row > label, .field-label { font-size: 13px; color: var(--ink); user-select: none; -webkit-user-select: none; }
.row > label { cursor: default; }
.row .val { font: 12px var(--mono); text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.row.wide { grid-template-columns: 92px 1fr; }
.sub { margin-top: 6px; }
.note { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 30px; background: transparent; margin: 0; cursor: pointer; touch-action: pan-y; }
input[type=range]::-webkit-slider-runnable-track { height: 2px; background: var(--line-strong); border-radius: 2px; }
input[type=range]::-moz-range-track { height: 2px; background: var(--line-strong); border-radius: 2px; }
input[type=range]::-moz-range-progress { height: 2px; background: var(--ink); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -7px; border-radius: 50%; background: var(--panel); border: 2px solid var(--ink); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--panel); border: 2px solid var(--ink); }
input[type=range]:focus-visible { outline: none; }
input[type=range]:focus-visible::-webkit-slider-thumb { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
input[type=range]:focus-visible::-moz-range-thumb { border-color: var(--accent); }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button { appearance: none; border: 0; background: transparent; min-height: 32px; padding: 0 11px; cursor: pointer; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button[aria-pressed="true"] { background: var(--chip-on); color: var(--chip-on-ink); }
.row .seg { justify-self: stretch; display: flex; min-width: 0; }
.row .seg button { flex: 1 1 auto; padding: 0 6px; min-width: 0; }

.switch { justify-self: start; appearance: none; width: 38px; height: 22px; border-radius: 22px; background: var(--line-strong); position: relative; cursor: pointer; border: 0; margin: 0; transition: background .15s; }
.switch::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--panel); transition: transform .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(16px); }
.check { display: flex; align-items: center; gap: 8px; min-height: 36px; }

select.select { appearance: none; -webkit-appearance: none; border: 1px solid var(--line-strong); border-radius: 8px; background: transparent; min-height: 34px; padding: 0 28px 0 10px; width: 100%;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
select.select option { background: var(--panel); color: var(--ink); }
.numrow { display: flex; gap: 6px; align-items: center; }
.text { border: 1px solid var(--line-strong); background: transparent; border-radius: 8px; min-height: 38px; padding: 0 10px; width: 100%; }

/* palettes */
.pal-tabs { margin-bottom: 10px; }
.pal-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pal {
  appearance: none; border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 6px 7px 7px; cursor: pointer; text-align: left;
  display: flex; flex-direction: column; gap: 5px; min-height: 44px;
}
.pal:hover { border-color: var(--line-strong); }
.pal[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.pal-name { font-size: 11.5px; color: var(--muted); line-height: 1; }
.pal[aria-pressed="true"] .pal-name { color: var(--ink); }
.strip { display: flex; width: 100%; align-self: stretch; height: 16px; border-radius: 3px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(127,127,127,.25); }
.strip i { flex: 1; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatch { position: relative; width: 40px; height: 40px; }
.swatch input[type=color] { width: 40px; height: 40px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 0; background: none; cursor: pointer; }
.swatch input[type=color]::-webkit-color-swatch-wrapper { padding: 2px; }
.swatch input[type=color]::-webkit-color-swatch { border: 0; border-radius: 5px; }
.swatch input[type=color]::-moz-color-swatch { border: 0; border-radius: 5px; }
.swatch .rm { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--panel); font-size: 13px; line-height: 17px; padding: 0; cursor: pointer; }
.add { width: 40px; height: 40px; border: 1px dashed var(--line-strong); border-radius: 8px; background: none; cursor: pointer; font-size: 20px; color: var(--muted); }
.result-strip { margin-top: 8px; }

/* dialogs */
dialog.sheet-dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink); padding: 0; width: min(440px, calc(100vw - 24px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog-body { padding: 18px 18px 16px; display: flex; flex-direction: column; gap: 12px; }
.dialog-body h2 { margin: 0 0 2px; font-size: 16px; font-weight: 650; }
.field { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.dialog-actions .btn { min-height: 42px; }
.progress { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .1s; }
.progress-label { margin: 0; font: 12.5px var(--mono); color: var(--muted); }
.vid-canvas { width: 100%; max-height: 40vh; object-fit: contain; background: #000; border-radius: 8px; image-rendering: pixelated; display: block; }

/* ---------- phone: bottom sheet ---------- */
@media (max-width: 820px) {
  :root { --bar-h: 50px; }
  body { display: block; }
  .bar { position: fixed; left: 0; right: 0; top: 0; height: calc(var(--bar-h) + var(--safe-t)); padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .brand > span:nth-child(2) { display: none; }
  .actions { gap: 4px; }
  .actions .btn { padding: 0 11px; min-height: 38px; }
  .stage { position: fixed; left: 0; right: 0; top: calc(var(--bar-h) + var(--safe-t)); bottom: calc(var(--peek) + var(--safe-b)); }
  .panel {
    position: fixed; left: 0; right: 0; bottom: 0; height: min(86dvh, calc(100dvh - var(--bar-h) - var(--safe-t) - 24px));
    border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
    transform: translateY(calc(100% - var(--peek) - var(--safe-b)));
    transition: transform .28s cubic-bezier(.2,.8,.2,1);
    box-shadow: 0 -8px 30px rgba(0,0,0,.12);
  }
  .panel.half { transform: translateY(46%); }
  .panel.full { transform: translateY(0); }
  .panel.dragging { transition: none; }
  .sheet-handle { display: flex; justify-content: center; align-items: center; height: 26px; flex: none; cursor: grab; touch-action: none; }
  .sheet-handle span { width: 40px; height: 4px; border-radius: 4px; background: var(--line-strong); }
  .group { padding: 10px 14px 10px; }
  .group.presets { padding-top: 2px; }
  .presets .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px 2px; }
  .presets .chips::-webkit-scrollbar { display: none; }
  .chip { min-height: 38px; }
  .row { min-height: 44px; grid-template-columns: 84px 1fr 42px; }
  .seg button { min-height: 38px; }
  .viewtools { right: 8px; bottom: 8px; }
  body.petri .brand .mode-tag.petri-only, body.remix .brand .mode-tag.remix-only { display: inline; }
  .brand .mode-tag::before { display: none; }
  .petri-transport { right: 8px; top: 8px; }
  .petri-hud { left: 8px; top: 58px; }
  .petri-stage .camera-bar { gap: 18px; bottom: 12px; }
  .petri-scrub { left: 8px; right: 8px; bottom: 88px; }
  .petri-stage { padding-top: 84px; }
  dialog.sheet-dialog { margin: auto auto 0; width: 100%; max-width: 100%; border-radius: 16px 16px 0 0; padding-bottom: var(--safe-b); }
}
@media (max-width: 480px) {
  body:not(.petri):not(.remix) .brand { display: none; }
  .actions { gap: 3px; }
  .actions .btn { padding: 0 9px; font-size: 13.5px; }
  .bar { justify-content: center; }
}
@media (max-width: 380px) {
  .actions .btn { padding: 0 7px; font-size: 13px; }
}

/* Photopea plugin panel: narrow, stacked, no sheet */
body.pp { display: flex; flex-direction: column; overflow: auto; height: auto; min-height: 100%; }
body.pp .bar { position: static; height: auto; padding: 8px 10px; flex-wrap: wrap; }
body.pp .brand { display: none; }
body.pp .stage { position: relative; inset: auto; height: 42vh; min-height: 200px; flex: none; }
body.pp .panel { position: static; transform: none; height: auto; border-radius: 0; border-left: 0; box-shadow: none; }
body.pp .sheet-handle { display: none; }
body.pp .panel-scroll { overflow: visible; }
