/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: #f0f4f8;
  color: #1e2938;
  height: 100vh; width: 100vw;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none; -webkit-user-select: none;
}

/* ── CSS VARIABLES ── */
:root {
  --lm-tint-bg: rgba(10,18,40,0.97);   /* master tint — updated by TINT palette */
  --lm-tint-border: rgba(255,255,255,0.12);
  --lm-label-color: rgba(15,25,45,0.90); /* label text — dark by default (light canvas in day) */
  --blue: #1a6fc4;
  --blue-dark: #155aa0;
  --amber: #d97706;
  --amber-border: #f59e0b;
  --red: #dc2626;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow: 0 4px 12px rgba(0,0,0,0.10);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.14);
  --radius: 10px;
}

/* ── NAVBAR (shared brand) ── */
#navbar {
  position: fixed; top: 0; left: 0; right: 0; height: 58px;
  background: var(--surface, #ffffff);
  border-bottom: 1px solid var(--border, #c7d4f0);
  display: flex; align-items: center; padding: 0 14px; gap: 8px;
  z-index: 200;
}
.nav-links { display: flex; gap: 4px; margin-left: auto; }
.nav-link {
  height: 30px; display: inline-flex; align-items: center;
  font-size: 0.78rem; font-weight: 600; color: #94a3b8;
  text-decoration: none; padding: 0 13px; border-radius: 6px;
  border: 1px solid transparent; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.nav-link:hover { color: #e2e8f0; background: rgba(255,255,255,0.09); border-color: rgba(255,255,255,0.15); }
.nav-link.active { color: #f59e0b; background: rgba(245,158,11,0.12); border-color: rgba(245,158,11,0.3); }
.nav-logout {
  height: 30px; display: inline-flex; align-items: center;
  font-size: 0.78rem; font-weight: 600; padding: 0 13px; border-radius: 6px;
  border: 1px solid rgba(220,38,38,0.35); background: rgba(220,38,38,0.12);
  color: #fca5a5; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s; margin-left: 6px;
}
.nav-logout:hover { background: rgba(220,38,38,0.25); border-color: #dc2626; color: #fff; }

/* Wordmark */
.nav-wordmark { display: flex; flex-direction: column; justify-content: center; text-decoration: none; gap: 1px; }
.nav-wordmark-name { font-size: 1.05rem; font-weight: 800; letter-spacing: -0.01em; color: #0f2040; line-height: 1; }
.nav-wordmark-name .wm-mark { color: #f59e0b !important; }
.nav-wordmark-name .wm-dot  { color: #94a3b8 !important; }
.nav-wordmark-name .wm-t    { color: #38bdf8 !important; }
.nav-wordmark-name .wm-e    { color: #f87171 !important; }
.nav-wordmark-name .wm-c    { color: #f59e0b !important; }
.nav-wordmark-name .wm-h    { color: #34d399 !important; }
.nav-wordmark-tag { font-size: 0.58rem; color: #4a6090; letter-spacing: 0.04em; font-weight: 500; text-transform: uppercase; }

/* Hamburger */
.nav-hamburger {
  display: none; flex-direction: column; justify-content: center; gap: 5px;
  background: none; border: none; width: 36px; height: 36px;
  cursor: pointer; padding: 6px; margin-left: 4px;
}
.nav-hamburger span { display: block; height: 2px; background: #94a3b8; border-radius: 2px; transition: 0.2s; }
/* ── NAV DROPDOWN: Beveled Crystal Glass ── */
#nav-dropdown {
  display: none;
  position: fixed;
  top: 58px;
  left: 0; right: 0; bottom: 0;
  z-index: 1500;
  flex-direction: column;
  padding: 14px 16px 22px;
  overflow: hidden;
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(36px) saturate(2.0) brightness(1.05);
  -webkit-backdrop-filter: blur(36px) saturate(2.0) brightness(1.05);
  border-top: 2px solid rgba(255,255,255,0.95);
  border-bottom: 2px solid rgba(245,158,11,0.65);
  box-shadow: 0 12px 48px rgba(56,189,248,0.14), 0 4px 16px rgba(0,0,0,0.10);
}
#nav-dropdown.open { display: flex; }
/* Style A — nav links */
.nav-dropdown-link {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 48px;
  border-radius: 10px;
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 600;
  color: #334155;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.13s, color 0.13s, padding-left 0.13s;
  background: rgba(0,0,0,0.04);
  border: none;
  border-left: 3px solid transparent;
  padding: 0 14px 0 13px;
}
.nav-dropdown-link .nd-link-icon { font-size: 1.2rem; line-height: 1; flex-shrink: 0; opacity: 0.75; transition: opacity 0.12s; }
.nav-dropdown-link .nd-link-label { flex: 1; letter-spacing: 0.01em; }
.nav-dropdown-link:hover { background: rgba(0,0,0,0.075); color: #0f2040; padding-left: 17px; }
.nav-dropdown-link:hover .nd-link-icon { opacity: 1; }
.nav-dropdown-link.active { background: rgba(225,29,72,0.10); color: #be123c; font-weight: 700; padding-left: 17px; }
.nav-dropdown-link.active .nd-link-icon { opacity: 1; }
.nav-dropdown-link[href="/landing.html"] { border-left-color: #3b82f6; }
.nav-dropdown-link[href="/index.html"]   { border-left-color: #0ea5e9; }
.nav-dropdown-link[href="/field.html"]   { border-left-color: #0d9488; }
.nav-dropdown-link[href="/mapguru.html"] { border-left-color: #6366f1; }
.nav-dropdown-link[href="/insight.html"] { border-left-color: #e11d48; }
.nav-dropdown-link[href="/logic.html"]   { border-left-color: #f59e0b; }
.nav-dropdown-link.active[href="/landing.html"] { background: rgba(59,130,246,0.10); color: #1d4ed8; }
.nav-dropdown-link.active[href="/index.html"]   { background: rgba(14,165,233,0.10); color: #0369a1; }
.nav-dropdown-link.active[href="/field.html"]   { background: rgba(13,148,136,0.10); color: #0f766e; }
.nav-dropdown-link.active[href="/mapguru.html"] { background: rgba(99,102,241,0.10); color: #4338ca; }
.nav-dropdown-link.active[href="/insight.html"] { background: rgba(225,29,72,0.10);  color: #be123c; }
.nav-dropdown-link.active[href="/logic.html"]   { background: rgba(245,158,11,0.12); color: #b45309; }
.nav-dropdown-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(56,189,248,0.40), transparent);
  margin: 6px 0 10px;
}
.nav-dropdown-row { display: flex; gap: 8px; padding: 4px 0; }
.nd-nav-links { display: flex; flex-direction: column; gap: 4px; padding: 4px 0 12px; width: 100%; flex: 1; overflow: hidden; }
.nd-tint-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 2px 14px;
  flex-wrap: wrap;
}
.nd-tint-label {
  font-size: 0.72rem;
  font-weight: 800;
  color: rgba(14,165,233,0.85);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-right: 4px;
  flex-shrink: 0;
}
.nd-swatch {
  width: 36px !important; height: 36px !important;
  min-width: 36px !important; min-height: 36px !important;
  max-width: 36px !important; max-height: 36px !important;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.80);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15), inset 0 1px 0 rgba(255,255,255,0.70);
  transition: transform 0.12s, box-shadow 0.12s;
  flex-shrink: 0;
  padding: 0;
}
.nd-swatch:hover { transform: scale(1.20); box-shadow: 0 3px 10px rgba(0,0,0,0.22); }
.nd-swatch.active { border-color: #f59e0b !important; box-shadow: 0 0 0 3px #f59e0b, 0 3px 10px rgba(245,158,11,0.35) !important; transform: scale(1.15); }
.nd-swatch, .nd-custom-color { width:36px!important;height:36px!important;min-width:36px!important;min-height:36px!important;max-width:36px!important;max-height:36px!important; }
.nd-custom-color {
  width: 24px; height: 24px;
  min-width: 24px !important; min-height: 24px !important;
  max-width: 24px; max-height: 24px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.70);
  padding: 0;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  overflow: hidden;
  flex-shrink: 0;
}

/* ── MAIN LAYOUT ── */
.insight-wrap {
  position: fixed;
  top: 58px; left: 0; right: 0;
  bottom: 0;
  display: flex; flex-direction: column;
}

/* Insight sub-header */
.insight-bar {
  flex: 0 0 auto;
  background: #f0f4ff;
  border-bottom: 1px solid #c7d4f0;
  display: flex; flex-direction: column;
  overflow: hidden;
}
/* Always-visible handle row */
.insight-bar-handle {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px;
  cursor: pointer;
  user-select: none;
}
/* Expandable button body — drops DOWN over canvas */
.insight-bar-body {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
  padding: 0 14px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease, padding 0.25s ease;
}
.insight-bar.ib-open .insight-bar-body {
  max-height: 200px;
  padding: 0 14px 10px;
}
.ib-chevron {
  font-size: 0.7rem; color: #4a6090;
  transition: transform 0.2s;
  margin-left: auto;
}
.insight-bar.ib-open .ib-chevron { transform: rotate(180deg); }
.insight-bar .tb-title { font-size: 0.88rem; font-weight: 700; color: #0f2040; }
.insight-bar .tb-sub   { font-size: 0.70rem; color: #4a6090; }
.tb-btn {
  appearance: none;
  background: #f0f4ff; border: 1px solid #c7d4f0; color: #0f2040;
  padding: 5px 12px; border-radius: 6px;
  font-size: 0.78rem; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background 0.15s;
}
.tb-btn:hover { background: #e0e8ff; }
.tb-btn.primary { background: var(--blue); border-color: var(--blue-dark); color: #fff; }
.tb-btn.active  { background: #f59e0b; border-color: #d97706; color: #000; font-weight: 700; }
.tb-btn.primary:hover { background: var(--blue-dark); }
.tb-btn.danger  { color: var(--red); border-color: rgba(220,38,38,0.3); }
.tb-spacer { flex: 1; }


/* ── CANVAS STAGE ── */
.stage {
  flex: 1 1 auto;
  position: relative; overflow: hidden;
  background-color: #e8edf4;
  background-image:
    linear-gradient(rgba(180,195,215,0.4) 1px, transparent 1px),
    linear-gradient(90deg, rgba(180,195,215,0.4) 1px, transparent 1px);
  background-size: 24px 24px;
  touch-action: none;
}
.stage canvas {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  touch-action: none;
  background: repeating-linear-gradient(0deg,transparent,transparent 19px,rgba(255,255,255,0.04) 20px),repeating-linear-gradient(90deg,transparent,transparent 19px,rgba(255,255,255,0.04) 20px);
}
#photoCanvas { z-index: 1; }
#drawCanvas  { z-index: 2; }

/* Empty state */
.empty-state {
  position: absolute; inset: 0; z-index: 3;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 24px; text-align: center;
  pointer-events: none;
}
.empty-state.hidden { display: none; }
.empty-state .es-icon { font-size: 52px; opacity: 0.35; }
.empty-state h2 { font-size: 1.1rem; font-weight: 700; color: #1e2938; margin: 0; }
.empty-state p  { font-size: 0.82rem; color: #6b7280; max-width: 260px; margin: 0; }
.empty-state .es-btn {
  pointer-events: auto;
  background: var(--blue); color: #fff; font-weight: 700;
  padding: 11px 20px; border-radius: 10px; border: none;
  font-size: 0.9rem; cursor: pointer;
  box-shadow: 0 2px 8px rgba(26,111,196,0.35);
}
.empty-state .es-btn:active { transform: scale(0.97); }

/* ── DRAW MODE BANNER ── */
.mode-banner {
  position: absolute; top: 10px; right: 10px; z-index: 10;
  padding: 6px 12px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700;
  pointer-events: none; display: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.mode-banner.show { display: inline-flex; align-items: center; gap: 5px; }
.mode-banner.draw { background: rgba(26,111,196,0.92); color: #fff; }
.mode-banner.pan  { background: rgba(250,204,21,0.92); color: #2a1a00; }

/* ── CRYSTAL / GLASS ZOOM PAD ── */
/* Collapsed state: just a glowing dot */
.zoom-dot {
  position: absolute;
  right: 14px; bottom: 14px; z-index: 20;
  width: 36px; height: 36px;
  border-radius: 50%;
  cursor: pointer;
  /* glass */
  background: radial-gradient(circle at 35% 35%,
    rgba(255,255,255,0.72) 0%,
    rgba(200,225,255,0.38) 40%,
    rgba(120,180,255,0.18) 100%
  );
  backdrop-filter: blur(12px) saturate(1.6);
  -webkit-backdrop-filter: blur(12px) saturate(1.6);
  border: 1px solid rgba(255,255,255,0.55);
  box-shadow:
    0 0 0 1px rgba(56,189,248,0.35),
    0 0 14px rgba(56,189,248,0.25),
    inset 0 1px 1px rgba(255,255,255,0.70);
  transition: opacity 0.25s, transform 0.25s, box-shadow 0.25s;
  display: flex; align-items: center; justify-content: center;
}
.zoom-dot:hover {
  box-shadow:
    0 0 0 2px rgba(56,189,248,0.55),
    0 0 20px rgba(56,189,248,0.40),
    inset 0 1px 1px rgba(255,255,255,0.70);
  transform: scale(1.08);
}
/* Inner crystal shine */
.zoom-dot::before {
  content: '';
  position: absolute;
  top: 5px; left: 7px;
  width: 12px; height: 7px;
  background: rgba(255,255,255,0.70);
  border-radius: 50%;
  transform: rotate(-20deg);
  pointer-events: none;
}
/* Dot icon */
.zoom-dot-icon {
  width: 8px; height: 8px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #a8d8ff 0%, #38bdf8 60%, #0ea5e9 100%);
  box-shadow: 0 0 6px rgba(56,189,248,0.8);
}

/* ── EXPANDED glass pad ── */
.zoom-pad {
  position: absolute;
  right: 10px; bottom: 10px; z-index: 20;
  display: none;
  flex-direction: column; gap: 6px;
  padding: 14px 12px 12px;
  border-radius: 22px;
  /* deep crystal glass */
  background: linear-gradient(145deg,
    rgba(255,255,255,0.82) 0%,
    rgba(210,235,255,0.60) 35%,
    rgba(170,215,255,0.38) 70%,
    rgba(140,200,255,0.22) 100%
  );
  backdrop-filter: blur(28px) saturate(2.2) brightness(1.08);
  -webkit-backdrop-filter: blur(28px) saturate(2.2) brightness(1.08);
  border: 1px solid rgba(255,255,255,0.75);
  border-top-color: rgba(255,255,255,0.95);
  border-left-color: rgba(255,255,255,0.90);
  box-shadow:
    0 0 0 1px rgba(56,189,248,0.28),
    0 12px 40px rgba(56,189,248,0.22),
    0 4px 16px rgba(0,0,0,0.12),
    inset 0 2px 0 rgba(255,255,255,0.95),
    inset 0 -1px 0 rgba(56,189,248,0.12),
    inset 2px 0 0 rgba(255,255,255,0.50);
  overflow: visible;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
/* Wide prismatic shine bar across top */
.zoom-pad::before {
  content: '';
  position: absolute;
  top: 7px; left: 12px; right: 35%;
  height: 5px;
  background: linear-gradient(90deg,
    rgba(255,255,255,0.90) 0%,
    rgba(200,240,255,0.70) 50%,
    rgba(255,255,255,0.30) 100%
  );
  border-radius: 3px;
  pointer-events: none;
}
/* Second subtle lower-right sheen */
.zoom-pad::after {
  content: '';
  position: absolute;
  bottom: 10px; right: 8px; left: 55%;
  height: 3px;
  background: rgba(56,189,248,0.18);
  border-radius: 2px;
  pointer-events: none;
}
.zoom-pad.show { display: flex; }
/* fade out when auto-hiding */
.zoom-pad.fading { opacity: 0; transform: scale(0.96); pointer-events: none; }

/* Collapse dot inside pad (top-right) */
.zp-collapse {
  position: absolute; top: -10px; right: -10px;
  width: 26px; height: 26px; border-radius: 50%;
  background: rgba(255,255,255,0.70);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.60);
  box-shadow: 0 0 8px rgba(56,189,248,0.35), inset 0 1px 1px rgba(255,255,255,0.80);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: #0ea5e9; font-weight: 800;
  transition: transform 0.15s, box-shadow 0.15s;
}
.zp-collapse:hover { transform: scale(1.12); box-shadow: 0 0 14px rgba(56,189,248,0.55); }

.zp-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  color: rgba(14,165,233,0.80); text-align: center; text-transform: uppercase;
  padding-bottom: 2px;
}
.zp-zoom-row { display: flex; gap: 6px; justify-content: center; }
.zp-pad-grid {
  display: grid;
  grid-template-columns: repeat(3, 38px);
  grid-template-rows: repeat(3, 38px);
  gap: 5px;
}
#zpUp    { grid-column: 2; grid-row: 1; }
#zpLeft  { grid-column: 1; grid-row: 2; }
#zpReset { grid-column: 2; grid-row: 2; }
#zpRight { grid-column: 3; grid-row: 2; }
#zpDown  { grid-column: 2; grid-row: 3; }

/* Glass button style */
.zbtn, .pbtn {
  appearance: none;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.80);
  border-bottom-color: rgba(200,230,255,0.45);
  border-right-color: rgba(200,230,255,0.45);
  background: linear-gradient(160deg,
    rgba(255,255,255,0.88) 0%,
    rgba(225,242,255,0.65) 40%,
    rgba(190,225,255,0.40) 100%
  );
  backdrop-filter: blur(10px) saturate(1.8);
  -webkit-backdrop-filter: blur(10px) saturate(1.8);
  box-shadow:
    0 2px 6px rgba(0,0,0,0.10),
    inset 0 1.5px 0 rgba(255,255,255,0.95),
    inset 0 -1px 0 rgba(56,189,248,0.10);
  color: #0369a1; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
}
.zbtn { width: 46px; height: 38px; font-size: 18px; }
.pbtn { width: 38px; height: 38px; font-size: 16px; }
.pbtn.blank { visibility: hidden; }
.zbtn:active, .pbtn:active {
  transform: scale(0.91);
  background: linear-gradient(160deg, rgba(56,189,248,0.30) 0%, rgba(14,165,233,0.18) 100%);
  box-shadow: 0 0 10px rgba(56,189,248,0.40), inset 0 1px 0 rgba(255,255,255,0.70);
}
.zlabel {
  font-size: 10px; font-weight: 700; color: rgba(14,165,233,0.75);
  text-align: center; letter-spacing: 0.03em;
}

/* ── BOTTOM TOOLBAR ── */
.toolbar {
  flex: 0 0 auto;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  display: flex; flex-direction: column; gap: 0;
  transition: max-height 0.25s ease;
  overflow: hidden;
}
.toolbar-handle { display: none; }
.toolbar-handle-bar { display: none; }
.toolbar-chevron { display: none; }
.toolbar-body { display: flex; flex-direction: column; gap: 10px; padding: 8px 14px 14px; }
.toolbar-quick { display: none; }
.t-row {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  overflow-x: auto; scrollbar-width: none; flex-wrap: wrap;
}
/* Color tray — collapsed by default on desktop, toggled open */
#deskColorTray { display: none; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
#deskColorTray.open { display: flex; }
#deskColorToggle {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid #d1d5db; cursor: pointer; flex: 0 0 auto;
  background: conic-gradient(red,orange,yellow,green,blue,violet,red);
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  transition: transform 0.1s;
}
#deskColorToggle:hover { transform: scale(1.12); }
#deskActiveColor {
  width: 12px; height: 12px; border-radius: 50%;
  background: #e11d2d;
  border: 1.5px solid rgba(255,255,255,0.8);
  box-shadow: 0 0 3px rgba(0,0,0,0.3);
  position: absolute; bottom: -2px; right: -2px;
  pointer-events: none;
}
#deskColorToggle { position: relative; }

/* ── SIZE TOGGLE BALL ── */
#deskSizeBall {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex: 0 0 auto; position: relative;
  background: rgba(30,41,59,0.85);
  border: 2px solid #4b5563;
  box-shadow: 0 1px 5px rgba(0,0,0,0.2);
  transition: transform 0.1s;
}
#deskSizeBall:hover { transform: scale(1.1); }
#deskSizeDot {
  border-radius: 50%;
  background: #e5e7eb;
  pointer-events: none;
  transition: width 0.15s, height 0.15s;
  /* default = sz 6 */
  width: 7px; height: 7px;
}
#deskSizeTray {
  display: none; align-items: center; gap: 6px;
}
#deskSizeTray.open { display: flex; }

/* ── SWITCH TOGGLE BALL WRAP ── */
#swBallWrap {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  flex: 0 0 auto;
}
#swModeTag {
  font-size: 0.58rem; font-weight: 800; letter-spacing: 0.08em;
  color: rgba(255,255,255,0.45); background: rgba(30,41,59,0.7);
  border-radius: 4px; padding: 1px 5px; pointer-events: none;
  border: 1px solid rgba(255,255,255,0.12);
  transition: color 0.2s, border-color 0.2s;
}
#swModeTag.mode-3w { color: #38bdf8; border-color: rgba(56,189,248,0.4); }

/* ── SWITCH STATE TOGGLE BALL ── */
#swToggleBall {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex: 0 0 auto;
  background: rgba(30,41,59,0.85);
  border: 2px solid rgba(251,191,36,0.4);
  box-shadow: 0 1px 5px rgba(0,0,0,0.25);
  transition: transform 0.1s, background 0.2s, border-color 0.2s, box-shadow 0.2s;
  user-select: none;
}
#swToggleBall:hover { transform: scale(1.1); }
/* OFF state — dim amber */
#swToggleBall[data-state="off"]  { border-color: rgba(251,191,36,0.35); background: rgba(30,41,59,0.85); }
#swToggleBall[data-state="off"]  #swToggleLabel { color: rgba(255,255,255,0.4); }
/* ON state — green glow */
#swToggleBall[data-state="on"]   { border-color: #22c55e; background: rgba(34,197,94,0.18); box-shadow: 0 0 10px rgba(34,197,94,0.45); }
#swToggleBall[data-state="on"]   #swToggleLabel { color: #4ade80; }
/* 3-WAY step — blue glow */
#swToggleBall[data-state="3w"]   { border-color: #38bdf8; background: rgba(56,189,248,0.18); box-shadow: 0 0 10px rgba(56,189,248,0.45); }
#swToggleBall[data-state="3w"]   #swToggleLabel { color: #38bdf8; }
#swToggleLabel { pointer-events: none; font-size: 0.7rem; font-weight: 800; line-height: 1; text-align: center; }

/* ── LIGHTNING BALL ── */
#deskLightningBall {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex: 0 0 auto;
  background: rgba(30,41,59,0.85);
  border: 2px solid rgba(250,204,21,0.35);
  box-shadow: 0 1px 5px rgba(0,0,0,0.2);
  font-size: 1rem; user-select: none;
  transition: transform 0.1s, border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
#deskLightningBall:hover { transform: scale(1.1); }
#deskLightningBall.active { border-color: #facc15; background: rgba(250,204,21,0.18); box-shadow: 0 0 10px rgba(250,204,21,0.45); }

/* ── SWITCH BALL ── */
#deskSwitchBall {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex: 0 0 auto;
  background: rgba(30,41,59,0.85);
  border: 2px solid rgba(251,191,36,0.4);
  box-shadow: 0 1px 5px rgba(0,0,0,0.2);
  font-size: 1rem; user-select: none;
  transition: transform 0.1s, border-color 0.2s, background 0.2s;
}
#deskSwitchBall:hover { transform: scale(1.1); }
#deskSwitchBall.active { border-color: #f59e0b; background: rgba(245,158,11,0.18); box-shadow: 0 0 10px rgba(245,158,11,0.4); }

/* ── ERASE BALL ── */
#deskEraseBall {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex: 0 0 auto;
  background: rgba(30,41,59,0.85);
  border: 2px solid rgba(239,68,68,0.35);
  box-shadow: 0 1px 5px rgba(0,0,0,0.2);
  font-size: 1rem; user-select: none;
  transition: transform 0.1s, border-color 0.2s, background 0.2s;
}
#deskEraseBall:hover { transform: scale(1.1); }
#deskEraseBall.active { border-color: #ef4444; background: rgba(239,68,68,0.18); box-shadow: 0 0 10px rgba(239,68,68,0.4); }
.t-row::-webkit-scrollbar { display: none; }

/* Color swatches */
.swatch {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%;
  border: 2px solid #d1d5db; cursor: pointer;
  transition: transform 0.08s, border-color 0.08s, box-shadow 0.08s;
}
.swatch.active { border-color: #fff; transform: scale(1.10); box-shadow: 0 0 0 2px #1a6fc4; }
.swatch[data-c="black"]  { background: #111; }
.swatch[data-c="red"]    { background: #e11d2d; }
.swatch[data-c="blue"]   { background: #2868d8; }
.swatch[data-c="green"]  { background: #16a34a; }
.swatch[data-c="white"]  { background: #f8f8f8; border-color: #ccc; }
.swatch[data-c="yellow"] { background: #facc15; }
.swatch[data-c="orange"] { background: #f97316; }
.swatch[data-c="custom"] {
  background: conic-gradient(red,orange,yellow,green,blue,violet,red);
}

/* Brush sizes */
.brush-btn {
  flex: 0 0 auto; width: 46px; height: 46px; border-radius: 10px;
  border: 1px solid #d1d5db; background: #f3f4f6;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.brush-btn.active { background: #1a6fc4; border-color: #155aa0; }
.brush-btn.active .bdot { background: #fff; }
.bdot { background: #374151; border-radius: 50%; }

/* Mode pill */
.mode-pill {
  display: inline-flex; background: transparent;
  border-radius: 10px; padding: 0; gap: 4px; flex: 0 0 auto;
}
.mode-opt {
  appearance: none;
  border: none;
  border-left: 3px solid #c7d4f0;
  background: rgba(0,0,0,0.04);
  cursor: pointer;
  color: #475569; font-size: 0.82rem; font-weight: 700;
  padding: 9px 14px 9px 11px; border-radius: 9px; white-space: nowrap;
  transition: background 0.13s, padding-left 0.12s, border-color 0.13s;
  height: 38px; display: inline-flex; align-items: center; gap: 5px;
}
.mode-opt:hover { background: rgba(0,0,0,0.08); padding-left: 15px; }
.mode-opt.active { background: rgba(26,111,196,0.14); border-left-color: #1a6fc4; color: #1d4ed8; }
.mode-opt[data-mode="lasso"].active { background: rgba(124,58,237,0.14); border-left-color: #7c3aed; color: #7c3aed; }
#lassoAssign {
  position: fixed; z-index: 8000;
  background: rgba(10,14,35,0.97);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1.5px solid rgba(255,255,255,0.18);
  border-radius: 14px;
  padding: 12px 14px 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  min-width: 200px; max-width: 260px;
  display: none;
}
#lassoAssign.show { display: block; }
.lasso-assign-title { font-size: 0.72rem; font-weight: 800; color: rgba(255,255,255,0.5); letter-spacing:.06em; text-transform:uppercase; margin-bottom:8px; }
.lasso-circuit-btn {
  display: flex; align-items: center; gap: 7px;
  width: 100%; padding: 8px 10px; margin-bottom: 5px;
  border-radius: 8px; border: 1.5px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06); color: #e2e8f0;
  font-size: 0.8rem; font-weight: 700; cursor: pointer; text-align: left;
  transition: background 0.12s, border-color 0.12s;
}
.lasso-circuit-btn:hover { background: rgba(255,255,255,0.14); border-color: rgba(255,255,255,0.35); }
.lasso-cancel-btn {
  width: 100%; padding: 6px; border-radius: 7px;
  border: none; background: none; color: rgba(255,255,255,0.3);
  font-size: 0.75rem; cursor: pointer; margin-top: 2px;
}

/* Action buttons row — Style A */
.act-row { display: flex; gap: 6px; }
.act-btn {
  flex: 1; appearance: none;
  border: none;
  border-left: 3px solid #c7d4f0;
  background: rgba(0,0,0,0.04); color: #334155;
  padding: 9px 14px 9px 11px; border-radius: 9px;
  font-size: 0.78rem; font-weight: 700; cursor: pointer; white-space: nowrap;
  transition: background 0.13s, padding-left 0.12s, border-color 0.13s;
  height: 38px; display: inline-flex; align-items: center; gap: 5px;
}
.act-btn:hover { background: rgba(0,0,0,0.08); padding-left: 15px; border-left-color: #e11d48; }
.act-btn:active { transform: scale(0.97); }
.act-btn.primary { background: rgba(26,111,196,0.10); border-left-color: #1a6fc4; color: #1d4ed8; }
.act-btn.primary:hover { background: rgba(26,111,196,0.18); }
.act-btn.danger  { border-left-color: #dc2626; color: #dc2626; }
.act-btn.danger:hover { background: rgba(220,38,38,0.08); }

/* Save to job modal */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.45); align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff; border-radius: 16px; padding: 24px 20px;
  max-width: 340px; width: 90%; box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal-box h3 { font-size: 1rem; font-weight: 800; color: #0f2040; margin-bottom: 8px; }
.modal-box p  { font-size: 0.82rem; color: #6b7280; margin-bottom: 16px; }
.modal-box select {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid #d1d5db; font-size: 0.88rem; color: #1e2938;
  background: #f9fafb; margin-bottom: 14px;
}
.modal-btns { display: flex; gap: 8px; }
.modal-btn {
  flex: 1; padding: 10px; border-radius: 8px; font-size: 0.82rem; font-weight: 700;
  border: 1px solid #d1d5db; background: #f3f4f6; cursor: pointer; color: #1e2938;
}
.modal-btn.primary { background: #1a6fc4; color: #fff; border-color: #155aa0; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 90px;
  transform: translateX(-50%);
  background: rgba(15,32,64,0.92); color: #fff;
  padding: 9px 16px; border-radius: 10px;
  font-size: 0.82rem; font-weight: 600;
  opacity: 0; transition: opacity 0.2s;
  pointer-events: none; z-index: 300; white-space: nowrap;
}
.toast.show { opacity: 1; }

/* Idle warning modal */
.idle-modal {
  display: none; position: fixed; inset: 0; z-index: 9000;
  background: rgba(0,0,0,0.55); align-items: center; justify-content: center;
}
.idle-modal.open { display: flex; }
.idle-inner {
  background: #fff; border-radius: 16px; padding: 28px 24px;
  max-width: 320px; width: 90%; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.idle-inner h3 { font-size: 1.1rem; font-weight: 800; margin-bottom: 8px; color: #0f2040; }
.idle-inner p  { font-size: 0.85rem; color: #6b7280; margin-bottom: 18px; }
.idle-inner .idle-count { font-size: 2rem; font-weight: 900; color: #dc2626; display: block; margin: 8px 0 16px; }
.idle-inner button {
  width: 100%; padding: 12px; border-radius: 10px; border: none;
  background: #1a6fc4; color: #fff; font-size: 0.92rem; font-weight: 700; cursor: pointer;
}

/* Hidden file input */
input[type=file] { display: none; }

/* Responsive: hide nav-links on small screen */
@media (max-width: 680px) {
  .nav-links { display: none !important; }
  .nav-hamburger { display: flex !important; }
  #theme-toggle-btn { display: none; }
}

/* ── Mode badges: reposition on iPad/iPhone so they clear the navbar ── */
@media (max-width: 1366px) {
  /* Both badges move below the 58px navbar, centered horizontally.
     They sit side-by-side if both are visible at the same time. */
  #eraseBadge {
    top: 66px !important;
    right: auto !important;
    left: 12px !important;
    transform: none !important;
  }
  #dotLockBadge {
    top: 66px !important;
    right: auto !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
  }
}

/* ══════════════════════════════════════════════════════════════
   TOUCH DEVICE OVERRIDES  (≤ 1024 px  =  iPhone + iPad)
   Everything lives in the insight-bar drop-down.
   No floating panels, no bottom tab bar.
   Desktop (> 1024 px) keeps all existing behaviour.
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 1366px) {

  /* Canvas: full height under navbar, nothing at bottom */
  .insight-wrap { top: 58px; bottom: 0; }

  /* Hide desktop toolbar + all legacy mobile widgets */
  #mainToolbar    { display: none !important; }

  /* Hide every float — their controls live in the drop-down */
  .float-panel    { display: none !important; }
  #sw43Panel      { display: none !important; }

  /* Nav: hide desktop links, show hamburger */
  .nav-links      { display: none !important; }
  .nav-hamburger  { display: flex !important; }
  #theme-toggle-btn { display: none; }

  /* insight-bar handle — always visible strip */
  .insight-bar-handle {
    padding: 0 10px;
    min-height: 48px;
    gap: 8px;
  }
  .insight-bar .tb-title { font-size: 0.82rem; }
  .insight-bar .tb-sub   { display: none; }
  #saveJobBtn, #uploadBtn {
    padding: 8px 14px !important;
    font-size: 0.85rem !important;
  }

  /* Drop-down body: scrollable, tall enough to hold everything */
  .insight-bar-body {
    display: flex !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    gap: 0 !important;
    max-height: 0;
    overflow: hidden;
    padding: 0;
    transition: max-height 0.3s ease, padding 0.3s ease;
  }
  .insight-bar.ib-open .insight-bar-body {
    max-height: 80vh;
    overflow-y: auto;
    /* Extra bottom padding so the floating mode bar never covers the last row */
    padding: 6px 10px calc(90px + env(safe-area-inset-bottom,0px));
    -webkit-overflow-scrolling: touch;
  }

  /* Modals: slide up as bottom sheet */
  .modal-overlay { align-items: flex-end !important; padding: 0 !important; }
  .modal-box {
    width: 100% !important; max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    padding: 20px 16px calc(24px + env(safe-area-inset-bottom,0px)) !important;
    max-height: 88vh; overflow-y: auto;
  }

  /* Mode banner */
  .mode-banner { font-size: 0.76rem !important; padding: 3px 10px !important; }
}

/* ── Drop-down section blocks (used on ≤ 1024px) ── */
.mdd-section {
  display: none;        /* hidden on desktop */
  border-top: 1px solid rgba(0,0,0,0.09);
  padding: 8px 0 4px;
  margin-top: 4px;
}
.mdd-label {
  font-size: 0.6rem; font-weight: 800; color: #6b7280;
  letter-spacing: .07em; text-transform: uppercase;
  margin-bottom: 5px;
}
/* Mode row */
.mdd-mode-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 2px; }
.mdd-mode-btn {
  flex: 1 1 auto; min-width: 56px;
  padding: 11px 6px; border-radius: 10px;
  border: 1.5px solid #d1d5db; background: #f3f4f6;
  font-size: 0.82rem; font-weight: 700; cursor: pointer;
  color: #374151; text-align: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s;
}
.mdd-mode-btn.mdd-active            { background:#1a6fc4; color:#fff; border-color:#155aa0; }
.mdd-mode-btn[data-m="switch"].mdd-active { background:#92400e; color:#fbbf24; border-color:#fbbf24; }
.mdd-mode-btn[data-m="lasso"].mdd-active  { background:#5b21b6; color:#c4b5fd; border-color:#7c3aed; }
.mdd-mode-btn[data-m="pan"].mdd-active    { background:#0369a1; color:#bae6fd; border-color:#0ea5e9; }
/* Color swatches */
.mdd-swatch-row { display:flex; gap:8px; flex-wrap:wrap; align-items:center; }
.mdd-swatch {
  width:34px; height:34px; border-radius:50%;
  border:2px solid rgba(0,0,0,0.15); cursor:pointer;
  flex-shrink:0; -webkit-tap-highlight-color:transparent;
  transition:transform 0.1s, box-shadow 0.1s;
}
.mdd-swatch.mdd-sw-active { transform:scale(1.2); box-shadow:0 0 0 3px #1a6fc4; }
/* Brush row */
.mdd-brush-row { display:flex; gap:6px; align-items:center; flex-wrap:wrap; }
.mdd-brush {
  width:44px; height:44px; border-radius:10px;
  border:1.5px solid #d1d5db; background:#f3f4f6;
  display:flex; align-items:center; justify-content:center;
  cursor:pointer; -webkit-tap-highlight-color:transparent;
  transition:background 0.1s;
}
.mdd-brush.mdd-active { background:#1a6fc4; border-color:#155aa0; }
.mdd-brush.mdd-active .mdd-dot { background:#fff !important; }
.mdd-dot { background:#374151; border-radius:50%; }
/* Action row */
.mdd-action-row { display:flex; gap:6px; flex-wrap:wrap; }
.mdd-action-btn {
  flex:1 1 auto; padding:10px 8px; border-radius:9px;
  border:1.5px solid #d1d5db; background:#f3f4f6;
  font-size:0.82rem; font-weight:700; cursor:pointer;
  color:#374151; text-align:center;
  -webkit-tap-highlight-color:transparent;
}
/* Circuit row */
.mdd-circuit-row { display:flex; gap:6px; }
.mdd-circuit-btn {
  flex:1; padding:9px 4px; border-radius:9px;
  border:1.5px solid; background:transparent;
  font-size:0.78rem; font-weight:800;
  cursor:pointer; text-align:center;
  -webkit-tap-highlight-color:transparent;
  transition:background 0.15s;
}
/* Switch spawn row */
.mdd-sw-row { display:flex; gap:6px; flex-wrap:wrap; }
.mdd-sw-btn {
  flex:1 1 auto; padding:10px 6px;
  border-radius:9px; border:1.5px solid;
  font-size:0.82rem; font-weight:800;
  cursor:pointer; text-align:center;
  -webkit-tap-highlight-color:transparent;
}
/* Show mdd-sections only on touch breakpoint */
@media (max-width: 1366px) {
  .mdd-section { display: block; }
}

/* ───────────────────────────────────────────────────────────
   CANVAS MODE — full immersive drawing space
   body.canvas-mode: hides navbar + insight-bar,
   canvas fills the entire screen.
   A single “Menu” pill in the top-left is the only UI.
   ─────────────────────────────────────────────────────────── */

/* The Menu pill — always in DOM, hidden until canvas-mode */
#canvasMenuBtn {
  display: none;
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 12px;
  z-index: 9200;
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(15,32,64,0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid rgba(245,158,11,0.55);
  color: #f59e0b;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(0,0,0,0.28);
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: auto;
}
#canvasMenuBtn:active { opacity: 0.75; transform: scale(0.96); }

/* In canvas-mode: show the Menu button, hide everything else */
body.canvas-mode #canvasMenuBtn   { display: block; }
body.canvas-mode #navbar           { transform: translateY(-100%); pointer-events: none; }
body.canvas-mode .insight-wrap     { top: 0 !important; }
body.canvas-mode .insight-bar      { max-height: 0 !important; overflow: hidden !important; pointer-events: none; }
/* Canvas mode: hide the navbar — bottom toolbar stays */
body.canvas-mode #navbar           { display: none !important; }
body.canvas-mode #stage            { top: 0 !important; bottom: 0 !important; }
body.canvas-mode .insight-wrap     { top: 0 !important; bottom: calc(58px + env(safe-area-inset-bottom,0px)) !important; }

/* Smooth slide animations */
#navbar { transition: transform 0.25s ease; }
.insight-bar { transition: max-height 0.25s ease, opacity 0.2s ease; }

/* iPhone-specific tweaks */
@media (max-width: 480px) {
  .insight-bar-handle { min-height: 44px; }
  #saveJobBtn { font-size:0.8rem !important; padding:7px 10px !important; }
  #uploadBtn  { font-size:0.8rem !important; padding:7px 10px !important; }
  .mdd-mode-btn { padding: 12px 4px; font-size: 0.78rem; }
  .mdd-brush    { width:40px; height:40px; }
  .mdd-swatch   { width:32px; height:32px; }
}

/* ── Mobile color tray (above tab bar) ── */


/* Feature 2: layer panel library open state */
#libraryPanel.open { display: flex !important; }
/* Feature 2: active layer button */
.layer-btn.layer-active { box-shadow: 0 0 0 2px #1a6fc4; }
.layer-btn.layer-live {
  animation: layer-pulse 1.6s ease-in-out infinite;
}
@keyframes layer-pulse {
  0%,100% { box-shadow: 0 0 0 2px currentColor, 0 0 6px 2px rgba(255,255,255,0.3); }
  50%      { box-shadow: 0 0 0 3px currentColor, 0 0 18px 6px rgba(255,255,255,0.55); }
}
.live-badge {
  font-size: 9px; font-weight: 800; letter-spacing: 0.06em;
  text-transform: uppercase; padding: 1px 5px; border-radius: 4px;
  background: rgba(255,255,255,0.25); color: inherit; white-space: nowrap;
}
/* Feature 3: active shape button */
.shape-pick-btn.shape-active { background: #1a6fc4 !important; color: #fff !important; border-color: #155aa0 !important; }


/* ── Recolor popover swatches ── */
.rcol-sw {
  width: 28px; height: 28px; border-radius: 50%;
  cursor: pointer; position: relative;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.rcol-sw:hover { transform: scale(1.18); border-color: rgba(255,255,255,0.6); }
.rcol-sw.selected { border-color: #fff; transform: scale(1.18); }

/* ── Floating / draggable panels ─────────────────────────── */
.float-panel {
  position: fixed !important;
  z-index: 8000;
  border-radius: 14px;
  box-shadow: 0 8px 36px rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.14);
  right: auto;
  user-select: none;
  -webkit-user-select: none;
}
.float-handle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 6px;
  cursor: grab;
  background: rgba(255,255,255,0.06);
  border-radius: 14px 14px 0 0;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  touch-action: none;
}
.float-handle:active { cursor: grabbing; }
.float-handle-dots {
  display: flex; gap: 3px; align-items: center;
}
.float-handle-dots span {
  width: 4px; height: 4px; border-radius: 50%;
  background: rgba(255,255,255,0.35);
  display: block;
}
.float-close {
  background: none; border: none; color: rgba(255,255,255,0.4);
  font-size: 14px; cursor: pointer; padding: 0 2px; line-height: 1;
}
.float-close:hover { color: #fff; }

/* ── Floating color palette ─────────────────────────────── */
#floatColor {
  background: rgba(20,20,35,0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 0;
  top: 80px; left: 16px;
  min-width: 220px;
}
#floatColor .float-body {
  padding: 10px 12px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
#floatColor .swatch-row {
  display: flex; gap: 7px; flex-wrap: wrap; align-items: center;
}

/* ── Floating brush/size palette ───────────────────────── */
#floatBrush {
  background: rgba(20,20,35,0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 0;
  top: 80px; left: 260px;
  min-width: 200px;
}
#floatBrush .float-body {
  padding: 10px 12px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
#floatBrush .size-row {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
}

/* Convert layerPanel + shapePanel to float */
#layerPanel, #shapePanel {
  border-radius: 14px !important;
  top: 80px !important; left: 16px !important;
  right: auto !important; bottom: auto !important;
  min-width: 300px;
  border-bottom: none !important;
}

/* lSwitch CSS removed */

  50%      { box-shadow: 0 0 0 3px #fbbf24, 0 0 22px 8px rgba(251,191,36,0.65); }
}
/* Ghost switch following finger while placing */
#swGhost {
  position: fixed; pointer-events: none; z-index: 9999;
  font-size: 0.72rem; font-weight: 800; padding: 6px 12px;
  border-radius: 20px; border: 2px solid; opacity: 0.88;
  transform: translate(-50%, -50%);
  display: none; white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
}

/* Switch mode */
.mode-opt[data-mode="switch"].active { background: #92400e; color: #fbbf24; border-color: #fbbf24; }
.mode-banner.switch-mode { background: rgba(120,60,0,0.95); color: #fbbf24; }
.mode-banner.grab { background: rgba(5,150,105,0.93); color: #fff; font-weight: 800; }

/* ═══════════════════════════════════════════════════
   RADIAL FAB  (mobile ≤1024px only)
   All controls live here. Insight-bar handle hidden.
═══════════════════════════════════════════════════ */
@media (max-width: 1366px) {
  /* Canvas fills everything */
  .insight-wrap { top: 0 !important; bottom: 0 !important; }
  /* Hide the insight-bar handle strip entirely on mobile — FAB handles Save/Load */
  .insight-bar-handle { display: none !important; }
  /* Hide old mode pill + switch pill */
}

/* FAB root — always visible on mobile */
/* ══════════════════════════════════════════════════════════
   MOBILE BOTTOM TOOLBAR  (≤1024px)
   Full-width bar pinned to bottom — always visible, never hidden
   ══════════════════════════════════════════════════════════ */

/* Top action bar (Undo/Redo/Load/Save) */
#mobileTopBar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  background: rgba(10,18,40,0.97);
  border-bottom: 1px solid rgba(255,255,255,0.10);
  z-index: 9300;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  gap: 6px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
@media (max-width: 1366px) { #mobileTopBar { display: flex; } }

/* Bottom toolbar shell — glass formula identical to nav dropdown */
#mobileBar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(58px + env(safe-area-inset-bottom,0px));
  padding-bottom: env(safe-area-inset-bottom,0px);
  background: rgba(255,255,255,0.18);
  backdrop-filter: blur(36px) saturate(2.0) brightness(1.05);
  -webkit-backdrop-filter: blur(36px) saturate(2.0) brightness(1.05);
  border-top: 2px solid rgba(255,255,255,0.95);
  z-index: 9200;
  align-items: stretch;
  justify-content: space-around;
  overflow: hidden;
}
/* Tint overlay — same as nav ::before — driven by --nd-tint */
#mobileBar::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--nd-tint, rgba(255,255,255,0));
  pointer-events: none;
  z-index: 0;
  transition: background 0.35s ease;
}
/* Buttons must sit above the tint overlay */
#mobileBar .mb-btn { position: relative; z-index: 1; }
@media (max-width: 1366px) { #mobileBar { display: flex; } }

/* Each mode button */
.mb-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  color: var(--lm-label-color, rgba(15,25,45,0.90));
  /* Ensure label text is always visible — JS overrides this per-theme */
  -webkit-font-smoothing: antialiased;
  cursor: pointer;
  border: none;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.13s, background 0.13s;
  border-radius: 0;
  padding: 0;
  position: relative;
  user-select: none;
  gap: 2px;
}
.mb-btn span.mb-label {
  font-size: 0.52rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: inherit;
  opacity: 0.75;
}
.mb-btn.mb-active {
  color: #f59e0b;
  background: rgba(245,158,11,0.10);
}
.mb-btn.mb-active::after {
  content: '';
  position: absolute;
  bottom: 0; left: 20%; right: 20%;
  height: 2.5px;
  background: #f59e0b;
  border-radius: 2px 2px 0 0;
}
/* Switch button active — amber */
.mb-btn[data-mode="switch"].mb-active { color: #fbbf24; background: rgba(251,191,36,0.10); }
.mb-btn[data-mode="switch"].mb-active::after { background: #fbbf24; }
/* Circuits button — green */
.mb-btn[data-mode="circuits"].mb-active { color: #4ade80; background: rgba(74,222,128,0.10); }
.mb-btn[data-mode="circuits"].mb-active::after { background: #4ade80; }

/* Color indicator dot on the draw button */
#mbDrawColorDot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #e11d2d;
  position: absolute;
  top: 7px; right: calc(50% - 16px);
  border: 1.5px solid rgba(255,255,255,0.4);
  pointer-events: none;
}

/* ── POPOVERS (slide up above their button) ── */
.mb-popover {
  position: fixed;
  bottom: calc(58px + env(safe-area-inset-bottom,0px));
  z-index: 9400;
  background: var(--lm-tint-bg);
  border: 1.5px solid var(--lm-tint-border);
  border-radius: 16px 16px 4px 4px;
  padding: 10px 10px 8px;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  min-width: 0;
}
.mb-popover.mb-pop-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Draw popover — anchored under draw button */
#mbPopDraw {
  left: 0; right: 0;
  border-radius: 16px;
}
.mbp-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 6px; }
.mbp-row:last-child { margin-bottom: 0; }
.mbp-swatch {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.22);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  flex-shrink: 0;
}
.mbp-swatch.mbp-active { transform: scale(1.28); box-shadow: 0 0 0 3px #f59e0b; }
/* Switch pill wrap — always on canvas */
#swPillWrap { z-index: 9600; }
.mbp-brush {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(15,30,61,0.95);
  border: 2px solid rgba(255,255,255,0.18);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  flex-shrink: 0;
}
.mbp-brush.mbp-sz-active { background: #1a6fc4; border-color: #60a5fa; }
.mbp-brush-dot { border-radius: 50%; background: #e2e8f0; pointer-events: none; }
.mbp-erase {
  font-size: 0.65rem; font-weight: 900; color: #f87171;
}

/* Erase sub-mode toggle pills (Free / Segment) */
.mbp-erase-sub {
  flex: 1;
  height: 36px;
  border-radius: 999px;
  border: 1.5px solid rgba(239,68,68,0.35);
  background: rgba(239,68,68,0.07);
  color: rgba(255,255,255,0.5);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.mbp-erase-sub.mbp-erase-sub-active {
  background: rgba(239,68,68,0.28);
  border-color: #ef4444;
  color: #fca5a5;
}
/* Size row dims in segment mode */
#mbEraseSizeRow.mbp-erase-dim {
  opacity: 0.35;
  pointer-events: none;
}

/* Switch popover */
#mbPopSwitch { left: 0; right: 0; border-radius: 16px; }
.mbp-sw-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.mbp-sw-token {
  min-width: 54px; height: 44px;
  border-radius: 10px; border: 2px solid;
  font-size: 0.78rem; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0 10px;
  transition: transform 0.1s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  -webkit-tap-highlight-color: transparent;
}
.mbp-sw-token:active { transform: scale(0.91); }
.mbp-sw-wide { min-width: 110px; }

/* Circuits popover */
#mbPopCircuits { left: 0; right: 0; border-radius: 16px; }
.mbp-phase-btn {
  min-width: 54px; height: 44px;
  border-radius: 10px; border: 2px solid;
  font-size: 0.78rem; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0 10px;
  transition: transform 0.1s, opacity 0.13s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  -webkit-tap-highlight-color: transparent;
  background: transparent;
  opacity: 0.65;
}
.mbp-phase-btn.mbp-phase-on { opacity: 1; font-size: 0.85rem; }
.mbp-phase-btn:active { transform: scale(0.91); }

/* Offset popovers so they appear above their own button */
#mbPopDraw    { left: 0; right: 0; }
#mbPopSwitch  { left: 0; right: 0; }
#mbPopCircuits{ left: 0; right: 0; }
#mbPopMore    { left: 0; right: 0; }

/* Push canvas content away from top/bottom bars on mobile */
@media (max-width: 1366px) {
  #stage { top: 0 !important; bottom: 0 !important; width: 100% !important; overflow: hidden !important; }
  /* insight-wrap top is set dynamically by JS to match real navbar height */
  .insight-wrap { bottom: calc(58px + env(safe-area-inset-bottom,0px)) !important; width: 100% !important; overflow: hidden !important; }
}

/* Hide old controls on mobile */
@media (max-width: 1366px) {
  .corner-fab, #radialFab, #rfabSaveBtn, #rfabLoadBtn,
  .insight-bar-handle { display: none !important; }
}


/* Circuits bubble — phase buttons */
.circ-phase-btn {
  min-width:48px; height:42px;
  border-radius:10px; border:2.5px solid;
  font-size:0.85rem; font-weight:900;
  display:flex; align-items:center; justify-content:center;
  cursor:pointer; padding:0 6px;
  transition:transform 0.1s, box-shadow 0.15s, background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color:transparent;
  opacity:0.45;
}
.circ-phase-btn:active { transform:scale(0.90); }
/* ON states — explicit per phase */
#cpC1.circ-on  { opacity:1; background:rgba(225,29,45,0.25)  !important; border-color:#e11d2d !important; box-shadow:0 0 14px 4px rgba(225,29,45,0.55); }
#cpC2.circ-on  { opacity:1; background:rgba(156,163,175,0.25)!important; border-color:#9ca3af !important; box-shadow:0 0 12px 3px rgba(156,163,175,0.45); }
#cpC3.circ-on  { opacity:1; background:rgba(56,189,248,0.25) !important; border-color:#38bdf8 !important; box-shadow:0 0 14px 4px rgba(56,189,248,0.55); }
#cpCN.circ-on  { opacity:1; background:rgba(107,114,128,0.22)!important; border-color:#6b7280 !important; box-shadow:0 0 10px 2px rgba(107,114,128,0.4); }
/* Lightning ON state */
#cpLightning.circ-lt-on {
  background:rgba(250,204,21,0.28) !important;
  border-color:#facc15 !important;
  color:#fff !important;
  box-shadow:0 0 18px 5px rgba(250,204,21,0.6) !important;
}
@media (max-width:1366px){ #circBubble { display:block; } }
@media (min-width:1367px){ #circBubble { display:none !important; } }

/* ── LOGIC GATE BUBBLE ── */
/* gate bubble removed */

/* ── Logic page gate spawn buttons ── */
.gate-btn {
  padding: 5px 9px;
  border-radius: 7px;
  border: 1.5px solid rgba(129,140,248,0.5);
  background: rgba(129,140,248,0.10);
  color: #a5b4fc;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, transform 0.1s;
}
.gate-btn:active { background: rgba(129,140,248,0.28); transform: scale(0.92); }

/* ── Logic page phase buttons (C1/C2/C3) ── */
.lgc-phase-btn {
  padding: 5px 10px;
  border-radius: 7px;
  border: 2px solid;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow 0.15s, background 0.15s, transform 0.1s;
}
.lgc-phase-btn:active { transform: scale(0.90); }
.lgc-phase-btn.layer-live-on {
  box-shadow: 0 0 0 2.5px currentColor, 0 0 14px 4px currentColor;
  filter: brightness(1.3);
}

/* ── Logic bubble element buttons ── */
.lgc-elem-btn {
  padding: 6px 11px;
  border-radius: 8px;
  border: 1.5px solid rgba(167,139,250,0.45);
  background: rgba(139,92,246,0.1);
  color: #c4b5fd;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  white-space: nowrap;
}
.lgc-elem-btn:active {
  background: rgba(139,92,246,0.28);
  transform: scale(0.91);
}

/* ── Logic page canvas workspace ── */
body.page-logic .stage {
  background-color: #f8fafc;
  background-image:
    linear-gradient(rgba(100,120,160,0.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(100,120,160,0.18) 1px, transparent 1px);
  background-size: 20px 20px;
}
/* Night mode */
body.night-mode.page-logic .stage {
  background-color: #080c18;
  background-image:
    linear-gradient(rgba(80,100,140,0.22) 1px, transparent 1px),
    linear-gradient(90deg, rgba(80,100,140,0.22) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* ══════════════════════════════════════════════════
   LOGIC PAGE — force stage to fill screen correctly
   ══════════════════════════════════════════════════ */
body.page-logic .insight-wrap {
  position: fixed !important;
  top: 58px !important;
  left: 0 !important; right: 0 !important;
  bottom: calc(64px + env(safe-area-inset-bottom, 0px)) !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

/* Hide desktop toolbar bar handle on logic — just shows the canvas */
body.page-logic .insight-bar {
  display: none !important;
}

/* Stage fills all remaining space */
body.page-logic .stage {
  flex: 1 1 0% !important;
  width: 100% !important;
  height: 100% !important;
  overflow: hidden !important;
  position: relative !important;
}

/* Canvas fills stage fully */
body.page-logic .stage canvas {
  position: absolute !important;
  top: 0 !important; left: 0 !important;
  width: 100% !important; height: 100% !important;
  display: block !important;
}

/* Desktop toolbar hidden on mobile for logic */
@media (max-width: 1024px) {
  body.page-logic .toolbar { display: none !important; }
}
