/* FacePaint — full-screen canvas with a few floating controls. */
:root {
  --bg: #0c0c0f;
  --glass: rgba(20, 20, 26, 0.78);
  --glass-2: rgba(32, 32, 40, 0.92);
  --line: rgba(255, 255, 255, 0.1);
  --line-2: rgba(255, 255, 255, 0.18);
  --text: #eeebe4;
  --text-2: rgba(238, 235, 228, 0.66);
  --text-3: rgba(238, 235, 228, 0.55);
  --gold: #e8c547;
  --sky: #47b8e8;
  --red: #ff6b6b;
  --green: #4ade80;
  --display: "Syne", system-ui, sans-serif;
  --mono: "Space Mono", ui-monospace, monospace;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r: 14px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --top: calc(10px + env(safe-area-inset-top));
  --bottom: calc(14px + env(safe-area-inset-bottom));
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.5 var(--ui); -webkit-font-smoothing: antialiased; }
body { overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; opacity: .35; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }
kbd { font: 11px var(--mono); padding: 1px 5px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; color: var(--text-2); }

.app { position: fixed; inset: 0; height: 100dvh; overflow: hidden; }
#paper { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: none; display: block; }
.app[data-mode="intro"] #paper { cursor: default; }
/* Bloom: a blurred copy of the ink, added on top as light. */
#bloom { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; filter: blur(14px) saturate(1.3); mix-blend-mode: screen; opacity: .9; }
.app[data-paper="light"] #bloom { mix-blend-mode: multiply; opacity: .45; }
#sparks { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* Brush cursor: a ring the size of the brush, filled while painting. */
#cursor { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 5; will-change: transform; }
#cursor i { position: absolute; width: calc(var(--s, 12px) + 10px); height: calc(var(--s, 12px) + 10px); left: 0; top: 0;
  transform: translate(-50%, -50%); border-radius: 50%; border: 2px solid var(--c, #fff);
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, .55), 0 0 14px rgba(0, 0, 0, .35); transition: background .12s, transform .12s; }
#cursor.is-drawing i { background: var(--c, #fff); transform: translate(-50%, -50%) scale(.82); }
#cursor.is-hidden { opacity: 0; }
.app[data-mode="intro"] #cursor, .app.is-calibrating #cursor, .app.is-replaying #cursor { opacity: 0; }

/* ── Top bar ── */
.top { position: absolute; top: var(--top); left: 12px; right: 12px; z-index: 16; display: flex; align-items: center; gap: 8px; pointer-events: none; }
.top > * { pointer-events: auto; }
.top-spacer { flex: 1; pointer-events: none; }
.logo { font: 800 18px/1 var(--display); letter-spacing: -.01em; padding: 0 6px; text-shadow: 0 1px 8px rgba(0,0,0,.6); }
.logo b, .intro-logo b { color: var(--gold); font-weight: 800; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--line); background: var(--glass); color: var(--text); text-decoration: none;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); transition: background .15s; }
.icon-btn:hover { background: var(--glass-2); }
.status { display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border-radius: 16px; border: 1px solid var(--line); background: var(--glass);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); font-size: 13px; font-weight: 500; white-space: nowrap; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex-shrink: 0; }
.status[data-tone="ready"] i { background: var(--sky); }
.status[data-tone="on"] i { background: var(--red); box-shadow: 0 0 0 4px rgba(255,107,107,.25); }
.status[data-tone="bad"] i { background: var(--gold); }
.app[data-mode="intro"] .top .status, .app[data-mode="intro"] .top .icon-btn:not([href]), .app[data-mode="intro"] .logo { visibility: hidden; }
/* Controls that only make sense for the camera, or for one kind of camera control. */
.app:not([data-mode="camera"]) [data-camera-only],
.app:not([data-mode="camera"]) [data-face-ctl], .app:not([data-mode="camera"]) [data-hand-ctl],
.app[data-control="hands"] [data-face-ctl], .app[data-control="face"] [data-hand-ctl] { display: none !important; }
#inputBtn svg { width: 21px; height: 21px; }
.app[data-control="face"] #inputBtn .ico-face, .app[data-control="hands"] #inputBtn .ico-hand { display: none; }

