:root {
  --bg: #0f172a;
  --panel: rgba(15, 23, 42, 0.88);
  --panel-border: rgba(148, 163, 184, 0.22);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-bg: rgba(56, 189, 248, 0.18);
  --danger: #f43f5e;
  --input-bg: rgba(30, 41, 59, 0.85);
}

html[data-theme="light"] {
  --bg: #f8fafc;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-border: rgba(15, 23, 42, 0.14);
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0284c7;
  --accent-bg: rgba(2, 132, 199, 0.14);
  --danger: #e11d48;
  --input-bg: rgba(241, 245, 249, 0.95);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

input, textarea, pre {
  user-select: text;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
}

/* 4-Layer Canvas */
#canvas-container {
  position: fixed;
  inset: 0;
  touch-action: none;
  overflow: hidden;
}

#canvas-container canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#layer-bg { z-index: 1; pointer-events: none; }
#layer-media { z-index: 2; pointer-events: none; }
#layer-strokes { z-index: 3; pointer-events: none; }
#layer-active { z-index: 4; cursor: crosshair; }

/* Panels */
.ui-panel {
  position: fixed;
  z-index: 20;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

body.zen-mode .ui-panel {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
}

#top-bar {
  top: 10px;
  left: 10px;
  right: 10px;
  border-radius: 12px;
  padding: 5px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

#top-bar::-webkit-scrollbar {
  display: none;
}

#top-bar .bar-group {
  gap: 4px;
  flex-shrink: 0;
}

#top-bar .btn-icon,
#top-bar .btn-chip,
#top-bar .select-ui {
  padding: 4px 7px;
  font-size: 12px;
}

#top-bar .btn-icon {
  padding: 4px 6px;
}

#bottom-bar {
  bottom: 12px;
  left: calc(var(--split-w, 0px) + 12px);
  transform: none;
  border-radius: 14px;
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100vw - var(--split-w, 0px) - 285px);
  overflow-x: auto;
  scrollbar-width: none;
}

#bottom-bar::-webkit-scrollbar {
  display: none;
}

@media (max-width: 820px) {
  #bottom-bar {
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100vw - 24px);
  }
}

body.zen-mode #bottom-bar {
  transform: translateY(16px);
}

#context-bar {
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 10px;
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

#zoom-pill {
  bottom: 12px;
  right: 12px;
  border-radius: 10px;
  padding: 4px 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Background Picker Popover */
.popover {
  top: 56px;
  right: 140px;
  border-radius: 12px;
  padding: 12px;
  width: 220px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 35;
}

.popover-title {
  font-weight: 600;
  font-size: 12.5px;
}

.popover-label {
  font-size: 11px;
  color: var(--muted);
}

.bg-swatch-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.bg-swatch {
  height: 28px;
  border-radius: 8px;
  border: 2px solid var(--panel-border);
  cursor: pointer;
  padding: 0;
}

.bg-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}

.swatch-mini {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid var(--panel-border);
  vertical-align: middle;
  margin-right: 4px;
}

.custom-bg-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.bar-group {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: nowrap;
}

.divider {
  width: 1px;
  height: 20px;
  background: var(--panel-border);
  margin: 0 2px;
}

/* Buttons & Inputs */
button, select, input {
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text);
}

.btn-icon, .btn-chip, .tool-btn, .btn-mini, .btn-primary {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  padding: 5px 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.btn-icon:hover, .btn-chip:hover, .tool-btn:hover, .btn-mini:hover {
  background: var(--accent-bg);
}

.btn-chip, .btn-mini {
  border-color: var(--panel-border);
}

.btn-mini {
  padding: 3px 7px;
  font-size: 12px;
}

.btn-chip.active, .tool-btn.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.btn-chip.danger {
  color: var(--danger);
  border-color: rgba(244, 63, 94, 0.35);
}

.btn-primary {
  background: var(--accent);
  color: #0f172a;
  font-weight: 600;
  padding: 7px 14px;
}

.select-ui {
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 4px 8px;
  outline: none;
}

.select-ui.full {
  width: 100%;
  margin-top: 4px;
}

#note-title {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 3px 6px;
  font-weight: 600;
  font-size: 13px;
  width: 125px;
  min-width: 88px;
  outline: none;
}

