:root {
  --accent: #2a2a2a;
  --accent-light: #ececec;
  --accent-contrast: #ffffff;
  --bg: #f5f5f7;
  --panel: #ffffff;
  --border: #e2e2e6;
  --text: #1c1c1e;
  --text-dim: #6e6e73;
  --canvas-bg: #fafafa;
  --dot: #d7d7dc;
}

:root[data-theme="dark"] {
  --accent: #ffffff;
  --accent-light: #3a3a3e;
  --accent-contrast: #1a1a1a;
  --bg: #1e1e22;
  --panel: #26262b;
  --border: #38383e;
  --text: #f0f0f2;
  --text-dim: #a0a0a8;
  --canvas-bg: #232326;
  --dot: #3a3a40;
}

/* Light mode variants: same palette as the base :root, only the accent (used for buttons,
   selection, and the whiteboard's page-border guides) changes per subject. */
:root[data-theme="physique"] {
  --accent: #FF8A1F;
  --accent-light: #FFECD9;
  --accent-contrast: #ffffff;
}
:root[data-theme="chimie"] {
  --accent: #57B3FE;
  --accent-light: #E2F2FF;
  --accent-contrast: #ffffff;
}
:root[data-theme="biologie"] {
  --accent: #6DC82A;
  --accent-light: #E7F7DA;
  --accent-contrast: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Splash screen: orbiting comet + trail + twinkling stars, shown while boards load */
#splash-screen {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease;
}
#splash-screen.splash-hidden {
  opacity: 0;
  pointer-events: none;
}
.splash-orbit {
  position: relative;
  width: 220px;
  height: 220px;
}
.splash-orbit svg:first-child {
  position: absolute;
  inset: 0;
  overflow: visible;
}
.splash-comet-group {
  transform-origin: 0 0;
  animation: splash-spin 1s linear infinite;
}
@keyframes splash-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(-360deg); }
}
.splash-text {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  text-align: center;
  width: 130px;
  animation: splash-glow 2.6s ease-in-out infinite;
}
@keyframes splash-glow {
  0%, 100% { text-shadow: 0 0 6px rgba(255,255,255,0.3), 0 0 2px rgba(255,255,255,0.4); opacity: 0.75; }
  50% { text-shadow: 0 0 18px rgba(255,255,255,0.95), 0 0 6px rgba(255,255,255,0.8); opacity: 1; }
}
.splash-star {
  position: absolute;
  width: 9px;
  height: 9px;
  fill: #fff;
  opacity: 0.5;
  animation: splash-twinkle 2.4s ease-in-out infinite;
}
.splash-star.s1 { top: 6%; left: 14%; width: 7px; height: 7px; animation-delay: 0s; }
.splash-star.s2 { top: 18%; right: 10%; width: 11px; height: 11px; animation-delay: 0.5s; }
.splash-star.s3 { bottom: 10%; left: 8%; width: 8px; height: 8px; animation-delay: 1s; }
.splash-star.s4 { bottom: 4%; right: 20%; width: 6px; height: 6px; animation-delay: 1.5s; }
.splash-star.s5 { top: 45%; left: -4%; width: 7px; height: 7px; animation-delay: 0.8s; }
.splash-star.s6 { top: 55%; right: -6%; width: 9px; height: 9px; animation-delay: 1.9s; }
@keyframes splash-twinkle {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 0.9; transform: scale(1.15); }
}

#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar */
#sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.15s ease;
}
#sidebar.collapsed {
  margin-left: -260px;
}

#sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

#logo {
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
/* Pulsing dot motif (logo + custom cursor), echoing the comet-head logo */
@keyframes pulse-ring-anim {
  0% { transform: scale(0.55); opacity: 0.55; }
  100% { transform: scale(1.9); opacity: 0; }
}
.pulse-dot-wrap {
  position: relative;
  width: 10px;
  height: 10px;
  flex-shrink: 0;
}
.pulse-dot-wrap .pulse-core {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--accent);
}
.pulse-dot-wrap .pulse-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.4px solid var(--accent);
  animation: pulse-ring-anim 2.2s ease-out infinite;
}
.pulse-dot-wrap .pulse-ring2 { animation-delay: 1.1s; }

