:root {
  --accent: #2563eb; --accent-soft: #dbeafe; --ink: #111827; --muted: #6b7280;
  --line: #e5e7eb; --panel: #ffffff; --shadow: 0 2px 10px rgba(15, 23, 42, .12);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #fff; color: var(--ink);
  font: 14px/1.35 "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-user-select: none; user-select: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

#top { position: fixed; inset: 0 0 auto 0; height: 46px; z-index: 30; display: flex; align-items: center; gap: 8px;
  padding: 0 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; letter-spacing: .2px; color: var(--accent); margin-right: 4px; white-space: nowrap; }
.spacer { flex: 1; }
.pill { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px; }
.pill:hover { background: #f3f4f6; }
.pill.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill.primary:hover { background: #1d4ed8; }
.pill.on { background: var(--accent-soft); border-color: #93c5fd; }
.icon-btn { width: 34px; height: 34px; border: 1px solid transparent; background: transparent; border-radius: 8px; font-size: 17px;
  display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.icon-btn:hover { background: #f3f4f6; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.wide { width: 52px; font-size: 13px; }

#tabs { display: flex; gap: 4px; overflow-x: auto; max-width: 52vw; padding: 4px 2px; scrollbar-width: thin; }
.tab { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #f9fafb; border-radius: 8px;
  padding: 4px 10px; white-space: nowrap; max-width: 180px; }
.tab:hover { background: #f1f5f9; }
.tab.active { background: var(--accent-soft); border-color: #93c5fd; font-weight: 600; }
.tab .lbl { overflow: hidden; text-overflow: ellipsis; }
.tab .x { border: 0; background: none; color: var(--muted); padding: 0 2px; border-radius: 4px; line-height: 1; font-size: 15px; }
.tab .x:hover { background: #fee2e2; color: #b91c1c; }
.tab input { width: 110px; font: inherit; border: 1px solid var(--accent); border-radius: 4px; padding: 1px 4px; user-select: text; -webkit-user-select: text; }

#users { display: flex; }
.avatar { width: 28px; height: 28px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center;
  border: 2px solid #fff; margin-left: -6px; }
.avatar:first-child { margin-left: 0; }
.avatar.me { outline: 2px solid var(--accent); }

.menu-wrap { position: relative; }
#menu { position: absolute; right: 0; top: 40px; min-width: 220px; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px; z-index: 50; }
#menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; }
#menu button:hover { background: #f3f4f6; }
#menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

body.student .tutor-only { display: none !important; }
body.tutor .student-only { display: none !important; }

#toolbar { position: fixed; left: 10px; top: 58px; z-index: 20; display: flex; flex-direction: column; flex-wrap: wrap; gap: 2px;
  max-height: calc(100vh - 150px); padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.tool { position: relative; width: 40px; height: 40px; border: 0; background: transparent; border-radius: 8px; display: grid; place-items: center; color: #374151; }
.tool:hover { background: #f3f4f6; }
.tool.active { background: var(--accent-soft); color: var(--accent); }
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tool .k { position: absolute; right: 3px; bottom: 1px; font-size: 9px; color: var(--muted); }
.tool-sep { width: 100%; height: 1px; background: var(--line); margin: 3px 0; flex-basis: 100%; }
body.noedit .tool[data-edit] { opacity: .35; pointer-events: none; }

#stage { position: fixed; inset: 46px 0 0 0; }
#svg { width: 100%; height: 100%; display: block; touch-action: none; background: #fff; }
#svg.t-pen, #svg.t-line, #svg.t-arrow, #svg.t-rect, #svg.t-ellipse, #svg.t-triangle, #svg.t-axes { cursor: crosshair; }
#svg.t-text, #svg.t-math { cursor: text; }
#svg.t-eraser { cursor: cell; }
#svg.t-pan { cursor: grab; } #svg.grabbing { cursor: grabbing; }
#objs, #live, #overlay { pointer-events: none; }

#cursors { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.rcursor { position: absolute; left: 0; top: 0; transition: transform .06s linear; will-change: transform; }
.rcursor svg { width: 18px; height: 18px; display: block; }
.rcursor span { position: absolute; left: 14px; top: 14px; color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 6px; white-space: nowrap; }

#selbar { position: absolute; z-index: 15; display: flex; gap: 2px; padding: 3px; background: #1f2937; border-radius: 9px; box-shadow: var(--shadow); transform: translate(-50%, -100%); }
#selbar button { border: 0; background: none; color: #f9fafb; padding: 5px 9px; border-radius: 6px; font-size: 13px; }
#selbar button:hover { background: #374151; }
#selbar button.danger:hover { background: #b91c1c; }

#props { position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 20; display: flex; flex-wrap: wrap; justify-content: center;
  align-items: center; gap: 6px 14px; padding: 6px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); max-width: calc(100vw - 420px); min-width: 120px; }
#props:empty { display: none; }
#props .row { display: flex; align-items: center; gap: 5px; }
#props .row > label { color: var(--muted); font-size: 12px; margin-right: 2px; }
.sw { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #d1d5db; padding: 0; }
.sw.on { box-shadow: 0 0 0 2px var(--accent); }
input[type=color] { width: 26px; height: 26px; padding: 0; border: 0; background: none; }
.wd { width: 30px; height: 30px; border: 1px solid transparent; border-radius: 8px; background: none; display: grid; place-items: center; padding: 0; }
.wd i { display: block; background: #374151; border-radius: 50%; }
.wd.on { background: var(--accent-soft); border-color: #93c5fd; }
.tg { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 3px 10px; font-size: 13px; }
.tg.on { background: var(--accent-soft); border-color: #93c5fd; color: var(--accent); }
#props input[type=range] { width: 90px; }
#props select { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 3px 6px; background: #fff; }

#corner { position: fixed; right: 10px; bottom: 12px; z-index: 20; display: flex; align-items: center; gap: 2px; padding: 3px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
#corner .sep { width: 1px; height: 22px; background: var(--line); margin: 0 3px; }

#editor { position: fixed; z-index: 40; width: min(460px, calc(100vw - 20px)); background: #fff; border: 1px solid #cbd5e1; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .25); padding: 10px; user-select: text; -webkit-user-select: text; }
.ed-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.hint { color: var(--muted); font-size: 11px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 3px 12px; }
.seg button.on { background: var(--accent); color: #fff; }
#edInput { width: 100%; resize: vertical; min-height: 44px; max-height: 40vh; border: 1px solid #cbd5e1; border-radius: 8px; padding: 8px;
  font: 15px/1.4 ui-monospace, "Cascadia Code", Consolas, monospace; user-select: text; -webkit-user-select: text; }
#edInput:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
#edPreview { min-height: 52px; max-height: 30vh; overflow: auto; margin-top: 8px; padding: 6px 10px; background: #f9fafb; border: 1px dashed var(--line); border-radius: 8px;
  display: flex; align-items: center; }
#edPreview .err { color: #b91c1c; font-size: 12px; font-family: ui-monospace, Consolas, monospace; white-space: pre-wrap; }
#edPreview .empty { color: var(--muted); font-size: 12px; }
#edPal { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 8px; max-height: 120px; overflow: auto; }
#edPal button { min-width: 34px; height: 30px; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 0 6px; font-size: 14px; }
#edPal button:hover { background: var(--accent-soft); }
.ed-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

#modalBack { position: fixed; inset: 0; z-index: 100; background: rgba(15, 23, 42, .4); display: grid; place-items: center; }
#modal { background: #fff; border-radius: 14px; padding: 18px 20px; width: min(460px, calc(100vw - 24px)); box-shadow: 0 20px 50px rgba(0, 0, 0, .3); user-select: text; -webkit-user-select: text; }
#modal h3 { margin: 0 0 8px; font-size: 17px; }
#modal p { margin: 6px 0; color: #374151; }
#modal .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
#modal .url { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
#modal .url code { flex: 1; background: #f3f4f6; border-radius: 8px; padding: 7px 10px; font-size: 14px; overflow-x: auto; }
#modal small { color: var(--muted); display: block; margin-top: 8px; }

#banner { position: fixed; top: 54px; left: 50%; transform: translateX(-50%); z-index: 60; padding: 6px 14px; border-radius: 999px; background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; box-shadow: var(--shadow); }
#banner.bad { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
#toast { position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%); z-index: 90; background: #111827; color: #fff; padding: 8px 16px; border-radius: 10px; box-shadow: var(--shadow); }

@media (max-width: 900px) {
  #props { max-width: calc(100vw - 20px); bottom: 62px; }
  #corner { left: 50%; right: auto; transform: translateX(-50%); }
  #tabs { max-width: 40vw; }
  .brand, #inviteBtn { display: none; }
}
