/* ==========================================================================
   True Scale Ruler - Core Stylesheet
   Modern, sleek, ergonomic workbench design for precision measurement
   ========================================================================== */

:root {
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;

  /* Color Palette - Linear.app Precision Utility (DESIGN.md) */
  --bg-main: #0B0D13;
  --bg-surface: #12161F;
  --bg-surface-elevated: #161B26;
  --bg-surface-glass: rgba(18, 22, 31, 0.85);
  --card-bg: #12161F;
  --btn-bg: #161B26;
  --btn-bg-hover: #1F2430;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.20);
  --border-focus: #5E6AD2;

  --text-primary: #ECEEEF;
  --text-main: #ECEEEF;
  --text-muted: #8A8F98;
  --text-dim: #606672;

  --primary: #5E6AD2;
  --primary-hover: #4F5BC0;
  --primary-light: rgba(94, 106, 210, 0.15);

  --accent-gold: #f59e0b;
  --accent-green: #10B981;
  --accent-red: #ef4444;
  --active-tab-bg: #1F2430;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.5);
  --shadow-glass: 0 8px 24px rgba(0, 0, 0, 0.45);
}

/* Light Theme Variables */
[data-theme="light"] {
  --bg-main: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f1f5f9;
  --bg-surface-glass: rgba(255, 255, 255, 0.88);
  --card-bg: #ffffff;
  --btn-bg: #f1f5f9;
  --btn-bg-hover: #e2e8f0;
  --border-color: rgba(0, 0, 0, 0.12);
  --border-subtle: rgba(15, 23, 42, 0.09);
  --border-hover: rgba(15, 23, 42, 0.18);
  --border-focus: #2563eb;

  --text-primary: #0f172a;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: rgba(37, 99, 235, 0.1);
  --active-tab-bg: #e2e8f0;

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.07);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 30px rgba(15, 23, 42, 0.12);
  --shadow-glass: 0 8px 32px 0 rgba(15, 23, 42, 0.07);
}

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

html, body {
  width: 100%;
  min-height: 100%;
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* Accessibility Skip Link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  background: var(--primary);
  color: #ffffff;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
  z-index: 9999;
  transition: top 0.2s ease;
}

.skip-link:focus-visible {
  top: 16px;
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

/* Typography Enhancements - Web Interface Guidelines */
h1, h2, h3, h4, h5, h6, .brand-title, .modal-title {
  text-wrap: balance;
}

/* Strict Monospace & Tabular Numbers for Live Measurement Readouts */
.val-primary,
.val-secondary,
.readout-chip span,
.readout-val,
.mobile-readout-text,
#mobileReadoutVal,
#hudReadout,
.span-badge-value,
.caliper-readout,
.box-badge-w,
.box-badge-h,
.box-badge-area,
.box-stat-val,
#boxWidthVal,
#boxHeightVal,
#boxDiagVal,
#boxAreaVal,
#boxRatioVal,
.protractor-readout-val,
#protractorDeg,
#protractorRad,
#protractorSlope,
#angleSliderVal,
.ring-stat-val,
#ringReadoutMm,
#ringReadoutIn,
#ringReadoutCirc,
#ringSizeVal,
#ringReadoutUs,
#ringReadoutUk,
#ringReadoutEu,
#ringReadoutJp,
.ring-table td,
.conv-input,
#rotationVal,
.banner-ppi,
.btn-stepper {
  font-family: var(--font-mono) !important;
  font-variant-numeric: tabular-nums !important;
  font-feature-settings: "tnum" 1, "zero" 1;
}

/* Focus-visible global consistency */
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* Background grid mesh - obsidian dark canvas */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    linear-gradient(to right, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 32px 32px, 32px 32px;
  pointer-events: none;
  z-index: 0;
}

/* Header */
.app-header {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-surface-glass);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
  gap: 12px;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

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

.brand-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-tag {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Navigation tabs - Primary Tool Mode Selector */
.tool-nav,
.nav-bar,
.tool-tabs {
  display: flex;
  align-items: center;
  background: #07090E;
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-top: 2px solid #5E6AD2;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  gap: 3px;
  overflow-x: auto;
}

.tool-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.tool-nav-btn:hover {
  color: var(--text-main);
  border-color: var(--border-hover);
  background: rgba(255, 255, 255, 0.03);
}

.tool-nav-btn.active,
.tool-tabs .active,
.nav-bar .active {
  color: #FFFFFF !important;
  background: #5E6AD2 !important;
  font-weight: 700 !important;
  border: 1px solid #7C88FF !important;
  box-shadow: 0 0 12px rgba(94, 106, 210, 0.35) !important;
}

.tool-nav-btn .tab-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: inherit;
}

/* Header Action Controls */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-cal-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px;
  background: var(--btn-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 0.82rem;
}

.btn-cal-banner:hover {
  background: var(--btn-bg-hover);
  border-color: var(--border-hover);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
}

.status-badge.success {
  background: rgba(16, 185, 129, 0.15);
  color: #10B981;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-badge.warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--btn-bg);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  box-sizing: border-box;
}

.btn-icon:hover {
  color: var(--text-primary);
  background: var(--btn-bg-hover);
  border-color: var(--border-hover);
}

.btn-icon.active {
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.18);
}

.btn-icon.is-muted {
  opacity: 0.5;
  color: var(--text-dim);
}

[data-theme="light"] .btn-icon {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.12);
  color: var(--text-muted);
}

[data-theme="light"] .btn-icon:hover {
  background: #f1f5f9;
  color: var(--text-main);
}

.utility-icon {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

/* Main Workbench Layout */
.app-main {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 70px);
}

.tool-panel {
  display: none;
  flex-direction: column;
  flex: 1;
}

.tool-panel.active {
  display: flex;
}

/* ==========================================================================
   Single Consolidated Unified Toolbar Architecture
   ========================================================================== */
.unified-toolbar {
  display: flex;
  flex-wrap: wrap;
  height: auto;
  min-height: 48px;
  gap: 8px 12px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  box-sizing: border-box;
  background: var(--bg-surface-glass);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 12;
  transition: padding 0.15s ease, background 0.15s ease;
}

[data-theme="light"] .unified-toolbar {
  background: rgba(248, 250, 252, 0.9);
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.toolbar-left,
.toolbar-center,
.toolbar-right,
.toolbar-group,
.form-select,
.readout-unified-badge,
.btn-copy-readout,
.btn-pill {
  flex-shrink: 0;
}

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

.toolbar-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Ensure all buttons and elements wrap and remain visible on all screen sizes */
/* Ensure all buttons and elements wrap and remain visible on all screen sizes */
@media (max-width: 1024px) {
  .unified-toolbar {
    justify-content: flex-start !important;
    gap: 8px 12px;
    padding: 8px 12px;
  }
  .toolbar-left,
  .toolbar-right {
    flex-wrap: wrap;
    gap: 8px;
  }
  .toolbar-center {
    order: 3;
    width: 100%;
    justify-content: flex-start;
    margin-top: 2px;
  }
  .readout-unified-badge {
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .readout-unified-badge::-webkit-scrollbar {
    display: none;
  }
}

@media (max-width: 768px) {
  .app-header {
    padding: 8px 12px;
    gap: 8px;
    flex-wrap: wrap;
  }

  .header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .header-actions::-webkit-scrollbar {
    display: none;
  }

  .btn-cal-banner {
    padding: 4px 8px;
    height: 34px;
    font-size: 0.75rem;
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-actions .btn-icon {
    width: 34px;
    height: 34px;
    min-width: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Tool Navigation Tabs */
  .tool-nav {
    margin: 4px auto 6px;
    padding: 3px 6px;
    gap: 4px;
    max-width: 100%;
    justify-content: center;
  }

  .tool-nav-btn {
    padding: 6px 10px;
    font-size: 0.78rem;
    height: 32px;
  }

  /* Unified Toolbar Grid on Mobile */
  .unified-toolbar {
    padding: 10px 12px;
    gap: 10px;
    display: flex;
    flex-direction: column;
    width: 100%;
    box-sizing: border-box;
    background: rgba(18, 22, 31, 0.75);
    border-radius: 12px;
  }

  .toolbar-left {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
  }

  .toolbar-left .toolbar-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    width: 100%;
  }

  .toolbar-left .toolbar-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--text-dim, #8A8F98);
    letter-spacing: 0.05em;
  }

  .toolbar-left select,
  .toolbar-left .form-select {
    width: 100%;
    height: 36px;
    font-size: 0.82rem;
  }

  .toolbar-right {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
  }

  .toolbar-right .dock-group {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .toolbar-right .dock-select {
    width: 100%;
    height: 36px;
    font-size: 0.82rem;
  }

  .toolbar-right .btn-pill {
    height: 36px;
    padding: 0 12px;
    font-size: 0.82rem;
    flex-shrink: 0;
  }

  /* Linear-Style Neat Readings Card */
  .toolbar-center {
    width: 100%;
    margin: 2px 0 0;
    order: 3;
  }

  .readout-unified-badge {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: space-between;
    padding: 8px 10px;
    gap: 10px;
    background: #12161F;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  }

  [data-theme="light"] .readout-unified-badge {
    background: #F8FAFC !important;
    border: 1px solid rgba(0, 0, 0, 0.10) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04) !important;
  }

  .badge-values {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .readout-chip {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 0.80rem;
  }

  .readout-chip .chip-lbl {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #8A8F98;
    min-width: 58px;
  }

  .readout-chip .val-primary {
    font-size: 0.88rem;
    font-weight: 700;
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    font-variant-numeric: tabular-nums;
  }

  .readout-chip .val-secondary {
    font-size: 0.76rem;
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    font-variant-numeric: tabular-nums;
    color: #8A8F98;
    margin-left: auto;
    padding-left: 8px;
  }

  .badge-divider {
    width: 1px;
    height: auto;
    background: rgba(255, 255, 255, 0.08);
    margin: 2px 0;
    flex-shrink: 0;
  }

  .btn-copy-readout {
    width: 68px;
    min-width: 68px;
    height: auto;
    min-height: 44px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 6px;
    background: rgba(94, 106, 210, 0.14);
    border: 1px solid rgba(94, 106, 210, 0.32);
    border-radius: 8px;
    color: #93c5fd;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
  }

  .btn-copy-readout:active,
  .btn-copy-readout:hover {
    background: #5E6AD2;
    border-color: #5E6AD2;
    color: #ffffff;
  }

  /* Collapsible Options Sub-Toolbar Mobile Polish (<768px) */
  .tool-options-subbar,
  #subbar-ruler,
  #subbar-protractor,
  #subbar-ringsizer,
  #subbar-box,
  #subbar-converter {
    display: none !important;
  }

  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) .tool-options-subbar.open,
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-ruler.open,
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-protractor.open,
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-ringsizer.open,
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-box.open,
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-converter.open {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scrollbar-width: none !important;
    -webkit-overflow-scrolling: touch !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 4px 10px !important;
    height: 42px !important;
    min-height: 42px !important;
    max-height: 42px !important;
    box-sizing: border-box !important;
    width: 100% !important;
    background: #0E121A !important;
    border: 1px solid rgba(255, 255, 255, 0.10) !important;
    border-radius: 8px !important;
    color: #F8FAFC !important;
  }

  /* Light Theme Subbar Overrides (<768px) */
  [data-theme="light"] body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) .tool-options-subbar.open,
  [data-theme="light"] body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-ruler.open,
  [data-theme="light"] body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-protractor.open,
  [data-theme="light"] body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-ringsizer.open,
  [data-theme="light"] body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-box.open,
  [data-theme="light"] body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-converter.open {
    background: #FFFFFF !important;
    border: 1px solid rgba(0, 0, 0, 0.12) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06) !important;
    color: #0F172A !important;
  }

  .tool-options-subbar::-webkit-scrollbar,
  #subbar-ruler::-webkit-scrollbar,
  #subbar-protractor::-webkit-scrollbar,
  #subbar-ringsizer::-webkit-scrollbar,
  #subbar-box::-webkit-scrollbar,
  #subbar-converter::-webkit-scrollbar {
    display: none !important;
  }

  .tool-options-subbar .toolbar-group,
  #subbar-ruler .toolbar-group,
  #subbar-protractor .toolbar-group,
  #subbar-ringsizer .toolbar-group,
  #subbar-box .toolbar-group,
  #subbar-converter .toolbar-group {
    display: inline-flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 6px !important;
    flex-shrink: 0 !important;
    width: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
  }

  .tool-options-subbar .toolbar-label,
  #subbar-ruler .toolbar-label,
  #subbar-protractor .toolbar-label,
  #subbar-ringsizer .toolbar-label,
  #subbar-box .toolbar-label,
  #subbar-converter .toolbar-label {
    font-size: 0.68rem !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.04em !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    height: auto !important;
    background: transparent !important;
    border: none !important;
    padding: 0 2px !important;
    margin: 0 !important;
    color: #8A8F98 !important;
  }

  [data-theme="light"] .tool-options-subbar .toolbar-label,
  [data-theme="light"] #subbar-ruler .toolbar-label,
  [data-theme="light"] #subbar-protractor .toolbar-label,
  [data-theme="light"] #subbar-ringsizer .toolbar-label,
  [data-theme="light"] #subbar-box .toolbar-label,
  [data-theme="light"] #subbar-converter .toolbar-label {
    color: #475569 !important;
  }

  /* Universal 30px height for all buttons and selects inside subbars */
  .tool-options-subbar .btn-pill,
  .tool-options-subbar .btn-secondary,
  .tool-options-subbar .btn-opt-ring,
  .tool-options-subbar .btn-opt-angle,
  .tool-options-subbar .btn-opt-box,
  .tool-options-subbar .btn-opt-conv,
  .tool-options-subbar select,
  .tool-options-subbar .form-select,
  #subbar-ruler .btn-pill,
  #subbar-ruler .btn-rotate,
  #subbar-ruler select,
  #subbar-ruler .form-select,
  #subbar-protractor .btn-pill {
    height: 30px !important;
    min-height: 30px !important;
    max-height: 30px !important;
    padding: 0 8px !important;
    font-size: 0.74rem !important;
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 6px !important;
    box-sizing: border-box !important;
  }

  [data-theme="light"] .tool-options-subbar .btn-pill,
  [data-theme="light"] .tool-options-subbar .btn-secondary,
  [data-theme="light"] .tool-options-subbar .btn-opt-ring,
  [data-theme="light"] .tool-options-subbar .btn-opt-angle,
  [data-theme="light"] .tool-options-subbar .btn-opt-box,
  [data-theme="light"] .tool-options-subbar .btn-opt-conv,
  [data-theme="light"] #subbar-ruler .btn-pill,
  [data-theme="light"] #subbar-ruler .btn-rotate,
  [data-theme="light"] #subbar-protractor .btn-pill {
    background: #F1F5F9 !important;
    border: 1px solid rgba(0, 0, 0, 0.12) !important;
    color: #0F172A !important;
  }

  [data-theme="light"] .tool-options-subbar select,
  [data-theme="light"] .tool-options-subbar .form-select,
  [data-theme="light"] #subbar-ruler select,
  [data-theme="light"] #subbar-ruler .form-select {
    background: #FFFFFF !important;
    border: 1px solid rgba(0, 0, 0, 0.14) !important;
    color: #0F172A !important;
  }

  .tool-options-subbar .stepper-group,
  #subbar-ruler .stepper-group {
    display: inline-flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 2px !important;
    height: 30px !important;
    flex-shrink: 0 !important;
  }

  .tool-options-subbar .btn-stepper,
  #subbar-ruler .btn-stepper {
    width: 26px !important;
    min-width: 26px !important;
    max-width: 26px !important;
    height: 28px !important;
    min-height: 28px !important;
    max-height: 28px !important;
    padding: 0 !important;
    font-size: 0.72rem !important;
    font-weight: 700 !important;
    flex-shrink: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 5px !important;
    box-sizing: border-box !important;
  }

  [data-theme="light"] .tool-options-subbar .btn-stepper,
  [data-theme="light"] #subbar-ruler .btn-stepper {
    background: #F1F5F9 !important;
    border: 1px solid rgba(0, 0, 0, 0.12) !important;
    color: #0F172A !important;
  }

  #subbar-ruler .rotation-control {
    display: inline-flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 4px !important;
    flex-shrink: 0 !important;
  }

  #subbar-ruler .rotation-control input[type="range"],
  #subbar-ruler .rotation-control #rotationVal {
    display: inline-flex !important;
  }
}