#note-title:focus {
  background: var(--input-bg);
  border-color: var(--accent);
}

.badge-muted {
  color: var(--muted);
  font-size: 11.5px;
}

/* Colors */
.color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.color-dot.active {
  border-color: var(--accent);
  transform: scale(1.15);
  box-shadow: 0 0 0 2px var(--bg);
}

#custom-color {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.size-wrap, .toggle-mini {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

#stroke-size, #stroke-smooth {
  width: 68px;
  accent-color: var(--accent);
}

/* Zen Mode Exit */
.zen-exit-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 30;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 99px;
  padding: 6px 12px;
  opacity: 0.35;
  cursor: pointer;
  transition: opacity 0.2s;
}

.zen-exit-btn:hover {
  opacity: 1;
}

/* Library Drawer */
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(330px, 90vw);
  z-index: 40;
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  backdrop-filter: none;
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 10px;
}

.drawer-header, .section-row, .drawer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.drawer-header h2 {
  margin: 0;
  font-size: 16px;
}

.drawer-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.drawer input[type="text"], .modal-card input[type="text"], .modal-card input[type="url"], .modal-card input[type="password"] {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 7px 10px;
  outline: none;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.meta-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  font-size: 12px;
}

.note-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.note-item {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.note-item.active {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.note-item-title {
  font-weight: 600;
  margin-bottom: 3px;
}

.note-item-meta {
  font-size: 11px;
  color: var(--muted);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: min(460px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header, .modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.modal-header h3 {
  margin: 0;
  font-size: 15px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
}

.hint-text {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

.sql-box pre {
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px;
  font-size: 11px;
  overflow-x: auto;
  margin: 6px 0 0;
}

/* Toast */
.toast {
  position: fixed;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--panel);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 99px;
  font-size: 12.5px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.hidden {
  display: none !important;
}

@media (max-width: 720px) {
  #zoom-pill { display: none; }
  #note-title { width: 110px; }
  .popover { right: 12px; }
}

/* Shortcut Modal */
.modal-wide {
  width: min(560px, 100%);
}

.detector-box {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px dashed var(--accent);
  background: var(--accent-bg);
  font-size: 12px;
  text-align: center;
  color: var(--text);
  cursor: crosshair;
  touch-action: none;
}

.shortcut-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--panel-border);
}

.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
}

.express-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.express-row {
  display: grid;
  grid-template-columns: 82px 1fr 1fr;
  align-items: center;
  gap: 8px;
}

.key-record-btn {
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 5px 8px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
  cursor: pointer;
  text-align: center;
}

.key-record-btn.recording {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(244, 63, 94, 0.14);
}

.express-row-clear {
  display: grid;
  grid-template-columns: 78px 1fr 1fr 28px;
  align-items: center;
  gap: 6px;
}

.kbd-ref {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 11.5px;
  color: var(--muted);
}

.kbd-ref kbd {
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 11px;
  color: var(--text);
}

.popover-divider {
  height: 1px;
  background: var(--panel-border);
  margin: 2px 0;
}

/* Quick Pen Presets */
.preset-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--panel-border);
  background: var(--input-bg);
  border-radius: 99px;
  padding: 3px 8px;
  font-size: 11.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
}

.preset-btn:hover {
  border-color: var(--accent);
}

.preset-btn.active {
  border-color: var(--accent);
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

.preset-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid rgba(148, 163, 184, 0.5);
  display: inline-block;
}

/* Inline Floating Text & LaTeX Editor */
.text-editor-box {
  position: fixed;
  z-index: 45;
  width: min(360px, calc(100vw - 24px));
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#text-editor-input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  resize: vertical;
  outline: none;
}

.text-editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#text-editor-size {
  width: 56px;
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 3px 6px;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* Bookmark Popover */
.bookmark-popover {
  bottom: 58px;
  right: 14px;
  width: min(290px, calc(100vw - 28px));
  max-height: 55vh;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 35;
}