/* Custom app cursor: a dot with two soft pulsing rings, following the pointer.
   Color is set inline via JS to match the current drawing color. */
#custom-cursor {
  position: absolute;
  top: 0;
  left: 0;
  width: 18px;
  height: 18px;
  pointer-events: none;
  z-index: 40;
  display: none;
  transform: translate(-50%, -50%) scale(var(--cs, 1));
  color: var(--text);
}
#custom-cursor.visible { display: block; }
#custom-cursor .pulse-core {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: currentColor;
}
#custom-cursor .pulse-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  border: 2.2px solid currentColor;
  animation: pulse-ring-anim-cursor 1.7s ease-out infinite;
}
#custom-cursor .pulse-ring2 { animation-delay: 0.85s; }
#cursor-badge {
  position: absolute;
  right: -10px;
  bottom: -10px;
  width: 15px;
  height: 15px;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text);
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: 4px;
}
#cursor-badge.visible { display: flex; }
#cursor-badge svg { width: 10px; height: 10px; }
@keyframes pulse-ring-anim-cursor {
  0% { transform: scale(0.7); opacity: 0.8; }
  100% { transform: scale(2.8); opacity: 0; }
}

/* Rotating dashed ring showing the eraser's actual hitbox, active when an
   eraser mode (full, partial, or the Wacom pen's temporary eraser) is on. */
#eraser-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  display: none;
  pointer-events: none;
  color: currentColor;
  animation: eraser-ring-spin 1.4s linear infinite;
}
#eraser-ring circle {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  opacity: 0.85;
}
@keyframes eraser-ring-spin {
  from { transform: translate(-50%, -50%) rotate(0deg); }
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Scientific calculator panel */
#calc-panel {
  position: absolute;
  top: 50%;
  right: 16px;
  transform: translateY(-50%);
  width: 260px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  z-index: 45;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#calc-panel.hidden { display: none; }
#calc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
#calc-header-actions { display: flex; gap: 4px; }
#calc-header-actions button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
  padding: 3px 7px;
  cursor: pointer;
}
#calc-header-actions button:hover { background: var(--bg); }
#calc-header-actions button.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
#calc-input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
#calc-input:focus { outline: none; border-color: var(--accent); }
#calc-result {
  min-height: 18px;
  padding: 0 2px;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  text-align: right;
  word-break: break-all;
}
#calc-result.error { color: #e0405a; font-weight: 500; font-size: 12px; }
#calc-buttons {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}
#calc-buttons button {
  border: none;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  border-radius: 6px;
  padding: 8px 0;
  cursor: pointer;
}
#calc-buttons button:hover { background: var(--accent-light); }
#calc-buttons button.calc-eq {
  background: var(--accent);
  color: var(--accent-contrast);
  grid-column: span 2;
  font-weight: 700;
}
#calc-buttons button.calc-eq:hover { opacity: 0.9; }

.hidden { display: none !important; }

#sidebar-actions {
  display: flex;
  gap: 6px;
}

#btn-new-board {
  flex: 1;
  padding: 9px 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
#btn-new-board:hover { opacity: 0.9; }

#btn-select-boards {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
#btn-select-boards:hover { background: var(--bg); }
#btn-select-boards.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }

#board-select-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}
.board-select-all {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  flex: 1;
}
#board-select-bar button {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text-dim);
}
#board-select-bar button:hover { background: var(--bg); }
#btn-delete-selected {
  color: #e0405a !important;
}
#btn-delete-selected:disabled {
  opacity: 0.4;
  cursor: default;
}
#btn-delete-selected:disabled:hover { background: none; }

.board-checkbox {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  cursor: pointer;
}

#board-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

#btn-promo {
  flex-shrink: 0;
  border: none;
  border-top: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  padding: 10px 12px;
  cursor: pointer;
  text-align: center;
  line-height: 1.4;
}
#btn-promo:hover { background: var(--bg); color: var(--text); }