/* Unified Measurement Readout Badge */
.readout-unified-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: var(--btn-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

[data-theme="light"] .readout-unified-badge {
  background: rgba(241, 245, 249, 0.85);
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.badge-values {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.badge-divider {
  width: 1px;
  height: 18px;
  background: var(--border-subtle);
  flex-shrink: 0;
}

/* Consolidated Live Readout Chips */
.readout-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 3px 8px;
  background: rgba(18, 22, 31, 0.6);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

[data-theme="light"] .readout-chip {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.readout-chip:hover {
  background: #1C2230;
  border-color: var(--border-hover);
}

[data-theme="light"] .readout-chip:hover {
  background: #e2e8f0;
}

.readout-chip.primary,
.readout-chip.metric {
  border-color: rgba(94, 106, 210, 0.35);
  background: rgba(94, 106, 210, 0.12);
}

[data-theme="light"] .readout-chip.primary,
[data-theme="light"] .readout-chip.metric {
  background: rgba(219, 234, 254, 0.7);
  border-color: rgba(59, 130, 246, 0.4);
}

.readout-chip.imperial {
  border-color: rgba(168, 85, 247, 0.25);
  background: rgba(88, 28, 135, 0.2);
}

[data-theme="light"] .readout-chip.imperial {
  background: rgba(243, 232, 255, 0.7);
  border-color: rgba(168, 85, 247, 0.3);
}

.readout-chip .chip-lbl {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.readout-chip .val-primary {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
}

.readout-chip.metric .val-primary,
.readout-chip.primary .val-primary {
  color: #60a5fa;
}

[data-theme="light"] .readout-chip.metric .val-primary,
[data-theme="light"] .readout-chip.primary .val-primary {
  color: #2563eb;
}

.readout-chip.imperial .val-primary {
  color: #c084fc;
}

[data-theme="light"] .readout-chip.imperial .val-primary {
  color: #7e22ce;
}

.readout-chip .val-secondary,
.readout-chip .chip-sub {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.dock-select {
  min-width: 125px;
  font-weight: 500;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  margin-right: 2px;
}

.btn-icon-svg {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  stroke: currentColor;
}

select,
.form-select {
  height: 36px;
  min-height: 36px;
  max-height: 36px;
  box-sizing: border-box;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
  line-height: 34px;
}

select:hover,
.form-select:hover {
  border-color: var(--border-hover);
  background: var(--btn-bg-hover);
}

select:focus-visible,
.form-select:focus-visible {
  outline: none;
  border-color: var(--border-focus, #5E6AD2);
  box-shadow: 0 0 0 2px rgba(94, 106, 210, 0.25);
}

/* Floating HUD Tool Dropdown */
.hud-tool-select {
  height: 28px !important;
  min-height: 28px !important;
  max-height: 28px !important;
  box-sizing: border-box;
  background: var(--btn-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 0 8px !important;
  font-size: 0.78rem !important;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
  font-family: inherit;
  line-height: 26px !important;
}

.hud-tool-select:hover {
  border-color: var(--border-hover);
  background: var(--btn-bg-hover);
}

.hud-tool-select:focus-visible {
  outline: none;
  border-color: var(--border-focus, #5E6AD2);
  box-shadow: 0 0 0 2px rgba(94, 106, 210, 0.25);
}

/* Mobile Bottom Sheet Touch Selects (Linear Obsidian Design matching all UI fonts) */
.sheet-select,
.mobile-bottom-sheet select,
.mobile-bottom-sheet .form-select {
  height: 42px !important;
  min-height: 42px !important;
  max-height: 42px !important;
  box-sizing: border-box;
  background-color: #161B26 !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238A8F98' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 12px center !important;
  background-size: 14px 14px !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  color: #ECEEEF !important;
  padding: 0 34px 0 12px !important;
  border-radius: 8px !important;
  font-size: 0.90rem !important;
  font-family: 'Inter', system-ui, -apple-system, sans-serif !important;
  font-weight: 500 !important;
  letter-spacing: -0.01em !important;
  cursor: pointer;
  outline: none;
  -webkit-appearance: none !important;
  appearance: none !important;
  transition: all 0.15s ease;
  line-height: 40px !important;
}

.sheet-select:hover,
.mobile-bottom-sheet select:hover {
  border-color: rgba(255, 255, 255, 0.25) !important;
  background-color: #1F2430 !important;
}

.sheet-select:focus,
.sheet-select:focus-visible,
.mobile-bottom-sheet select:focus,
.mobile-bottom-sheet select:focus-visible {
  outline: none !important;
  border-color: rgba(94, 106, 210, 0.6) !important;
  box-shadow: 0 0 0 2px rgba(94, 106, 210, 0.2) !important;
}

/* Custom Dropdown Option Popups */
select option,
.form-select option,
.hud-tool-select option,
.sheet-select option {
  background: #12161F;
  color: #ECEEEF;
  padding: 8px 12px;
  font-size: 13px;
}

[data-theme="light"] select,
[data-theme="light"] .form-select {
  background: #FFFFFF;
  border-color: rgba(0, 0, 0, 0.12);
  color: #0F172A;
}

[data-theme="light"] select:hover,
[data-theme="light"] .form-select:hover {
  background: #F8FAFC;
  border-color: rgba(0, 0, 0, 0.22);
}

[data-theme="light"] .hud-tool-select {
  background: #FFFFFF;
  border-color: rgba(0, 0, 0, 0.15);
  color: #0F172A;
}

[data-theme="light"] .hud-tool-select:hover {
  background: #F1F5F9;
}

[data-theme="light"] .sheet-select,
[data-theme="light"] .mobile-bottom-sheet select,
[data-theme="light"] .mobile-bottom-sheet .form-select {
  background-color: #F8FAFC !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") !important;
  border-color: rgba(0, 0, 0, 0.12) !important;
  color: #0F172A !important;
}

[data-theme="light"] .sheet-select:hover,
[data-theme="light"] .mobile-bottom-sheet select:hover {
  background-color: #F1F5F9 !important;
  border-color: rgba(0, 0, 0, 0.22) !important;
}

[data-theme="light"] select option,
[data-theme="light"] .form-select option,
[data-theme="light"] .hud-tool-select option,
[data-theme="light"] .sheet-select option {
  background: #FFFFFF;
  color: #0F172A;
  padding: 8px 12px;
  font-size: 13px;
}

.btn-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  min-height: 36px;
  box-sizing: border-box;
  padding: 0 12px;
  background: var(--btn-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-pill:hover {
  background: var(--btn-bg-hover);
  border-color: var(--border-hover);
}

.btn-pill.locked {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.rotation-control {
  display: flex;
  align-items: center;
  gap: 6px;
}

.range-slider {
  -webkit-appearance: none;
  width: 90px;
  height: 4px;
  border-radius: 2px;
  background: var(--btn-bg);
  cursor: pointer;
}

.range-slider:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
}

.btn-copy-readout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  background: var(--btn-bg);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-copy-readout:hover {
  background: var(--btn-bg-hover);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.btn-copy-readout:active {
  transform: scale(0.97);
}

.btn-copy-readout.copied {
  background: #10B981 !important;
  border-color: #10B981 !important;
  color: #ffffff !important;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.4) !important;
}

/* ==========================================================================
   Inline Collapsible 3rd Options Sub-Toolbar (.tool-options-subbar)
   ========================================================================== */
.tool-options-subbar {
  display: none;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 12px 18px;
  padding: 8px 18px;
  background: rgba(18, 22, 31, 0.85);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: relative;
  z-index: 9999;
  pointer-events: auto;
  transition: all 0.15s ease;
  box-sizing: border-box;
}

#subbar-box {
  flex-wrap: nowrap;
  overflow-x: auto;
}

[data-theme="light"] .tool-options-subbar {
  background: rgba(248, 250, 252, 0.9);
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

.tool-options-subbar.open {
  display: flex !important;
}

.btn-toggle-options.active,
.btn-advanced-toggle.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: #93c5fd;
}

.btn-dock {
  padding: 4px 8px;
  font-size: 0.76rem;
  font-weight: 600;
}

.btn-dock:hover {
  background: var(--primary-light);
  color: #93c5fd;
}

/* Mobile Bottom Sheet - Slide-up Drawer */
.mobile-sheet-backdrop {
  display: block;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 99998;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.mobile-sheet-backdrop.active {
  opacity: 1 !important;
  pointer-events: auto !important;
  visibility: visible !important;
}

.mobile-bottom-sheet {
  display: block;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 85vh;
  background: #12161F;
  border-top: 1px solid var(--border-subtle);
  border-radius: 16px 16px 0 0;
  z-index: 99999;
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translateY(105%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.3s ease;
  padding: 14px 20px 36px;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  visibility: hidden;
}

.mobile-bottom-sheet.open {
  transform: translateY(0) !important;
  pointer-events: auto !important;
  visibility: visible !important;
}

/* Light Mode Overrides for Mobile Bottom Sheet */
[data-theme="light"] .mobile-bottom-sheet {
  background: #FFFFFF !important;
  border-top-color: rgba(0, 0, 0, 0.12) !important;
  box-shadow: 0 -10px 40px rgba(15, 23, 42, 0.16) !important;
  color: #0F172A !important;
}

[data-theme="light"] .mobile-sheet-backdrop {
  background: rgba(15, 23, 42, 0.35) !important;
}

[data-theme="light"] .mobile-sheet-drag-handle {
  background: rgba(0, 0, 0, 0.2) !important;
}

[data-theme="light"] .mobile-sheet-header {
  border-bottom-color: rgba(0, 0, 0, 0.08) !important;
}

[data-theme="light"] .mobile-sheet-title {
  color: #0F172A !important;
}

[data-theme="light"] .mobile-sheet-close {
  background: #F1F5F9 !important;
  border: 1px solid rgba(0, 0, 0, 0.12) !important;
  color: #0F172A !important;
}

[data-theme="light"] .mobile-sheet-close:hover {
  background: #E2E8F0 !important;
}

[data-theme="light"] .sheet-section-title {
  color: #475569 !important;
}

[data-theme="light"] .sheet-label,
[data-theme="light"] .sheet-row-label {
  color: #1E293B !important;
}

[data-theme="light"] .sheet-row {
  border-bottom-color: rgba(0, 0, 0, 0.06) !important;
}

[data-theme="light"] .sheet-tool-btn {
  background: #F8FAFC !important;
  border-color: rgba(0, 0, 0, 0.1) !important;
  color: #334155 !important;
}

[data-theme="light"] .sheet-tool-btn.active {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #FFFFFF !important;
}

[data-theme="light"] .btn-sheet-dock,
[data-theme="light"] .btn-sheet-rotate,
[data-theme="light"] .sheet-toggle-btn,
[data-theme="light"] .btn-view-mode-toggle,
[data-theme="light"] .btn-sheet-nudge {
  background: #F1F5F9 !important;
  border-color: rgba(0, 0, 0, 0.12) !important;
  color: #0F172A !important;
}

[data-theme="light"] .btn-sheet-dock:hover,
[data-theme="light"] .btn-sheet-rotate:hover,
[data-theme="light"] .sheet-toggle-btn:hover,
[data-theme="light"] .btn-view-mode-toggle:hover,
[data-theme="light"] .btn-sheet-nudge:hover {
  background: #E2E8F0 !important;
  border-color: rgba(0, 0, 0, 0.22) !important;
}

.mobile-sheet-drag-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.2);
  margin: 0 auto 14px;
}

.mobile-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 16px;
}

.mobile-sheet-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.mobile-sheet-close {
  background: var(--btn-bg);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  pointer-events: auto;
  z-index: 1000;
  touch-action: manipulation;
  transition: all 0.15s ease;
}

.mobile-sheet-close:hover {
  background: var(--btn-bg-hover);
  border-color: var(--border-hover);
}

.sheet-tool-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.sheet-tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--btn-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  pointer-events: auto;
  touch-action: manipulation;
}

.sheet-tool-btn .tab-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: inherit;
}

.sheet-tool-btn:hover {
  color: var(--text-primary);
  background: var(--btn-bg-hover);
  border-color: var(--border-hover);
}

.sheet-tool-btn.active {
  color: var(--text-primary);
  background: var(--active-tab-bg);
  border-color: var(--border-hover);
  font-weight: 600;
}

.sheet-section {
  margin-bottom: 20px;
}

.sheet-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: 0.02em;
  margin-bottom: 12px;
}

.sheet-button-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.sheet-button-grid .btn-pill,
.sheet-button-grid button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  pointer-events: auto;
  z-index: 1000;
  touch-action: manipulation;
}

.sheet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  gap: 14px;
}

.sheet-label,
.sheet-row label {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 0.90rem;
  font-weight: 500;
  color: var(--text-muted, #8A8F98);
  flex-shrink: 0;
}

.sheet-select {
  flex: 1;
  min-height: 42px;
  max-width: 220px;
  pointer-events: auto;
  z-index: 1000;
  touch-action: manipulation;
}

.sheet-toggles-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sheet-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  pointer-events: auto;
  z-index: 1000;
  touch-action: manipulation;
}

/* Tool Mode Selector inside Bottom Sheet */
.sheet-tool-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.sheet-tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 14px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  pointer-events: auto;
  z-index: 1000;
  touch-action: manipulation;
}

.sheet-tool-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
  border-color: var(--border-hover);
}

.sheet-tool-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.mobile-tool-sec .btn-action-primary,
.mobile-tool-sec .btn-secondary {
  min-height: 44px;
  font-size: 0.9rem;
  font-weight: 600;
  pointer-events: auto;
  z-index: 1000;
  touch-action: manipulation;
}

/* Base Desktop Visibility for Mobile-Only Header Controls (Hidden on >=769px) */
.mobile-header-readout {
  display: none;
}

.btn-mobile-header-controls {
  display: none;
}

/* Digital Measurement Readout Bar (Legacy & Fallback) */
.readout-ribbon {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.7) 0%, rgba(15, 23, 42, 0.7) 100%);
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
  gap: 16px;
}

