/* ===================================================
   Draw2Function — Ethereal Professionalism Design System
   Light Glass UI Refactor
   =================================================== */

@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&display=swap');

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* ── Surface Tokens ── */
  --surface: #f6fafe;
  --surface-container-low: #edf2f7;
  --surface-container-lowest: rgba(246, 250, 254, 0.80);
  --surface-glass: rgba(246, 250, 254, 0.65);
  --surface-glass-deep: rgba(237, 242, 247, 0.72);

  /* ── Ghost Border ── */
  --ghost-border: rgba(164, 180, 190, 0.15);
  --ghost-border-hover: rgba(120, 148, 168, 0.28);
  --ghost-border-focus: rgba(81, 95, 116, 0.40);

  /* ── Text ── */
  --text-primary: #26343d;
  --text-secondary: #556070;
  --text-muted: #8a9aaa;

  /* ── Accent ── */
  --accent: #515f74;
  --accent-mid: #455368;
  --accent-light: #7b92a8;
  --accent-glow: rgba(81, 95, 116, 0.18);

  /* ── Danger ── */
  --danger: #c0392b;
  --danger-glow: rgba(192, 57, 43, 0.12);

  /* ── Canvas ── */
  --canvas-bg: #f6fafe;

  /* ── Radii ── */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  /* ── Shadows ── */
  --shadow-sm: 0 1px 4px rgba(60, 80, 100, 0.08);
  --shadow-md: 0 6px 24px rgba(60, 80, 100, 0.12);
  --shadow-glow: 0 0 20px var(--accent-glow);

  /* ── Typography ── */
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-head: 'Manrope', 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* ── Layout ── */
  --toolbar-h: 54px;
  --status-h: 32px;
}

/* ===================================================
   Base
   =================================================== */
html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--surface);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

@keyframes canvasEnter {
  from {
    opacity: 0;
    filter: blur(8px);
    scale: 1.05;
  }

  to {
    opacity: 1;
    filter: blur(0px);
    scale: 1;
  }
}

@keyframes islandEnter {
  from {
    opacity: 0;
    translate: 0 16px;
    scale: 0.95;
  }

  to {
    opacity: 1;
    translate: 0 0;
    scale: 1;
  }
}

@keyframes popupEnter {
  from {
    opacity: 0;
    scale: 0.85;
  }

  to {
    opacity: 1;
    scale: 1;
  }
}

@keyframes popupExit {
  from {
    opacity: 1;
    scale: 1;
  }

  to {
    opacity: 0;
    scale: 0.85;
  }
}

.closing {
  animation: popupExit 0.15s ease-in both !important;
  pointer-events: none !important;
}

#canvas-wrapper {
  animation: canvasEnter 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

#right-pane-container {
  animation: islandEnter 0.5s ease-out both;
  border-radius: var(--radius-xl);
}

.floating-island,
#status-bar {
  animation: popupEnter 0.45s ease-out both;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.hidden {
  display: none !important;
}

/* ===================================================
   App Shell
   =================================================== */
#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

/* ===================================================
   LEFT PANE (was equations, now empty / kept for JS compat)
   We hide the old left pane entirely — equations move to right pane
   =================================================== */
#left-pane-container {
  display: none !important;
}

/* ===================================================
   FLOATING ISLANDS
   =================================================== */

.floating-island {
  position: absolute;
  background: rgba(246, 250, 254, 0.55);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow:
    0 2px 8px rgba(60, 80, 100, 0.10),
    0 1px 2px rgba(60, 80, 100, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  z-index: 10;
  border-radius: var(--radius-xl);
  transform: translateY(0px);
  transition:
    background 0.25s ease,
    box-shadow 0.25s ease,
    border-color 0.25s ease,
    transform 0.25s ease,
    backdrop-filter 0.25s ease;
}

.floating-island:hover {
  background: rgba(246, 250, 254, 0.75);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border: 1px solid rgba(255, 255, 255, 0.70);
  box-shadow:
    0 8px 28px rgba(60, 80, 100, 0.16),
    0 2px 6px rgba(60, 80, 100, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.80);
  transform: translateY(-2px);
}

/* 1. App Name Chip */
#app-name-chip {
  top: 24px;
  left: 24px;
  z-index: 11;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
  background: rgba(246, 250, 254, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.52);
  box-shadow:
    0 2px 10px rgba(60, 80, 100, 0.10),
    inset 0 1px 0 rgba(255, 255, 255, 0.60);
  transition:
    background 0.25s ease,
    box-shadow 0.25s ease,
    border-color 0.25s ease,
    transform 0.25s ease;
}

#app-name-chip:hover {
  background: rgba(246, 250, 254, 0.82);
  border-color: rgba(255, 255, 255, 0.75);
  box-shadow:
    0 6px 20px rgba(60, 80, 100, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.85);
  transform: translateY(-2px);
}

.pane-logo-mark {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pane-logo-mark svg {
  width: 100%;
  height: 100%;
  display: block;
}

#app-name-chip .pane-logo-text {
  user-select: none;
  font-family: var(--font-head);
  font-size: 18px;
  font-weight: 1000;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

#app-name-chip .pane-logo-text span {
  font-weight: 500;
}