#subscribe-btn-wrap {
  position: relative;
  flex-shrink: 0;
  overflow: visible;
}
#subscribe-btn-stars {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  width: 100%;
  height: 30px;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}
.subscribe-star {
  position: absolute;
  bottom: 0;
  fill: var(--accent);
  opacity: 0;
  animation-name: subscribe-star-rise;
  animation-timing-function: ease-in;
  animation-iteration-count: infinite;
}
@keyframes subscribe-star-rise {
  0% { transform: translate(-50%, 0); opacity: 0; }
  14% { opacity: var(--peak-op, 0.5); }
  60% { opacity: var(--peak-op, 0.5); }
  100% { transform: translate(-50%, -30px); opacity: 0; }
}
#btn-subscribe {
  position: relative;
  z-index: 2;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-top: 1px solid var(--border);
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 10px 12px;
  cursor: pointer;
  text-align: center;
}
#btn-subscribe svg { width: 15px; height: 15px; flex-shrink: 0; }
#btn-subscribe:hover { background: var(--accent-light); }

#subscribe-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}
#subscribe-panel {
  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  padding: 16px;
  transition: width 0.15s ease;
}
#subscribe-panel.wide { width: 660px; }

#pdf-prefs-columns { display: flex; gap: 18px; align-items: flex-start; }
#pdf-prefs-form-col { flex: 1 1 auto; min-width: 0; }
#pdf-prefs-preview-col { flex: 0 0 180px; position: sticky; top: 0; }
#pdf-preview-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}
#pdf-preview-loading { font-size: 12px; color: var(--text-dim); padding: 20px 0; }
.pdf-preview-page {
  width: 150px;
  height: 212px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  flex-shrink: 0;
}
.pdf-preview-band { flex: 0 0 auto; display: block; width: 100%; height: auto; }
.pdf-preview-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-dim);
  background:
    repeating-linear-gradient(var(--bg) 0px, var(--bg) 17px, var(--border) 18px);
}
.pdf-preview-full-img { width: 150px; height: 212px; display: block; object-fit: cover; flex-shrink: 0; box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.pdf-preview-endpdf-placeholder {
  width: 150px;
  height: 212px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px dashed var(--border);
  flex-shrink: 0;
  text-align: center;
  padding: 8px;
}
.pdf-preview-endpdf-placeholder svg { width: 28px; height: 28px; }
.pdf-preview-label { font-size: 10px; color: var(--text-dim); text-align: center; }
#subscribe-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}
#btn-subscribe-close {
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
}
#btn-subscribe-close:hover { background: var(--bg); }

#shortcuts-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}
#shortcuts-panel {
  width: 340px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  padding: 16px;
}
#shortcuts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
#btn-shortcuts-close {
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
}
#btn-shortcuts-close:hover { background: var(--bg); }
#shortcuts-intro { font-size: 12px; color: var(--text-dim); margin: 0 0 12px; line-height: 1.5; }
#shortcuts-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.shortcut-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 4px; border-radius: 6px;
}
.shortcut-row-label { font-size: 13px; color: var(--text); }
.shortcut-key-btn {
  min-width: 34px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  font-family: inherit;
}
.shortcut-key-btn:hover { border-color: var(--accent); }
.shortcut-key-btn.listening {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}
#btn-shortcuts-reset {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
}
#btn-shortcuts-reset:hover { background: var(--bg); color: var(--text); }

#portal-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}
#portal-modal-inner {
  width: 480px;
  max-width: calc(100vw - 32px);
  height: 720px;
  max-height: calc(100vh - 32px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
#portal-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
#btn-portal-close {
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
}
#btn-portal-close:hover { background: var(--bg); }
#portal-modal-slot {
  flex: 1 1 auto;
  min-height: 0;
}
#portal-modal-slot.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a1a1a;
}
#portal-modal-slot.loading .splash-orbit { position: relative; }
#subscribe-status {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 12px;
}
.subscribe-label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.subscribe-email-row {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}
.subscribe-email-row input {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}
.subscribe-email-row button {
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  background: var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.subscribe-email-row button:hover { background: var(--text-dim); color: var(--panel); }
.subscribe-link-btn {
  margin-top: 10px;
  padding: 0;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  display: block;
}
.subscribe-link-btn:hover { color: var(--text); }
#subscribe-plans {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.subscribe-plan-btn {
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.subscribe-plan-btn:hover { opacity: 0.9; }
#subscribe-cancel-note {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--text-dim);
  text-align: center;
}
#pdf-prefs-cancel-notice {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 12px;
  line-height: 1.5;
}

