/* Runway Sketch booth: dark atelier around one white page. iPad first (landscape or portrait). */
:root {
  --bg: #1c1b19; --bg2: #252421; --bg3: #2e2c29; --line: #3a3833; --cream: #f7f5f1; --mute: #9a958c;
  --gold: #b8892b; --gold-2: #d2a548; --ink: #2a2a2a; --bad: #e0a089;
  --serif: "Bodoni Moda", Didot, "Bodoni 72", Georgia, serif;
  --sans: Inter, "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", Menlo, monospace;
  --share-w: min(400px, 36vw);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--cream); font-family: var(--sans); overflow: hidden; }
body { display: grid; grid-template-rows: auto 1fr; height: 100dvh; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.cap { font-size: 13px; color: var(--mute); }

/* ---------- top bar ---------- */
.top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 10px max(20px, env(safe-area-inset-left)); }
.brand { font-family: var(--serif); font-size: 24px; letter-spacing: .02em; padding: 6px 12px; touch-action: none; }
.brand em { color: var(--gold-2); font-style: italic; }
.pill { display: inline-flex; align-items: center; gap: 12px; height: 52px; padding: 0 18px 0 10px; border-radius: 999px;
  background: var(--bg2); border: 1px solid var(--line); }
.pill.lib { justify-self: end; padding: 0 18px; gap: 8px; font-size: 15px; }
.pill.lib i { font-style: normal; font-family: var(--mono); color: var(--mute); }
.pill.lib .chk { color: var(--gold-2); }
.wait { justify-self: start; text-align: left; }
.wait .dot { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--bg3); border: 1px solid var(--line);
  font: 500 15px var(--mono); color: var(--bg); transition: background .3s, border-color .3s; }
.wait .dot.on { background: var(--gold-2); border-color: var(--gold-2); }
.wait .lbl { display: grid; line-height: 1.2; }
.wait .lbl b { font-weight: 500; font-size: 15px; }
.wait .lbl small { font-size: 12px; color: var(--mute); }

/* ---------- stage + page ---------- */
.stage { position: relative; min-height: 0; display: grid; place-items: center;
  padding: 4px max(20px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); }
body.sharing .stage { padding-right: calc(var(--share-w) + 40px); }
.idle { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; pointer-events: none; }
.idle p { margin: 0; font: 400 34px var(--serif); color: var(--cream); opacity: .9; }
.idle small { display: block; margin-top: 10px; font: 12px var(--sans); letter-spacing: .28em; text-transform: uppercase; color: var(--mute); }
.sheet { position: relative; background: #fff; line-height: 0; box-shadow: 0 30px 70px -24px rgba(0,0,0,.75), 0 0 0 1px rgba(255,255,255,.04);
  transition: transform .55s cubic-bezier(.4,0,.2,1), opacity .55s, width .5s cubic-bezier(.2,.7,.2,1), height .5s cubic-bezier(.2,.7,.2,1); }
.sheet.leaving { transform: translateY(40px) scale(.96); opacity: 0; }
.sheet.arriving { animation: arrive .45s cubic-bezier(.2,.7,.2,1); }
@keyframes arrive { from { transform: translateY(24px); opacity: 0; } }
.sheet canvas { display: block; width: 100%; height: 100%; }
.sheet canvas.ov { position: absolute; inset: 0; pointer-events: none; }
.nib { position: absolute; left: 0; top: 0; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #555, #111 70%); box-shadow: 0 6px 10px rgba(0,0,0,.35);
  pointer-events: none; opacity: 0; transition: opacity .12s, width .2s, height .2s, margin .2s; will-change: transform; }