.bookmark-add-row {
  display: flex;
  gap: 6px;
}

.bookmark-add-row input {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 5px 8px;
  outline: none;
}

.bookmark-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 220px;
  overflow-y: auto;
}

.bookmark-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  cursor: pointer;
  font-size: 12.5px;
}

.bookmark-item:hover {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.bookmark-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bookmark-kbd {
  font-size: 10.5px;
  color: var(--muted);
  margin-right: 4px;
}

/* Export PDF Progress Bar */
.export-progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 4px;
}

.export-progress-bar {
  width: 100%;
  height: 8px;
  border-radius: 99px;
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  overflow: hidden;
}

.export-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s ease;
}

/* Manual DPI Input & Presets */
.dpi-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#export-dpi {
  width: 82px;
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 6px 8px;
  font-weight: 600;
  outline: none;
}

#export-dpi:focus {
  border-color: var(--accent);
}

.dpi-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.dpi-preset.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.hint-warn {
  color: #f59e0b;
}

/* Graph Plotter Modal */
.graph-preview-canvas {
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: #ffffff;
}

#graph-expr {
  width: 100%;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 7px 9px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  outline: none;
  resize: vertical;
}

#graph-expr::placeholder {
  color: var(--muted);
}

#graph-expr:focus {
  border-color: var(--accent);
}

.graph-range-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.graph-range-grid input,
.modal-card input[type="number"],
.modal-card input[type="text"],
.modal-card textarea {
  width: 100%;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  padding: 6px 8px;
  outline: none;
}

.graph-range-grid input:focus {
  border-color: var(--accent);
}

/* Stamp Drawer Popover */
.stamp-popover {
  bottom: 58px;
  right: 14px;
  width: min(340px, calc(100vw - 28px));
  max-height: 58vh;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 35;
}

.stamp-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}

.stamp-card {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: var(--input-bg);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, transform 0.1s;
}

.stamp-card:hover {
  border-color: var(--accent);
}

.stamp-preview {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  background: rgba(15, 23, 42, 0.35);
}

.stamp-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.stamp-preview-text {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 11px;
  color: var(--text);
  text-align: center;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.stamp-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px;
  gap: 4px;
}

.stamp-card-name {
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Floating Replay / Timelapse Bar */
.replay-bar {
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 14px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 40;
  max-width: calc(100vw - 24px);
}

#replay-scrubber {
  width: min(240px, 34vw);
  accent-color: var(--accent);
}

/* Phase 5C: Split-View Left Reference Pane */
.split-pane {
  position: fixed;
  top: 56px;
  left: 10px;
  bottom: 12px;
  width: 38vw;
  min-width: 240px;
  max-width: 62vw;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  z-index: 22;
  overflow: hidden;
}

body.zen-mode .split-pane {
  top: 10px;
  opacity: 1 !important;
  pointer-events: auto !important;
}

.split-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--panel-border);
}

.split-filename {
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.split-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--panel-border);
  background: var(--input-bg);
}

.split-viewer {
  flex: 1;
  overflow: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: rgba(15, 23, 42, 0.25);
}

.split-viewer canvas,
.split-viewer img {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  border-radius: 4px;
  max-width: none;
}

.split-empty {
  margin: auto;
  text-align: center;
  max-width: 240px;
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.split-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  background: transparent;
}

.split-resizer:hover {
  background: var(--accent-bg);
}

/* Phase 5C.5: Compact Floating Mini-Pill Timer */
.timer-widget {
  position: fixed;
  top: 62px;
  right: 14px;
  width: auto;
  min-width: 170px;
  border-radius: 12px;
  padding: 5px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 32;
}

body.zen-mode .timer-widget:not(.zen-keep) {
  opacity: 0;
  pointer-events: none;
}

body.zen-mode .timer-widget.zen-keep {
  opacity: 0.92 !important;
  pointer-events: auto !important;
}