/* 2. Left Toolbar */
#toolbar-left {
  left: 24px;
  bottom: calc(var(--status-h) + 24px);
  display: flex;
  z-index: 10;
  flex-direction: column;
  align-items: center;
  padding: 12px 6px;
  gap: 12px;
  pointer-events: auto;
  border-radius: 40px;
  background: rgba(240, 246, 252, 0.60);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.50);
  box-shadow:
    0 2px 10px rgba(60, 80, 100, 0.10),
    0 1px 3px rgba(60, 80, 100, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.58);
  transition:
    background 0.25s ease,
    box-shadow 0.25s ease,
    border-color 0.25s ease,
    transform 0.25s ease;
}

#toolbar-left:hover {
  background: rgba(240, 246, 252, 0.80);
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow:
    0 8px 26px rgba(60, 80, 100, 0.15),
    0 2px 6px rgba(60, 80, 100, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
  transform: translateY(-2px);
}

/* Right Group Container (dynamic anchoring) */
#right-group-container {
  position: absolute;
  right: 24px;
  top: 24px;
  bottom: calc(var(--status-h) + 24px);
  display: flex;
  flex-direction: row;
  align-items: stretch;
  /* Stretch to allow top/bottom positioning inside children */
  gap: 16px;
  z-index: 10;
  pointer-events: none;
}

#right-toolbars-stack {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-end;
  /* Align both islands to the right of this column */
  height: 100%;
  pointer-events: none;
}

#right-toolbars-stack>* {
  pointer-events: auto;
}

#right-group-container>* {
  pointer-events: auto;
}

/* 3. Right Toolbar */
#toolbar-right {
  right: calc(var(--right-pane-width) + 5px);
  bottom: 0px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 6px;
  gap: 12px;
  border-radius: 40px;
  background: rgba(240, 246, 252, 0.60);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.50);
  box-shadow:
    0 2px 10px rgba(60, 80, 100, 0.10),
    0 1px 3px rgba(60, 80, 100, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.58);
  transition: all 0.25s ease;
}

#toolbar-top-right {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 6px 12px;
  gap: 12px;
  border-radius: 40px;
  background: rgba(240, 246, 252, 0.60);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.50);
  box-shadow:
    0 2px 10px rgba(60, 80, 100, 0.10),
    0 1px 3px rgba(60, 80, 100, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.58);
  transition: all 0.25s ease;
}

#toolbar-right:hover,
#toolbar-top-right:hover {
  background: rgba(240, 246, 252, 0.80);
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow:
    0 8px 26px rgba(60, 80, 100, 0.15),
    0 2px 6px rgba(60, 80, 100, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
  transform: translateY(-2px);
}

/* Shared Pill Toolbar Elements */
.pill-toolbar .tool-btn {
  padding: 8px;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.pill-toolbar .tool-btn--mode.active {
  background: var(--text-primary);
  color: var(--surface);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toolbar-sep-horizontal {
  width: 20px;
  height: 1px;
  background: var(--ghost-border);
  margin: 4px 0;
}

.toolbar-sep-vertical {
  width: 1px;
  height: 20px;
  background: var(--ghost-border);
  margin: 0 4px;
}

/* Erase submode positioning */
#erase-submode {
  position: absolute;
  left: 100%;
  margin-left: 10px;
  top: 50px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  background: rgba(240, 246, 252, 0.62);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.50);
  padding: 6px;
  border-radius: 20px;
  box-shadow:
    0 2px 8px rgba(60, 80, 100, 0.10),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  z-index: 20;
  transition:
    background 0.25s ease,
    box-shadow 0.25s ease,
    border-color 0.25s ease,
    transform 0.25s ease;
}

#erase-submode:hover {
  background: rgba(240, 246, 252, 0.82);
  border-color: rgba(255, 255, 255, 0.70);
  box-shadow:
    0 6px 18px rgba(60, 80, 100, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.80);
  transform: translateY(-2px);
}

/* Flyouts */
.flyout-panel {
  position: absolute;
  left: 100%;
  margin-left: 10px;
  display: none;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  background: rgba(240, 246, 252, 0.62);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.50);
  padding: 8px;
  border-radius: 20px;
  box-shadow:
    0 2px 8px rgba(60, 80, 100, 0.10),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  z-index: 20;
  pointer-events: auto;
  transition:
    background 0.25s ease,
    box-shadow 0.25s ease,
    border-color 0.25s ease,
    transform 0.25s ease;
}

.flyout-panel:hover {
  background: rgba(240, 246, 252, 0.82);
  border-color: rgba(255, 255, 255, 0.70);
  box-shadow:
    0 6px 18px rgba(60, 80, 100, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.80);
  transform: translateY(-2px);
}

.flyout-panel.visible {
  display: flex !important;
  animation: popupEnter 0.25s ease-out both;
}

/* Ensure flyouts stay within viewport on left side */
#brush-control,
#palette,
#style-control {
  position: absolute;
  left: 100%;
  margin-left: 24px;
  top: 50%;
  transform: translateY(-50%);
}

.brush-flyout-trigger,
.color-flyout-trigger,
.style-flyout-trigger {
  position: relative;
}

/* Style specific */
.style-dot,
.style-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--ghost-border);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
}

.style-dot:hover,
.style-btn:hover {
  background: rgba(255, 255, 255, 0.4);
  border-color: var(--ghost-border-hover);
  color: var(--text-primary);
}

.style-dot.active,
.style-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff !important;
}