.readout-cards {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.readout-card {
  display: flex;
  flex-direction: column;
  padding: 6px 14px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  min-width: 95px;
}

.readout-card.primary {
  border-color: rgba(59, 130, 246, 0.4);
  background: rgba(30, 58, 138, 0.2);
}

.readout-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.readout-val {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.readout-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-action-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-action-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.5);
}

/* Toast Message */
.app-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  border: 1px solid var(--border-focus);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.88rem;
  box-shadow: var(--shadow-lg);
  transform: translateY(100px);
  opacity: 0;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
  z-index: 9999;
  pointer-events: none;
}

.app-toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* FAQ Section - Linear Obsidian Aesthetic (DESIGN.md) */
.faq-section {
  max-width: 1040px;
  margin: 24px auto 36px auto;
  padding: 36px 40px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  font-family: var(--font-sans);
}

.faq-header {
  margin-bottom: 24px;
}

.faq-title {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.015em;
}

.faq-subtitle {
  font-size: 0.92rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

details.faq-item {
  background: var(--bg-surface-elevated, #161B26);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

details.faq-item:hover {
  border-color: var(--border-hover, rgba(255, 255, 255, 0.20));
  background: var(--btn-bg-hover, #1F2430);
}

details.faq-item[open] {
  border-color: rgba(94, 106, 210, 0.45);
}

summary.faq-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: color 0.15s ease;
}

summary.faq-summary::-webkit-details-marker {
  display: none;
}

.faq-chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), color 0.15s ease;
  margin-left: 12px;
}

details.faq-item:hover .faq-chevron {
  color: var(--text-primary);
}

details.faq-item[open] .faq-chevron {
  transform: rotate(180deg);
  color: var(--primary, #5E6AD2);
}

.faq-content {
  padding: 0 20px 18px 20px;
  border-top: 1px solid var(--border-subtle);
  margin-top: 2px;
  padding-top: 14px;
}

.faq-content p {
  color: var(--text-muted);
  font-size: 0.90rem;
  line-height: 1.65;
  margin-bottom: 10px;
}

.faq-content p:last-child {
  margin-bottom: 0;
}

.faq-content ol {
  padding-left: 20px;
  margin: 8px 0;
}

.faq-content li {
  color: var(--text-muted);
  font-size: 0.90rem;
  line-height: 1.6;
  margin-bottom: 6px;
}

.faq-content strong {
  color: var(--text-primary);
  font-weight: 600;
}

[data-theme="light"] .faq-section {
  box-shadow: var(--shadow-sm);
}

[data-theme="light"] details.faq-item {
  background: var(--bg-surface-elevated, #f1f5f9);
}

[data-theme="light"] details.faq-item:hover {
  background: var(--btn-bg-hover, #e2e8f0);
}

/* FAQ Mobile Responsiveness */
@media (max-width: 768px) {
  .faq-section {
    margin: 16px 12px 24px 12px;
    padding: 20px 14px;
    border-radius: 10px;
  }

  .faq-title {
    font-size: 1.25rem;
  }

  summary.faq-summary {
    padding: 12px 16px;
    font-size: 0.90rem;
  }

  .faq-content {
    padding: 0 16px 14px 16px;
    padding-top: 10px;
  }

  .faq-content p,
  .faq-content li {
    font-size: 0.86rem;
  }
}

/* SEO Content Section - Linear Obsidian Aesthetic (DESIGN.md) */
.seo-content-section {
  max-width: 1040px;
  margin: 48px auto 28px auto;
  padding: 40px 36px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-muted);
  font-family: var(--font-sans);
  line-height: 1.7;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.seo-content-section .seo-container {
  width: 100%;
}

.seo-content-section h1 {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.seo-content-section h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 36px;
  margin-bottom: 14px;
  line-height: 1.35;
  letter-spacing: -0.01em;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 8px;
}

.seo-content-section h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 24px;
  margin-bottom: 10px;
  line-height: 1.4;
}

.seo-content-section p {
  margin-bottom: 16px;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.seo-content-section p.seo-lead {
  font-size: 1rem;
  color: var(--text-main);
  line-height: 1.75;
  margin-bottom: 24px;
}

.seo-content-section ol,
.seo-content-section ul {
  margin-bottom: 20px;
  padding-left: 24px;
}

.seo-content-section li {
  margin-bottom: 10px;
  font-size: 0.92rem;
  line-height: 1.65;
  color: var(--text-muted);
}

.seo-content-section strong {
  color: var(--text-primary);
  font-weight: 600;
}

[data-theme="light"] .seo-content-section {
  box-shadow: var(--shadow-sm);
}

/* SEO Content Mobile Responsiveness */
@media (max-width: 768px) {
  .seo-content-section {
    margin: 24px 12px 16px 12px;
    padding: 24px 16px;
    border-radius: 10px;
  }

  .seo-content-section h1 {
    font-size: 1.35rem;
    line-height: 1.35;
  }

  .seo-content-section h2 {
    font-size: 1.15rem;
    margin-top: 26px;
    margin-bottom: 12px;
  }

  .seo-content-section h3 {
    font-size: 1rem;
    margin-top: 20px;
  }

  .seo-content-section p,
  .seo-content-section li {
    font-size: 0.88rem;
    line-height: 1.6;
  }

  .seo-content-section ol,
  .seo-content-section ul {
    padding-left: 18px;
    margin-bottom: 16px;
  }
}

/* Header Discreet Links */
.header-link {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.header-link:hover {
  color: var(--text-primary);
  background: var(--btn-bg-hover);
  border-color: var(--border-color);
}

/* Subpage Dedicated Header */
.subpage-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
}

.subpage-brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.subpage-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.subpage-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-subpage-home {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--btn-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn-subpage-home:hover {
  background: var(--btn-bg-hover);
  border-color: var(--border-hover);
  color: #ffffff;
}

/* Page Container (Subpages) - Linear Obsidian Aesthetic (DESIGN.md) */
.page-container {
  max-width: 900px;
  margin: 40px auto 48px auto;
  padding: 40px 48px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  font-family: var(--font-sans);
  color: var(--text-muted);
  line-height: 1.7;
}

.page-header {
  margin-bottom: 32px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 20px;
}

.page-title {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.025em;
  line-height: 1.25;
}

.page-meta {
  font-size: 0.82rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.legal-content h2,
.about-content h2,
.contact-content h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 36px;
  margin-bottom: 12px;
  letter-spacing: -0.01em;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 8px;
}

.legal-content h3,
.about-content h3,
.contact-content h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 24px;
  margin-bottom: 8px;
}

.legal-content p,
.about-content p,
.contact-content p {
  margin-bottom: 16px;
  font-size: 0.94rem;
  line-height: 1.75;
}

.legal-content ul,
.legal-content ol,
.about-content ul,
.about-content ol {
  padding-left: 24px;
  margin-bottom: 20px;
}

.legal-content li,
.about-content li {
  margin-bottom: 8px;
  font-size: 0.94rem;
  line-height: 1.65;
}

.legal-content strong,
.about-content strong,
.contact-content strong {
  color: var(--text-primary);
  font-weight: 600;
}

.callout-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px 24px;
  margin: 24px 0;
  border-left: 3px solid var(--primary);
}

.callout-card h4 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.callout-card p {
  margin-bottom: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Contact Cards Grid */
.contact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
  margin: 28px 0;
}

.contact-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 24px 20px;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.contact-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
}

.contact-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(94, 106, 210, 0.12);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}

.contact-card h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 0;
  margin-bottom: 8px;
}

