:root {
  --bg: #fff; --ink: #1f2328; --muted: #6b7280; --line: #d9dde3; --panel: rgba(255,255,255,.96);
  --accent: #1e88e5; --shadow: 0 2px 10px rgba(0,0,0,.18);
}
@media (prefers-color-scheme: dark) { :root { --panel: rgba(38,40,44,.96); --ink: #eceff3; --line: #4a4f57; --muted: #9aa3ae; } }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #fff; font-family: Roboto, system-ui, sans-serif; color: var(--ink); overscroll-behavior: none; }
#board { position: fixed; inset: 0; width: 100vw; height: 100vh; touch-action: none; cursor: crosshair; display: block; }
#board.hand { cursor: grab; } #board.select { cursor: default; } #board.view { cursor: grab; }

#topleft { position: fixed; top: 10px; left: 12px; display: flex; gap: 10px; align-items: center; pointer-events: none; }
#boardname { font-family: 'Permanent Marker', cursive; font-size: 18px; color: #444; }
#status { font-size: 12px; color: var(--muted); }
#topright { position: fixed; top: 8px; right: 10px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; max-width: calc(100vw - 20px); }
.pill { font: 500 13px Roboto, sans-serif; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; box-shadow: var(--shadow); }
.pill:hover { border-color: var(--accent); }
.pill.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill[hidden] { display: none; }
.pill img { width: 18px; height: 18px; border-radius: 50%; vertical-align: -4px; margin-right: 6px; }

#toolbar { position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; align-items: center; gap: 4px; padding: 6px 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); max-width: calc(100vw - 16px); overflow-x: auto; }
#toolbar .sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; flex: none; }
#toolbar button { flex: none; width: 38px; height: 38px; border: 1px solid transparent; border-radius: 9px; background: none; color: var(--ink); cursor: pointer; display: grid; place-items: center; padding: 0; }
#toolbar button:hover { background: rgba(127,127,127,.15); }
#toolbar button.on { border-color: var(--accent); background: rgba(30,136,229,.14); }
#toolbar button:disabled { opacity: .35; cursor: default; }
#toolbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#toolbar .sw { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--line); }
#toolbar button.swb { width: 32px; height: 32px; }
#toolbar button.swb.on .sw { box-shadow: 0 0 0 2px var(--accent); }
#toolbar .dot { background: currentColor; border-radius: 50%; }
#toolbar input[type=color] { width: 28px; height: 28px; border: 0; padding: 0; background: none; cursor: pointer; flex: none; }
#toolbar.viewonly > :not(.keep) { display: none; }

#texted { position: fixed; display: none; margin: 0; padding: 0; border: 1px dashed var(--accent); outline: none; background: rgba(255,255,255,.6); resize: none; overflow: hidden; white-space: pre; font-family: 'Permanent Marker', cursive; min-width: 40px; }

#modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 10; }
#modal[hidden], #toast[hidden] { display: none; }
#modalbox { background: var(--panel); color: var(--ink); border-radius: 14px; padding: 20px; width: min(420px, calc(100vw - 24px)); max-height: 85vh; overflow: auto; box-shadow: 0 8px 30px rgba(0,0,0,.35); }
#modalbox h2 { margin: 0 0 6px; font-size: 18px; font-weight: 500; }
#modalbox p { margin: 6px 0 12px; color: var(--muted); font-size: 13px; }
#modalbox .row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
#modalbox input[type=text], #modalbox input[type=password], #modalbox input[type=email], #modalbox select { flex: 1; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--ink); font: inherit; min-width: 0; }
#modalbox .btn { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; font: inherit; }
#modalbox .btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
#modalbox .btn.wide { width: 100%; }
#modalbox hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
#modalbox .board { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; cursor: pointer; }
#modalbox .board:hover { background: rgba(127,127,127,.14); }
#modalbox .board.cur { outline: 1px solid var(--accent); }
#modalbox .board .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#modalbox .board .m { font-size: 12px; color: var(--muted); }
#modalbox .x { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 15px; }
#toast { position: fixed; top: 54px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 20; }

#imgbar { position: fixed; left: 50%; bottom: 74px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); font-size: 13px; }
#imgbar[hidden], #shapebar[hidden] { display: none; }
#imgbar input[type=range] { width: 110px; }

#people { position: fixed; top: 36px; left: 12px; display: flex; gap: 6px; flex-wrap: wrap; max-width: 60vw; pointer-events: none; }
#people .chip { font-size: 12px; padding: 3px 9px 3px 7px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); display: inline-flex; align-items: center; gap: 6px; }
#people .chip i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
#modalbox label.row input[type=checkbox] { width: 18px; height: 18px; flex: none; }

/* top-right: handwritten logo above the action buttons */
#topright { flex-direction: column; align-items: flex-end; gap: 6px; }
#actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
#logo { font-family: 'Permanent Marker', cursive; font-size: 28px; line-height: 1; text-decoration: none; transform: rotate(-0.7deg); transform-origin: right center; margin: 2px 4px 0 0; letter-spacing: .5px; text-shadow: 0 0 1px rgba(0,0,0,.25); }
#logo .cloud { color: #8a8f98; }
#logo .com { color: #111; }
@media (max-width: 560px) { #logo { font-size: 20px; } }

.tagrow { display: flex; flex-wrap: wrap; gap: 5px; margin: 4px 0; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: rgba(127,127,127,.18); color: var(--ink); white-space: nowrap; }
.tag.btn { cursor: pointer; font-size: 12px; border: 1px solid transparent; }
.tag.btn:hover { border-color: var(--accent); }
.tag.btn.on { background: var(--accent); color: #fff; }
#modalbox .board.edit { cursor: default; }
#modalbox .board.edit:hover { background: none; }

#cta { position: fixed; left: 12px; bottom: 14px; font-size: 12px; padding: 6px 12px; border-radius: 999px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow); text-decoration: none; z-index: 2; }
#cta[hidden] { display: none; }
#cta:hover { border-color: var(--accent); }
@media (max-width: 640px) { #cta { bottom: 70px; left: 50%; transform: translateX(-50%); white-space: nowrap; } }

#shapebar { position: fixed; left: 50%; bottom: 74px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); font-size: 13px; max-width: calc(100vw - 16px); flex-wrap: wrap; justify-content: center; }
#shapebar input[type=color] { width: 30px; height: 26px; border: 0; padding: 0; background: none; cursor: pointer; }
#shapebar .muted { color: var(--muted); }
#modalbox.wide { width: min(880px, calc(100vw - 24px)); }
#modalbox .tabs { display: flex; gap: 6px; margin: 4px 0 12px; flex-wrap: wrap; }
#modalbox .tab { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; font: inherit; }
#modalbox .tab.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#modalbox .lib h3 { margin: 14px 0 6px; font-size: 14px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
#modalbox .cells { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 6px; }
#modalbox .cell { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; border: 1px solid transparent; border-radius: 10px; background: #fff; color: #333; cursor: pointer; font: 11px Roboto, sans-serif; }
#modalbox .cell:hover { border-color: var(--accent); }
#modalbox .cards2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
#modalbox .card2 { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: transparent; color: var(--ink); cursor: pointer; text-align: left; font: inherit; }
#modalbox .card2:hover { border-color: var(--accent); }
#modalbox .card2 canvas { border: 1px solid var(--line); border-radius: 8px; background: #fff; max-width: 100%; }
#modalbox .card2 span { color: var(--muted); font-size: 12px; }
#modalbox textarea { width: 100%; font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--ink); resize: vertical; }
#modalbox pre.errs { color: #e53935; white-space: pre-wrap; margin: 6px 0; font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; }

#modalbox .board .desc { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#aibar { position: fixed; left: 50%; bottom: 128px; transform: translateX(-50%); width: min(700px, calc(100vw - 16px)); padding: 10px 12px; background: var(--panel); border: 1px solid var(--accent); border-radius: 14px; box-shadow: var(--shadow); z-index: 3; }
#aibar[hidden] { display: none; }
#aibar .airow { display: flex; gap: 8px; align-items: center; }
#aibar input { flex: 1; min-width: 0; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--ink); font: inherit; }
#aibar .aix { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 4px 6px; }
#aibar .aimsg { margin-top: 8px; font-size: 14px; min-height: 1.2em; white-space: pre-wrap; }
#aibar .aimsg.err { color: #e53935; }
#aibar .aiextra { margin-top: 6px; font-size: 13px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
#aibar .aiextra .pill { padding: 3px 10px; font-size: 12px; }
#aibar .aisug { width: 100%; }
#aibar .aimeta { margin-top: 6px; font-size: 11px; color: var(--muted); }

#modalbox .card2.static { cursor: default; }
#modalbox .card2.static:hover { border-color: var(--line); }
#modalbox .card2 .row { margin: 6px 0 0; }

#btnAi.locked { border-style: dashed; opacity: .9; }

/* ---- slides: editor strip + play mode ---- */
#slidebar { position: fixed; left: 50%; bottom: 74px; transform: translateX(-50%); width: min(980px, calc(100vw - 16px)); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 8px 10px; z-index: 6; }
#slidebar[hidden] { display: none; }
#slidebar .strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
#slidebar .slide { position: relative; flex: none; width: 150px; height: 84px; padding: 0; border: 2px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; overflow: hidden; }
#slidebar .slide.on { border-color: #8e24aa; }
#slidebar .slide canvas { width: 100%; height: 100%; display: block; }
#slidebar .slide .num { position: absolute; left: 4px; top: 3px; background: #8e24aa; color: #fff; border-radius: 5px; font: 500 11px Roboto, sans-serif; padding: 1px 6px; }
#slidebar .slide .ttl { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.55); color: #fff; font: 11px Roboto, sans-serif; padding: 2px 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
#slidebar .slide .cut { position: absolute; right: 4px; top: 3px; background: #222; color: #fff; border-radius: 5px; font: 10px Roboto, sans-serif; padding: 1px 5px; }
#slidebar .ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; }
#slidebar .ctl .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
#slidebar .ctl input[type=text] { width: 170px; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--ink); font: inherit; }
#slidebar .ctl select { padding: 5px 6px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--ink); font: inherit; }
#slidebar .ctl .btn:disabled { opacity: .35; }
#slidebar .muted { color: var(--muted, #888); }
body.playing #toolbar, body.playing #topleft, body.playing #topright, body.playing #people, body.playing #cta, body.playing #imgbar,
body.playing #shapebar, body.playing #aibar, body.playing #slidebar { display: none !important; }
#play { position: fixed; inset: 0; z-index: 40; cursor: default; touch-action: none; user-select: none; }
#play[hidden] { display: none; }
#play .hudtop, #play .side { opacity: 0; transition: opacity .25s; }
#play.hud .hudtop, #play.hud .side { opacity: 1; }
#play .hudtop { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: linear-gradient(rgba(0,0,0,.35), transparent); color: #fff; font: 500 14px Roboto, sans-serif; }
#play .grow { flex: 1; }
#play button { background: rgba(0,0,0,.55); color: #fff; border: 0; border-radius: 999px; cursor: pointer; font-size: 18px; width: 38px; height: 38px; }
#play .side { position: absolute; top: 50%; transform: translateY(-50%); font-size: 30px; line-height: 1; }
#play .side.left { left: 12px; } #play .side.right { right: 12px; }
@media (max-width: 700px) { #slidebar { bottom: 66px; } #slidebar .slide { width: 110px; height: 62px; } }
body.playing #toast { z-index: 60; }
#slidebar .btn { padding: 5px 11px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; font: inherit; }
#slidebar .btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
#slidebar .slide .zoomn { position: absolute; right: 4px; bottom: 3px; background: #8e24aa; color: #fff; border-radius: 5px; font: 500 10px Roboto, sans-serif; padding: 1px 5px; }
#slidebar .slide .ttl ~ .zoomn { bottom: 20px; }
#fontbar { position: fixed; z-index: 7; display: flex; gap: 4px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
#fontbar[hidden] { display: none; }
#fontbar .ffb { width: 40px; height: 34px; border: 1px solid transparent; border-radius: 8px; background: none; color: var(--ink); font-size: 18px; cursor: pointer; }
#fontbar .ffb:hover { background: rgba(127,127,127,.15); }
#fontbar .ffb.on { border-color: var(--accent); background: rgba(30,136,229,.14); }
body.playing #fontbar { display: none !important; }