.subscribe-intro {
  font-size: 13px;
  color: var(--text);
  margin: 0 0 10px;
}
#subscribe-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.subscribe-compare-col {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: var(--bg);
}
.subscribe-compare-col-highlight {
  border-color: var(--accent);
  background: var(--accent-light);
}
.subscribe-compare-head {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  text-align: center;
}
.subscribe-compare-row {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px 0;
  border-top: 1px solid var(--border);
}
.subscribe-compare-row:first-of-type { border-top: none; }
.sc-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.sc-value {
  font-size: 11px;
  color: var(--text);
  line-height: 1.3;
}

.pdf-prefs-section {
  margin-bottom: 14px;
}
#pdf-prefs-header-text,
#pdf-prefs-footer-text {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  box-sizing: border-box;
}
#pdf-prefs-logo-row,
#pdf-prefs-endpdf-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
#pdf-prefs-logo-preview {
  max-width: 60px;
  max-height: 32px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
}
#pdf-prefs-logo-empty,
#pdf-prefs-endpdf-name {
  font-size: 12px;
  color: var(--text-dim);
  flex: 1;
}
.pdf-prefs-section button {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 11px;
  white-space: nowrap;
}
.pdf-prefs-section button:hover { background: var(--border); }
.pdf-prefs-toggles {
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.pdf-pref-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  padding: 6px 0;
  cursor: pointer;
}
#manage-status {
  font-size: 13px;
  color: var(--text);
  line-height: 1.6;
  margin: 0 0 14px;
}
#btn-pdf-prefs-save {
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.board-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  position: relative;
}
.board-item:hover { background: var(--bg); }
.board-item.active { background: var(--accent-light); }

.board-thumb {
  width: 44px;
  height: 32px;
  border-radius: 4px;
  background: var(--canvas-bg);
  border: 1px solid var(--border);
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}

.board-info { flex: 1; min-width: 0; }
.board-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.board-name-edit {
  font-size: 13px;
  font-weight: 500;
  width: 100%;
  padding: 1px 4px;
  border-radius: 4px;
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}
.board-date {
  font-size: 11px;
  color: var(--text-dim);
}

.board-menu-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0.55;
}
.board-item:hover .board-menu-btn { opacity: 1; }
.board-menu-btn:hover { background: var(--border); }

.board-dropdown {
  position: absolute;
  right: 8px;
  top: 36px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  z-index: 50;
  overflow: hidden;
  min-width: 140px;
}
.board-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}
.board-dropdown button:hover { background: var(--bg); }
.board-dropdown button.danger { color: #e0405a; }

.page-mode-dropdown {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  z-index: 200;
  overflow: hidden;
  min-width: 220px;
  padding: 4px;
}
.page-mode-dropdown button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: none;
  border-radius: 6px;
  background: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}
.page-mode-dropdown button:hover { background: var(--bg); }
.page-mode-dropdown button.active-option { background: var(--accent-light); box-shadow: inset 0 0 0 1.5px var(--accent); }
.page-mode-dropdown .pmd-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  flex-shrink: 0;
  color: var(--text-dim);
}
.page-mode-dropdown .pmd-icon svg, .page-mode-dropdown .pmd-icon img { display: block; }
.page-mode-dropdown button.active-option .pmd-icon { color: var(--accent); }

/* Main */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tb-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tb-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 4px;
}

#board-title {
  border: 1px dashed var(--border);
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  padding: 6px 8px;
  border-radius: 6px;
  width: 180px;
  cursor: text;
}
#board-title:hover {
  background: var(--bg);
  border-color: var(--text-dim);
}
#board-title:focus {
  background: var(--bg);
  border: 1px solid var(--accent);
  outline: none;
}