.contact-card p {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 14px;
  line-height: 1.55;
}

.contact-card-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  word-break: break-all;
}

/* ==========================================================================
   Error Pages (404, 500, 403) - Precision Utility Styling
   ========================================================================== */
.error-card-container {
  text-align: center;
  max-width: 820px;
  padding: 48px 36px;
  position: relative;
  overflow: hidden;
}

.error-badge-pill {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
}

.error-badge-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  border-radius: var(--radius-full);
  background: rgba(94, 106, 210, 0.1);
  border: 1px solid rgba(94, 106, 210, 0.25);
  color: var(--primary);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  margin-bottom: 24px;
}

.error-pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
  animation: pulseDot 2s infinite ease-in-out;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.error-graphic-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 12px 0 20px 0;
}

.error-code-numeral {
  font-family: var(--font-mono);
  font-size: clamp(4.5rem, 14vw, 7.5rem);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, var(--text-primary) 30%, var(--text-dim) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  user-select: none;
}

.error-ruler-display {
  width: 100%;
  max-width: 440px;
  height: 48px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface-elevated);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  margin-bottom: 8px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.error-ruler-ticks {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0 12px;
  height: 100%;
}

.error-ruler-ticks .tick {
  width: 1px;
  height: 10px;
  background: var(--border-color);
}

.error-ruler-ticks .tick.t-mid {
  height: 16px;
  background: var(--text-dim);
}

.error-ruler-ticks .tick.t-major {
  height: 24px;
  background: var(--text-muted);
}

.error-caliper-jaw {
  position: absolute;
  top: 0;
  left: 68%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.error-caliper-jaw .jaw-line {
  width: 2px;
  height: 28px;
  background: var(--primary);
  box-shadow: 0 0 6px var(--primary);
}

.error-caliper-jaw .jaw-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--bg-main);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  margin-top: 2px;
  white-space: nowrap;
}

.error-fault-icon-wrap {
  width: 68px;
  height: 68px;
  border-radius: 16px;
  background: rgba(239, 68, 68, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.error-heading {
  font-size: clamp(1.4rem, 4vw, 1.85rem);
  font-weight: 700;
  color: var(--text-primary);
  margin: 12px 0 10px 0;
  letter-spacing: -0.015em;
}

.error-subtext {
  font-size: 0.98rem;
  color: var(--text-muted);
  max-width: 540px;
  margin: 0 auto 28px auto;
  line-height: 1.6;
}

.error-actions-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 40px;
}

.btn-error-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.btn-error-cta.primary {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary-hover);
  box-shadow: 0 2px 8px rgba(94, 106, 210, 0.3);
}

.btn-error-cta.primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-error-cta.secondary {
  background: var(--btn-bg);
  border-color: var(--border-color);
  color: var(--text-primary);
}

.btn-error-cta.secondary:hover {
  background: var(--btn-bg-hover);
  border-color: var(--border-hover);
  transform: translateY(-1px);
}

.error-quick-tools {
  border-top: 1px solid var(--border-subtle);
  padding-top: 32px;
  text-align: left;
}

.error-quick-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 16px;
  text-align: center;
}

.error-tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.error-tool-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: all 0.15s ease;
}

.error-tool-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  background: var(--btn-bg-hover);
}

.error-tool-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.error-tool-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.error-tool-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

.error-tool-desc {
  font-size: 0.74rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.error-checklist-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 600px;
  margin: 0 auto;
}

.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.55;
  text-align: left;
}

.checklist-bullet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(94, 106, 210, 0.15);
  color: var(--primary);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

.checklist-item strong {
  color: var(--text-primary);
}