/* ── Camera preview ── */
.pip { position: absolute; z-index: 9; top: calc(var(--top) + 52px); right: 12px; display: flex; gap: 6px; align-items: stretch; }
.pip-video { position: relative; width: 168px; aspect-ratio: 4 / 3; border-radius: var(--r); overflow: hidden; border: 1px solid var(--line-2); background: #000; box-shadow: 0 10px 30px -10px rgba(0,0,0,.7); }
.pip-cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.pip-mesh { position: absolute; inset: 0; width: 100%; height: 100%; }
.pip-msg { position: absolute; inset: auto 0 0 0; margin: 0; padding: 6px; text-align: center; font-size: 12px; font-weight: 600; background: linear-gradient(transparent, rgba(0,0,0,.75)); }
.pip-meter { position: relative; width: 8px; border-radius: 4px; background: var(--glass); border: 1px solid var(--line); overflow: hidden; }
.pip-meter i { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: var(--text-2); transition: height .08s linear; }
.pip-meter b { position: absolute; left: -2px; right: -2px; bottom: 66.7%; height: 2px; background: var(--gold); }
.pip-meter.is-on i { background: var(--red); }
.app.no-preview .pip, .app[data-mode="intro"] .pip { display: none; }
.app[data-control="face"][data-trigger="hold"] .pip-meter { display: none; }

/* Brush-size readout while the off hand resizes. */
.size-hud { position: absolute; z-index: 12; left: 50%; top: 50%; transform: translate(-50%, -50%); display: grid; place-items: center; gap: 10px; min-width: 96px; min-height: 96px; padding: 14px;
  border-radius: 22px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); pointer-events: none; }
.size-hud i { display: block; border-radius: 50%; box-shadow: 0 0 0 1px rgba(255,255,255,.35); transition: width .06s, height .06s; }
.size-hud span { font: 700 13px var(--mono); color: var(--text-2); }

/* ── First-run hint ── */
.hint { position: absolute; z-index: 8; left: 50%; bottom: calc(var(--bottom) + 70px); transform: translateX(-50%); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center;
  width: max-content; max-width: calc(100vw - 24px); padding: 8px; border-radius: 18px; border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.hint span { display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; font-size: 13px; color: var(--text-2); }
.hint span b { font-weight: 500; color: inherit; }
.hint svg { width: 16px; height: 16px; color: var(--gold); }
.hint-ok { border: 0; background: var(--gold); color: #1b1606; font-weight: 700; font-size: 13px; padding: 7px 14px; border-radius: 12px; }
.app[data-mode="mouse"] .hint { display: none; }

/* ── Dock ── */
.dock { position: absolute; z-index: 10; left: 50%; bottom: var(--bottom); transform: translateX(-50%); display: flex; align-items: center; gap: 2px; padding: 6px;
  border-radius: 20px; border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); box-shadow: 0 14px 40px -14px rgba(0,0,0,.8); }
.app[data-mode="intro"] .dock { display: none; }
.dock-btn { width: 46px; height: 46px; border: 0; border-radius: 14px; background: transparent; display: grid; place-items: center; transition: background .15s; }
.dock-btn:hover:not(:disabled), .dock-btn[aria-expanded="true"] { background: rgba(255,255,255,.08); }
.dock-sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; }
.dock-save { color: var(--gold); }
/* Colour: a palette whose big blob is the current colour (small dots: the next ones a wink reaches).
   Size: a squiggle drawn at the current thickness. */
.dock-btn .ico-palette, .dock-btn .ico-size { width: 28px; height: 28px; }
.ico-palette path { stroke-width: 1.5; }
.ico-palette circle { stroke: rgba(0,0,0,.35); stroke-width: .6; }
.ico-size path { transition: stroke-width .12s; }
#fxBtn { position: relative; }
.fx-dot { position: absolute; top: 9px; right: 9px; width: 7px; height: 7px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 8px var(--gold); opacity: 0; transition: opacity .15s; }
#fxBtn.is-on { color: var(--gold); }
#fxBtn.is-on .fx-dot { opacity: 1; }
.app.is-replaying .dock { opacity: .5; }

.pop { position: absolute; z-index: 11; left: 50%; bottom: calc(var(--bottom) + 68px); transform: translateX(-50%); padding: 10px; border-radius: 18px; border: 1px solid var(--line);
  background: var(--glass-2); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); box-shadow: 0 14px 40px -14px rgba(0,0,0,.8); animation: pop-in .16s var(--ease); }
