:root {
  --font-sans: "Plus Jakarta Sans", "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
  --font-rtl: "IBM Plex Sans Arabic", "Plus Jakarta Sans", system-ui, -apple-system, Tahoma, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --bg-stage: #e8eef6;
  --dot-stage: rgba(100, 116, 139, 0.28);
  --bg-panel: rgba(255, 255, 255, 0.74);
  --bg-surface: rgba(255, 255, 255, 0.88);
  --bg-surface-solid: #ffffff;
  --bg-muted: rgba(15, 23, 42, 0.065);
  --bg-hover: rgba(15, 23, 42, 0.05);
  --border-hairline: rgba(15, 23, 42, 0.09);
  --border-strong: rgba(15, 23, 42, 0.16);
  --glass-border: rgba(255, 255, 255, 0.78);
  --glass-highlight: rgba(255, 255, 255, 0.92);
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #526277;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.10);
  --accent-border: rgba(37, 99, 235, 0.34);
  --danger-bg: #fef2f2;
  --danger-border: #fca5a5;
  --danger-text: #b91c1c;
  --radius-shell: 18px;
  --radius: 9px;
  --radius-sm: 7px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-stage);
  color: var(--text-primary);
  font-family: var(--font-sans);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

button, a, [role="button"], .seg-btn, .mode-btn, .quick-pick-btn, .mobile-nav-btn {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.mobile-top-bar,
.mobile-bottom-nav,
.mobile-export-head,
.mobile-print-btn,
.mobile-quick-export {
  display: none;
}

html[dir="rtl"] body,
[dir="rtl"] {
  font-family: var(--font-rtl);
}

::selection {
  background: rgba(37, 99, 235, 0.18);
  color: var(--text-primary);
}

input, select, button {
  font-family: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell {
  display: flex;
  height: 100vh;
  width: 100vw;
  background-color: var(--bg-stage);
  background-image:
    radial-gradient(ellipse 65% 55% at 72% 18%, rgba(255, 255, 255, 0.80) 0%, rgba(255, 255, 255, 0) 70%),
    radial-gradient(ellipse 45% 55% at 14% 85%, rgba(37, 99, 235, 0.08) 0%, rgba(37, 99, 235, 0) 70%),
    radial-gradient(var(--dot-stage) 1.1px, transparent 1.1px);
  background-size: 100% 100%, 100% 100%, 18px 18px;
}

/* LEFT FLOATING FROSTED-GLASS PANEL (Concept A + Compact Header B + Hairline Sections C) */
.control-panel {
  width: 342px;
  min-width: 320px;
  margin: 12px;
  margin-inline-end: 0;
  height: calc(100vh - 24px);
  background: var(--bg-panel);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-shell);
  display: flex;
  flex-direction: column;
  z-index: 20;
  overflow: hidden;
  box-shadow:
    0 20px 48px rgba(15, 23, 42, 0.10),
    0 2px 8px rgba(15, 23, 42, 0.04),
    inset 0 1px 0 var(--glass-highlight);
}

/* Compact Studio Header (from Concept B) */
.panel-header {
  padding: 11px 14px 10px;
  border-bottom: 1px solid var(--border-hairline);
  background: rgba(255, 255, 255, 0.42);
  flex-shrink: 0;
}

.header-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.header-badges {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  white-space: nowrap;
  flex-shrink: 0;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  padding: 2px 6px;
  border-radius: 999px;
}

.license-chip {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: 5px;
  padding: 2px 5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.author-card {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.header-title-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.panel-header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--text-primary);
}

.panel-subtitle {
  margin: 0;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Scroll Region with 1px Hairline Sections (from Concept C) */
.panel-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(15, 23, 42, 0.18) transparent;
}

.panel-scroll::-webkit-scrollbar {
  width: 6px;
}

.panel-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.panel-scroll::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.16);
  border-radius: 999px;
}

.lang-strip {
  display: grid;
  grid-template-columns: 1.25fr 0.9fr;
  align-items: end;
  gap: 8px;
  padding: 10px 14px 11px;
  border-bottom: 1px solid var(--border-hairline);
}

/* HAIRLINE-DIVIDED ACCORDIONS (No Card-in-Card Boxes) */
.studio-accordion {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-hairline);
  overflow: visible;
}

.studio-accordion:last-of-type {
  border-bottom: none;
}

.acc-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  transition: background-color 150ms var(--ease-out);
}

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

.acc-title-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.acc-icon {
  width: 15px;
  height: 15px;
  color: var(--accent);
  flex-shrink: 0;
}

