:root {
  --bg: #1d1f24; --panel: #262930; --panel2: #2e323a; --line: #3a3f49; --text: #e8eaee; --muted: #9aa1ad;
  --accent: #4f8cff; --danger: #e5484d; --stagebg: #5b606b;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 9px; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: #59606d; background: #353a44; }
button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: #fff; background: #7a2a2d; border-color: #93363a; }
input, select, textarea { background: #181a1f; border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px; }
textarea { width: 100%; resize: vertical; }
.muted { color: var(--muted); }

/* ---------- Stage ---------- */
.stage { position: relative; overflow: hidden; background: var(--stagebg); touch-action: none; user-select: none; }
.stage .world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.stage .base .page { position: absolute; background: #fff; box-shadow: 0 2px 14px rgba(0,0,0,.35); image-rendering: auto; }
.stage .col-title { position: absolute; color: #fff; font: 600 16px system-ui, sans-serif; text-align: center; opacity: .8; }
.mark .symbol { stroke: none; }
.toolbar select { padding: 2px 3px; }
.stage .hires { position: absolute; inset: 0; pointer-events: none; transition: opacity .15s; }
.stage .hires canvas { position: absolute; }
.stage .over { pointer-events: none; }
.stage .over svg { position: absolute; left: 0; top: 0; overflow: visible; }
.mark .shape { stroke: var(--c); fill-opacity: .22; stroke-width: 2.5px; vector-effect: non-scaling-stroke; transition: opacity .25s; }
.mark .shape[fill="none"] { stroke-width: 3px; }
.mark .pen { fill: none; stroke: var(--c); stroke-linecap: round; stroke-linejoin: round; opacity: .9; }
.mark.ghost { opacity: .28; }
.mark.ghost .shape { stroke-dasharray: 5 4; }
.mark.sel .shape { stroke-width: 3.5px; filter: drop-shadow(0 0 2px rgba(0,0,0,.45)); }
.mark .selshape { stroke-dasharray: 7 4; }
.labels { position: absolute; left: 0; top: 0; }
.label-anchor { position: absolute; width: 0; height: 0; transform: scale(var(--k)); transform-origin: 0 0; }
.label-anchor.ghost { opacity: .35; }
.label {
  position: absolute; left: 0; bottom: 2px; white-space: nowrap; color: #fff; font-weight: 600;
  font-size: max(11px, calc(var(--u, 10px) * 1.05)); padding: .1em .45em; border-radius: .3em; box-shadow: 0 1px 3px rgba(0,0,0,.35);
  text-shadow: 0 1px 1px rgba(0,0,0,.35);
}
.cards { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; gap: calc(var(--u) * 1.5);
  background: rgba(20, 22, 26, .55); padding: calc(var(--u) * 3); pointer-events: none; }
.cards.on { display: flex; }
.card { background: #fffdf8; color: #222; border-left: calc(var(--u) * .7) solid var(--c); border-radius: calc(var(--u) * .6);
  padding: calc(var(--u) * 2) calc(var(--u) * 3); max-width: 86%; max-height: 100%; overflow: hidden; box-shadow: 0 8px 40px rgba(0,0,0,.45);
  font-family: Georgia, "Times New Roman", serif; }
.card h2 { margin: 0 0 .5em; font-size: calc(var(--u) * 2.6); color: var(--c); font-family: system-ui, sans-serif; }
.card p { margin: .35em 0; font-size: calc(var(--u) * 2.05); line-height: 1.35; }
.card sup { color: var(--c); font-weight: 700; margin-right: .15em; font-family: system-ui, sans-serif; font-size: .6em; }
.blackout { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .4s; }
.blackout.on { opacity: 1; }
.stage-status { display: none; }

/* ---------- Publikum ---------- */
body.view { overflow: hidden; background: var(--stagebg); }
body.view #stage { position: fixed; inset: 0; }
body.view.idle, body.view.idle * { cursor: none !important; }
#hint { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.6); color: #fff; padding: 6px 12px;
  border-radius: 20px; font-size: 13px; transition: opacity .6s; pointer-events: none; }
body.idle #hint { opacity: 0; }
body.view.offline::after { content: ''; position: fixed; right: 8px; bottom: 8px; width: 8px; height: 8px; border-radius: 50%; background: #e5484d; opacity: .7; }

/* ---------- Login ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; }
.login-box { background: var(--panel); padding: 28px; border-radius: 12px; width: min(340px, 90vw); display: grid; gap: 12px; }
.login-box h1 { margin: 0; font-size: 22px; }
.login-box p { margin: 0; color: var(--muted); }
.login-box input { padding: 9px; }
.login-box button { padding: 9px; background: var(--accent); border-color: var(--accent); color: #fff; }
.login .err { color: var(--danger); min-height: 1em; }

/* ---------- Redner ---------- */
body.presenter { display: flex; flex-direction: column; overflow: hidden; font-size: 14px; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; }
.status { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); display: inline-block; }
.dot.ok { background: #30a46c; }
.spacer { flex: 1; }
#btnBlackout.active { background: #000; color: #fff; border-color: #fff; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel2); }
.menu summary::-webkit-details-marker { display: none; }
.menu-body { position: absolute; right: 0; top: 34px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px;
  width: 330px; display: grid; gap: 8px; z-index: 20; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.menu-body a { color: var(--accent); }
.menu-body hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 2px 0; }
.filebtn { cursor: pointer; color: var(--accent); }
.help { color: var(--muted); font-size: 12px; line-height: 1.5; }

.layout { flex: 1; display: grid; grid-template-columns: 1fr 400px; min-height: 0; }
.editor-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; gap: 5px; align-items: center; padding: 6px 8px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 3px; }
.toolbar input[type=number] { width: 48px; }
.toolbar .jump { display: inline-flex; gap: 4px; }
.toolbar .target { margin-left: auto; font-size: 13px; }
.editor { flex: 1; min-height: 0; cursor: default; }
.editor[data-tool=rect], .editor[data-tool=ellipse], .editor[data-tool=note], .editor[data-tool=pen], .editor[data-tool=frame], .editor[data-tool=breath] { cursor: crosshair; }
.editor[data-tool=pan], .editor.panning { cursor: grab; }
.ui .liveframe { fill: none; stroke: #ff3b30; vector-effect: none; }
.ui .liveframe-label { fill: #ff3b30; font-weight: 700; font-family: system-ui, sans-serif; }
.ui .handle { fill: #fff; stroke: #4f8cff; }
.ui .draft { fill: rgba(79,140,255,.15); stroke: #4f8cff; }
.ui .draft.frame { fill: rgba(255,59,48,.08); stroke: #ff3b30; }
.ui .draft.pen { fill: none; stroke: #4f8cff; stroke-linecap: round; stroke-linejoin: round; }

.side { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 1px solid var(--line); }
.preview-box { padding: 8px; border-bottom: 1px solid var(--line); display: grid; gap: 6px; }
.preview-head { font-size: 13px; display: flex; justify-content: space-between; color: var(--muted); }
.preview-head b { color: var(--text); }
.preview-outer { width: 100%; display: flex; justify-content: center; }
.preview { border: 2px solid #ff3b30; border-radius: 4px; }
.cam-ctrl { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.cam-ctrl select { flex: 1; min-width: 0; }
.cam-ctrl input { width: 46px; }
.tree-head { display: flex; justify-content: space-between; align-items: center; padding: 8px; border-bottom: 1px solid var(--line); }
.tree { flex: 1; overflow-y: auto; padding: 4px 6px 40px; }

.sec { margin: 6px 0 10px; }
.sec-head { display: flex; align-items: center; gap: 6px; padding: 5px 4px; cursor: pointer; border-radius: 6px; background: #30343d; }
.sec-title { font-weight: 700; flex: 1; }
.caret { color: var(--muted); width: 10px; }
.cat { margin: 4px 0 6px 10px; border-left: 2px solid var(--line); padding-left: 6px; }
.cat-head { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.cat-name { flex: 1; font-weight: 600; cursor: text; }
.count { color: var(--muted); font-size: 12px; }
.note { color: var(--muted); font-style: italic; font-size: 12px; margin: 0 0 3px 30px; }
.swatch { width: 24px; height: 22px; padding: 0; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; background: none; }
.mini { padding: 1px 7px; font-size: 12px; }
.eye { width: 30px; padding: 2px 0; text-align: center; font-size: 13px; }
.eye.on { background: #2b5ab8; border-color: #3d6fd6; }
.eye.some { background: #3a4660; }
.eye.empty { opacity: .45; }
.pt { margin: 2px 0 2px 6px; border-radius: 6px; }
.pt-row { display: flex; align-items: center; gap: 7px; padding: 3px 4px; border-radius: 6px; cursor: pointer; }
.pt-row:hover { background: #30343d; }
.pt.sel > .pt-row { background: #34405a; }
.pt-name { flex: 1; }
.pt.vis .pt-name { font-weight: 600; }
.dot { flex: none; }
.pt .dot { width: 11px; height: 11px; border-radius: 3px; }
.tag { font-size: 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 6px; }
.detail { background: #20232a; border: 1px solid var(--line); border-radius: 6px; margin: 4px 0 8px; padding: 8px; display: grid; gap: 7px; font-size: 13px; }
.detail .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.detail .row input { width: 46px; }
.detail label input:not([type]) { width: 220px; }
.detail .block { display: grid; gap: 3px; }
.detail .hint { color: var(--muted); font-size: 12px; }
.popmenu { position: fixed; z-index: 40; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px; display: grid; width: 180px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.popmenu button { border: 0; background: none; text-align: left; }
.popmenu button:hover { background: var(--panel2); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(20px); background: #111; color: #fff; padding: 8px 14px; border-radius: 8px;
  opacity: 0; transition: all .25s; pointer-events: none; z-index: 60; }
.toast.on { opacity: 1; transform: translateX(-50%); }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 55% 45%; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
}