@keyframes pop-in { from { opacity: 0; transform: translate(-50%, 6px); } }
.colors { display: grid; grid-template-columns: repeat(6, 38px); gap: 8px; }
.colors button { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--c); box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
.colors button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--glass-2), 0 0 0 4px var(--text); }
.sizes { display: flex; gap: 6px; }
.sizes button { width: 46px; height: 46px; border-radius: 12px; border: 1px solid transparent; background: transparent; display: grid; place-items: center; }
.sizes button svg { width: 30px; height: 30px; }
.sizes button[aria-pressed="true"] { border-color: var(--line-2); background: rgba(255,255,255,.08); }
.pop-list { width: min(300px, calc(100vw - 24px)); padding: 6px; display: grid; gap: 2px; }
.pop-fx { width: min(340px, calc(100vw - 24px)); padding: 12px; display: grid; gap: 8px; }
.fx-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 30px; }
.fx-head b { font: 700 11px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--text-3); }
.fx-head i { font-style: normal; font-size: 12px; color: var(--text-3); }
.chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 6px; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span { display: block; text-align: center; padding: 9px 4px; border-radius: 11px; border: 1px solid var(--line); background: rgba(255,255,255,.04); font-size: 13.5px; font-weight: 500; color: var(--text-2); transition: background .15s, border-color .15s, color .15s; }
.chip:hover span { background: rgba(255,255,255,.08); }
.chip input:checked + span { color: #1b1606; background: var(--gold); border-color: var(--gold); font-weight: 700; box-shadow: 0 0 16px -4px rgba(232,197,71,.7); }
.chip input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }
.fx-note { margin: 2px 2px 0; min-height: 18px; font-size: 12.5px; color: var(--text-3); }
.seg-sm { padding: 2px; border-radius: 10px; }
.seg-sm span { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; white-space: nowrap; }
.pop-save { width: auto; min-width: 200px; }
.menu-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 14px; border: 0; border-radius: 12px; background: transparent; font-size: 14px; font-weight: 500; text-align: left; }
.menu-row:hover { background: rgba(255,255,255,.07); }
.menu-row svg { color: var(--gold); }

/* ── Intro ── */
.intro { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: calc(56px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom)); overflow-y: auto;
  background: radial-gradient(ellipse at 50% 0%, rgba(232,197,71,.12), transparent 60%), radial-gradient(ellipse at 100% 100%, rgba(71,184,232,.1), transparent 55%), var(--bg); }
.intro-back { position: absolute; top: var(--top); left: 16px; color: var(--text-2); text-decoration: none; font-size: 14px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 20px; }
.intro-back:hover { color: var(--text); }
.intro-card { width: min(720px, 100%); text-align: center; }
.intro-logo { font: 800 clamp(44px, 9vw, 76px)/1 var(--display); letter-spacing: -.03em; margin: 0; }
.intro-seg { max-width: 340px; margin: 0 auto 18px; }
.intro-seg span { padding: 10px 8px; font-size: 14px; }
.intro-sub { margin: 10px 0 28px; color: var(--text-2); font-size: 17px; }
.steps { list-style: none; padding: 0; margin: 0 0 34px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; text-align: left; }
.steps li { padding: 18px; border-radius: var(--r); border: 1px solid var(--line); background: rgba(255,255,255,.03); display: flex; flex-direction: column; gap: 6px; }
.steps b { font: 700 16px var(--display); }
.steps li > span:last-child { color: var(--text-2); font-size: 14px; }
.step-ico svg { width: 40px; height: 40px; stroke: var(--gold); stroke-width: 1.6; margin-bottom: 6px; }
.btn-primary { border: 0; background: var(--gold); color: #1b1606; font: 700 16px var(--ui); padding: 15px 30px; border-radius: 16px; min-width: 240px; transition: transform .1s, filter .15s; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: translateY(1px); }
.btn-link { display: block; margin: 16px auto 0; border: 0; background: none; color: var(--text-2); font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
.btn-link:hover { color: var(--text); }
.btn-secondary { width: 100%; border: 1px solid var(--line-2); background: transparent; color: var(--text); font-weight: 600; padding: 11px; border-radius: 12px; margin-top: 6px; }
.intro-loading { display: inline-flex; align-items: center; gap: 12px; color: var(--text-2); padding: 14px; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--gold); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.intro-error { color: #ffb4b4; background: rgba(255,107,107,.1); border: 1px solid rgba(255,107,107,.3); border-radius: 12px; padding: 10px 14px; margin: 14px auto 0; max-width: 460px; font-size: 14px; }
.intro-privacy { display: inline-flex; align-items: center; gap: 8px; margin-top: 28px; color: var(--text-3); font-size: 13px; }
.intro-privacy svg { width: 15px; height: 15px; }

/* ── Calibration ── */
.calib { position: absolute; inset: 0; z-index: 15; display: grid; place-content: center; justify-items: center; text-align: center; padding: 20px; background: rgba(8,8,10,.55); backdrop-filter: blur(2px); }
.calib-ring { position: relative; width: 120px; height: 120px; }
.calib-ring svg { width: 120px; height: 120px; transform: rotate(-90deg); }
.calib-ring .track { stroke: var(--line-2); stroke-width: 4; }
.calib-ring .prog { stroke: var(--gold); stroke-width: 4; stroke-dasharray: 327; stroke-dashoffset: 327; transition: stroke-dashoffset .1s linear; }
.calib-dot { position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 6px rgba(232,197,71,.2); }
.calib-title { font: 700 22px var(--display); margin: 18px 0 4px; }
.calib-sub { margin: 0; color: var(--text-2); }
.calib .btn-link { margin-top: 22px; }

/* ── Settings sheet ── */
dialog.sheet { width: min(440px, calc(100vw - 24px)); max-height: min(86dvh, 720px); padding: 0; border: 1px solid var(--line); border-radius: 20px; background: #16161c; color: var(--text); box-shadow: 0 30px 80px -20px #000; }
dialog.sheet::backdrop { background: rgba(0,0,0,.5); backdrop-filter: blur(2px); }
.sheet form { display: flex; flex-direction: column; max-height: inherit; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 16px 8px 20px; }
.sheet-head h2 { margin: 0; font: 700 19px var(--display); }
.sheet-head .icon-btn { background: transparent; border-color: transparent; }
.sheet-body { padding: 4px 20px 20px; overflow-y: auto; }
fieldset { border: 0; padding: 0; margin: 0 0 18px; display: grid; gap: 14px; }
legend { font: 700 11px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--text-3); margin-bottom: 10px; padding: 0; }
.range { display: grid; gap: 6px; font-size: 14px; }
.range input { width: 100%; accent-color: var(--gold); margin: 0; height: 24px; }
.range-ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-3); }
.range-ends i { font-style: normal; }
.field { display: grid; gap: 8px; font-size: 14px; }
.seg { display: flex; gap: 4px; padding: 3px; border-radius: 12px; background: rgba(255,255,255,.05); border: 1px solid var(--line); }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; text-align: center; padding: 8px 6px; border-radius: 9px; font-size: 13.5px; color: var(--text-2); }
.seg input:checked + span { background: rgba(255,255,255,.12); color: var(--text); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--gold); }
.switch { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px; cursor: pointer; }
.switch input { appearance: none; width: 42px; height: 24px; border-radius: 12px; background: rgba(255,255,255,.18); position: relative; margin: 0; flex-shrink: 0; cursor: pointer; transition: background .2s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s var(--ease); }
.switch input:checked { background: var(--gold); }
.switch input:checked::after { transform: translateX(18px); }
.sheet-note { margin: 16px 0 0; font-size: 12.5px; color: var(--text-3); line-height: 1.9; }