.sel-style-options {
  display: flex;
  align-items: center;
  gap: 6px;
}


/* ===================================================
   Right Pane Container (equations pane — collapsible)
   =================================================== */
#right-pane-container {
  display: flex;
  position: relative;
  z-index: 10;
  height: 100%;
  background: transparent;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: none;
  box-shadow: none;
  flex-shrink: 0;
  transition:
    background 0.25s ease,
    box-shadow 0.25s ease,
    border-color 0.25s ease,
    transform 0.25s ease;
}

#right-pane-container:not(.collapsed):hover {
  transform: translateY(-2px);
}

#right-pane {
  width: 320px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: rgba(243, 248, 253, 0.58);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(26px);
  -webkit-backdrop-filter: blur(26px);
  border: 1px solid rgba(255, 255, 255, 0.48);
  box-shadow:
    0 2px 12px rgba(60, 80, 100, 0.10),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  overflow: hidden;
  flex-shrink: 0;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

#right-pane:hover {
  background: rgba(243, 248, 253, 0.76);
  border-color: rgba(255, 255, 255, 0.68);
  box-shadow:
    0 8px 28px rgba(60, 80, 100, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.78);
}

#right-pane-container.collapsed #right-pane {
  border: none;
  box-shadow: none;
}

/* ── Resizer ── */
#right-pane-resizer {
  width: 16px;
  height: auto;
  cursor: col-resize;
  background: transparent;
  position: absolute;
  left: -10px;
  top: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
}

#right-pane-resizer::after {
  content: "";
  width: 5px;
  margin-right: 5px;
  height: 32px;
  background: var(--accent-light);
  border-radius: 10px;
  opacity: 0;
  transition: all 0.2s ease;
}

#right-pane-resizer:hover::after,
#right-pane-resizer.dragging::after {
  opacity: 0.8;
  height: 48px;
}

#right-pane-container.collapsed #right-pane-resizer {
  display: none;
}

/* ── Toggle button ── */
@keyframes fadeInToggleRight {
  0% {
    opacity: 0;
    transform: translateY(-50%) translateX(10px);
  }

  100% {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
  }
}

#toggle-right-pane {
  position: absolute;
  right: 100%;
  margin-right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 48px;
  background: rgba(246, 250, 254, 0.55);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  outline: 1px solid var(--ghost-border);
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  box-shadow: var(--shadow-sm);
  transition: color 0.2s ease, background 0.2s ease;
}

#right-pane-container.collapsed #toggle-right-pane {
  display: flex;
  animation: fadeInToggleRight 0.3s ease forwards;
}


#toggle-right-pane:hover {
  color: var(--text-primary);
  background: rgba(246, 250, 254, 0.75);
}

/* Arrow points LEFT when pane is open (to close), RIGHT when collapsed (to open) */
#right-pane-container:not(.collapsed) #toggle-right-pane svg {
  transform: rotate(0deg);
}

#right-pane-container.collapsed #toggle-right-pane svg {
  transform: rotate(180deg);
}

/* ── Right pane header ── */
#right-header {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px 20px;
  border-bottom: 3px solid var(--ghost-border);
  background: transparent;
  flex-shrink: 0;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.pane-title {
  font-family: var(--font-head);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.pane-subtitle {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ── Equation list (right pane body) ── */
#equation-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--ghost-border) transparent;
}

#equation-list::-webkit-scrollbar {
  width: 4px;
}

#equation-list::-webkit-scrollbar-thumb {
  background: var(--ghost-border);
  border-radius: 2px;
}

/* Placeholder */
#equation-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 60px;
  color: var(--text-muted);
  text-align: center;
  padding: 0 20px;
  pointer-events: none;
}

#equation-placeholder svg {
  width: 72px;
  height: 72px;
  color: var(--text-muted);
  opacity: 0.4;
}

#equation-placeholder p {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-muted);
}

/* ── Equation Cards ── */
@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.eq-card {
  display: flex;
  align-items: stretch;
  background: rgba(246, 250, 254, 0.55);
  outline: 1px solid var(--ghost-border);
  border: none;
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: background 0.18s ease-out, outline-color 0.18s ease-out, box-shadow 0.18s ease-out;
  cursor: default;
  user-select: none;
  flex-shrink: 0;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.eq-card-new {
  animation: cardEnter 0.22s ease forwards;
}

.eq-card:hover {
  background: rgba(237, 242, 247, 0.82);
  outline-color: var(--ghost-border-hover);
  box-shadow: var(--shadow-sm);
}

.eq-card.editing,
.eq-card.selected {
  outline-color: var(--accent);
  background: rgba(81, 95, 116, 0.08);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.eq-card.editing:hover,
.eq-card.selected:hover {
  background: rgba(81, 95, 116, 0.12);
}

.eq-swatch {
  width: 3px;
  flex-shrink: 0;
}

.eq-body {
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.eq-line {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.eq-line::-webkit-scrollbar {
  display: none;
}

/* Legacy */
.equation-card {
  background: rgba(246, 250, 254, 0.55);
  outline: 1px solid var(--ghost-border);
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  animation: cardEnter 0.22s ease;
  transition: background 0.18s, box-shadow 0.18s;
}

.equation-card:hover {
  background: rgba(237, 242, 247, 0.82);
  box-shadow: var(--shadow-sm);
}

.equation-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}

.equation-text {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-primary);
  word-break: break-all;
  line-height: 1.6;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Add function bar ── */
#add-fn-bar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--ghost-border);
  flex-shrink: 0;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

#add-fn-btn,
#add-pts-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px;
  background: var(--surface-container-low);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#add-fn-btn:hover,
#add-pts-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(81, 130, 200, 0.2);
  background-color: var(--surface-container-high);
  border-color: var(--ghost-border-hover);
  color: var(--text-primary);
}

#add-pts-btn:hover {
  color: #4a7fc1;
  border-color: rgba(81, 130, 200, 0.35);
  box-shadow: 0 4px 12px rgba(81, 130, 200, 0.25);
}

/* ===================================================
   Right Pane (old #right-pane = main area, now renamed in HTML)
   The main drawing area wrapper
   =================================================== */
#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}

/* ===================================================
   Toolbar
   =================================================== */
#toolbar {
  height: var(--toolbar-h);
  min-height: var(--toolbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--surface-glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  outline: 1px solid var(--ghost-border);
  border: none;
  gap: 8px;
  z-index: 5;
  flex-shrink: 0;
  overflow-x: auto;
}

#toolbar-left,
#toolbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

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

/* Color picker */
#color-picker {
  width: 0;
  height: 0;
  opacity: 0;
  position: absolute;
  pointer-events: none;
}