.icon-btn, .tool-btn {
  border: none;
  background: transparent;
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.icon-btn:hover, .tool-btn:hover { background: var(--bg); }
.tool-btn.active, .icon-btn.active { background: var(--accent-light); color: var(--accent); }

.icon-btn svg, .tool-btn svg, .flyout-btn svg, #zoom-pill button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool-btn[data-tool="select"] svg { fill: currentColor; stroke: none; }

#zoom-level {
  font-size: 12px;
  color: var(--text-dim);
  width: 42px;
  text-align: center;
}

/* Contextual flyout above the toolbar (pen / shapes presets) */
#tool-flyout {
  position: absolute;
  left: 50%;
  bottom: 78px;
  transform: translateX(-50%) translateY(6px);
  display: none;
  flex-direction: column;
  gap: 4px;
  background: var(--panel);
  border-radius: 16px;
  padding: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.16), 0 1px 3px rgba(0,0,0,0.08);
  z-index: 25;
  opacity: 0;
  transition: opacity 0.12s ease, transform 0.12s ease;
}
#tool-flyout.visible {
  display: flex;
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.flyout-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.flyout-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text);
  flex-shrink: 0;
}
.flyout-btn:hover { background: var(--bg); }
.flyout-btn.active { background: var(--accent-light); box-shadow: inset 0 0 0 2px var(--accent); }
.flyout-btn.close { color: var(--text-dim); font-size: 16px; }
.flyout-btn-label {
  width: auto;
  border-radius: 10px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

/* Partial eraser: filled circle (black in light mode, white in dark mode) */
.flyout-btn-filled {
  background: var(--accent);
  color: var(--accent-contrast);
}
.flyout-btn-filled:hover { background: var(--accent); opacity: 0.85; }
.flyout-btn-filled.active { background: var(--accent); color: var(--accent-contrast); box-shadow: inset 0 0 0 2px var(--accent-contrast); }

.flyout-dot {
  position: relative;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-block;
  background: currentColor;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12);
  transition: transform 0.18s cubic-bezier(.34,1.56,.64,1);
}
.flyout-dot::after {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  animation: pulse-ring-anim 2.3s ease-out infinite;
  pointer-events: none;
}
.flyout-btn:hover .flyout-dot {
  transform: translateY(-4px) scale(1.12);
}

.flyout-shape-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

.flyout-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

.flyout-color-input {
  width: 26px;
  height: 26px;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.flyout-width-select {
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  background: var(--panel);
  color: var(--text);
  flex-shrink: 0;
}

/* Bottom-right floating zoom pill */
#zoom-pill {
  position: absolute;
  right: 16px;
  bottom: 20px;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--panel);
  border-radius: 999px;
  padding: 6px 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.16), 0 1px 3px rgba(0,0,0,0.08);
  z-index: 20;
}
#zoom-pill button {
  border: none;
  background: transparent;
  color: var(--text);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#zoom-pill button:hover { background: var(--bg); }

/* Canvas */
#canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--canvas-bg);
}

#empty-state {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--canvas-bg);
}
#empty-state.hidden { display: none; }
.empty-state-inner {
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}
.empty-state-inner p { margin: 0 0 14px; }
#btn-empty-new {
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
#btn-empty-new:hover { opacity: 0.9; }

#main.no-board #bottom-toolbar,
#main.no-board #zoom-pill,
#main.no-board #topbar-actions,
#main.no-board #toolbar-stars {
  display: none;
}

/* Decorative sparkle stars rising from the bottom of the screen, fading out
   as they reach the top of the toolbar, echoing the logo */
#toolbar-stars {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 560px;
  max-width: calc(100% - 32px);
  height: 92px;
  pointer-events: none;
  z-index: 15;
  overflow: visible;
}
.toolbar-star {
  position: absolute;
  bottom: 0;
  fill: var(--accent);
  opacity: 0;
  animation-name: toolbar-star-rise;
  animation-timing-function: ease-in;
  animation-iteration-count: infinite;
}
@keyframes toolbar-star-rise {
  0% { transform: translate(-50%, 0); opacity: 0; }
  14% { opacity: var(--peak-op, 0.5); }
  60% { opacity: var(--peak-op, 0.5); }
  100% { transform: translate(-50%, -92px); opacity: 0; }
}