.checklist-item kbd {
  display: inline-block;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Light Theme Adaptations for Error Pages */
[data-theme="light"] .error-code-numeral {
  background: linear-gradient(180deg, #1e293b 30%, #64748b 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-theme="light"] .error-card-container {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .error-ruler-display {
  background: #f1f5f9;
  border-color: rgba(15, 23, 42, 0.12);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .error-caliper-jaw .jaw-label {
  background: #ffffff;
  border-color: rgba(15, 23, 42, 0.15);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .error-tool-card {
  background: #ffffff;
  border-color: rgba(15, 23, 42, 0.1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .error-tool-card:hover {
  background: #f8fafc;
  border-color: var(--border-hover);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .error-checklist-card {
  background: #ffffff;
  border-color: rgba(15, 23, 42, 0.1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .checklist-item kbd {
  background: #f1f5f9;
  border-color: rgba(15, 23, 42, 0.15);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Multi-Column Responsive App Footer */
.app-footer {
  background: var(--bg-main);
  border-top: 1px solid var(--border-subtle);
  padding: 48px 32px 32px 32px;
  margin-top: 56px;
  font-family: var(--font-sans);
  width: 100%;
  box-sizing: border-box;
}

.footer-container {
  max-width: 1040px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 48px;
  text-align: left;
  padding-bottom: 36px;
  width: 100%;
  box-sizing: border-box;
}

.footer-brand-col {
  display: flex;
  flex-direction: column;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  text-decoration: none;
}

.footer-brand-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.footer-tagline {
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.6;
  max-width: 360px;
}

.footer-nav-col {
  display: flex;
  flex-direction: column;
}

.footer-col-title {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.footer-links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.footer-links a,
.footer-links button.footer-link-btn {
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 400;
  line-height: 1.5;
  text-decoration: none;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  display: inline-block;
  text-align: left;
  transition: color 0.15s ease;
}

.footer-links a:hover,
.footer-links button.footer-link-btn:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

.footer-bottom {
  max-width: 1040px;
  margin: 0 auto;
  border-top: 1px solid var(--border-subtle);
  padding-top: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.82rem;
  line-height: 1.6;
  width: 100%;
  box-sizing: border-box;
}

.footer-bottom p {
  margin: 0;
  text-align: center;
  width: 100%;
}

/* Light Mode Overrides for Subpages & Footer */
[data-theme="light"] .page-container {
  box-shadow: var(--shadow-md);
}

[data-theme="light"] .callout-card,
[data-theme="light"] .contact-card {
  background: var(--bg-surface-elevated);
}

/* Mobile Responsiveness for Subpages & Footer */
@media (max-width: 768px) {
  .subpage-header {
    padding: 10px 14px;
  }

  .page-container {
    margin: 16px 12px 28px 12px;
    padding: 24px 16px;
    border-radius: 10px;
  }

  .page-title {
    font-size: 1.5rem;
  }

  .legal-content h2,
  .about-content h2,
  .contact-content h2 {
    font-size: 1.15rem;
    margin-top: 26px;
  }

  .app-footer {
    padding: 40px 24px 32px 24px;
    margin-top: 40px;
  }

  .footer-container {
    grid-template-columns: 1fr;
    gap: 28px;
    padding-bottom: 24px;
  }

  .footer-tagline {
    max-width: 100%;
  }

  .footer-bottom {
    padding-top: 20px;
    text-align: center;
    font-size: 0.78rem;
    line-height: 1.6;
  }

  .footer-bottom p {
    text-align: center;
  }
}

/* ==========================================================================
   Light Mode Element Overrides
   ========================================================================== */

[data-theme="light"] body::before {
  background-image: 
    radial-gradient(100% 700px at 50% -80px, rgba(94, 106, 210, 0.05) 0%, rgba(248, 250, 252, 0) 100%),
    radial-gradient(circle, rgba(15, 23, 42, 0.065) 1px, transparent 1px);
  background-size: 100% 700px, 24px 24px;
  background-position: top center, 0 0;
  background-repeat: no-repeat, repeat;
  opacity: 0.85;
}

[data-theme="light"] .brand-title {
  background: linear-gradient(135deg, #0f172a 0%, #334155 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-theme="light"] .tool-nav,
[data-theme="light"] .nav-bar,
[data-theme="light"] .tool-tabs {
  background: #E2E8F0;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-top: 2px solid #5E6AD2;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .tool-nav-btn {
  color: #475569;
}

[data-theme="light"] .tool-nav-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #0f172a;
}

[data-theme="light"] .tool-nav-btn.active,
[data-theme="light"] .tool-tabs .active,
[data-theme="light"] .nav-bar .active {
  background: #2563EB !important;
  color: #FFFFFF !important;
  border: 1px solid #1D4ED8 !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) !important;
  font-weight: 700 !important;
}

[data-theme="light"] #calibration-object-preview,
[data-theme="light"] #currencyPreviewBox,
[data-theme="light"] .currency-preview-box,
[data-theme="light"] .object-outline-box {
  background: #F1F5F9;
  background: rgba(94, 106, 210, 0.08);
  color: #0F172A;
  border: 2px solid #5E6AD2;
}

[data-theme="light"] .btn-cal-banner {
  background: #ffffff;
  color: #0f172a;
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: var(--shadow-sm);
}

[data-theme="light"] .btn-cal-banner:hover {
  background: #f1f5f9;
}

[data-theme="light"] .btn-icon {
  background: #ffffff;
  color: #475569;
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: var(--shadow-sm);
}

[data-theme="light"] .btn-icon:hover {
  background: #f1f5f9;
  color: #0f172a;
}

[data-theme="light"] .btn-pill {
  background: #f1f5f9;
  border-color: rgba(0, 0, 0, 0.12);
  color: #0f172a;
}

[data-theme="light"] .btn-pill:hover {
  background: #e2e8f0;
  border-color: rgba(0, 0, 0, 0.20);
}

[data-theme="light"] .btn-copy-readout {
  background: #f1f5f9;
  border-color: rgba(0, 0, 0, 0.12);
  color: #0f172a;
}

[data-theme="light"] .btn-copy-readout:hover {
  background: #e2e8f0;
  border-color: rgba(0, 0, 0, 0.20);
  color: #0f172a;
}

[data-theme="light"] .form-select {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.12);
  color: #0f172a;
}

[data-theme="light"] .form-select:hover {
  background: #f8fafc;
  border-color: rgba(0, 0, 0, 0.22);
}

[data-theme="light"] .tool-options-subbar {
  background: rgba(255, 255, 255, 0.95);
  border-bottom-color: rgba(0, 0, 0, 0.09);
  color: #0f172a;
}

[data-theme="light"] .toolbar-ribbon {
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .readout-ribbon {
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.95) 0%, rgba(241, 245, 249, 0.95) 100%);
  border-bottom: 1px solid var(--border-subtle);
}

[data-theme="light"] .readout-card {
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}

[data-theme="light"] .readout-card.primary {
  background: rgba(37, 99, 235, 0.07);
  border-color: rgba(37, 99, 235, 0.35);
}

/* ==========================================================================
   Mobile-First Responsive Styles
   ========================================================================== */

/* Small Mobile & Viewports (<600px) */
@media (max-width: 600px) {
  :root {
    --font-size-base: 13px;
  }

  html, body {
    font-size: 13px;
  }

  /* 4. STRICT CANVAS WORKSPACE GUARD ON SMALL SCREENS (<600px) */
  .app-header {
    padding: 4px 8px;
    gap: 4px;
    flex-wrap: wrap;
    min-height: auto;
  }

  .brand-title {
    font-size: 0.95rem;
  }

  .brand-tag {
    font-size: 0.6rem;
    display: none; /* Hide tag on very small screens */
  }

  .brand-logo {
    width: 26px;
    height: 26px;
  }

  .brand-logo svg {
    width: 100%;
    height: 100%;
  }

  /* 1. ACTIVE MODE LABEL IN MOBILE NAV BAR */
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) .tool-nav {
    order: 3;
    width: 100%;
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    scrollbar-width: none !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 3px 4px !important;
    gap: 4px !important;
    justify-content: flex-start !important;
    box-sizing: border-box !important;
    background: #07090E !important;
    border-radius: var(--radius-md) !important;
  }
  .tool-nav::-webkit-scrollbar {
    display: none;
  }

  [data-theme="light"] body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) .tool-nav {
    background: #F1F5F9 !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
  }

  /* Inactive tabs: SVG icon only */
  .nav-tab,
  .tool-nav-btn {
    flex: 0 0 auto !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    height: 36px !important;
    padding: 0 10px !important;
    font-size: 0.78rem !important;
    min-width: auto !important;
    border-radius: var(--radius-sm, 6px) !important;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
    white-space: nowrap !important;
  }

  [data-theme="light"] .nav-tab:not(.active),
  [data-theme="light"] .tool-nav-btn:not(.active) {
    color: #64748B !important;
  }

  [data-theme="light"] .nav-tab:not(.active):hover,
  [data-theme="light"] .tool-nav-btn:not(.active):hover {
    background: rgba(0, 0, 0, 0.05) !important;
    color: #0F172A !important;
  }

  .nav-tab span,
  .tool-nav-btn span {
    display: none;
  }

  /* Active tab: Expand to show both icon and mode name label */
  .nav-tab.active,
  .tool-nav-btn.active {
    padding: 0 14px !important;
    background: #5E6AD2 !important;
    border-color: #7C88FF !important;
    color: #FFFFFF !important;
  }

  [data-theme="light"] .nav-tab.active,
  [data-theme="light"] .tool-nav-btn.active {
    background: #2563EB !important;
    border: 1px solid #1D4ED8 !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) !important;
    color: #FFFFFF !important;
  }

  .nav-tab.active span,
  .tool-nav-btn.active span,
  [data-theme="light"] .nav-tab.active span,
  [data-theme="light"] .tool-nav-btn.active span {
    display: inline-block !important;
    font-weight: 600 !important;
    font-size: 13px !important;
    margin-left: 6px !important;
    color: #FFFFFF !important;
    letter-spacing: -0.01em !important;
  }

  .nav-tab.active svg,
  .tool-nav-btn.active svg,
  [data-theme="light"] .nav-tab.active svg,
  [data-theme="light"] .tool-nav-btn.active svg {
    stroke: #FFFFFF !important;
  }

  .btn-cal-banner {
    padding: 4px 6px;
    font-size: 0.7rem;
    gap: 4px;
    flex: 1;
    min-width: 0;
  }

  .status-badge {
    font-size: 0.6rem;
    padding: 1px 5px;
  }

  .banner-ppi {
    font-size: 0.7rem;
  }

  .btn-icon {
    width: 28px;
    height: 28px;
    font-size: 0.85rem;
  }

  /* ==========================================================================
     UNIFIED MOBILE TOOLBAR ARCHITECTURE (<600px)
     Consistent layout, aligned controls, and horizontal sliders
     ========================================================================== */
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) .unified-toolbar {
    padding: 6px 8px !important;
    gap: 6px !important;
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    box-sizing: border-box !important;
    max-height: none !important;
    overflow: visible !important;
    border-radius: 10px !important;
  }

  /* ==========================================================================
     UNIVERSAL 2-ROW TOOLBAR: ALL MODES (<600px)
     Row 1: Single Horizontal Sliding Track (1fr) + Pinned Options Button (auto)
     Row 2: Compact Consolidated Measurement Readout Badge (center center)
     Matches 2D Box Mode perfectly across Ruler, Protractor, Ring Sizer, Converter
     ========================================================================== */
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) .unified-toolbar,
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #tool-ruler .unified-toolbar,
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #tool-protractor .unified-toolbar,
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #tool-ringsizer .unified-toolbar,
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #tool-box .unified-toolbar,
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #tool-converter .unified-toolbar {
    display: grid !important;
    grid-template-columns: 1fr auto !important;
    grid-template-areas:
      "left right"
      "center center" !important;
    gap: 6px !important;
    align-items: center !important;
    padding: 6px 8px !important;
    box-sizing: border-box !important;
    width: 100% !important;
  }

  /* Single-Row Horizontally Sliding Track for all Tool Controls */
  .toolbar-left,
  #tool-ruler .toolbar-left,
  #tool-protractor .toolbar-left,
  #tool-ringsizer .toolbar-left,
  #tool-box .toolbar-left,
  #tool-converter .toolbar-left {
    grid-area: left !important;
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scrollbar-width: none !important;
    -webkit-overflow-scrolling: touch !important;
    align-items: center !important;
    gap: 6px !important;
    min-width: 0 !important;
    width: 100% !important;
  }
  .toolbar-left::-webkit-scrollbar,
  #tool-ruler .toolbar-left::-webkit-scrollbar,
  #tool-protractor .toolbar-left::-webkit-scrollbar,
  #tool-ringsizer .toolbar-left::-webkit-scrollbar,
  #tool-box .toolbar-left::-webkit-scrollbar,
  #tool-converter .toolbar-left::-webkit-scrollbar {
    display: none !important;
  }

  .toolbar-left .toolbar-group {
    display: inline-flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 5px !important;
    flex-shrink: 0 !important;
    width: auto !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .toolbar-left .toolbar-label {
    font-size: 0.68rem !important;
    text-transform: uppercase !important;
    font-weight: 700 !important;
    letter-spacing: 0.04em !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
  }

  .toolbar-left select,
  .toolbar-left .form-select {
    height: 32px !important;
    min-height: 32px !important;
    max-height: 32px !important;
    padding: 0 8px !important;
    font-size: 0.78rem !important;
    width: auto !important;
    flex-shrink: 0 !important;
    border-radius: 6px !important;
  }

  /* Right Side: Pinned Options Button */
  .toolbar-right,
  #tool-ruler .toolbar-right,
  #tool-protractor .toolbar-right,
  #tool-ringsizer .toolbar-right,
  #tool-box .toolbar-right,
  #tool-converter .toolbar-right {
    grid-area: right !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    width: auto !important;
    flex-shrink: 0 !important;
  }

  /* Center: Full-Width Readout Badge */
  .toolbar-center,
  #tool-ruler .toolbar-center,
  #tool-protractor .toolbar-center,
  #tool-ringsizer .toolbar-center,
  #tool-box .toolbar-center,
  #tool-converter .toolbar-center {
    grid-area: center !important;
    width: 100% !important;
    margin: 0 !important;
  }

  /* Compact 1-Row Stepper Buttons (Ring Sizer) */
  .ring-step-group,
  .toolbar-left .toolbar-group.ring-step-group {
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 6px !important;
    width: auto !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    overflow-x: auto !important;
    scrollbar-width: none !important;
    -webkit-overflow-scrolling: touch !important;
  }
  .ring-step-group::-webkit-scrollbar {
    display: none;
  }

  .ring-stepper-segmented,
  .ring-step-group .segmented-pill-group {
    display: inline-flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    gap: 2px !important;
    height: 34px !important;
    max-height: 34px !important;
    background: rgba(255, 255, 255, 0.04) !important;
    padding: 2px !important;
    border-radius: 8px !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    align-items: center !important;
    flex-shrink: 0 !important;
  }

  .ring-stepper-segmented .btn-ring-step,
  .btn-ring-step {
    height: 30px !important;
    max-height: 30px !important;
    min-height: 30px !important;
    padding: 0 8px !important;
    font-size: 0.74rem !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex: 0 0 auto !important;
    border-radius: 6px !important;
  }

  /* Universal Options Toggle Button Styling Across All Modes */
  .btn-options-toggle,
  .btn-toggle-options {
    height: 34px !important;
    min-height: 34px !important;
    padding: 0 12px !important;
    font-size: 0.78rem !important;
    font-weight: 600 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 5px !important;
    border-radius: 8px !important;
    flex-shrink: 0 !important;
    white-space: nowrap !important;
  }

  /* Single-Row Measurement Readout Badge Across All Modes */
  .toolbar-center {
    width: 100% !important;
    margin: 0 !important;
  }

  .readout-unified-badge {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 3px 6px !important;
    gap: 6px !important;
    background: #12161F !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    border-radius: 8px !important;
    min-height: 34px !important;
    box-sizing: border-box !important;
    width: 100% !important;
  }

  [data-theme="light"] .readout-unified-badge {
    background: #F8FAFC !important;
    border: 1px solid rgba(0, 0, 0, 0.10) !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04) !important;
  }

  .badge-values {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    scrollbar-width: none !important;
    -webkit-overflow-scrolling: touch !important;
    align-items: center !important;
    gap: 6px !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
  }
  .badge-values::-webkit-scrollbar {
    display: none;
  }

  .readout-chip {
    flex: 0 0 auto !important;
    width: auto !important;
    white-space: nowrap !important;
    min-width: max-content !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 4px !important;
    padding: 2px 6px !important;
    height: 26px !important;
    font-size: 0.72rem !important;
  }

  [data-theme="light"] .readout-chip {
    background: #FFFFFF !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    color: #0F172A !important;
  }
  [data-theme="light"] .readout-chip .chip-lbl {
    color: #64748B !important;
  }
  [data-theme="light"] .readout-chip .val-primary {
    color: #0F172A !important;
  }
  [data-theme="light"] .readout-chip.metric .val-primary {
    color: #2563EB !important;
  }
  [data-theme="light"] .readout-chip.imperial .val-primary {
    color: #7C3AED !important;
  }
  [data-theme="light"] .readout-chip .val-secondary {
    color: #64748B !important;
  }
  [data-theme="light"] .btn-copy-readout {
    background: rgba(94, 106, 210, 0.10) !important;
    border: 1px solid rgba(94, 106, 210, 0.25) !important;
    color: #2563EB !important;
  }

  @media (max-width: 480px) {
    .readout-chip .val-secondary {
      display: none !important;
    }
    .readout-chip.px {
      display: none !important;
    }
  }

  .badge-divider {
    display: none !important;
  }

  .btn-copy-readout {
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: auto !important;
    height: 26px !important;
    min-height: 26px !important;
    padding: 0 8px !important;
    flex-direction: row !important;
    gap: 4px !important;
    font-size: 0.72rem !important;
  }

  /* ==========================================================================
     OPTIONS SUBBAR: UNIFIED SINGLE-ROW HORIZONTAL SLIDER (<600px)
     Eliminates awkward 2-line wraps and makes all presets + reset 1 neat slider
     ========================================================================== */
  .tool-options-subbar,
  #subbar-ruler,
  #subbar-protractor,
  #subbar-ringsizer,
  #subbar-box,
  #subbar-converter {
    display: none !important;
  }

  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) .tool-options-subbar.open,
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-ruler.open,
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-protractor.open,
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-ringsizer.open,
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-box.open,
  body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-converter.open {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    scrollbar-width: none !important;
    -webkit-overflow-scrolling: touch !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 4px 8px !important;
    background: #0E121A !important;
    border: 1px solid rgba(255, 255, 255, 0.10) !important;
    border-radius: 8px !important;
    margin: 4px 0 6px !important;
    box-sizing: border-box !important;
    width: 100% !important;
    height: 42px !important;
    min-height: 42px !important;
    max-height: 42px !important;
    overflow-y: hidden !important;
    color: #F8FAFC !important;
  }

  [data-theme="light"] body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) .tool-options-subbar.open,
  [data-theme="light"] body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-ruler.open,
  [data-theme="light"] body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-protractor.open,
  [data-theme="light"] body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-ringsizer.open,
  [data-theme="light"] body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-box.open,
  [data-theme="light"] body:not(.view-mobile):not(.hide-ui):not(.ui-hidden) #subbar-converter.open {
    background: #FFFFFF !important;
    border: 1px solid rgba(0, 0, 0, 0.12) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06) !important;
    color: #0F172A !important;
  }

  .tool-options-subbar::-webkit-scrollbar,
  #subbar-ruler::-webkit-scrollbar,
  #subbar-protractor::-webkit-scrollbar,
  #subbar-ringsizer::-webkit-scrollbar,
  #subbar-box::-webkit-scrollbar,
  #subbar-converter::-webkit-scrollbar {
    display: none;
  }

  /* All groups inside subbar align inline as a continuous track */
  .tool-options-subbar .toolbar-group,
  #subbar-ruler .toolbar-group,
  #subbar-protractor .toolbar-group,
  #subbar-ringsizer .toolbar-group,
  #subbar-box .toolbar-group,
  #subbar-converter .toolbar-group {
    display: inline-flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 6px !important;
    flex-shrink: 0 !important;
    width: auto !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .tool-options-subbar .toolbar-label,
  #subbar-ruler .toolbar-label,
  #subbar-protractor .toolbar-label,
  #subbar-ringsizer .toolbar-label,
  #subbar-box .toolbar-label,
  #subbar-converter .toolbar-label {
    font-size: 0.68rem !important;
    text-transform: uppercase !important;
    font-weight: 700 !important;
    color: #8A8F98 !important;
    letter-spacing: 0.05em !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    margin-right: 2px !important;
  }

  [data-theme="light"] .tool-options-subbar .toolbar-label,
  [data-theme="light"] #subbar-ruler .toolbar-label,
  [data-theme="light"] #subbar-protractor .toolbar-label,
  [data-theme="light"] #subbar-ringsizer .toolbar-label,
  [data-theme="light"] #subbar-box .toolbar-label,
  [data-theme="light"] #subbar-converter .toolbar-label {
    color: #475569 !important;
  }

  /* All preset buttons and Reset buttons in subbar */
  .tool-options-subbar .btn-pill,
  .tool-options-subbar .btn-secondary,
  .tool-options-subbar .btn-opt-ring,
  .tool-options-subbar .btn-opt-angle,
  .tool-options-subbar .btn-opt-box,
  .tool-options-subbar .btn-opt-conv,
  .tool-options-subbar .btn-rotate,
  #subbar-ruler .btn-pill,
  #subbar-ruler .btn-rotate,
  #subbar-protractor .btn-pill {
    height: 30px !important;
    min-height: 30px !important;
    max-height: 30px !important;
    padding: 0 8px !important;
    font-size: 0.74rem !important;
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 6px !important;
    box-sizing: border-box !important;
    background: #1A202C !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    color: #F8FAFC !important;
  }

  [data-theme="light"] .tool-options-subbar .btn-pill,
  [data-theme="light"] .tool-options-subbar .btn-secondary,
  [data-theme="light"] .tool-options-subbar .btn-opt-ring,
  [data-theme="light"] .tool-options-subbar .btn-opt-angle,
  [data-theme="light"] .tool-options-subbar .btn-opt-box,
  [data-theme="light"] .tool-options-subbar .btn-opt-conv,
  [data-theme="light"] .tool-options-subbar .btn-rotate,
  [data-theme="light"] #subbar-ruler .btn-pill,
  [data-theme="light"] #subbar-ruler .btn-rotate,
  [data-theme="light"] #subbar-protractor .btn-pill {
    background: #F1F5F9 !important;
    border: 1px solid rgba(0, 0, 0, 0.12) !important;
    color: #0F172A !important;
  }

  .tool-options-subbar .form-select,
  .tool-options-subbar select,
  #subbar-ruler .form-select,
  #subbar-ruler select {
    height: 30px !important;
    min-height: 30px !important;
    max-height: 30px !important;
    padding: 0 8px !important;
    font-size: 0.74rem !important;
    flex-shrink: 0 !important;
    border-radius: 6px !important;
    box-sizing: border-box !important;
    background: #12161F !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    color: #F8FAFC !important;
  }

  [data-theme="light"] .tool-options-subbar .form-select,
  [data-theme="light"] .tool-options-subbar select,
  [data-theme="light"] #subbar-ruler .form-select,
  [data-theme="light"] #subbar-ruler select {
    background: #FFFFFF !important;
    border: 1px solid rgba(0, 0, 0, 0.14) !important;
    color: #0F172A !important;
  }

  .tool-options-subbar .stepper-group,
  #subbar-ruler .stepper-group {
    display: inline-flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 2px !important;
    height: 30px !important;
    flex-shrink: 0 !important;
  }

  .tool-options-subbar .btn-stepper,
  #subbar-ruler .btn-stepper {
    width: 26px !important;
    min-width: 26px !important;
    max-width: 26px !important;
    height: 28px !important;
    min-height: 28px !important;
    max-height: 28px !important;
    padding: 0 !important;
    font-size: 0.72rem !important;
    font-weight: 700 !important;
    flex-shrink: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 5px !important;
    box-sizing: border-box !important;
    background: #1A202C !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    color: #F8FAFC !important;
  }

  [data-theme="light"] .tool-options-subbar .btn-stepper,
  [data-theme="light"] #subbar-ruler .btn-stepper {
    background: #F1F5F9 !important;
    border: 1px solid rgba(0, 0, 0, 0.12) !important;
    color: #0F172A !important;
  }

  .tool-options-subbar .rotation-control,
  #subbar-ruler .rotation-control {
    display: inline-flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 4px !important;
    flex-shrink: 0 !important;
  }

  .form-select {
    height: 34px;
    min-height: 34px;
    max-height: 34px;
    padding: 0 8px;
    font-size: 0.78rem;
    line-height: 32px;
  }

  .btn-pill {
    padding: 4px 8px;
    font-size: 0.72rem;
  }

  /* 4. CANVAS WORKSPACE GUARD: Dedicated 65-70% Viewport for Interactive Canvas */
  .tool-panel {
    display: none;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
  }

  .tool-panel.active {
    display: flex !important;
  }

  .ruler-workspace,
  .ring-stage,
  .protractor-stage,
  .box-stage {
    flex: 1 1 auto !important;
    min-height: 65vh !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 6px !important;
    box-sizing: border-box !important;
  }

  .ruler-workspace {
    padding-top: 36px !important;
  }

  .ruler-drag-bar {
    top: -28px;
    font-size: 0.65rem;
    padding: 2px 8px;
  }

  .ring-controls {
    margin-top: 6px !important;
    gap: 6px !important;
    width: 100%;
    max-width: 320px;
  }

  .ring-size-table-container {
    display: none !important; /* Hide 10-row comparison chart in stage on small screens to conserve canvas */
  }

  .box-stage {
    min-height: 65vh !important;
    padding: 8px !important;
  }

  .converter-view {
    margin: 10px auto;
    padding: 0 8px;
  }

  .converter-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 12px;
  }

  .conv-field {
    gap: 3px;
  }

  .conv-label {
    font-size: 0.65rem;
  }

  .conv-input {
    padding: 6px 30px 6px 8px;
    font-size: 0.85rem;
  }

  .conv-unit-tag {
    font-size: 0.65rem;
    right: 6px;
  }

  .modal-card {
    max-width: 95vw;
    margin: 5px;
    max-height: 95vh;
  }

  .modal-header {
    padding: 12px 14px;
  }

  .modal-title {
    font-size: 0.95rem;
  }

  .cal-tabs {
    flex-wrap: wrap;
  }

  .cal-tab-btn {
    padding: 6px 8px;
    font-size: 0.7rem;
    flex: 1;
    min-width: 70px;
  }

  .modal-body {
    padding: 12px;
  }

  .credit-card-visual {
    width: 100%;
    max-width: 300px;
    height: auto;
    aspect-ratio: 1.5858;
  }

  .cal-slider-container {
    max-width: 100%;
  }

  .range-slider {
    width: 100%;
    max-width: 300px;
  }

  .currency-preview-box,
  .object-outline-box,
  #calibration-object-preview {
    width: 100%;
    max-width: 220px;
  }

  .app-toast {
    bottom: 8px;
    right: 8px;
    left: 8px;
    text-align: center;
    font-size: 0.8rem;
    padding: 8px 12px;
  }

  .app-footer {
    padding: 32px 20px 24px 20px;
    margin-top: 32px;
  }

  .footer-container {
    gap: 24px;
    padding-bottom: 20px;
  }

  .footer-links a,
  .footer-links button.footer-link-btn {
    font-size: 0.88rem;
  }

  .footer-bottom {
    padding-top: 16px;
    font-size: 0.74rem;
    line-height: 1.5;
  }
}