#color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  border: 2.5px solid rgba(255, 255, 255, 0.85);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 1px 6px var(--accent-glow);
}

#color-swatch:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 10px var(--accent-glow);
}

.tool-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color 0.15s;
}

.tool-label:hover {
  color: var(--text-primary);
}

/* Palette */
#palette {
  align-items: center;
  gap: 6px;
  padding-left: 6px;
  border-left: 1px solid var(--ghost-border);
  margin-left: 2px;
}

.palette-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  box-shadow: 0 1px 4px rgba(60, 80, 100, 0.18);
}

.palette-dot:hover {
  transform: scale(1.2);
}

.palette-dot.active {
  border-color: var(--text-primary);
  transform: scale(1.15);
}

/* Brush size */
#brush-control {
  align-items: center;
  gap: 8px;
  padding-left: 6px;
  border-left: 1px solid var(--ghost-border);
  margin-left: 2px;
}

#brush-size {
  -webkit-appearance: none;
  appearance: none;
  width: 72px;
  height: 4px;
  background: var(--surface-container-low);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  border: 1px solid var(--ghost-border);
}

#brush-size::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px var(--accent-glow);
}

#brush-size::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
}

/* ===================================================
   Tool Buttons
   =================================================== */
.tool-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: none;
  outline: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s ease-out, color 0.18s ease-out,
    outline-color 0.18s ease-out, transform 0.18s ease-out,
    box-shadow 0.18s ease-out;
  white-space: nowrap;
  flex-shrink: 0;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  outline-color: var(--ghost-border);
  color: var(--text-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.tool-btn:active {
  opacity: 0.75;
  transform: scale(0.98);
}

.tool-btn--icon {
  padding: 5px 7px;
}

/* Mode group pill */
#mode-group {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--surface-container-low);
  outline: 1px solid var(--ghost-border);
  border-radius: calc(var(--radius-sm) + 4px);
  padding: 3px;
}

.tool-btn--mode {
  border: none;
  outline: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  padding: 4px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  transition: all 0.16s ease-out;
}

.tool-btn--mode:hover {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
  outline-color: var(--ghost-border);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.tool-btn--mode.active {
  background: linear-gradient(135deg, var(--accent-mid), var(--accent));
  outline-color: transparent;
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
}

#mode-erase.active {
  background: linear-gradient(135deg, #9a4a2a, #7d3c1a);
  box-shadow: 0 2px 8px rgba(154, 74, 42, 0.25);
}

#mode-cursor.active {
  background: linear-gradient(135deg, #2d6a4f, #1b4332);
  box-shadow: 0 2px 8px rgba(45, 106, 79, 0.28);
}

/* Erase sub-mode */
#erase-submode {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--surface-container-low);
  outline: 1px solid rgba(154, 74, 42, 0.2);
  border-radius: calc(var(--radius-sm) + 4px);
  padding: 3px;
  transform-origin: left center;
  animation: popupEnter 0.25s ease-out both;
}

.tool-btn--erase-sub {
  border: none;
  outline: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  padding: 4px 9px;
  font-size: 11px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease-out;
  gap: 4px;
}

.tool-btn--erase-sub:hover {
  background: rgba(255, 220, 180, 0.15);
  color: var(--text-primary);
  outline-color: var(--ghost-border);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.tool-btn--erase-sub.active {
  background: linear-gradient(135deg, #9a4a2a, #7d3c1a);
  outline-color: transparent;
  color: #fde68a;
  box-shadow: 0 2px 8px rgba(154, 74, 42, 0.28);
}

.tool-btn--danger:hover {
  background: rgba(192, 57, 43, 0.15);
  outline-color: rgba(192, 57, 43, 0.35);
  color: var(--danger);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(192, 57, 43, 0.3);
}

/* Undo / Redo — blue tint */
#undo-btn:hover,
#redo-btn:hover {
  background: rgba(81, 130, 200, 0.15);
  outline-color: rgba(81, 130, 200, 0.3);
  color: #4a7fc1;
}

/* CSV import/export — green tint */
#csv-upload-btn:hover,
#export-csv-btn:hover {
  background: rgba(40, 160, 100, 0.15);
  outline-color: rgba(40, 160, 100, 0.3);
  color: #28a064;
}