/* Same rising-star decoration as the toolbar, scoped to the calculator panel */
#calc-stars {
  position: absolute;
  top: 50%;
  right: 16px;
  transform: translateY(-50%);
  width: 260px;
  height: 600px;
  pointer-events: none;
  z-index: 44;
  overflow: visible;
  display: none;
}
#calc-stars.visible { display: block; }
.calc-star {
  position: absolute;
  bottom: 0;
  fill: var(--accent);
  opacity: 0;
  animation-name: calc-star-rise;
  animation-timing-function: ease-in;
  animation-iteration-count: infinite;
}
@keyframes calc-star-rise {
  0% { transform: translate(-50%, 0); opacity: 0; }
  14% { opacity: var(--peak-op, 0.5); }
  60% { opacity: var(--peak-op, 0.5); }
  100% { transform: translate(-50%, -600px); opacity: 0; }
}

/* Floating bottom toolbar (Whiteboard-style pill) */
#bottom-toolbar {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--panel);
  border-radius: 999px;
  padding: 6px 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.16), 0 1px 3px rgba(0,0,0,0.08);
  z-index: 20;
  max-width: calc(100% - 32px);
  overflow-x: auto;
}

.bt-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 6px;
  flex-shrink: 0;
}

#bottom-toolbar .tool-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
}
#bottom-toolbar .tool-btn.active {
  background: var(--accent);
  color: var(--accent-contrast);
}
#bottom-toolbar .tool-btn[data-tool="pen"].active {
  background: transparent;
  border: 2px solid currentColor;
  color: var(--accent);
}

#board-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#overlay-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.overlay-editable {
  position: absolute;
  pointer-events: auto;
  outline: none;
  border: 1.5px dashed var(--accent);
  background: transparent;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.note-editable {
  border: none;
  border-radius: 4px;
  padding: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}

#selection-toolbar {
  position: absolute;
  display: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  padding: 4px;
  gap: 2px;
  z-index: 30;
}
#selection-toolbar.visible { display: flex; }
#selection-toolbar button {
  border: none;
  background: none;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}
#selection-toolbar button:hover { background: var(--bg); }
#selection-toolbar button.active { background: var(--accent); color: var(--accent-contrast); }
.sel-color-btn {
  position: relative;
  transition: transform 0.18s cubic-bezier(.34,1.56,.64,1);
}
.sel-color-btn::after {
  content: '';
  position: absolute;
  inset: 1px;
  border-radius: 50%;
  border: 1.4px solid currentColor;
  animation: pulse-ring-anim 2.3s ease-out infinite;
  pointer-events: none;
}
.sel-color-btn:hover {
  background: none !important;
  transform: translateY(-4px) scale(1.15);
}

.sel-stepper {
  display: flex;
  align-items: center;
  gap: 2px;
}
.sel-stepper button {
  width: 22px !important;
  font-size: 15px !important;
  font-weight: 700;
}
.sel-tick-input {
  width: 34px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  font-size: 11px;
  text-align: center;
  padding: 0;
}
.sel-tick-input:focus { outline: none; border-color: var(--accent); }

#status-bar {
  display: none;
}

/* Scrollbar */
#board-list::-webkit-scrollbar { width: 8px; }
#board-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Touch targets: inert on desktop (mouse is a "fine" pointer, this media query never matches),
   only kicks in for real touchscreens — the tablet PWA and desktop share this file as-is. */
@media (pointer: coarse) {
  .icon-btn, .tool-btn { width: 40px; height: 40px; }
  #bottom-toolbar .tool-btn { width: 46px; height: 46px; }
  .icon-btn svg, .tool-btn svg, .flyout-btn svg, #zoom-pill button svg { width: 20px; height: 20px; }
  .board-menu-btn { padding: 8px 10px; }
  .shortcut-key-btn { min-width: 42px; padding: 8px 10px; }
}