/* ── Toast ── */
.toast { position: absolute; z-index: 30; left: 50%; top: calc(var(--top) + 52px); transform: translate(-50%, -8px); opacity: 0; pointer-events: none; display: flex; align-items: center; gap: 12px;
  padding: 9px 9px 9px 16px; border-radius: 14px; background: var(--glass-2); border: 1px solid var(--line); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); font-size: 14px; font-weight: 500;
  transition: opacity .2s, transform .2s var(--ease); white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast:not(:has(button:not([hidden]))) { padding-right: 16px; }
.toast button { border: 0; background: var(--gold); color: #1b1606; font-weight: 700; font-size: 13px; padding: 6px 12px; border-radius: 10px; }

/* ── Phones ── */
@media (max-width: 640px) {
  .logo { display: none; }
  .status { font-size: 12.5px; padding: 0 10px; }
  .pip-video { width: 92px; aspect-ratio: 3 / 4; }
  .pip { top: calc(var(--top) + 50px); right: 10px; }
  .dock { gap: 0; padding: 5px; border-radius: 18px; }
  .dock-btn { width: 44px; height: 44px; }
  .dock-sep { margin: 0 2px; }
  .colors { grid-template-columns: repeat(6, 36px); gap: 8px; }
  .colors button { width: 36px; height: 36px; }
  .hint { bottom: calc(var(--bottom) + 66px); }
  .hint span { padding: 4px 8px; font-size: 12.5px; }
  .steps { grid-template-columns: 1fr; gap: 8px; margin-bottom: 26px; }
  .steps li { flex-direction: row; flex-wrap: wrap; align-items: center; column-gap: 12px; padding: 12px 14px; }
  .steps li > span:last-child { flex-basis: 100%; padding-left: 52px; margin-top: -8px; }
  .step-ico svg { width: 34px; height: 34px; margin: 0; }
  .intro-sub { margin-bottom: 24px; }
  .btn-primary { width: 100%; }
  dialog.sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 20px 20px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
}
@media (max-width: 360px) { .dock-btn { width: 40px; height: 42px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
@media (hover: none) and (pointer: coarse) { .sheet-note { display: none; } }