.acc-chevron {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  transition: transform 220ms var(--ease-out);
  flex-shrink: 0;
}

.studio-accordion[open] > .acc-summary .acc-chevron {
  transform: rotate(180deg);
}

.acc-collapse {
  overflow: visible;
  transition: height 220ms var(--ease-out), opacity 180ms var(--ease-out);
}

.acc-collapse.is-animating {
  overflow: hidden;
}

.acc-body {
  padding: 2px 14px 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.ctrl-label {
  display: block;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
  margin-bottom: 4px;
}

.ctrl-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

/* Segmented Controls with Sliding Active Pill */
.segmented {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-muted);
  padding: 3px;
  border-radius: var(--radius);
  border: 1px solid var(--border-hairline);
  gap: 2px;
}

.segmented-3 {
  grid-template-columns: repeat(3, 1fr);
}

.seg-indicator {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 0;
  border-radius: 6px;
  background: var(--accent);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.28);
  pointer-events: none;
  z-index: 0;
  transition: transform 220ms var(--ease-out), width 220ms var(--ease-out);
}

.seg-indicator.no-anim {
  transition: none;
}

.seg-btn {
  position: relative;
  z-index: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 5px 6px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: color 160ms var(--ease-out), transform 120ms var(--ease-out);
}

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

.seg-btn.active {
  color: #ffffff;
}

/* Fallback when indicator hasn't initialized yet */
.segmented:not(.has-indicator) .seg-btn.active {
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.26);
}

/* Searchable Combobox + Origin-Aware Dropdown */
.combo-wrap {
  position: relative;
}

.combo-input-box {
  position: relative;
  display: flex;
  align-items: center;
}

.combo-input-box input {
  width: 100%;
  background: var(--bg-surface-solid);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding-block: 7px;
  padding-inline: 10px 30px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  outline: none;
  transition: border-color 150ms var(--ease-out), box-shadow 150ms var(--ease-out);
}

.combo-input-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.combo-clear {
  position: absolute;
  inset-inline-end: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 150ms var(--ease-out), background-color 150ms var(--ease-out), transform 120ms var(--ease-out);
}

.combo-clear:active {
  transform: scale(0.94);
}

.combo-dropdown {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  max-height: 245px;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.16), 0 2px 6px rgba(15, 23, 42, 0.06);
  z-index: 60;
  transform-origin: top center;
  display: block !important;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out), visibility 180ms var(--ease-out);
}

.combo-dropdown[hidden] {
  display: block !important;
  opacity: 0;
  transform: translateY(-4px) scale(0.96);
  visibility: hidden;
  pointer-events: none;
}

.combo-item {
  padding: 8px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  transition: background-color 120ms var(--ease-out);
}

.combo-item:last-child {
  border-bottom: none;
}

.combo-item.active {
  background: var(--accent-soft);
}

.combo-item .ci-main {
  font-weight: 600;
  color: var(--text-primary);
}

.combo-item .ci-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.combo-item .ci-code {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

.selected-pill {
  font-size: 11.5px;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
}

/* Custom Study Area Upload */
.upload-row {
  display: flex;
  gap: 6px;
}

.btn-upload, .btn-reset-area {
  flex: 1;
  background: var(--bg-surface);
  border: 1px dashed var(--accent-border);
  color: var(--accent);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out), transform 120ms var(--ease-out);
}

.btn-upload:active, .btn-reset-area:active {
  transform: scale(0.97);
}

.btn-reset-area {
  flex: 0 0 auto;
  border-style: solid;
  border-color: var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger-text);
}

.custom-area-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.crs-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.crs-lbl {
  font-size: 10.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.crs-select {
  width: 100%;
  background: var(--bg-surface-solid);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  outline: none;
  cursor: pointer;
  transition: border-color 150ms var(--ease-out), box-shadow 150ms var(--ease-out);
}

.crs-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* Thematic Overlay Modes & Basemap Grids */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.mode-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  color: var(--text-secondary);
  padding: 7px 7px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out), color 150ms var(--ease-out), transform 120ms var(--ease-out);
}

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

.mode-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-hover);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.14);
}

#modeGrid .mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 6px;
  line-height: 1.2;
}

.mode-btn-title {
  font-size: 11px;
  font-weight: 600;
}

.mode-btn-sub {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  line-height: 1.2;
}

#modeGrid .mode-btn.active .mode-btn-sub {
  color: var(--accent);
  opacity: 0.85;
}