/* Canvas import/export — teal tint */
#import-canvas-btn:hover,
#export-canvas-btn:hover {
  background: rgba(20, 140, 140, 0.15);
  outline-color: rgba(20, 140, 140, 0.3);
  color: #148c8c;
}

/* Image upload — golden yellow tint */
#img-upload-btn:hover {
  background: rgba(234, 179, 8, 0.15);
  outline-color: rgba(234, 179, 8, 0.3);
  color: #eab308;
}

/* Status bar zoom buttons */
.status-icon-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  transition: background 0.18s ease-out, color 0.18s ease-out,
    transform 0.18s ease-out, box-shadow 0.18s ease-out;
}

/* ===================================================
   Canvas Wrapper
   =================================================== */
#canvas-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--surface);
}

#drawing-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  position: relative;
  z-index: 1;
}

#drawing-canvas.mode-draw {
  cursor: crosshair;
}

#drawing-canvas.mode-erase {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='10' stroke='%23455368' stroke-width='1.5' fill='white' opacity='0.9'/%3E%3Ccircle cx='12' cy='12' r='1.5' fill='%23455368' opacity='0.9'/%3E%3C/svg%3E") 12 12, cell;
}

#drawing-canvas.mode-erase-partial {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='10' stroke='%23455368' stroke-width='1.5' fill='none' opacity='0.7'/%3E%3Ccircle cx='12' cy='12' r='1.5' fill='%23455368' opacity='0.7'/%3E%3C/svg%3E") 12 12, cell;
}

#drawing-canvas.mode-cursor {
  cursor: default;
}

#drawing-canvas.mode-cursor.panning {
  cursor: grabbing;
}

/* Canvas hint */
#canvas-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  user-select: none;
  transition: opacity 0.4s;
  animation: popupEnter 0.3s ease-out both;

  /* Island background */
  z-index: 100;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 20px 30px;
  border-radius: 20px;
  background: rgba(246, 250, 254, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.32);
  box-shadow:
    0 0px 20px rgba(135, 151, 162, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.40);

  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
}

/* Pulse dot — sits above the text as its own block */
#canvas-hint::before {
  content: '';
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 0.7;
    transform: scale(1);
  }

  50% {
    opacity: 1;
    transform: scale(1.4);
  }
}

/* ===================================================
   Status Bar
   =================================================== */
#status-bar {
  height: var(--status-h);
  min-height: var(--status-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(240, 245, 250, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 11px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.status-left,
.status-center,
.status-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.status-left {
  justify-content: flex-start;
}

.status-center {
  justify-content: center;
}

.status-right {
  justify-content: flex-end;
}

.status-icon-btn {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease, color 0.15s ease;
  font-family: inherit;
  font-size: inherit;
}

.status-icon-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-primary);
}

#coords-display {
  min-width: 140px;
  text-align: right;
}

#segment-display {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
  margin-left: 12px;
  text-align: left;
}

/* ===================================================
   Plot Bar
   =================================================== */
#plot-bar {
  position: absolute;
  bottom: 24px;
  left: 0;
  right: 0;
  width: max-content;
  margin-inline: auto;
  transform-origin: center bottom;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(240, 246, 252, 0.60);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.50);
  border-radius: var(--radius-xl);
  padding: 8px 14px;
  box-shadow:
    0 2px 10px rgba(60, 80, 100, 0.10),
    0 1px 3px rgba(60, 80, 100, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.58);
  z-index: 20;
  min-width: 420px;
  animation: popupEnter 0.25s ease-out both;
  transition:
    background 0.25s ease,
    box-shadow 0.25s ease,
    border-color 0.25s ease,
    transform 0.25s ease;
}

#plot-bar:hover {
  background: rgba(240, 246, 252, 0.80);
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow:
    0 8px 26px rgba(60, 80, 100, 0.15),
    0 2px 6px rgba(60, 80, 100, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
  transform: translateY(-2px);
}

#plot-bar-prefix {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  user-select: none;
  padding-right: 4px;
  border-right: 1px solid var(--ghost-border);
  margin-right: 2px;
}

#plot-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-primary);
  caret-color: var(--accent);
  min-width: 240px;
  height: auto;
  padding: 2px 0;
}

#plot-input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

#plot-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--accent-mid), var(--accent));
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s ease-out;
  white-space: nowrap;
  box-shadow: 0 2px 8px var(--accent-glow);
}

#plot-btn:hover {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  transform: scale(1.02);
  box-shadow: 0 4px 14px var(--accent-glow);
}

#plot-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s;
  flex-shrink: 0;
}

#plot-close-btn:hover {
  color: var(--text-primary);
}

/* ===================================================
   Point Entry Bar
   =================================================== */
#point-entry-bar {
  position: absolute;
  bottom: 24px;
  left: 0;
  right: 0;
  width: max-content;
  margin-inline: auto;
  transform-origin: center bottom;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(240, 246, 252, 0.60);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.50);
  border-radius: var(--radius-xl);
  padding: 8px 14px;
  box-shadow:
    0 2px 10px rgba(60, 80, 100, 0.10),
    0 1px 3px rgba(60, 80, 100, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.58);
  z-index: 20;
  min-width: 420px;
  animation: popupEnter 0.25s ease-out both;
  transition: all 0.25s ease;
}