.timer-mini-row {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: grab;
  user-select: none;
}

.timer-mini-row:active {
  cursor: grabbing;
}

.timer-icon {
  font-size: 13px;
  opacity: 0.85;
}

.timer-display {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 0 4px;
}

.timer-settings {
  border-top: 1px solid var(--panel-border);
  padding-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.timer-mode-btn.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.timer-widget.timer-done .timer-display {
  color: #f43f5e;
  animation: recPulse 0.8s infinite;
}

#timer-minutes {
  width: 52px;
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 3px 5px;
  text-align: center;
}

/* Phase 5C: Live Recording Pill */
.rec-pill {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 99px;
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 42;
  border-color: rgba(244, 63, 94, 0.65);
}

body.zen-mode .rec-pill {
  top: 12px;
  opacity: 0.92 !important;
  pointer-events: auto !important;
}

.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f43f5e;
  animation: recPulse 1s infinite;
}

.rec-time {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  font-weight: 600;
}

#btn-record.rec-active {
  color: #f43f5e;
  background: rgba(244, 63, 94, 0.16);
  border-color: rgba(244, 63, 94, 0.5);
}

@keyframes recPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* Phase 5D: Split-View Sections & Web Browser Tab */
.split-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.split-url-input {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 12px;
  outline: none;
}

.split-url-input:focus {
  border-color: var(--accent);
}

.split-web-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: rgba(15, 23, 42, 0.25);
}

.split-web-frame {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
  background: #ffffff;
}

/* v21.1: Delete Confirmation & Interactive Undo Toast */
.btn-danger-solid {
  background: #e11d48;
  color: #ffffff;
  border: 1px solid #be123c;
  border-radius: 8px;
  padding: 6px 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-danger-solid:hover {
  background: #be123c;
}

.toast.toast-interactive {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.toast-action-btn {
  background: rgba(56, 189, 248, 0.22);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.55);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.toast-action-btn:hover {
  background: #38bdf8;
  color: #0f172a;
}

/* ==========================================================================
   Phase 6: Operate-Mode UI/UX Polish & 3-Layer CSS Design Tokens
   ========================================================================== */
:root {
  /* Layer 1: Primitive Tokens */
  --p-slate-950: #020617;
  --p-slate-900: #0f172a;
  --p-slate-800: #1e293b;
  --p-slate-700: #334155;
  --p-slate-400: #94a3b8;
  --p-slate-200: #e2e8f0;
  --p-slate-100: #f1f5f9;
  --p-slate-50: #f8fafc;
  --p-sky-400: #38bdf8;
  --p-sky-500: #0ea5e9;
  --p-rose-500: #f43f5e;

  /* Layer 2: Semantic Tokens (Dark default) */
  --surface-panel: rgba(15, 23, 42, 0.84);
  --surface-popover: rgba(15, 23, 42, 0.94);
  --border-subtle: rgba(148, 163, 184, 0.22);
  --shadow-island: 0 8px 28px rgba(2, 6, 23, 0.38), 0 1px 2px rgba(2, 6, 23, 0.24);
  --radius-island: 14px;
  --radius-btn: 9px;
  --t-fast: 140ms cubic-bezier(0.2, 0, 0, 1);

  /* Sync legacy variables to semantic tokens */
  --panel: var(--surface-panel);
  --panel-border: var(--border-subtle);
  --shadow: var(--shadow-island);
}

html[data-theme="light"] {
  --surface-panel: rgba(255, 255, 255, 0.88);
  --surface-popover: rgba(255, 255, 255, 0.96);
  --border-subtle: rgba(15, 23, 42, 0.12);
  --shadow-island: 0 8px 26px rgba(15, 23, 42, 0.10), 0 1px 2px rgba(15, 23, 42, 0.06);
  --panel: var(--surface-panel);
  --panel-border: var(--border-subtle);
  --shadow: var(--shadow-island);
}

/* Refined Floating Islands */
.ui-panel {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-island);
  transition: opacity var(--t-fast), transform var(--t-fast), background var(--t-fast);
}

#top-bar {
  top: 10px;
  left: 12px;
  right: 12px;
  border-radius: var(--radius-island);
  padding: 5px 10px;
}