.osm-status-pill {
  font-size: 11px;
  color: var(--accent-hover);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.access-filter-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-top: 2px;
}

.osm-status-pill.warn {
  color: var(--danger-text);
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

/* Custom Range Sliders & Outline Only Toggle */
.opacity-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

.opacity-row .range-val {
  min-width: 36px;
  text-align: end;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.opacity-row input[type="range"] {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  height: 5px;
  background: var(--bg-muted);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}

.opacity-row input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.25);
  cursor: pointer;
  transition: transform 120ms var(--ease-out);
}

.opacity-row input[type="range"]:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Color Presets & Pickers */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.preset-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  color: var(--text-secondary);
  padding: 6px 6px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out), color 150ms var(--ease-out), transform 120ms var(--ease-out);
}

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

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

.preset-swatch {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(15, 23, 42, 0.25);
}

.color-pickers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.color-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

.color-item input[type="color"] {
  width: 24px;
  height: 20px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: none;
  padding: 0;
  cursor: pointer;
}

.btn-nofill-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out), color 150ms var(--ease-out), transform 120ms var(--ease-out);
}

.btn-nofill-toggle:active {
  transform: scale(0.97);
}

.btn-nofill-toggle .nofill-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 2px solid var(--text-secondary);
  background: transparent;
  flex-shrink: 0;
}

.btn-nofill-toggle.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-hover);
}

.btn-nofill-toggle.active .nofill-dot {
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.16);
}

/* North Arrow Grid */
.north-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.north-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  padding: 5px 3px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out), color 150ms var(--ease-out), transform 120ms var(--ease-out);
}

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

.north-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* Metadata Inputs */
.meta-fields {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.meta-fields input {
  width: 100%;
  background: var(--bg-surface-solid);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  outline: none;
  transition: border-color 150ms var(--ease-out), box-shadow 150ms var(--ease-out);
}

.meta-fields input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.credit-toggle-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 3px 2px;
  user-select: none;
}

.credit-toggle-row input[type="checkbox"] {
  width: auto !important;
  padding: 0 !important;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* UNIFIED EXPORT DOCK: 1 Primary Cobalt CTA + 3 Refined Tonal Secondary */
.panel-footer {
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border-hairline);
  background: rgba(255, 255, 255, 0.56);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  flex-shrink: 0;
}

.btn-export {
  border-radius: var(--radius);
  padding: 8px 9px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out), color 150ms var(--ease-out), box-shadow 150ms var(--ease-out), transform 120ms var(--ease-out);
}

.btn-export:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-export:disabled,
.tool-chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-export-primary {
  border: 1px solid #0f172a;
  background: #0f172a;
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.22);
}

.btn-export-tonal {
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-primary);
}

.btn-export-tonal svg {
  color: var(--text-secondary);
}

.mobile-export-head,
.mobile-print-btn,
.mobile-quick-export {
  display: none;
}

/* RIGHT ARCHITECTURAL DOT-GRID STAGE */
.stage-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Floating Frosted-Glass Stage Toolbar Pill */
.stage-toolbar {
  margin: 12px 12px 0 12px;
  height: 44px;
  padding: 0 8px 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-panel);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  box-shadow:
    0 10px 28px rgba(15, 23, 42, 0.07),
    inset 0 1px 0 var(--glass-highlight);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.status-cluster {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
}

.tool-chip {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  color: var(--text-primary);
  border-radius: 9px;
  padding: 6px 11px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out), color 150ms var(--ease-out), transform 120ms var(--ease-out);
}

.tool-chip:active:not(:disabled) {
  transform: scale(0.97);
}

.a4-viewport {
  flex: 1;
  padding: 16px 20px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.a4-paper {
  position: relative;
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 2px;
  box-shadow: 0 22px 54px rgba(15, 23, 42, 0.14), 0 4px 12px rgba(15, 23, 42, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: width 220ms var(--ease-out), height 220ms var(--ease-out);
}

/* Floating Glass Zoom Controls Pill */
.map-zoom-controls {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.12), inset 0 1px 0 var(--glass-highlight);
  z-index: 20;
}

@media (min-width: 769px) {
  .map-zoom-controls {
    top: 14%;
    left: 4.5%;
  }
}

.zoom-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out), color 150ms var(--ease-out), transform 120ms var(--ease-out);
}

.zoom-btn:active {
  transform: scale(0.95);
}

#a4Svg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  user-select: none;
}

#a4Svg .commune-path {
  stroke-linejoin: round;
  stroke-linecap: round;
}