#point-entry-bar:hover {
  background: rgba(240, 246, 252, 0.80);
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow:
    0 8px 26px rgba(60, 80, 100, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
  transform: translateY(-2px);
}

#point-bar-prefix {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  padding-right: 4px;
  border-right: 1px solid var(--ghost-border);
  margin-right: 2px;
}

#point-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-primary);
  caret-color: var(--accent);
}

.point-bar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

#point-add-btn,
#point-done-btn {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

#point-add-btn {
  background: rgba(81, 130, 200, 0.15);
  border: 1px solid rgba(81, 130, 200, 0.3);
  color: #4a7fc1;
}

#point-add-btn:hover {
  background: rgba(81, 130, 200, 0.25);
  transform: translateY(-1px);
}

#point-done-btn {
  background: linear-gradient(135deg, var(--accent-mid), var(--accent));
  border: none;
  color: #fff;
  box-shadow: 0 2px 6px var(--accent-glow);
}

#point-done-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px var(--accent-glow);
}

#point-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 4px;
  border-radius: var(--radius-sm);
}

#point-close-btn:hover {
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.05);
}

/* ===================================================
   Selection Panel
   =================================================== */
#selection-panel {
  position: absolute;
  bottom: 74px;
  left: 0;
  right: 0;
  width: max-content;
  margin-inline: auto;
  transform-origin: center bottom;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(240, 246, 252, 0.60);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.50);
  border-radius: var(--radius-xl);
  padding: 8px 14px;
  box-shadow:
    0 2px 10px rgba(60, 80, 100, 0.10),
    0 1px 3px rgba(60, 80, 100, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.58);
  z-index: 20;
  min-width: 420px;
  animation: popupEnter 0.25s ease-out both;
  white-space: nowrap;
  transition:
    background 0.25s ease,
    box-shadow 0.25s ease,
    border-color 0.25s ease,
    transform 0.25s ease;
}

#selection-panel:hover {
  background: rgba(240, 246, 252, 0.80);
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow:
    0 8px 26px rgba(60, 80, 100, 0.15),
    0 2px 6px rgba(60, 80, 100, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
  transform: translateY(-2px);
}

.sel-section {
  display: flex;
  align-items: center;
  gap: 7px;
}

.sel-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-transform: uppercase;
  user-select: none;
}

.sel-swatches {
  display: flex;
  align-items: center;
  gap: 5px;
}

.sel-swatch-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  box-shadow: 0 1px 3px rgba(60, 80, 100, 0.2);
}

.sel-swatch-dot:hover {
  transform: scale(1.2);
}

.sel-swatch-dot.active {
  border-color: var(--text-primary);
  transform: scale(1.15);
}

.sel-custom-color-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px dashed var(--ghost-border-hover);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}

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

#sel-color-picker {
  width: 0;
  height: 0;
  opacity: 0;
  position: absolute;
  pointer-events: none;
}

#sel-brush-size {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 4px;
  background: var(--surface-container-low);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  border: 1px solid var(--ghost-border);
}

#sel-brush-size::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 3px var(--accent-glow);
}

#sel-brush-value {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  min-width: 24px;
}

.sel-divider {
  width: 1px;
  height: 22px;
  background: var(--ghost-border);
  flex-shrink: 0;
  margin: 0 2px;
}

.sel-delete-btn,
.sel-action-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease-out;
}

.sel-delete-btn:hover {
  background: var(--danger-glow);
  border-color: rgba(192, 57, 43, 0.3);
  color: var(--danger);
}

.sel-action-btn:hover,
#img-trace-btn:hover {
  background: rgba(234, 179, 8, 0.15);
  border-color: rgba(234, 179, 8, 0.3);
  color: #eab308;
}

/* ===================================================
   Image Panel (overlay image controls)
   =================================================== */
#image-panel {
  position: absolute;
  bottom: 74px;
  left: 0;
  right: 0;
  width: max-content;
  margin-inline: auto;
  transform-origin: center bottom;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(240, 246, 252, 0.60);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.50);
  border-radius: var(--radius-xl);
  padding: 8px 14px;
  box-shadow:
    0 2px 10px rgba(60, 80, 100, 0.10),
    0 1px 3px rgba(60, 80, 100, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.58);
  z-index: 20;
  min-width: 420px;
  animation: popupEnter 0.25s ease-out both;
  white-space: nowrap;
  transition:
    background 0.25s ease,
    box-shadow 0.25s ease,
    border-color 0.25s ease,
    transform 0.25s ease;
}

#image-panel:hover {
  background: rgba(240, 246, 252, 0.80);
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow:
    0 8px 26px rgba(60, 80, 100, 0.15),
    0 2px 6px rgba(60, 80, 100, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
  transform: translateY(-2px);
}

/* Reuse sel-brush-size styles for opacity slider */
#img-opacity-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 88px;
  height: 4px;
  background: var(--surface-container-low);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  border: 1px solid var(--ghost-border);
}

#img-opacity-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #eab308;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(234, 179, 8, 0.35);
}

#img-opacity-slider::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #eab308;
  border: 2px solid #fff;
}

#img-opacity-value {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  min-width: 34px;
}

