/* LightBoard — Material Design 3 blue theme, shared by Web / Windows / Android */
:root {
  --primary: #1565C0;
  --primary-light: #64B5F6;
  --primary-container: #D7E3FF;
  --on-primary: #FFFFFF;
  --on-primary-container: #0B3D91;
  --surface: #F7F9FC;
  --surface-2: #FFFFFF;
  --surface-variant: #EDF2FA;
  --on-surface: #1A2233;
  --on-surface-dim: #5B6B82;
  --outline: #C7D4E8;
  --error: #B3261E;
  --success: #2E7D32;
  --shadow: 0 4px 16px rgba(21, 101, 192, .12), 0 1px 3px rgba(21, 101, 192, .10);
  --shadow-lg: 0 12px 32px rgba(21, 101, 192, .18);
  --r-sm: 4px; --r-md: 8px; --r-lg: 12px; --r-xl: 16px;
  --font: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--surface); color: var(--on-surface); font-family: var(--font); font-size: 14px; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.lb-app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; width: 100vw; overflow: hidden; }

/* Top bar */
.lb-topbar { height: 60px; flex: 0 0 60px; display: flex; align-items: center; gap: 12px; padding: 0 14px; background: linear-gradient(100deg, #0D47A1, #1565C0 55%, #1976D2); color: #FFF; box-shadow: var(--shadow); z-index: 30; }
.lb-brand { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.lb-logo { width: 34px; height: 34px; border-radius: var(--r-sm); }
.lb-brand-name { font-size: 17px; font-weight: 700; letter-spacing: .3px; }
.lb-title-input { flex: 1 1 200px; min-width: 90px; max-width: 340px; height: 36px; border: 1px solid rgba(255,255,255,.3); border-radius: var(--r-md); padding: 0 12px; background: rgba(255,255,255,.14); color: #FFF; outline: none; }
.lb-title-input:focus { background: rgba(255,255,255,.24); border-color: #FFF; }
.lb-top-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.lb-btn { height: 36px; padding: 0 12px; border: 1px solid transparent; border-radius: var(--r-md); background: rgba(255,255,255,.16); color: #FFF; font-weight: 600; transition: background .16s, transform .08s, box-shadow .16s; white-space: nowrap; }
.lb-btn:hover { background: rgba(255,255,255,.28); }
.lb-btn:active { transform: scale(.96); }
.lb-btn:disabled { opacity: .45; cursor: not-allowed; }
.lb-btn:focus-visible { outline: 2px solid #FFF; outline-offset: 2px; }
.lb-btn-primary { background: #FFF; color: var(--primary); box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.lb-btn-primary:hover { background: var(--primary-container); }
.lb-btn-icon { width: 36px; padding: 0; font-size: 17px; display: inline-grid; place-items: center; }
.lb-btn-block { width: 100%; }
.lb-exit { background: rgba(0,0,0,.18); }
.lb-select { height: 36px; border-radius: var(--r-md); border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.16); color: #FFF; padding: 0 6px; }
.lb-select option { color: var(--on-surface); }
.lb-menu-wrap { position: relative; }
.lb-menu { position: absolute; right: 0; top: 42px; background: var(--surface-2); color: var(--on-surface); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); padding: 6px; min-width: 150px; z-index: 50; }
.lb-menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; color: inherit; padding: 9px 12px; border-radius: var(--r-sm); }
.lb-menu button:hover { background: var(--surface-variant); }

/* Main layout */
.lb-main { flex: 1 1 auto; display: flex; min-height: 0; position: relative; }
.lb-toolrail { width: 62px; flex: 0 0 62px; padding: 10px 6px; display: flex; flex-direction: column; align-items: center; gap: 6px; background: var(--surface-2); border-right: 1px solid var(--outline); overflow-y: auto; scrollbar-width: thin; z-index: 20; }
.lb-toolgroup { display: flex; flex-direction: column; gap: 6px; }
.lb-divider { width: 34px; height: 1px; background: var(--outline); margin: 3px 0; }
.lb-tool { width: 46px; height: 46px; border-radius: var(--r-md); border: 1px solid transparent; background: var(--surface-variant); color: var(--on-surface); display: grid; place-items: center; font-size: 18px; line-height: 1; position: relative; transition: background .14s, transform .08s; }
.lb-tool span { font-size: 9px; position: absolute; bottom: 2px; left: 0; right: 0; text-align: center; color: var(--on-surface-dim); }
.lb-tool:hover { background: var(--primary-container); }
.lb-tool:active { transform: scale(.92); }
.lb-tool.active { background: var(--primary); color: #FFF; box-shadow: 0 3px 10px rgba(21,101,192,.35); }
.lb-tool.active span { color: #FFF; }
.lb-tool-more { margin-top: auto; }

.lb-board-wrap { flex: 1 1 auto; position: relative; overflow: hidden; background: #FFF; min-width: 0; }
.lb-canvas { position: absolute; inset: 0; touch-action: none; display: block; }
.lb-board-overlay { position: absolute; inset: 0; pointer-events: none; }
.lb-board-overlay > * { pointer-events: auto; }
.lb-style-bar { position: absolute; left: 12px; top: 12px; display: flex; align-items: center; gap: 14px; padding: 8px 12px; background: rgba(255,255,255,.94); border: 1px solid var(--outline); border-radius: var(--r-lg); box-shadow: var(--shadow); z-index: 12; flex-wrap: wrap; }
.lb-style-bar label { display: flex; align-items: center; gap: 5px; color: var(--on-surface-dim); font-size: 12px; }
.lb-style-bar input[type="color"] { width: 30px; height: 26px; border: 0; border-radius: var(--r-sm); padding: 0; background: transparent; }
.lb-style-bar input[type="range"] { width: 90px; accent-color: var(--primary); }
.lb-switch { cursor: pointer; }
.lb-switch input { accent-color: var(--primary); }
.lb-inline-text { position: absolute; z-index: 14; min-width: 120px; min-height: 40px; border: 2px dashed var(--primary); border-radius: var(--r-sm); background: rgba(255,255,255,.92); padding: 4px; outline: none; resize: both; }

.lb-side { width: 196px; flex: 0 0 196px; background: var(--surface-2); border-left: 1px solid var(--outline); display: flex; flex-direction: column; min-height: 0; z-index: 20; }
.lb-side-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px; font-weight: 700; border-bottom: 1px solid var(--outline); font-size: 12px; color: var(--on-surface-dim); }
.lb-side-head .lb-btn { width: 28px; height: 28px; background: var(--surface-variant); color: var(--on-surface); }
.lb-page-list, .lb-bookmarks { flex: 1 1 auto; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.lb-bookmarks { flex: 0 0 88px; flex-direction: row; flex-wrap: wrap; align-content: flex-start; }
.lb-page-thumb { border: 2px solid transparent; border-radius: var(--r-lg); background: var(--surface-variant); padding: 5px; position: relative; cursor: pointer; }
.lb-page-thumb canvas { width: 100%; height: auto; display: block; border-radius: var(--r-sm); background: #FFF; }
.lb-page-thumb.active { border-color: var(--primary); box-shadow: var(--shadow); }
.lb-page-thumb small { display: block; text-align: center; color: var(--on-surface-dim); font-size: 10px; margin-top: 3px; }
.lb-bookmark-chip { padding: 6px 9px; background: var(--primary-container); color: var(--on-primary-container); border-radius: var(--r-sm); font-size: 11px; cursor: pointer; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-side-bottom { padding: 8px; display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--outline); }
.lb-side-bottom .lb-btn { background: var(--surface-variant); color: var(--on-surface); font-size: 12px; }
.lb-side-bottom .lb-btn:hover { background: var(--primary-container); }

.lb-statusbar { height: 28px; flex: 0 0 28px; display: flex; align-items: center; gap: 16px; padding: 0 12px; background: var(--surface-variant); border-top: 1px solid var(--outline); color: var(--on-surface-dim); font-size: 11px; z-index: 25; }
.lb-statusbar span:last-child { margin-left: auto; }
.lb-status-dot.online { color: var(--success); font-weight: 700; }
.lb-status-dot.offline { color: var(--error); font-weight: 700; }

/* Dialogs */
.lb-dialog { width: min(560px, 94vw); max-height: 88vh; border: 0; border-radius: var(--r-xl); padding: 0; background: var(--surface-2); color: var(--on-surface); box-shadow: var(--shadow-lg); overflow: hidden; }
.lb-dialog::backdrop { background: rgba(26,34,51,.42); backdrop-filter: blur(3px); }
.lb-dialog form { display: flex; flex-direction: column; max-height: 88vh; }
.lb-dialog header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; background: var(--primary-container); color: var(--on-primary-container); }
.lb-dialog header h3 { margin: 0; font-size: 16px; }
.lb-dialog header .lb-btn { background: rgba(11,61,145,.12); color: var(--on-primary-container); }
.lb-dialog-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.lb-dialog footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--outline); }
.lb-dialog .lb-btn { background: var(--surface-variant); color: var(--on-surface); }
.lb-dialog .lb-btn-primary { background: var(--primary); color: #FFF; }
.lb-input { width: 100%; height: 38px; border: 1px solid var(--outline); border-radius: var(--r-md); padding: 0 10px; outline: none; background: var(--surface-2); }
.lb-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(21,101,192,.12); }
.lb-field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.lb-field-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--on-surface-dim); }
.lb-field-grid input { height: 34px; border: 1px solid var(--outline); border-radius: var(--r-md); padding: 0 8px; }
.lb-hint { color: var(--on-surface-dim); font-size: 12px; margin: 0; }
.lb-checks { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; }
.lb-checks input { accent-color: var(--primary); }
.lb-dialog-note { padding: 10px; background: var(--surface-variant); border-radius: var(--r-md); font-size: 12px; color: var(--on-surface-dim); }
.lb-formula-preview { min-height: 54px; padding: 10px; background: var(--surface-variant); border-radius: var(--r-md); font-size: 24px; }
.lb-frac { display: inline-flex; flex-direction: column; text-align: center; vertical-align: middle; font-size: .75em; }
.lb-frac span:first-child { border-bottom: 1px solid currentColor; padding: 0 3px; }
.lb-rad { border-top: 1px solid currentColor; }
.lb-symbol-grid { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.lb-symbol-grid button { height: 34px; border: 1px solid var(--outline); border-radius: var(--r-sm); background: var(--surface-variant); }
.lb-members { display: flex; gap: 6px; flex-wrap: wrap; }
.lb-member-chip { padding: 5px 10px; border-radius: 999px; background: var(--primary-container); color: var(--on-primary-container); font-size: 12px; }
.lb-pending { display: flex; flex-direction: column; gap: 6px; }
.lb-invite { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 8px; border: 1px solid var(--outline); border-radius: var(--r-sm); font-size: 12px; }
.lb-invite span { flex: 1 1 auto; }
.lb-invite button { border: 1px solid var(--outline); border-radius: var(--r-sm); background: var(--surface-variant); padding: 4px 8px; }
.lb-invite button[data-accept] { background: var(--primary); color: #FFF; border-color: var(--primary); }
.lb-cast-video { width: 100%; max-height: 300px; border-radius: var(--r-md); background: #000; }

.lb-drawer { position: fixed; right: 0; top: 60px; bottom: 28px; width: min(340px, 92vw); background: var(--surface-2); box-shadow: var(--shadow-lg); z-index: 60; border-left: 1px solid var(--outline); display: flex; flex-direction: column; }
.lb-drawer header { padding: 14px; font-weight: 700; display: flex; justify-content: space-between; background: var(--primary-container); color: var(--on-primary-container); }
.lb-drawer header button { border: 0; background: transparent; font-size: 16px; }
.lb-drawer-grid { padding: 12px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; overflow-y: auto; }
.lb-drawer-grid .lb-tool { width: 100%; background: var(--surface-variant); color: var(--on-surface); }

.lb-toast { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--on-surface); color: #FFF; padding: 10px 18px; border-radius: var(--r-lg); box-shadow: var(--shadow-lg); z-index: 80; max-width: 80%; font-size: 13px; }

/* Floating modular panels */
.lb-panel-layer, .lb-widget-layer { position: absolute; inset: 0; pointer-events: none; z-index: 15; }
.lb-panel, .lb-widget { pointer-events: auto; position: absolute; background: rgba(255,255,255,.97); border: 1px solid var(--outline); border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden; }
.lb-panel { width: 236px; }
.lb-panel.dock-right { right: 8px; top: 70px; }
.lb-panel.dock-left { left: 8px; top: 70px; }
.lb-panel.dock-top { top: 8px; left: 50%; transform: translateX(-50%); }
.lb-panel.dock-bottom { bottom: 8px; left: 50%; transform: translateX(-50%); }
.lb-panel.floating { left: 0; top: 0; }
.lb-panel-head { display: flex; align-items: center; gap: 6px; padding: 7px 8px; background: var(--primary-container); color: var(--on-primary-container); cursor: move; user-select: none; }
.lb-panel-title { font-weight: 700; font-size: 12px; flex: 1; }
.lb-panel-tools { display: flex; gap: 2px; }
.lb-panel-tools button { width: 22px; height: 22px; border: 0; border-radius: var(--r-sm); background: rgba(255,255,255,.5); font-size: 11px; }
.lb-panel-body { padding: 8px 10px; max-height: 46vh; overflow: auto; font-size: 12px; }
.lb-panel.collapsed .lb-panel-body { display: none; }
.lb-panel.follow-canvas { border-color: var(--primary); }

.lb-widget { width: 250px; left: 40px; top: 80px; }
.lb-widget header { display: flex; justify-content: space-between; padding: 7px 10px; background: var(--primary-container); color: var(--on-primary-container); font-weight: 700; font-size: 12px; cursor: move; }
.lb-widget header button { border: 0; background: transparent; }
.lb-widget-content { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.lb-widget-time { font-size: 28px; font-weight: 700; text-align: center; color: var(--primary); font-variant-numeric: tabular-nums; }
.lb-widget-controls { display: flex; gap: 6px; }
.lb-widget-controls button { flex: 1; border: 1px solid var(--outline); border-radius: var(--r-sm); background: var(--surface-variant); padding: 5px; }
.lb-ruler { height: 26px; background: repeating-linear-gradient(90deg, #EDF2FA 0 9px, #90A4C0 9px 10px); border: 1px solid var(--primary); border-radius: var(--r-sm); }
.lb-grid-ruler { width: 200px; height: 100px; background-image: linear-gradient(#C7D4E8 1px, transparent 1px), linear-gradient(90deg, #C7D4E8 1px, transparent 1px); background-size: 20px 20px; border: 1px solid var(--primary); }
.lb-spotlight-hole { position: absolute; border-radius: 50%; box-shadow: 0 0 0 9999px rgba(10,18,35,.82); border: 2px solid #FFF; cursor: move; }
.lb-camera-preview { position: absolute; right: 16px; bottom: 46px; width: 260px; border-radius: var(--r-lg); border: 2px solid var(--primary); box-shadow: var(--shadow-lg); z-index: 18; cursor: crosshair; }
.lb-freeze-overlay { position: fixed; inset: 0; z-index: 90; background: rgba(26,34,51,.55); display: grid; place-items: center; cursor: pointer; }
.lb-freeze-hint { color: #FFF; font-size: 18px; background: rgba(0,0,0,.4); padding: 14px 22px; border-radius: var(--r-xl); }

/* Responsive */
@media (max-width: 1180px) { .lb-side { width: 156px; flex-basis: 156px; } .lb-brand-name { display: none; } }
@media (max-width: 960px) {
  .lb-topbar { gap: 6px; padding: 0 8px; }
  #btn-import, #btn-collab, #btn-cast, #btn-settings { display: none; }
  .lb-side { width: 118px; flex-basis: 118px; }
  .lb-style-bar { gap: 8px; }
  .lb-style-bar label { font-size: 11px; }
}
@media (max-width: 720px) {
  .lb-topbar { height: 52px; flex-basis: 52px; }
  .lb-title-input { max-width: 110px; }
  #btn-save { padding: 0 8px; }
  .lb-toolrail { width: 52px; flex-basis: 52px; }
  .lb-tool { width: 42px; height: 42px; }
  .lb-side { display: none; }
  .lb-style-bar { left: 6px; right: 6px; top: 6px; padding: 6px; }
  .lb-style-bar input[type="range"] { width: 58px; }
  .lb-panel { width: min(250px, 84vw); }
  .lb-drawer { top: 52px; }
}
@media (max-width: 480px) {
  .lb-top-actions .lb-btn:not(.lb-btn-primary):not(.lb-btn-icon) { display: none; }
  .lb-style-bar label:nth-child(3) { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ===== 自绘模态层（替代原生 <dialog>/alert/confirm/prompt） ===== */
.lb-modal-root { position: fixed; inset: 0; z-index: 2000; }
.lb-modal-mask { position: fixed; inset: 0; background: rgba(26,34,51,.5); backdrop-filter: blur(3px); display: grid; place-items: center; animation: lbFade .14s ease-out; }
.lb-modal-mask[hidden] { display: none !important; }
.lb-modal-mask.closing { animation: lbFade .14s ease-in reverse; }
.lb-modal { max-height: 88vh; border-radius: var(--r-xl); padding: 0; background: var(--surface-2); color: var(--on-surface); box-shadow: var(--shadow-lg); overflow: hidden; display: flex; flex-direction: column; }
.lb-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; background: var(--primary-container); color: var(--on-primary-container); }
.lb-modal-head h3 { margin: 0; font-size: 16px; }
.lb-modal-head .lb-btn { background: rgba(11,61,145,.12); color: var(--on-primary-container); }
.lb-modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.lb-modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--outline); }
.lb-modal .lb-btn { background: var(--surface-variant); color: var(--on-surface); }
.lb-modal .lb-btn-primary { background: var(--primary); color: #FFF; }
.lb-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--on-surface-dim); }
@keyframes lbFade { from { opacity: 0; } to { opacity: 1; } }

/* 升级后的 .lb-dialog 作为 lb-modal 显示 */
.lb-modal > form { display: flex; flex-direction: column; max-height: 88vh; }
.lb-modal > form .lb-dialog-body { overflow-y: auto; }

/* 工具按钮：图标在上、功能名称在下（名称 succinct，不用解释文案） */
.lb-tool .lb-tool-name { font-size: 9px; line-height: 1.1; color: var(--on-surface-dim); text-align: center; margin-top: 2px; max-width: 46px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-tool.active .lb-tool-name { color: #FFF; }
.lb-tool .lb-icon { width: 22px; height: 22px; }

/* 笔色/背景色色板（统一控件，去原生 input[type=color]） */
.lb-swatches { display: inline-flex; gap: 5px; vertical-align: middle; }
.lb-swatch { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--outline); cursor: pointer; padding: 0; }
.lb-swatch.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-container); }
.lb-check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--on-surface-dim); }