#a4Svg.panning {
  cursor: grabbing;
}

.a4-paper.landscape {
  width: min(100%, calc((100vh - 102px) * 1.4142857));
  aspect-ratio: 297 / 210;
}

.a4-paper.portrait {
  height: min(100%, calc((100vw - 398px) * 1.4142857));
  aspect-ratio: 210 / 297;
}

/* Interactive Empty State Overlay inside A4 Sheet */
.empty-state-overlay {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(520px, calc(100% - 48px));
  height: fit-content;
  padding: 28px 30px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--border-hairline);
  box-shadow:
    0 20px 46px rgba(15, 23, 42, 0.09),
    0 2px 8px rgba(15, 23, 42, 0.04),
    inset 0 1px 0 var(--glass-highlight);
  display: flex !important;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  z-index: 25;
  opacity: 1;
  transform: scale(1);
  transition: opacity 220ms var(--ease-out), transform 220ms var(--ease-out), visibility 220ms var(--ease-out);
}

.empty-state-overlay[hidden] {
  display: flex !important;
  opacity: 0;
  transform: scale(0.97);
  visibility: hidden;
  pointer-events: none;
}

.empty-icon-badge {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
}

.empty-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
  color: var(--text-primary);
}

.empty-subtitle {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-secondary);
  max-width: 420px;
}

.quick-picks-wrap {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.quick-picks-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.quick-picks-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
}

.quick-pick-btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface-solid);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
  transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out), color 150ms var(--ease-out), transform 120ms var(--ease-out);
}

.quick-pick-btn:active {
  transform: scale(0.97);
}

.quick-pick-code {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.empty-stats-row {
  margin-top: 8px;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.empty-stat-card {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--border-hairline);
  border-radius: 10px;
  padding: 9px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.empty-stat-val {
  font-family: var(--font-mono);
  font-size: 13.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.empty-stat-lbl {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}

/* Sonner-Style Floating Toast (400ms ease, symmetric enter/exit) */
.toast {
  position: fixed;
  bottom: 22px;
  right: 24px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  color: #ffffff;
  border: 1px solid rgba(37, 99, 235, 0.55);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.24);
  z-index: 100;
  display: inline-flex !important;
  align-items: center;
  gap: 8px;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity 400ms ease, transform 400ms ease, visibility 400ms ease;
}

.toast[hidden] {
  display: inline-flex !important;
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  visibility: hidden;
  pointer-events: none;
}

/* Fine-Pointer Hover Gating (prevent sticky touch hovers) */
@media (hover: hover) and (pointer: fine) {
  .acc-summary:hover {
    background: var(--bg-hover);
  }
  .seg-btn:hover:not(.active) {
    color: var(--text-primary);
  }
  .combo-clear:hover {
    color: var(--text-primary);
    background: var(--bg-muted);
  }
  .combo-item:hover {
    background: var(--accent-soft);
  }
  .btn-upload:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
  }
  .btn-reset-area:hover {
    background: #fee2e2;
  }
  .mode-btn:hover:not(.active),
  .preset-btn:hover:not(.active),
  .btn-nofill-toggle:hover:not(.active),
  .north-btn:hover:not(.active) {
    background: var(--bg-surface-solid);
    border-color: var(--border-strong);
    color: var(--text-primary);
  }
  .opacity-row input[type="range"]:hover::-webkit-slider-thumb {
    transform: scale(1.1);
  }
  .btn-export-primary:hover:not(:disabled) {
    background: #1e293b;
    border-color: #1e293b;
  }
  .btn-export-tonal:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.85);
    border-color: #0f172a;
    color: #0f172a;
  }
  .btn-export-tonal:hover:not(:disabled) svg {
    color: #0f172a;
  }
  .tool-chip:hover:not(:disabled) {
    background: var(--bg-surface-solid);
    border-color: var(--accent);
    color: var(--accent);
  }
  .quick-pick-btn:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-hover);
  }
  .zoom-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
  }
}