.nib.on { opacity: .9; }
.nib.lift { opacity: .35; }
.nib.pencil { background: radial-gradient(circle at 40% 40%, #9a9ca2, #5a5c62 70%); width: 8px; height: 8px; margin: -4px 0 0 -4px; }
.nib.marker { width: 30px; height: 30px; margin: -15px 0 0 -15px; background: var(--mc, #c99); mix-blend-mode: multiply; opacity: 0; }
.nib.marker.on { opacity: .45; }
.prep { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; background: rgba(255,255,255,.7); }
.prep p { margin: 0; font: 13px var(--mono); color: #6b6760; line-height: 1.4; }
.spin { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #d9d4ca; border-top-color: var(--gold); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.go { position: absolute; right: max(24px, env(safe-area-inset-right)); bottom: max(26px, env(safe-area-inset-bottom)); display: grid; gap: 10px; justify-items: end; }
.sketchit { height: 76px; padding: 0 40px; border-radius: 999px; border: 0; background: var(--gold); color: #fff;
  font: italic 500 30px var(--serif); box-shadow: 0 10px 22px -12px rgba(0,0,0,.7); transition: transform .12s, opacity .2s; }
.sketchit:active { transform: scale(.97); }
.sketchit:disabled { opacity: .4; cursor: default; }
.ghost { height: 44px; padding: 0 18px; border-radius: 999px; background: transparent; border: 1px solid var(--line); color: var(--cream); font-size: 14px; }
.pri { height: 52px; padding: 0 26px; border-radius: 14px; border: 0; background: var(--cream); color: var(--ink); font-weight: 500; font-size: 16px; }
.pri:disabled { opacity: .5; }

.bstatus { position: fixed; left: max(20px, env(safe-area-inset-left)); bottom: max(8px, env(safe-area-inset-bottom)); font: 11px var(--mono); color: #6b6760; pointer-events: none; max-width: 60vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bstatus.bad { color: var(--bad); }

/* ---------- waiting drawer ---------- */
.drawer { position: fixed; inset: 0; z-index: 20; }
.drawer .shade { position: absolute; inset: 0; background: rgba(10,10,9,.6); animation: fade .25s; }
.drawer .panel { position: absolute; left: 0; right: 0; bottom: 0; background: var(--bg2); border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0; padding: 18px max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  animation: up .32s cubic-bezier(.2,.7,.2,1); }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.dhd { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.dhd b { font: 400 22px var(--serif); }
.dhd .cap { flex: 1; }
.x { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: transparent; font-size: 22px; line-height: 1; color: var(--cream); }
.film { display: flex; gap: 14px; overflow-x: auto; padding: 4px 2px 10px; scrollbar-width: none; }
.film::-webkit-scrollbar { display: none; }
.frame { flex: 0 0 auto; display: grid; gap: 8px; padding: 0; background: none; border: 0; text-align: left; }
.frame .im { height: 190px; aspect-ratio: var(--ar, .66); background: #fff; border-radius: 8px; overflow: hidden; border: 2px solid transparent; }
.frame img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .3s; }
.frame img.ld { opacity: 1; }
.frame:active .im { border-color: var(--gold-2); }
.frame .no { display: flex; justify-content: space-between; gap: 10px; font: 12px var(--mono); color: var(--mute); }
.dempty { padding: 30px 0 18px; text-align: center; }
.dempty p { margin: 0 0 6px; font: 400 24px var(--serif); }

/* ---------- share panel ---------- */
.share { position: fixed; z-index: 15; top: 84px; right: max(20px, env(safe-area-inset-right)); bottom: max(22px, env(safe-area-inset-bottom)); width: var(--share-w);
  background: var(--bg2); border: 1px solid var(--line); border-radius: 22px; padding: 26px 24px 20px; display: flex; flex-direction: column;
  transform: translateX(calc(100% + 40px)); transition: transform .5s cubic-bezier(.2,.7,.2,1); overflow-y: auto; }
body.sharing .share { transform: none; }
.share section { display: flex; flex-direction: column; gap: 14px; flex: 1; }
.share .kick { font-size: 11px; letter-spacing: .28em; text-transform: uppercase; color: var(--gold-2); }
.share h2 { margin: 0; font: 400 32px/1.1 var(--serif); }
.share p { margin: 0; color: var(--mute); line-height: 1.5; font-size: 15px; }
.opts { display: grid; gap: 10px; margin-top: 6px; }
.big { display: grid; gap: 4px; text-align: left; padding: 18px 18px; border-radius: 16px; background: var(--bg3); border: 1px solid var(--line); }
.big b { font-weight: 500; font-size: 17px; }
.big span { font-size: 13px; color: var(--mute); }
.big:disabled { opacity: .45; }
.foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 14px; }
.foot .note { font-size: 12px; color: var(--mute); }
.foot .ghost:last-child { margin-left: auto; }
.qrbox { align-self: center; padding: 14px; background: #fff; border-radius: 14px; line-height: 0; }
.qrbox img, .qrbox canvas { display: block; width: 240px; height: 240px; }
.bwait { font-size: 14px; color: #6b6760; line-height: 1.4; margin: 0; padding: 20px; max-width: 240px; }
form.send { display: flex; gap: 10px; }
form.send input { flex: 1; min-width: 0; height: 52px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); color: var(--cream); font: 18px var(--sans); }
form.send input:focus { outline: 2px solid var(--gold-2); outline-offset: 1px; }
.err { min-height: 1em; color: var(--bad); font-size: 14px; }
.fine { font-size: 12px !important; }

/* ---------- library ---------- */
.libv { position: fixed; inset: 0; z-index: 25; background: var(--bg); display: grid; grid-template-rows: auto 1fr; animation: fade .2s; }
.libhd { display: flex; align-items: center; gap: 14px; padding: max(16px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 14px max(20px, env(safe-area-inset-left)); border-bottom: 1px solid var(--line); }
.libhd b { font: 400 26px var(--serif); }
.libhd input { flex: 1; max-width: 320px; height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); color: var(--cream); font: 15px var(--sans); }
.tabs { display: flex; gap: 4px; margin-left: auto; background: var(--bg2); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.tabs button { height: 36px; padding: 0 16px; border-radius: 999px; border: 0; background: transparent; color: var(--mute); font-size: 14px; }
.tabs button.on { background: var(--bg3); color: var(--cream); }
.libgrid { overflow-y: auto; padding: 18px max(20px, env(safe-area-inset-right)) 40px max(20px, env(safe-area-inset-left));
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; align-content: start; }
.lcard { background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: grid; }
.lcard img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; background: #fff; display: block; }
.lcard .m { display: flex; justify-content: space-between; gap: 8px; padding: 10px 12px 2px; font: 12px var(--mono); }
.lcard .m span:last-child { color: var(--mute); }
.lcard .st { padding: 0 12px 8px; font-size: 12px; color: var(--mute); }
.lcard .st.dev { color: var(--gold-2); }
.lcard .acts { display: flex; gap: 6px; padding: 0 10px 12px; }
.lcard .acts button { flex: 1; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--cream); font-size: 13px; }
.lcard .acts button.p { background: var(--cream); color: var(--ink); border-color: var(--cream); }
.libempty { grid-column: 1 / -1; padding: 60px 0; text-align: center; color: var(--mute); }
.reshare { position: fixed; z-index: 26; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(640px, calc(100vw - 40px));
  background: var(--bg2); border: 1px solid var(--line); border-radius: 20px; padding: 18px; display: flex; gap: 18px; align-items: center; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.reshare .x { position: absolute; top: 10px; right: 10px; }
.reshare .qr { flex: 0 0 auto; padding: 10px; background: #fff; border-radius: 12px; line-height: 0; }
.reshare .qr img, .reshare .qr canvas { width: 150px; height: 150px; }
.reshare .rs { flex: 1; display: grid; gap: 8px; padding-right: 40px; }
.reshare .rs b { font: 400 22px var(--serif); }
.reshare .rs p { margin: 0; color: var(--mute); font-size: 14px; }

/* ---------- toast + operator panel ---------- */
.toast { position: fixed; z-index: 40; left: 50%; top: 84px; transform: translate(-50%, -10px); background: var(--cream); color: var(--ink);
  padding: 12px 18px; border-radius: 12px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 40px); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.ops { position: fixed; inset: 0; z-index: 50; background: rgba(10,10,9,.7); display: grid; place-items: center; padding: 20px; overflow-y: auto; }
.ops .card { width: min(620px, 100%); background: var(--bg2); border: 1px solid var(--line); border-radius: 20px; padding: 24px; display: grid; gap: 10px; user-select: text; -webkit-user-select: text; }
.ops h2 { margin: 0; font: 400 28px var(--serif); }
.ops p { margin: 0; color: var(--mute); font-size: 14px; line-height: 1.45; }
.ops .small { font-size: 12px; word-break: break-all; }
.ops .small a { color: var(--gold-2); }
.ops label { font-size: 13px; color: var(--mute); display: flex; justify-content: space-between; gap: 8px; }
.ops label b { font-weight: 400; color: var(--cream); font-family: var(--mono); }
.ops label.tog { justify-content: flex-start; align-items: center; color: var(--cream); font-size: 15px; }
.ops input[type=text], .ops input[type=password], .ops select, .ops textarea { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--cream); font: 15px var(--sans); }
.ops input[type=range] { width: 100%; accent-color: var(--gold); }
.ops input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--gold); }
.ops fieldset { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px 14px; display: grid; gap: 8px; margin: 4px 0; }
.ops fieldset:disabled { opacity: .5; }
.ops legend { padding: 0 6px; font-size: 13px; color: var(--cream); }
.ops .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ops .two > div { display: grid; gap: 8px; }
.ops .row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }

@media (orientation: portrait) {
  :root { --share-w: calc(100vw - 40px); }
  body.sharing .stage { padding-right: max(20px, env(safe-area-inset-right)); padding-bottom: 46vh; }
  .share { top: auto; height: 42vh; transform: translateY(calc(100% + 40px)); }
}
@media (max-width: 700px) {
  .brand { font-size: 19px; }
  .wait .lbl small { display: none; }
  .sketchit { height: 60px; font-size: 24px; padding: 0 28px; }
  .frame .im { height: 140px; }
  .ops .two { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .sheet, .share, .stage { transition: none; }
  .drawer .panel, .drawer .shade, .sheet.arriving { animation: none; }
}