/* Image selection handles on canvas (drawn via JS, no extra CSS needed) */

/* ===================================================
   Snap toggle
   =================================================== */
.snap-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: auto 8px auto 0;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  border: none;
  outline: 1px solid var(--ghost-border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease-out;
}

.snap-toggle:hover {
  background: rgba(81, 95, 116, 0.07);
  outline-color: var(--ghost-border-hover);
  color: var(--accent);
  transform: scale(1.05);
}

/* ===================================================
   Scrollbar global
   =================================================== */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--ghost-border) transparent;
}

/* ===================================================
   Responsive
   =================================================== */
@media (max-width: 700px) {
  #right-pane-container {
    display: none;
  }

  #palette {
    display: none;
  }

  #brush-control {
    display: none;
  }
}

@media (max-width: 900px) {
  .tool-btn--mode {
    padding: 5px 8px;
  }

  #mode-draw span,
  #mode-erase span,
  #mode-cursor span {
    display: none;
  }
}

/* ===================================================
   Key Points Tooltip
   =================================================== */

#key-point-tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 200;
  display: none;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  background: rgba(246, 250, 254, 0.82);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.60);
  border-radius: var(--radius-md);
  box-shadow:
    0 4px 16px rgba(60, 80, 100, 0.14),
    0 1px 4px rgba(60, 80, 100, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.70);
  white-space: nowrap;
  transform: translate(14px, -50%);
  transition: opacity 0.12s ease;
}

#key-point-tooltip.visible {
  display: flex;
  animation: popupEnter 0.25s ease-out both;
}

.kp-tooltip-label {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.kp-tooltip-coords {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
}

/* ===================================================
   Shortcuts Popup
   =================================================== */
#shortcuts-popup {
  position: fixed;
  top: 90px;
  left: 24px;
  z-index: 100;
  width: 420px;

  /* Subtle toolbar-like glassmorphism */
  background: rgba(243, 248, 253, 0.58);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.50);
  border-radius: 40px;
  box-shadow:
    0 2px 10px rgba(60, 80, 100, 0.10),
    0 1px 3px rgba(60, 80, 100, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.58);

  padding: 16px;
  animation: popupEnter 0.25s ease-out both;
}

/* ===================================================
   Settings Modal backdrop
   =================================================== */
@keyframes backdropEnter {
  from { background: transparent; }
  to   { background: rgba(0, 0, 0, 0.35); }
}

@keyframes backdropExit {
  from { background: rgba(0, 0, 0, 0.35); }
  to   { background: transparent; }
}

#settings-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  animation: backdropEnter 0.25s ease both;
}

#settings-modal.backdrop-exit {
  animation: backdropExit 0.15s ease-in both;
}

/* ===================================================
   Settings Modal Card
   =================================================== */
#settings-card {
  position: relative;
  width: 420px;
  max-width: 90vw;
  border-radius: var(--radius-xl);
  padding: 28px 32px;
  background: rgba(243, 248, 253, 0.831);
  border: 1px solid rgba(255, 255, 255, 0.48);
  box-shadow:
    0 8px 32px rgba(60, 80, 100, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  animation: popupEnter 0.25s ease-out both;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.settings-title {
  font-family: var(--font-head);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.settings-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
  padding: 4px;
  transition: color 0.15s ease, background 0.15s ease;
}

.settings-close-btn:hover {
  color: var(--text-primary);
  background: var(--surface-container-low);
}

.settings-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.settings-row {
  display: flex;
  gap: 8px;
}

.settings-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--ghost-border-hover);
  border-radius: var(--radius-md);
  background: var(--surface-container-low);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
}

.settings-save-btn {
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--accent-mid), var(--accent));
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.settings-save-btn:hover {
  opacity: 0.88;
}

.settings-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 10px;
  line-height: 1.7;
}

.settings-hint strong {
  color: var(--text-secondary);
}

.settings-hint a {
  color: var(--accent-light);
}