/* Tablet & Resized Desktop (769px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .unified-toolbar {
    padding: 8px 14px;
    gap: 8px 12px;
    justify-content: space-between;
  }

  /* Row 1 (High Priority): Primary Inputs + Consolidated Measurement Badge + Copy Button */
  .toolbar-left {
    order: 1;
    flex-shrink: 0;
  }

  .toolbar-center {
    order: 2;
    flex: 1 1 auto;
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
  }

  /* Row 2 (Secondary): Align/Snap controls + Options toggle */
  .toolbar-right {
    order: 3;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }

  [data-theme="light"] .toolbar-right {
    border-top-color: rgba(0, 0, 0, 0.06);
  }

  /* Ring Sizer & 2D Box Area Tablet Layout: Readout Badge stays prominent on Row 1 */
  #tool-ringsizer .toolbar-center,
  #tool-box .toolbar-center {
    order: 1;
    width: 100%;
    justify-content: center;
    margin-bottom: 2px;
  }

  #tool-ringsizer .toolbar-left,
  #tool-box .toolbar-left {
    order: 2;
  }

  #tool-ringsizer .toolbar-right,
  #tool-box .toolbar-right {
    order: 3;
    width: auto;
    margin-left: auto;
    border-top: none;
    padding-top: 0;
  }

  .tool-nav {
    gap: 2px;
  }

  .tool-nav-btn {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .converter-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }
}