/* Centered, Zero-Scroll Bottom Dock */
#bottom-bar {
  bottom: 12px;
  left: calc(var(--split-w, 0px) + (100vw - var(--split-w, 0px)) / 2);
  transform: translateX(-50%);
  border-radius: 16px;
  padding: 5px 8px;
  gap: 6px;
  max-width: calc(100vw - var(--split-w, 0px) - 24px);
  overflow-x: visible;
}

.tool-group {
  gap: 3px;
}

/* Uniform 34x34 Touch Targets for Stylus & Tablet */
.tool-btn,
.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-btn);
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}

.tool-btn:active,
.btn-icon:active,
.btn-chip:active {
  transform: scale(0.95);
}

.tool-btn.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-bg);
}

.btn-chip {
  height: 32px;
  padding: 0 9px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: var(--radius-btn);
  font-size: 12.5px;
  font-weight: 500;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}

.divider-soft {
  width: 1px;
  height: 18px;
  background: var(--border-subtle);
  margin: 0 2px;
}

/* Tool Settings Trigger Pill */
.tool-settings-trigger {
  gap: 6px;
  padding: 0 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.ink-preview-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f8fafc;
  border: 1px solid rgba(148, 163, 184, 0.55);
  flex-shrink: 0;
}

/* Contextual Popovers (Top Menus & Bottom Tool Settings) */
.menu-popover {
  position: fixed;
  top: 58px;
  min-width: 210px;
  padding: 6px;
  border-radius: 12px;
  background: var(--surface-popover);
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 45;
  animation: popIn var(--t-fast);
}

.board-popover {
  width: 256px;
  padding: 10px 12px;
  gap: 8px;
}

.menu-item {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background var(--t-fast);
}

.menu-item:hover {
  background: var(--accent-bg);
  color: var(--accent);
}

.tool-settings-popover {
  position: fixed;
  bottom: 66px;
  left: 50%;
  width: 264px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-popover);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 45;
  animation: popIn var(--t-fast);
}

.popover-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.popover-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.popover-label {
  font-size: 12.5px;
  color: var(--text);
}

.popover-val {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

.popover-slider-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.popover-slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.popover-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 2px 0;
}

/* Focus-visible accessibility ring */
button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@keyframes popIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.tool-settings-popover {
  animation: popIn var(--t-fast);
}

#bg-popover {
  z-index: 50;
  background: var(--surface-popover);
}

@keyframes popInCenter {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Tablet compactness (< 1024px): keep 1-row top bar & zero-scroll bottom dock */
@media (max-width: 1024px) {
  #top-bar .btn-chip span {
    display: none;
  }
  #note-title {
    width: 110px;
  }
  #bottom-bar {
    gap: 4px;
    padding: 4px 6px;
  }
  .tool-btn, .btn-icon {
    width: 32px;
    height: 32px;
  }
}



/* ==========================================================================
   v22.2: QA Hardening — Zero-Collision Layout, WCAG AA Contrast, Tablet Polish
   ========================================================================== */
:root {
  color-scheme: dark;
}

html[data-theme="light"] {
  color-scheme: light;
}

/* WCAG AA Contrast for Primary & Toast Buttons in Light Mode */
html[data-theme="light"] .btn-primary {
  background: #0369a1;
  color: #ffffff;
}

html[data-theme="light"] .btn-primary:hover {
  background: #075985;
}

html[data-theme="light"] .toast-action-btn {
  background: rgba(3, 105, 161, 0.14);
  color: #0369a1;
  border-color: rgba(3, 105, 161, 0.45);
}

html[data-theme="light"] .toast-action-btn:hover {
  background: #0369a1;
  color: #ffffff;
}

/* Make white preset/color dots clearly visible on Light Mode surfaces */
html[data-theme="light"] .preset-dot,
html[data-theme="light"] .color-dot,
html[data-theme="light"] .ink-preview-dot {
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.28);
}

