:root {
  --ink: #23303a;
  --bar: #2f4858;
  --bar-ink: #f4f1ea;
  --paper: #fbfaf7;
  --accent: #e0a458;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--paper); overflow: hidden; overscroll-behavior: none; }
body { display: flex; flex-direction: column; height: 100dvh; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

#top {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 8px; padding-top: max(4px, env(safe-area-inset-top));
  background: var(--bar); color: var(--bar-ink); min-height: 48px;
}
.nav { font-size: 28px; line-height: 1; width: 44px; height: 40px; border-radius: 8px; }
.nav:active, .chip:active, .tool:active { background: rgba(255,255,255,.15); }
.title { font-size: 19px; font-weight: 600; padding: 6px 8px; border-radius: 8px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { border: 1px solid rgba(255,255,255,.4); border-radius: 999px; padding: 4px 12px; font-size: 14px; margin-left: 4px; }
.status { margin-left: auto; font-size: 12px; opacity: .85; white-space: nowrap; }
.status::before { content: "●"; margin-right: 5px; color: #8fd18f; }
.status.pending::before { color: var(--accent); }
.status.offline::before { color: #e07a5f; }
.status.demo::before { color: #9ecbf0; }

#stage { position: relative; flex: 1; min-height: 0; touch-action: none; overflow-x: hidden; overflow-y: auto;
  overscroll-behavior: contain; scrollbar-width: thin; }
#pane { position: sticky; top: 0; height: 100%; z-index: 1; }
#pane canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#sizer { position: absolute; top: 0; left: 0; width: 1px; pointer-events: none; }
#tools.viewonly [data-tool], #tools.viewonly .sep { display: none; }
#live { touch-action: none; }
#live.number { cursor: pointer; }

#tools {
  display: flex; align-items: center; gap: 6px; justify-content: center;
  padding: 6px 8px; padding-bottom: max(6px, env(safe-area-inset-bottom));
  background: #ece8df; border-top: 1px solid #d9d3c6;
}
.sep { width: 1px; height: 28px; background: #d3ccbd; margin: 0 6px; }
.tool { position: relative; width: 48px; height: 44px; border-radius: 10px; font-size: 22px; display: grid; place-items: center; }
.tool.on { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.18); }
.tool:disabled { opacity: .3; }
#penDot { position: absolute; right: 5px; bottom: 5px; border-radius: 50%; border: 1px solid rgba(255,255,255,.8); }

.popover {
  position: fixed; bottom: calc(66px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  width: min(340px, calc(100vw - 16px));
  background: #fff; border-radius: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.25);
  padding: 12px; z-index: 5; display: grid; gap: 10px;
  max-height: calc(100dvh - 140px); overflow-y: auto;
}
.popover[hidden] { display: none; }
.swatches { display: grid; grid-template-columns: repeat(5, 40px); gap: 8px 12px; justify-content: center; }
.swatch.empty { border: 2px dashed #d3ccbd; background: none; cursor: default; }
.linkbtn { justify-self: center; font-size: 14px; font-weight: 600; color: var(--bar); padding: 6px 12px; border-radius: 8px; }
.linkbtn:hover { background: #f1eee7; }
#wheelBox { display: grid; gap: 10px; }
#wheelBox[hidden] { display: none; }
.swatch { aspect-ratio: 1; border-radius: 50%; border: 2px solid transparent; }
.swatch.on { border-color: #fff; box-shadow: 0 0 0 2px var(--ink); }
#wheel { width: 200px; height: 200px; justify-self: center; touch-action: none; cursor: crosshair; }
.row { display: grid; grid-template-columns: 76px 1fr 60px; align-items: center; gap: 8px; font-size: 14px; }
.row b { font-weight: 500; font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.row input[type=range] { width: 100%; }
#preview { width: 100%; height: 56px; border-radius: 8px; background: #fbfaf7; }
#emojiIn { font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid #cfc8b9; border-radius: 10px; width: 100%; }
.sticker-pop { width: min(380px, calc(100vw - 16px)); padding: 6px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: #f1eee7; border-radius: 10px; padding: 3px; }
.tabs button { padding: 8px; border-radius: 8px; font-size: 14px; font-weight: 600; color: #6b7178; }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.sticker-lib { height: min(380px, 55dvh); overflow-y: auto; padding: 0 4px 6px; }
.sticker-lib[hidden], #pickerHost[hidden] { display: none; }
.sticker-lib h3 { font-size: 12px; font-weight: 600; color: #6b7178; margin: 12px 4px 6px; }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.sticker-grid button { aspect-ratio: 1; border-radius: 12px; padding: 6px; }
.sticker-grid button:active { background: #f1eee7; }
.sticker-grid img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.sticker-lib .empty { font-size: 14px; line-height: 1.5; color: #4a545c; padding: 12px 6px; }
.sticker-lib code { background: #f1eee7; padding: 1px 5px; border-radius: 4px; font-size: 12px; overflow-wrap: anywhere; }
#stickerBtn img { width: 30px; height: 30px; object-fit: contain; }
emoji-picker { width: 100%; height: min(380px, 55dvh); --num-columns: 8; --emoji-size: 1.55rem;
  --border-size: 0; --background: #fff; --input-border-radius: 10px; --input-font-size: 16px; }

.menu-btn { font-size: 22px; margin-left: 2px; }
.menu { position: fixed; top: calc(52px + env(safe-area-inset-top)); right: 8px; z-index: 6; width: min(300px, calc(100vw - 16px));
  background: #fff; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.25); padding: 6px; }
.menu[hidden] { display: none; }
.menu button { display: block; width: 100%; text-align: left; padding: 12px; border-radius: 8px; font-weight: 600; }
.menu button:hover:not(:disabled), .menu button:active:not(:disabled) { background: #f1eee7; }
.menu button:disabled { color: #a4a8ad; cursor: default; }
.menu hr { border: 0; border-top: 1px solid #ece8df; margin: 4px 8px; }
.menu small { display: block; font-weight: 400; font-size: 12px; color: #6b7178; margin-top: 2px; }
.menu a { display: block; padding: 12px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 600; }
.menu a:active, .menu a:hover { background: #f1eee7; }
.menu p { margin: 0 12px 10px; font-size: 13px; line-height: 1.4; color: #6b7178; }
.gate { position: fixed; inset: 0; background: rgba(47,72,88,.92); display: grid; place-items: center; z-index: 10; padding: 24px; }
.gate[hidden] { display: none; }
.card { background: var(--paper); border-radius: 16px; padding: 24px; max-width: 420px; line-height: 1.45; }
.card h1 { margin-top: 0; }

@media (max-width: 640px) {
  .title { font-size: 17px; }
  .chip { padding: 3px 9px; }
  .status span { display: none; }
}

#toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #23303a; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; opacity: 0;
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 20; white-space: nowrap; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
@media (max-width: 480px) {
  .status { font-size: 0; }                 /* only the coloured dot on phones */
  .status::before { font-size: 12px; margin-right: 0; }
  .chip { margin-left: 0; }
}

.dialog { position: fixed; inset: 0; background: rgba(35,48,58,.45); display: grid; place-items: center; z-index: 15; padding: 16px; }
.dialog[hidden] { display: none; }
.dialog .card { position: relative; width: min(380px, 100%); background: #fff; border-radius: 16px; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.dialog h2 { margin: 0 0 14px; font-size: 19px; }
.dialog label { display: block; font-size: 13px; color: #6b7178; margin-bottom: 6px; }
.dialog input { font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid #cfc8b9; border-radius: 10px; width: 100%; min-width: 0; }
.dialog .inrow { display: flex; gap: 8px; margin-top: 10px; }
.dialog form .inrow { margin-top: 0; }
.dialog .inrow button { flex: none; padding: 10px 14px; border-radius: 10px; font-weight: 600; background: #f1eee7; }
.dialog .inrow button.primary { background: var(--bar); color: #fff; }
.dialog #inviteResult .inrow button { flex: 1; }
.dialog .note { font-size: 13px; line-height: 1.45; color: #4a545c; margin: 10px 0; }
.dialog .note.err { color: #c0392b; }
#inviteQr { display: grid; place-items: center; margin-top: 16px; }
#inviteQr svg { width: 200px; height: 200px; }
.dialog .close { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border-radius: 50%; font-size: 16px; color: #6b7178; }
.dialog .close:hover { background: #f1eee7; }

.selbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(68px + env(safe-area-inset-bottom)); z-index: 4;
  display: grid; grid-template-columns: auto minmax(100px, 200px) 44px; align-items: center; gap: 10px;
  background: #fff; border-radius: 999px; padding: 8px 16px; box-shadow: 0 4px 16px rgba(0,0,0,.2); font-size: 13px; }
.selbar[hidden] { display: none; }
.selbar b { font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; }
#penArea { height: 140px; border: 2px dashed #cfc8b9; border-radius: 12px; background: #fbfaf7; touch-action: none; }
#penLog { font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; color: #23303a; max-height: 220px; overflow: hidden; }
#penVerdict { font-weight: 600; color: #2e8b57; min-height: 1em; }

.add-image { display: flex; align-items: center; gap: 10px; width: calc(100% - 8px); margin: 6px 4px 2px; padding: 12px; border-radius: 12px;
  border: 2px dashed #cfc8b9; color: #4a545c; font-weight: 600; font-size: 14px; }
.add-image span { font-size: 20px; line-height: 1; }
.add-image:hover, .add-image:active { background: #f7f4ee; }