/* ==========================================================================
   Mobile-Only Elements (Hidden by default in desktop view, active in view-mobile)
   ========================================================================== */
body:not(.view-mobile) .mobile-header-readout,
body:not(.view-mobile) .mobile-header-actions,
body:not(.view-mobile) .btn-mobile-header-controls,
body:not(.view-mobile) .btn-mobile-header-view {
  display: none !important;
}

body:not(.view-mobile) .tool-nav {
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
body:not(.view-mobile) .tool-nav::-webkit-scrollbar {
  display: none;
}

body:not(.view-mobile) .unified-toolbar {
  flex-wrap: wrap;
  gap: 8px 12px;
}

/* Snap and view mode active pill styling */
.btn-protractor-snap.active,
.btn-protractor-preset.active,
.btn-mobile-snap-angle.active,
.btn-view-mode-toggle.active {
  background: var(--primary, #5E6AD2) !important;
  border-color: rgba(255, 255, 255, 0.45) !important;
  color: #ffffff !important;
  font-weight: 700 !important;
  box-shadow: 0 0 12px rgba(94, 106, 210, 0.4) !important;
}

/* ==========================================================================
   Mobile View Mode Styles
   Active whenever body.view-mobile is toggled or initialized for mobile devices
   ========================================================================== */
body.view-mobile .unified-toolbar,
body.view-mobile #tool-ruler .unified-toolbar,
body.view-mobile #tool-protractor .unified-toolbar,
body.view-mobile #tool-ringsizer .unified-toolbar,
body.view-mobile #tool-box .unified-toolbar,
body.view-mobile #tool-converter .unified-toolbar,
body.view-mobile .toolbar-left,
body.view-mobile .toolbar-right,
body.view-mobile .toolbar-center,
body.view-mobile .readout-unified-badge,
body.view-mobile .tool-options-subbar,
body.view-mobile #subbar-ruler,
body.view-mobile #subbar-protractor,
body.view-mobile #subbar-ringsizer,
body.view-mobile #subbar-box,
body.view-mobile #subbar-converter,
body.view-mobile .tool-nav,
body.view-mobile #toolNav,
body.view-mobile #topNav {
  display: none !important;
}

body.view-mobile .app-header {
  height: 50px;
  padding: 0 12px;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  box-sizing: border-box;
  z-index: 100;
}

body.view-mobile .brand-section {
  gap: 6px;
  flex-shrink: 0;
}

body.view-mobile .brand-logo {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

/* Hide brand title on mobile to prevent 3-line vertical word wrapping */
body.view-mobile .brand-title {
  display: none !important;
}

body.view-mobile .brand-tag {
  display: none !important;
}

body.view-mobile .tool-nav {
  display: none !important;
}

body.view-mobile .header-actions {
  display: none !important;
}

/* Live Readout Badge pinned in Mobile Header */
body.view-mobile .mobile-header-readout {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border-subtle);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary);
  flex: 1 1 auto;
  min-width: 0;
  max-width: 175px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-theme="light"] body.view-mobile .mobile-header-readout {
  background: #FFFFFF !important;
  border-color: rgba(0, 0, 0, 0.12) !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

body.view-mobile .mobile-readout-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.view-mobile .btn-mobile-copy {
  background: rgba(94, 106, 210, 0.15);
  border: 1px solid rgba(94, 106, 210, 0.3);
  color: #93c5fd;
  font-size: 0.85rem;
  padding: 4px 7px;
  cursor: pointer;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  min-height: 28px;
  min-width: 28px;
}

body.view-mobile .btn-mobile-copy:hover,
body.view-mobile .btn-mobile-copy:active {
  background: #5E6AD2;
  color: #ffffff;
}

body.view-mobile .btn-mobile-copy.copied {
  background: #10B981 !important;
  border-color: #10B981 !important;
  color: #ffffff !important;
  transform: scale(1.08);
}

/* Mobile Header Actions (Switch to Desktop button + Controls button) */
body.view-mobile .mobile-header-actions {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

body.view-mobile .btn-mobile-header-view {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: #161B26;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 0 10px;
  height: 36px;
  min-height: 36px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: none;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

/* On mobile viewports <= 480px, make desktop toggle an icon-only button to save space */
@media (max-width: 480px) {
  body.view-mobile .btn-mobile-header-view {
    width: 36px;
    padding: 0;
    justify-content: center;
  }
  body.view-mobile .btn-mobile-header-view span {
    display: none;
  }
}

body.view-mobile .btn-mobile-header-view:hover {
  border-color: var(--border-hover);
  background: #1C2230;
  color: var(--primary);
}

body.view-mobile .btn-mobile-header-controls {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  background: #161B26;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 0 12px;
  height: 36px;
  min-height: 36px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: none;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

body.view-mobile .btn-mobile-header-controls:hover {
  border-color: var(--border-hover);
  background: #1C2230;
}

/* Light Mode for Mobile Header Buttons - ELIMINATES THE BLACK MASK */
[data-theme="light"] body.view-mobile .btn-mobile-header-view,
[data-theme="light"] body.view-mobile .btn-mobile-header-controls {
  background: #FFFFFF !important;
  border-color: rgba(0, 0, 0, 0.12) !important;
  color: #0F172A !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
}

[data-theme="light"] body.view-mobile .btn-mobile-header-view:hover,
[data-theme="light"] body.view-mobile .btn-mobile-header-controls:hover {
  background: #F1F5F9 !important;
  border-color: rgba(0, 0, 0, 0.22) !important;
  color: var(--primary) !important;
}

/* In normal mode on mobile, readout is inside the top header, so floating HUD is hidden */
body.view-mobile:not(.hide-ui) .floating-hud {
  display: none !important;
}

/* In Hide-UI mode on mobile, hide app header and show top floating HUD */
body.view-mobile.hide-ui .app-header {
  display: none !important;
}

body.view-mobile.hide-ui .floating-hud {
  display: flex !important;
  top: max(10px, env(safe-area-inset-top, 10px));
}

body.view-mobile.hide-ui .floating-hud #btnHudShowUI {
  display: inline-flex !important;
}

/* Maximize measurement stage area in mobile view */
body.view-mobile .ruler-workspace,
body.view-mobile .protractor-stage,
body.view-mobile .ring-stage,
body.view-mobile .box-stage {
  min-height: calc(100vh - 50px) !important;
  padding: 8px !important;
}

body.view-mobile .converter-view {
  margin: 12px auto !important;
  padding: 0 10px !important;
}

body.view-mobile .converter-grid {
  grid-template-columns: 1fr !important;
  gap: 10px !important;
  padding: 14px !important;
}

/* Large screens - ensure ruler doesn't get too wide */
@media (min-width: 1400px) {
  .ruler-stage {
    max-width: 1200px;
  }
}

/* Hide UI mode - for full-screen clean view */
body.ui-hidden header,
body.ui-hidden .nav-bar,
body.ui-hidden .tool-bar,
body.ui-hidden .tool-options-subbar,
body.ui-hidden #subbar-ruler,
body.ui-hidden #subbar-protractor,
body.ui-hidden #subbar-ringsizer,
body.ui-hidden #subbar-box,
body.ui-hidden #subbar-converter,
body.ui-hidden .app-header,
body.ui-hidden .tool-nav,
body.ui-hidden #toolNav,
body.ui-hidden #topNav,
body.ui-hidden .unified-toolbar,
body.ui-hidden #tool-ruler .unified-toolbar,
body.ui-hidden #tool-protractor .unified-toolbar,
body.ui-hidden #tool-ringsizer .unified-toolbar,
body.ui-hidden #tool-box .unified-toolbar,
body.ui-hidden #tool-converter .unified-toolbar,
body.ui-hidden .toolbar-left,
body.ui-hidden .toolbar-right,
body.ui-hidden .toolbar-center,
body.ui-hidden .readout-unified-badge,
body.ui-hidden .toolbar-ribbon,
body.ui-hidden .readout-ribbon,
body.ui-hidden .seo-content-section,
body.ui-hidden .faq-section,
body.ui-hidden .app-footer,
body.ui-hidden .mobile-bottom-sheet,
body.ui-hidden .mobile-sheet-backdrop,
body.hide-ui header,
body.hide-ui .nav-bar,
body.hide-ui .tool-bar,
body.hide-ui .tool-options-subbar,
body.hide-ui #subbar-ruler,
body.hide-ui #subbar-protractor,
body.hide-ui #subbar-ringsizer,
body.hide-ui #subbar-box,
body.hide-ui #subbar-converter,
body.hide-ui .app-header,
body.hide-ui .tool-nav,
body.hide-ui #toolNav,
body.hide-ui #topNav,
body.hide-ui .unified-toolbar,
body.hide-ui #tool-ruler .unified-toolbar,
body.hide-ui #tool-protractor .unified-toolbar,
body.hide-ui #tool-ringsizer .unified-toolbar,
body.hide-ui #tool-box .unified-toolbar,
body.hide-ui #tool-converter .unified-toolbar,
body.hide-ui .toolbar-left,
body.hide-ui .toolbar-right,
body.hide-ui .toolbar-center,
body.hide-ui .readout-unified-badge,
body.hide-ui .toolbar-ribbon,
body.hide-ui .readout-ribbon,
body.hide-ui .seo-content-section,
body.hide-ui .faq-section,
body.hide-ui .app-footer,
body.hide-ui .mobile-bottom-sheet,
body.hide-ui .mobile-sheet-backdrop {
  display: none !important;
}

body.ui-hidden .app-main,
body.hide-ui .app-main {
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}

/* Only show the ACTIVE tool panel in hide-ui mode */
body.ui-hidden .tool-panel,
body.hide-ui .tool-panel {
  display: none !important;
  height: 100vh;
}

body.ui-hidden .tool-panel.active,
body.hide-ui .tool-panel.active {
  display: flex !important;
  flex-direction: column;
  height: 100vh;
}

body.hide-ui .ruler-workspace {
  flex: 1;
  min-height: 0;
  height: auto;
  padding: 20px;
  justify-content: center;
  align-items: center;
  overflow: visible;
}

body.hide-ui .protractor-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-height: 0;
  overflow: hidden;
}

body.hide-ui .ring-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-height: 0;
  overflow: hidden;
}

body.hide-ui .box-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-height: 0;
  overflow: hidden;
}

body.hide-ui .converter-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 20px;
  width: 100%;
  max-width: 100%;
  min-height: 0;
  overflow: hidden;
}

body.hide-ui .converter-grid {
  width: 100%;
  max-width: 800px;
  height: auto;
}

/* Ensure canvases don't overflow in hide-ui mode */
body.hide-ui #rulerCanvas,
body.hide-ui #protractorCanvas,
body.hide-ui #ringCanvas {
  max-width: 100%;
  max-height: 100%;
  height: auto;
  width: auto;
}

body.hide-ui #boxContainer {
  max-width: 100%;
  max-height: 100%;
}