.shortcuts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.shortcuts-title {
  font-family: var(--font-head);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.shortcuts-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.shortcuts-close-btn:hover {
  color: var(--text-primary);
  background: rgba(81, 95, 116, 0.08);
}

.shortcuts-grid {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.shortcuts-columns {
  display: flex;
  flex-direction: row;
  gap: 0;
}

.shortcuts-col {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.shortcuts-col-divider {
  width: 1px;
  background: var(--ghost-border);
  margin: 0 12px;
  flex-shrink: 0;
}

.shortcuts-section-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: 10px;
  margin-bottom: 2px;
}

.shortcuts-section-label:first-child {
  margin-top: 0;
}

.shortcut-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 0;
}

.shortcut-row span {
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: auto;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  background: rgba(246, 250, 254, 0.90);
  border: 1px solid rgba(120, 148, 168, 0.30);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(60, 80, 100, 0.10);
  white-space: nowrap;
  min-width: 20px;
}

/* ═══════════════════════════════════════════════════════════════
   LIQUID GLASS
   backdrop-filter: blur → frosted base
   filter: url(#glass-distortion) → refractive distortion on top
   ::after → thin frosted overlay for readability + specular edge
   ═══════════════════════════════════════════════════════════════ */

:root {
  --lg-shadow: 0 0 0 1px rgba(255, 255, 255, .45), 0 8px 32px rgba(0, 0, 0, .18);
  --lg-shadow-hover: 0 0 0 1px rgba(255, 255, 255, .65), 0 12px 40px rgba(0, 0, 0, .22);
}

/* Apply blur + distortion directly on the element */
.floating-island,
#app-name-chip,
#toolbar-left,
#toolbar-right,
#toolbar-top-right,
#plot-bar,
#point-entry-bar,
#selection-panel,
#image-panel,
#shortcuts-popup,
#erase-submode,
.flyout-panel,
#key-point-tooltip,
#status-bar,
#toggle-right-pane,
#canvas-hint,
#settings-card {
  backdrop-filter: url(#glass-distortion) !important;
  -webkit-backdrop-filter: url(#glass-distortion) !important;
  filter: none !important;
  box-shadow: var(--lg-shadow) !important;
  border: 1px solid rgba(255, 255, 255, .3) !important;
}

/* Frosted overlay + specular highlight via ::after */
.floating-island::after,
#app-name-chip::after,
#toolbar-left::after,
#toolbar-right::after,
#toolbar-top-right::after,
#right-pane::after,
#plot-bar::after,
#point-entry-bar::after,
#selection-panel::after,
#image-panel::after,
#shortcuts-popup::after,
#erase-submode::after,
.flyout-panel::after,
#key-point-tooltip::after,
#status-bar::after,
#toggle-right-pane::after,
#canvas-hint::after,
#settings-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 255, 255, .10);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5);
  pointer-events: none;
  z-index: 0;
}

/* Content above overlay */
.floating-island>*,
#app-name-chip>*,
#toolbar-left>*:not(#erase-submode),
#toolbar-right>*,
#toolbar-top-right>*,
#right-pane>*,
#plot-bar>*,
#point-entry-bar>*,
#selection-panel>*,
#image-panel>*,
#shortcuts-popup>*,
#erase-submode>*,
.flyout-panel>*,
#key-point-tooltip>*,
#status-bar>*,
#toggle-right-pane>*,
#canvas-hint>*,
#settings-card>* {
  position: relative;
  z-index: 1;
}


#status-bar {
  border-top: 1px solid rgba(255, 255, 255, .3) !important;
  border-left: none !important;
  border-right: none !important;
  border-bottom: none !important;
  border-radius: 0 !important;
  overflow: visible !important;
}

/* ── Equation cards — subtle liquid tint ─────────────────────── */
.eq-card {
  background: rgba(255, 255, 255, 0.08) !important;
  backdrop-filter: blur(16px) !important;
  -webkit-backdrop-filter: blur(16px) !important;
  border: none !important;
  outline: 1px solid rgba(255, 255, 255, 0.22) !important;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.50),
    0 2px 8px rgba(30, 50, 80, 0.06) !important;
  transition: background 0.18s ease, outline-color 0.18s ease,
    box-shadow 0.18s ease !important;
}

.eq-card:hover {
  background: rgba(255, 255, 255, 0.15) !important;
  outline-color: rgba(255, 255, 255, 0.45) !important;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.75),
    0 4px 14px rgba(30, 50, 80, 0.10) !important;
}

.eq-card.selected,
.eq-card.editing {
  outline-color: var(--accent) !important;
  background: rgba(81, 95, 116, 0.12) !important;
}

/* ── Dark mode adjustments ────────────────────────────────────── */
body.dark {
  --lg-bg: rgba(20, 28, 40, 0.30);
  --lg-bg-hover: rgba(30, 40, 58, 0.48);
  --lg-border: rgba(255, 255, 255, 0.14);
  --lg-border-hover: rgba(255, 255, 255, 0.28);
  --lg-shadow:
    0 0 0 0.5px rgba(255, 255, 255, 0.18),
    0 12px 40px rgba(0, 0, 0, 0.35),
    0 3px 10px rgba(0, 0, 0, 0.20),
    inset 0 1.5px 0 rgba(255, 255, 255, 0.25),
    inset 1px 0 0 rgba(255, 255, 255, 0.12),
    inset 0 -1px 0 rgba(0, 0, 0, 0.15),
    inset -1px 0 0 rgba(0, 0, 0, 0.10);
  --lg-shadow-hover:
    0 0 0 0.5px rgba(255, 255, 255, 0.28),
    0 16px 52px rgba(0, 0, 0, 0.45),
    0 4px 14px rgba(0, 0, 0, 0.28),
    inset 0 1.5px 0 rgba(255, 255, 255, 0.35),
    inset 1px 0 0 rgba(255, 255, 255, 0.18),
    inset 0 -1px 0 rgba(0, 0, 0, 0.18),
    inset -1px 0 0 rgba(0, 0, 0, 0.12);
}

body.dark .floating-island::before,
body.dark #toolbar-left::before,
body.dark #toolbar-right::before,
body.dark #toolbar-top-right::before,
body.dark #plot-bar::before,
body.dark #point-entry-bar::before,
body.dark #selection-panel::before,
body.dark #image-panel::before,
body.dark #shortcuts-popup::before,
body.dark #erase-submode::before,
body.dark .flyout-panel::before,
body.dark #key-point-tooltip::before,
body.dark #right-pane::before {
  background: linear-gradient(138deg,
      rgba(255, 255, 255, 0.10) 0%,
      rgba(255, 255, 255, 0.03) 30%,
      transparent 55%,
      rgba(255, 255, 255, 0.03) 100%);
}