/* Reduced Transparency Accessibility Fallback */
@media (prefers-reduced-transparency: reduce) {
  .control-panel,
  .stage-toolbar,
  .map-zoom-controls,
  .combo-dropdown,
  .empty-state-overlay {
    background: #ffffff;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .toast {
    background: #0f172a;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

/* Reduced Motion Accessibility Fallback (gentler fade/color, no spatial travel) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
  .seg-btn:active,
  .mode-btn:active,
  .preset-btn:active,
  .north-btn:active,
  .btn-export:active,
  .tool-chip:active,
  .zoom-btn:active {
    transform: none;
  }
  .toast {
    transition: opacity 160ms ease, visibility 160ms ease !important;
  }
  .toast[hidden] {
    transform: none;
  }
  .combo-dropdown {
    transition: opacity 140ms ease, visibility 140ms ease !important;
  }
  .combo-dropdown[hidden] {
    transform: none;
  }
  .empty-state-overlay {
    transition: opacity 160ms ease, visibility 160ms ease !important;
  }
  .empty-state-overlay[hidden] {
    transform: none;
  }
  .quick-pick-btn:active {
    transform: none;
  }
}

/* Coarse pointer / mobile input zoom prevention */
@media (pointer: coarse) {
  input, textarea, select {
    font-size: 16px;
  }
}

/* Tablet Layout (769px - 900px) */
@media (min-width: 769px) and (max-width: 900px) {
  html, body {
    overflow: auto;
    height: auto;
  }
  .app-shell {
    flex-direction: column;
    height: auto;
    width: 100%;
  }
  .control-panel {
    width: 100%;
    min-width: 0;
    height: auto;
    margin: 0;
    border-radius: 0;
    border-inline-end: none;
    border-inline-start: none;
    border-top: none;
    border-bottom: 1px solid var(--border-hairline);
    background: rgba(255, 255, 255, 0.94);
    box-shadow: none;
    overflow: visible;
  }
  .panel-scroll {
    max-height: none;
    overflow: visible;
  }
  .panel-footer {
    position: sticky;
    bottom: 0;
    z-index: 30;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.08);
  }
  .stage-area {
    overflow: visible;
  }
  .stage-toolbar {
    margin: 12px 12px 0;
  }
  .a4-viewport {
    padding: 12px;
  }
  .a4-paper.landscape,
  .a4-paper.portrait {
    width: 100%;
    height: auto;
  }
  .a4-paper.is-empty {
    aspect-ratio: auto;
    min-height: 290px;
  }
  .empty-state-overlay {
    position: relative;
    inset: auto;
    width: calc(100% - 24px);
    margin: 14px auto;
    padding: 20px 16px;
  }
}

/* Mobile Native Studio Layout (<= 768px) */
@media (max-width: 768px) {
  html, body {
    height: 100%;
    overflow: hidden;
  }
  input, textarea, select {
    font-size: 16px;
  }
  .app-shell {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100%;
    overflow: hidden;
  }
  .mobile-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: calc(7px + env(safe-area-inset-top, 0px)) 12px 8px;
    background: rgba(255, 255, 255, 0.90);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border-hairline);
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
    flex-shrink: 0;
    z-index: 35;
  }
  .mobile-top-brand {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    flex: 1;
  }
  .mobile-app-title {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mobile-lang-seg {
    flex-shrink: 0;
    width: 104px;
  }
  .mobile-lang-seg .seg-btn {
    padding: 4px 4px;
    font-size: 11px;
  }

  .control-panel {
    width: 100%;
    min-width: 0;
    height: auto;
    margin: 0;
    border-radius: 0;
    border: none;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: none;
    flex: 1;
    min-height: 0;
  }
  .panel-header {
    display: none;
  }
  .lang-strip {
    grid-template-columns: 1fr;
  }
  .lang-strip > div:first-child {
    display: none;
  }
  .panel-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 16px;
  }

  .stage-area {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }
  .stage-toolbar {
    display: none;
  }
  .a4-viewport {
    position: relative;
    flex: 1;
    min-height: 0;
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }
  .a4-paper:not(.is-empty) {
    position: static;
    margin: 0;
    flex-shrink: 0;
  }
  .a4-paper.landscape:not(.is-empty) {
    width: min(94vw, calc(100vw - 24px), calc((100dvh - 156px) * 1.4142857));
    height: auto;
    aspect-ratio: 297 / 210;
  }
  .a4-paper.portrait:not(.is-empty) {
    width: min(94vw, calc(100vw - 24px), calc((100dvh - 156px) * 0.7070707));
    height: auto;
    aspect-ratio: 210 / 297;
  }
  .a4-paper:not(.is-empty) #a4Svg {
    touch-action: none;
  }
  .a4-paper.is-empty {
    width: 100%;
    height: auto;
    max-height: 100%;
    background: transparent;
    border: none;
    box-shadow: none;
    aspect-ratio: auto;
    margin: 0;
  }
  .a4-paper.is-empty #a4Svg {
    display: none;
  }
  .empty-state-overlay {
    position: relative;
    inset: auto;
    margin: 0 auto;
    width: min(460px, calc(100vw - 24px));
    max-height: calc(100dvh - 138px);
    padding: 18px 16px;
    gap: 8px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .empty-state-overlay[hidden] {
    display: none !important;
  }
  .empty-icon-badge {
    width: 38px;
    height: 38px;
    border-radius: 11px;
  }
  .empty-title {
    font-size: 15.5px;
  }
  .empty-subtitle {
    font-size: 12px;
    line-height: 1.45;
  }
  .quick-pick-btn {
    padding: 6px 11px;
    font-size: 12px;
  }
  .empty-stat-card {
    padding: 7px 6px;
  }
  .empty-stat-val {
    font-size: 12.5px;
  }

  .a4-viewport .map-zoom-controls {
    position: absolute;
    top: 12px;
    left: 12px;
  }

  .mobile-quick-export {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: #0f172a;
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 999px;
    padding: 9px 16px;
    font-size: 12.5px;
    font-weight: 600;
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.22);
    z-index: 22;
    cursor: pointer;
    white-space: nowrap;
    transition: transform 120ms var(--ease-out), background-color 150ms var(--ease-out);
  }
  .mobile-quick-export:active:not(:disabled) {
    transform: translateX(-50%) scale(0.97);
  }
  .mobile-quick-export:disabled {
    opacity: 0.45;
    cursor: not-allowed;
  }

  /* Tab Switching */
  .app-shell[data-mobile-tab="preview"] .control-panel {
    display: none;
  }
  .app-shell[data-mobile-tab="preview"] .stage-area {
    display: flex;
  }
  .app-shell[data-mobile-tab="controls"] .stage-area {
    display: none;
  }
  .app-shell[data-mobile-tab="controls"] .control-panel {
    display: flex;
  }
  .app-shell[data-mobile-tab="controls"] .panel-footer {
    display: none;
  }
  .app-shell[data-mobile-tab="export"] .stage-area {
    display: none;
  }
  .app-shell[data-mobile-tab="export"] .control-panel {
    display: flex;
  }
  .app-shell[data-mobile-tab="export"] .panel-scroll {
    display: none;
  }
  .app-shell[data-mobile-tab="export"] .panel-footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 16px 14px;
    flex: 1;
    align-content: start;
    background: transparent;
    border-top: none;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .mobile-export-head {
    display: flex;
    flex-direction: column;
    gap: 4px;
    grid-column: 1 / -1;
    margin-bottom: 4px;
  }
  .mobile-export-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
  }
  .mobile-export-sub {
    margin: 0;
    font-size: 12px;
    color: var(--text-muted);
  }
  .app-shell[data-mobile-tab="export"] .btn-export {
    padding: 13px 12px;
    font-size: 13px;
    border-radius: 12px;
  }
  .app-shell[data-mobile-tab="export"] .btn-export-primary {
    grid-column: 1 / -1;
  }
  .app-shell[data-mobile-tab="export"] .mobile-print-btn {
    display: inline-flex;
  }

  .mobile-bottom-nav {
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    gap: 6px;
    height: calc(54px + env(safe-area-inset-bottom, 0px));
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid var(--border-hairline);
    box-shadow: 0 -6px 24px rgba(15, 23, 42, 0.06);
    flex-shrink: 0;
    z-index: 35;
  }
  .mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 10.5px;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    transition: color 150ms var(--ease-out), background-color 150ms var(--ease-out), transform 110ms var(--ease-out);
  }
  .mobile-nav-btn.active {
    color: var(--accent);
    background: var(--accent-soft);
  }
  .mobile-nav-btn:active {
    transform: scale(0.96);
  }

  .toast {
    bottom: calc(66px + env(safe-area-inset-bottom, 0px));
    right: 12px;
    left: 12px;
    justify-content: center;
  }
}

/* System Print / Vector PDF Rules */
@media print {
  @page { margin: 0; }
  html, body { background: #ffffff; overflow: visible; }
  .app-shell { background: #ffffff; background-image: none; }
  .control-panel, .stage-toolbar, .toast, .map-zoom-controls, .empty-state-overlay, .mobile-top-bar, .mobile-bottom-nav, .mobile-quick-export { display: none !important; }
  .stage-area, .a4-viewport { padding: 0; margin: 0; background: #ffffff; background-image: none; display: block; overflow: visible; }
  .a4-paper {
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    width: 100% !important;
    height: 100% !important;
  }
}