/* Floating Minimal HUD (Pinned at top-center when UI is hidden) */
/* Floating Minimal HUD (Pinned at top-center when UI is hidden) */
.floating-hud {
  position: fixed;
  top: max(14px, env(safe-area-inset-top, 14px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  user-select: none;
  width: max-content;
  max-width: calc(100vw - 16px);
  box-sizing: border-box;
  animation: hudSlideDown 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

body.hide-ui .floating-hud {
  display: flex !important;
}

.floating-hud-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  max-width: 100%;
  box-sizing: border-box;
  background: rgba(18, 22, 31, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full, 9999px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
  color: var(--text-main, #ECEEEF);
  white-space: nowrap;
}

[data-theme="light"] .floating-hud-badge {
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  color: #0f172a;
}

.hud-tool-select {
  height: 28px;
  background: #161B26;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: var(--radius-sm, 6px);
  color: var(--text-primary, #ECEEEF);
  padding: 0 8px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
  font-family: inherit;
  flex-shrink: 0;
  text-overflow: ellipsis;
  overflow: hidden;
}

.hud-tool-select:hover {
  border-color: rgba(255, 255, 255, 0.25);
  background: #1F2430;
}

[data-theme="light"] .hud-tool-select {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.15);
  color: #0f172a;
}

[data-theme="light"] .hud-tool-select:hover {
  background: #f1f5f9;
}

.hud-tool-tag {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  background: rgba(94, 106, 210, 0.2);
  color: #93c5fd;
  border: 1px solid rgba(94, 106, 210, 0.35);
  border-radius: 9999px;
  flex-shrink: 0;
}

[data-theme="light"] .hud-tool-tag {
  background: rgba(59, 130, 246, 0.12);
  color: #2563eb;
  border-color: rgba(59, 130, 246, 0.25);
}

.hud-readout-val {
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-variant-numeric: tabular-nums;
  font-size: 0.84rem;
  font-weight: 600;
  color: #f8fafc;
  letter-spacing: 0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 0 1 auto;
}

[data-theme="light"] .hud-readout-val {
  color: #0f172a;
}

.hud-divider {
  width: 1px;
  height: 16px;
  background: rgba(255, 255, 255, 0.14);
  flex-shrink: 0;
}

[data-theme="light"] .hud-divider {
  background: rgba(0, 0, 0, 0.12);
}

.btn-hud-action {
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main, #ECEEEF);
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

[data-theme="light"] .btn-hud-action {
  background: rgba(0, 0, 0, 0.06);
  border-color: rgba(0, 0, 0, 0.08);
  color: #0f172a;
}

.btn-hud-action:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

[data-theme="light"] .btn-hud-action:hover {
  background: rgba(0, 0, 0, 0.10);
  border-color: rgba(0, 0, 0, 0.18);
}

.btn-hud-action.highlight {
  background: var(--color-primary, #5E6AD2);
  border-color: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.btn-hud-action.highlight:hover {
  background: #4B55C0;
  border-color: rgba(255, 255, 255, 0.3);
}

/* Mobile responsive optimizations for Floating HUD */
@media (max-width: 768px) {
  .floating-hud,
  body.view-mobile .floating-hud {
    top: max(10px, env(safe-area-inset-top, 10px));
    max-width: calc(100vw - 16px);
    width: auto;
  }

  .floating-hud-badge,
  body.view-mobile .floating-hud-badge {
    gap: 6px;
    padding: 4px 8px;
    max-width: 100%;
  }

  .hud-tool-select,
  body.view-mobile .hud-tool-select {
    height: 26px;
    padding: 0 4px;
    font-size: 0.72rem;
    max-width: 78px;
  }

  .hud-readout-val,
  body.view-mobile .hud-readout-val {
    font-size: 0.76rem;
    max-width: 190px;
  }

  .hud-divider,
  body.view-mobile .hud-divider {
    height: 14px;
  }

  .btn-hud-action,
  body.view-mobile .btn-hud-action {
    padding: 4px 8px;
    font-size: 0.74rem;
    height: 26px;
  }

  /* Compact copy icon-only on mobile screens */
  .btn-hud-copy span,
  body.view-mobile .btn-hud-copy span {
    display: none;
  }

  .btn-hud-copy,
  body.view-mobile .btn-hud-copy {
    padding: 4px 7px;
  }

  .btn-hud-show-ui,
  body.view-mobile .btn-hud-show-ui {
    padding: 4px 9px;
  }
}

@media (max-width: 380px) {
  .floating-hud-badge,
  body.view-mobile .floating-hud-badge {
    gap: 4px;
    padding: 3px 6px;
  }

  .hud-tool-select,
  body.view-mobile .hud-tool-select {
    max-width: 66px;
    font-size: 0.68rem;
  }

  .hud-readout-val,
  body.view-mobile .hud-readout-val {
    font-size: 0.71rem;
    max-width: 145px;
  }

  .btn-hud-show-ui span,
  body.view-mobile .btn-hud-show-ui span {
    display: none;
  }

  .btn-hud-show-ui,
  body.view-mobile .btn-hud-show-ui {
    padding: 4px 7px;
  }
}

/* Tool Options Modal Sections */
.tool-opt-section {
  display: none;
}

.tool-opt-section.active {
  display: block;
}

.opt-preset-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.opt-preset-btn {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-elevated);
  color: var(--text-main);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.15s ease;
}

.opt-preset-btn:hover {
  border-color: var(--primary, #3b82f6);
  background: var(--primary-light, rgba(59, 130, 246, 0.15));
  color: #93c5fa;
}

[data-theme="light"] .opt-preset-btn:hover {
  color: #1d4ed8;
}

/* In Hide-UI / Fullscreen mode: ensure ONLY the sleek top floating pill is visible; hide all corner buttons */
body.ui-hidden .mobile-bottom-sheet,
body.ui-hidden .mobile-sheet-backdrop,
body.hide-ui .mobile-bottom-sheet,
body.hide-ui .mobile-sheet-backdrop {
  display: none !important;
}

/* Guarantee Top Navigation, Header, Toolbars, and Subbars have high z-index and handle clicks */
.app-header,
.top-nav,
.tool-nav,
.tool-bar,
.unified-toolbar,
.tool-options-subbar {
  position: relative;
  z-index: 9999;
  pointer-events: auto;
}

/* Guarantee background grids, guides, and full-screen canvas containers never block pointer events */
.canvas-container,
.bg-grid,
.ruler-workspace,
.protractor-stage,
.ring-stage,
.box-stage,
.measurement-guide,
.bezel-indicator {
  pointer-events: none;
}

/* Guarantee interactive handles, stages, and controls receive clicks and taps instantly without blocking */
.ruler-stage,
.ruler-drag-bar,
.jaw-handle,
.span-badge,
#protractorCanvas,
#ringCanvas,
.ring-controls,
#ringSizeSlider,
.ring-size-table-container,
#boxContainer,
.box-rect,
.box-handle,
button,
select,
input,
.btn-pill,
.btn-icon,
.btn-cal-banner,
.tool-nav-btn,
.sheet-tool-btn,
.btn-toggle-options,
.btn-mobile-copy,
.btn-mobile-header-controls,
.floating-hud,
.floating-hud button,
.mobile-bottom-sheet button,
.mobile-bottom-sheet select {
  pointer-events: auto;
  touch-action: manipulation;
  cursor: pointer;
}

/* Fullscreen mode adjustments */
:fullscreen .app-header,
:-webkit-full-screen .app-header {
  /* Header stays visible in fullscreen by default */
}

:fullscreen body.hide-ui .app-header,
:-webkit-full-screen body.hide-ui .app-header {
  display: none !important;
}

/* Landscape mobile orientation adjustments */
@media (max-height: 500px) and (orientation: landscape) {
  .app-header {
    padding: 6px 12px;
  }

  .toolbar-ribbon {
    padding: 6px 12px;
  }

  .readout-ribbon {
    padding: 6px 12px;
  }

  .ruler-workspace {
    min-height: 250px;
    padding: 15px 10px;
  }

  .protractor-stage,
  .ring-stage,
  .box-stage {
    padding: 15px 10px;
  }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
  .btn-pill,
  .btn-icon,
  .btn-stepper,
  .btn-protractor-preset,
  .btn-ring-step,
  .btn-box-step,
  .form-select,
  .conv-input,
  .range-slider {
    touch-action: manipulation;
  }

  .ruler-drag-bar {
    opacity: 1 !important;
  }

  .jaw-handle {
    width: 40px !important;
    height: 46px !important;
    left: -20px !important;
  }

  .jaw-a .jaw-handle {
    top: -50px !important;
  }

  .jaw-b .jaw-handle {
    bottom: -50px !important;
  }

  .span-badge {
    padding: 6px 14px;
    font-size: 0.85rem;
  }

  .box-handle {
    width: 24px !important;
    height: 24px !important;
  }

  .handle-br {
    width: 28px !important;
    height: 28px !important;
  }
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
  .app-header {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .app-footer {
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  .ui-hidden-toggle {
    bottom: max(20px, env(safe-area-inset-bottom));
    right: max(20px, env(safe-area-inset-right));
  }

  body.hide-ui .ruler-workspace {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
}

/* ==========================================================================
   Mobile View Mode: Hide Desktop Options Sub-Toolbar (Mobile uses Drawer)
   ========================================================================== */
body.view-mobile .tool-options-subbar {
  display: none !important;
}

/* ==========================================================================
   High-Contrast Button Active States (Dark & Light Mode)
   ========================================================================== */
/* Dark Mode Active Buttons & Segmented Controls */
.tool-nav-btn.active,
.tool-tabs .active,
.nav-bar .active,
.btn.is-active,
.nav-tab.active,
.btn-toggle.active,
.btn-pill.active,
.btn-protractor-snap.active,
.btn-protractor-preset.active,
.btn-mobile-snap-angle.active,
.btn-view-mode-toggle.active,
.sheet-tool-btn.active,
.btn-sheet-dock.active,
.btn-sheet-rotate.active,
.sheet-toggle-btn.active,
.btn-rotate.active,
.cal-tab-btn.active {
  background: #5E6AD2 !important;
  color: #FFFFFF !important;
  border: 1px solid #7C88FF !important;
  box-shadow: 0 0 12px rgba(94, 106, 210, 0.35) !important;
  font-weight: 700 !important;
}

/* Light Mode Active Buttons & Segmented Controls */
[data-theme="light"] .tool-nav-btn.active,
[data-theme="light"] .tool-tabs .active,
[data-theme="light"] .nav-bar .active,
[data-theme="light"] .btn.is-active,
[data-theme="light"] .nav-tab.active,
[data-theme="light"] .btn-toggle.active,
[data-theme="light"] .btn-pill.active,
[data-theme="light"] .btn-protractor-snap.active,
[data-theme="light"] .btn-protractor-preset.active,
[data-theme="light"] .btn-mobile-snap-angle.active,
[data-theme="light"] .btn-view-mode-toggle.active,
[data-theme="light"] .sheet-tool-btn.active,
[data-theme="light"] .btn-sheet-dock.active,
[data-theme="light"] .btn-sheet-rotate.active,
[data-theme="light"] .sheet-toggle-btn.active,
[data-theme="light"] .btn-rotate.active,
[data-theme="light"] .cal-tab-btn.active {
  background: #2563EB !important;
  color: #FFFFFF !important;
  border: 1px solid #1D4ED8 !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) !important;
  font-weight: 700 !important;
}

/* Distinct Muted Inactive State */
.tool-nav-btn:not(.active),
.btn-pill:not(.active),
.sheet-tool-btn:not(.active),
.btn-sheet-dock:not(.active),
.btn-sheet-rotate:not(.active) {
  background: var(--btn-bg);
  color: var(--text-muted);
}

/* Print styles */
@media print {
  .app-header,
  .unified-toolbar,
  .toolbar-ribbon,
  .readout-ribbon,
  .seo-content-section,
  .faq-section,
  .app-footer,
  .ui-hidden-toggle,
  #calibrationModal,
  #shortcutsModal {
    display: none !important;
  }

  .app-main {
    min-height: auto;
  }

  .ruler-workspace {
    min-height: auto;
    padding: 0;
  }

  .tool-panel {
    display: block !important;
    page-break-inside: avoid;
  }
}