/* Prevent Toast from overlapping the Recording Stop Pill */
body.is-recording .toast {
  top: 112px;
}

/* Zero-Collision Bottom Dock:
   Stack cleanly above #zoom-pill on laptops (<= 1480px), tablets, and whenever Split-View is active.
   Allow smooth horizontal scroll ONLY if viewport is narrower than the dock (e.g. 800px Portrait). */




/* Portrait Tablet (<= 860px): comfortable touch & guaranteed inside viewport */
@media (max-width: 860px) {
  #bottom-bar {
    left: 12px;
    right: 12px;
    transform: none;
    max-width: calc(100vw - 24px);
    width: auto;
    justify-content: flex-start;
  }
}

/* Larger touch comfort on touch/tablet devices */
@media (pointer: coarse) {
  .tool-btn,
  .btn-icon {
    width: 38px;
    height: 38px;
  }
  .color-dot {
    width: 24px;
    height: 24px;
  }
}

/* ==========================================================================
   v22.3: Operate-Mode Slim Dock (ALWAYS bottom: 12px, Zero Frame Intrusion)
   ========================================================================== */
#bottom-bar {
  bottom: 12px !important;
  padding: 4px 7px;
  gap: 5px;
}

/* Ultra-compact Pen Presets (colored dot + size number only) */
.preset-btn {
  padding: 3px 7px;
  gap: 4px;
  font-size: 11.5px;
  min-width: 0;
  height: 28px;
}

/* Bottom Flyout Popovers (Extra Tools & Utilitas) */
.bottom-flyout {
  top: auto !important;
  bottom: 62px;
  min-width: 215px;
}

.tool-btn-menu {
  width: 100% !important;
  height: auto !important;
  justify-content: flex-start !important;
  padding: 8px 10px !important;
  border-radius: 8px !important;
}

.kbd-hint {
  margin-left: auto;
  font-size: 11px;
  opacity: 0.65;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
}

/* During Recording: place Toast at bottom-center (above dock) so it NEVER covers #rec-pill */
body.is-recording .toast {
  top: auto !important;
  bottom: 64px !important;
}

/* Keep #bottom-bar cleanly to the left of #zoom-pill on narrow/split viewports */
@media (max-width: 1024px) {
  #bottom-bar {
    left: calc(var(--split-w, 0px) + 10px);
    transform: none;
    max-width: calc(100vw - var(--split-w, 0px) - var(--zoom-safe, 232px));
    overflow-x: auto;
    scrollbar-width: none;
  }
  #bottom-bar::-webkit-scrollbar {
    display: none;
  }
}

body.split-active #bottom-bar {
  left: calc(var(--split-w, 0px) + 10px);
  transform: none;
  max-width: calc(100vw - var(--split-w, 0px) - var(--zoom-safe, 232px));
  overflow-x: auto;
  scrollbar-width: none;
}

body.split-active #bottom-bar::-webkit-scrollbar {
  display: none;
}



/* ==========================================================================
   v22.4: Crisp Solid Matte Panels (Zero Backdrop-Filter GPU Overhead)
   ========================================================================== */
:root {
  --surface-panel: #111a2e;
  --surface-popover: #0f172a;
  --panel: var(--surface-panel);
}

html[data-theme="light"] {
  --surface-panel: #ffffff;
  --surface-popover: #ffffff;
  --panel: var(--surface-panel);
}

.ui-panel {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  background: var(--surface-panel);
}

/* ==========================================================================
   QA Polish: Zero-Collision Bottom Dock (always bottom: 12px) & Crisp Solid UI
   ========================================================================== */
.drawer {
  background: var(--surface-panel);
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

@media (max-width: 1180px) {
  #bottom-bar {
    left: calc(var(--split-w, 0px) + 10px);
    transform: none;
    max-width: calc(100vw - var(--split-w, 0px) - var(--zoom-safe, 232px));
    overflow-x: auto;
    scrollbar-width: none;
  }
  #bottom-bar::-webkit-scrollbar {
    display: none;
  }
}
