/* ============================================
   How Maps Lie — Signal Theme
   ============================================ */

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

:root {
  --bg: #0a0e1a;
  --panel-bg: rgba(12, 16, 28, 0.92);
  --panel-border: rgba(255, 0, 111, 0.1);
  --accent: #ff006f;
  --accent-hover: #ff3389;
  --accent-glow: rgba(255, 0, 111, 0.15);
  --text: #c8d0dc;
  --text-muted: #6a7080;
  --text-dim: #363a44;
  --surface: rgba(255, 255, 255, 0.035);
  --surface-hover: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.06);
  --danger: #ef4444;

  --ocean: #0c1624;
  --land: #162030;
  --land-stroke: #243040;
  --graticule-color: rgba(255, 255, 255, 0.045);

  --font-display: 'Exo 2', system-ui, sans-serif;
  --font-body: 'Outfit', 'M PLUS 1', system-ui, sans-serif;

  --panel-w: 340px;
  --r: 8px;
  --r-lg: 16px;
}

/* ===== Light Theme — Cool Signal ===== */

[data-theme="light"] {
  --bg: #f0f4f8;
  --panel-bg: rgba(238, 242, 248, 0.92);
  --panel-border: rgba(212, 0, 90, 0.1);
  --accent: #d4005a;
  --accent-hover: #e8006a;
  --accent-glow: rgba(212, 0, 90, 0.1);
  --text: #1e293b;
  --text-muted: #64748b;
  --text-dim: #c0c8d4;
  --surface: rgba(0, 0, 0, 0.04);
  --surface-hover: rgba(0, 0, 0, 0.07);
  --border: rgba(0, 0, 0, 0.08);
  --danger: #dc2626;

  --ocean: #c0d4e6;
  --land: #e6e2d8;
  --land-stroke: #b8b4a8;
  --graticule-color: rgba(0, 0, 0, 0.06);
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== Layout ===== */

#app {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
}

#map-container {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  display: flex;
}

.map-wrapper {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.map-wrapper + .map-wrapper {
  border-left: 1px solid var(--border);
}

.map-wrapper::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  box-shadow: inset 0 0 80px 16px rgba(10, 14, 26, 0.35);
}

[data-theme="light"] .map-wrapper::after {
  box-shadow: inset 0 0 80px 16px rgba(240, 244, 248, 0.3);
}

.map-svg {
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

.map-svg:active {
  cursor: grabbing;
}

.map-label {
  position: absolute;
  top: 10px;
  left: 12px;
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.25s;
}

.dual-mode .map-label {
  opacity: 1;
}

#projection-b-section {
  margin-top: 10px;
}

/* ===== Floating Panel ===== */

#controls {
  position: absolute;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: var(--panel-w);
  background: var(--panel-bg);
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 20;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.3),
    0 4px 24px rgba(0, 0, 0, 0.4),
    0 0 60px -10px var(--accent-glow);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.panel-handle {
  display: none;
}

#mobile-header {
  display: none;
}

.panel-peek {
  display: none;
}

.panel-header {
  padding: 24px 24px 0;
  flex-shrink: 0;
}

.panel-header h1 {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.panel-header .subtitle {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 4px;
  letter-spacing: 0.06em;
  line-height: 1.2;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.panel-body::-webkit-scrollbar {
  width: 4px;
}

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

.panel-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.panel-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ===== Control Sections ===== */

.control-section {
  margin-bottom: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.control-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.control-section h2 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 12px;
  letter-spacing: 0.04em;
}

label {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ===== Select ===== */

select {
  width: 100%;
  padding: 10px 32px 10px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-family: var(--font-body);
  font-size: 0.85rem;
  margin-bottom: 12px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7' fill='none'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236a7080' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

select:hover {
  background-color: var(--surface-hover);
  border-color: rgba(255, 255, 255, 0.1);
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

select option {
  background: #0e1424;
  color: var(--text);
}

/* ===== Range Slider ===== */

input[type="range"] {
  width: 100%;
  height: 6px;
  margin: 8px 0 14px;
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface);
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 0 8px var(--accent-glow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 0 14px rgba(255, 0, 111, 0.3);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 0 8px var(--accent-glow);
  cursor: pointer;
}

input[type="range"]::-moz-range-track {
  height: 6px;
  background: var(--surface);
  border-radius: 3px;
  border: none;
}

/* ===== Buttons ===== */

button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
}

#add-circle {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  font-size: 0.82rem;
  border-radius: var(--r);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
}

#add-circle:hover {
  background: var(--accent-hover);
  box-shadow: 0 2px 16px var(--accent-glow);
}

#add-circle:active {
  transform: scale(0.98);
}

/* ===== Circle List ===== */

#circle-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.circle-item {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 0.82rem;
  transition: background 0.15s, border-color 0.15s;
  position: relative;
  overflow: hidden;
}

.circle-preview-btn {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  position: relative;
  background: transparent;
  text-align: left;
}

.circle-preview-btn::after {
  content: "⧉";
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.4;
  transition: opacity 0.15s;
  pointer-events: none;
}

.circle-preview-btn:hover {
  background: var(--surface-hover);
}

.circle-preview-btn:hover::after {
  opacity: 0.7;
}

.circle-preview-btn:focus-visible,
.circle-item .delete-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.circle-item .color-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.circle-item .circle-info {
  flex: 1;
  min-width: 0;
}

.circle-item .circle-info .source-name {
  display: block;
  font-weight: 600;
  color: var(--text);
  font-size: 0.82rem;
}

.circle-item .circle-info .circle-details {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.circle-item .delete-btn {
  width: auto;
  padding: 2px 6px;
  margin-right: 6px;
  background: transparent;
  color: var(--text-dim);
  font-size: 1.1rem;
  line-height: 1;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.circle-item .delete-btn:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* ===== Toggle Label ===== */

.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.toggle-label input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

/* ===== Segmented Control ===== */

.segmented {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
}

.segmented-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0;
  padding: 7px 6px;
  border-radius: 5px;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
  color: var(--text-muted);
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s, background 0.15s;
}

.segmented-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-option:hover {
  color: var(--text);
}

.segmented-option:has(input:checked) {
  background: var(--accent);
  color: #fff;
}

.segmented-option:has(input:focus-visible) {
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ===== Help Text ===== */

.help-text p {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 6px;
}

/* ===== Language Switcher ===== */

.lang-switcher {
  display: flex;
}

.lang-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  min-width: 140px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #0e1828;
  border: 1px solid var(--panel-border);
  border-radius: var(--r);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 30;
  animation: popup-enter 0.15s ease-out both;
}

.lang-menu[hidden] {
  display: none;
}

.lang-menu button {
  padding: 7px 10px;
  font-size: 0.78rem;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 5px;
  transition: color 0.15s, background 0.15s;
}

.lang-menu button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.lang-menu button.active {
  color: var(--accent);
  font-weight: 600;
}

[data-theme="light"] .lang-menu {
  background: #f0f4f8;
}

/* ===== Projection Popup ===== */

.projection-popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 24px;
  z-index: 100;
  pointer-events: none;
}

.projection-popup {
  pointer-events: auto;
  background: #0e1828;
  border: 1px solid var(--panel-border);
  border-radius: var(--r-lg);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  max-width: 440px;
  width: 90%;
  animation: popup-enter 0.2s ease-out both;
}

@keyframes popup-enter {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes popup-exit {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(12px); }
}

.projection-popup.popup-closing {
  animation: popup-exit 0.15s ease-in forwards;
}

.projection-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.projection-popup-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--accent);
}

.projection-popup-close {
  width: auto;
  padding: 4px 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.projection-popup-close:hover {
  color: var(--text);
  background: var(--surface);
}

.projection-popup-map {
  width: 100%;
  display: block;
}

.projection-popup-caption {
  padding: 8px 18px 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

.projection-popup-map--interactive {
  cursor: grab;
}

.projection-popup-map--interactive:active {
  cursor: grabbing;
}

.projection-popup-center {
  padding: 10px 18px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.center-label {
  font-size: 0.72rem;
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

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

.center-coord-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.center-coord-label input {
  width: 72px;
  padding: 4px 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 0.8rem;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.15s;
}

.center-coord-label input:focus {
  border-color: var(--accent);
}

.center-reset-btn {
  margin-left: auto;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-family: var(--font-body);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.center-reset-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.center-hint {
  font-size: 0.68rem;
  color: var(--text-muted);
  opacity: 0.7;
}

/* ===== About Modal ===== */

.about-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.about-modal {
  background: #0e1828;
  border: 1px solid var(--panel-border);
  border-radius: var(--r-lg);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  max-width: 360px;
  width: 90%;
  overflow: hidden;
}

.about-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.about-modal-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--accent);
}

.about-modal-close {
  width: auto;
  padding: 4px 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.about-modal-close:hover {
  color: var(--text);
  background: var(--surface);
}

.about-modal-body {
  padding: 18px;
}

.about-author {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.about-author-name {
  font-size: 0.88rem;
  color: var(--text);
  font-weight: 500;
}

.about-social {
  display: flex;
  gap: 8px;
  align-items: center;
}

.about-social a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.about-social a:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--surface-hover);
}

.about-social a svg {
  fill: currentColor;
}

.about-credits {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.about-credits dt {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 4px;
  margin-top: 10px;
}

.about-credits dt:first-child {
  margin-top: 0;
}

.about-credits dd {
  font-size: 0.78rem;
  color: var(--text);
  line-height: 1.5;
  margin: 0;
}

.about-credits a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.about-credits a:hover {
  color: var(--accent);
}

[data-theme="light"] .about-modal {
  background: #f0f4f8;
}

/* ===== Map SVG Styles ===== */

.sphere {
  fill: var(--ocean);
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 0.5;
  vector-effect: non-scaling-stroke;
}

.graticule {
  fill: none;
  stroke: var(--graticule-color);
  stroke-width: 0.4;
  vector-effect: non-scaling-stroke;
}

.countries path {
  fill: var(--land);
  stroke: var(--land-stroke);
  stroke-width: 0.5;
  vector-effect: non-scaling-stroke;
}

.circle-fill {
  stroke-width: 2;
  cursor: move;
  fill-opacity: 0.2;
  stroke-opacity: 0.85;
  vector-effect: non-scaling-stroke;
}

.circle-fill:hover {
  fill-opacity: 0.3;
  stroke-opacity: 1;
}

.circle-center {
  fill: var(--accent);
  stroke: var(--bg);
  stroke-width: 2;
  cursor: move;
  pointer-events: all;
  vector-effect: non-scaling-stroke;
}

.resize-handle {
  fill: var(--bg);
  stroke: var(--accent);
  stroke-width: 1.5;
  cursor: ew-resize;
  pointer-events: all;
  vector-effect: non-scaling-stroke;
}

.resize-handle:hover {
  fill: var(--accent);
  stroke: var(--bg);
}

.hide-handles .circle-center,
.hide-handles .resize-handle {
  display: none !important;
  pointer-events: none !important;
}

/* ===== Panel Toggle (FAB) ===== */

#panel-toggle {
  display: none;
  position: absolute;
  z-index: 25;
  align-items: center;
  justify-content: center;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 0, 111, 0.5);
  color: var(--accent);
  box-shadow:
    0 2px 16px rgba(0, 0, 0, 0.3),
    0 0 30px -8px var(--accent-glow);
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s, opacity 0.25s;
}

#panel-toggle:hover {
  background: var(--surface-hover);
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.4),
    0 0 40px -6px var(--accent-glow);
}

#panel-toggle:active {
  transform: scale(0.92);
}

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

#panel-toggle svg {
  display: block;
}

/* Panel Overlay */

#panel-overlay {
  display: none;
  touch-action: none;
}

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

[data-theme="light"] select option {
  background: #f0f4f8;
  color: #1e293b;
}

[data-theme="light"] .sphere {
  stroke: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] #map-container::after {
  box-shadow: inset 0 0 60px 12px rgba(200, 210, 224, 0.3);
}

[data-theme="light"] #controls {
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.06),
    0 4px 24px rgba(0, 0, 0, 0.08),
    0 0 60px -10px var(--accent-glow);
}

[data-theme="light"] .projection-popup {
  background: #f0f4f8;
}

[data-theme="light"] .circle-fill {
  fill-opacity: 0.25;
  stroke-opacity: 0.9;
}

/* ===== Theme Toggle ===== */

.footer-row {
  position: relative; /* .lang-menu の位置基準 */
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.footer-buttons {
  display: flex;
  gap: 6px;
  align-items: center;
}

#theme-toggle,
#about-toggle,
#lang-toggle {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 50%;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

#theme-toggle:hover,
#about-toggle:hover,
#lang-toggle:hover,
#lang-toggle[aria-expanded="true"] {
  background: var(--surface-hover);
  color: var(--accent);
  border-color: var(--accent);
}

#theme-toggle .icon-moon {
  display: none;
}

[data-theme="light"] #theme-toggle .icon-sun {
  display: none;
}

[data-theme="light"] #theme-toggle .icon-moon {
  display: block;
}

/* ===== Desktop ===== */

@media (min-width: 769px) {
  #panel-toggle {
    display: none;
  }

  #map-container {
    left: calc(var(--panel-w) + 32px);
  }

  .projection-popup-overlay {
    padding: 0 0 24px calc(var(--panel-w) + 40px);
  }

  .projection-popup {
    width: 400px;
  }
}

/* ===== Mobile (max-width: 768px) ===== */

@media (max-width: 768px) {
  #dual-map-section {
    display: none;
  }

  #map-container {
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  }

  #app.panel-open #map-container {
    transform: translateY(-25dvh);
  }

  #controls {
    position: absolute;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 70dvh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-bottom: none;
    transform: translateY(0);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  }

  #controls.collapsed {
    transform: translateY(calc(100% - 60px));
  }

  .panel-handle {
    display: block;
    width: 100%;
    height: 20px;
    flex-shrink: 0;
    cursor: pointer;
    position: relative;
  }

  .panel-handle::after {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: background 0.2s;
  }

  .panel-handle:hover::after {
    background: rgba(255, 255, 255, 0.6);
  }

  /* Mobile header */
  #mobile-header {
    display: flex;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    z-index: 10;
    align-items: center;
    justify-content: center;
    background: linear-gradient(to bottom,
      rgba(10, 14, 26, 0.9) 0%,
      rgba(10, 14, 26, 0.5) 60%,
      transparent 100%);
    pointer-events: none;
  }

  #mobile-header h1 {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 0.04em;
    text-shadow: 0 1px 12px rgba(0, 0, 0, 0.5);
  }

  /* Peek strip — visible in collapsed/peek state */
  .panel-peek {
    display: flex;
    align-items: center;
    padding: 12px 20px 14px;
    gap: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    max-height: 60px;
    opacity: 1;
    overflow: hidden;
    transition: max-height 0.25s ease, opacity 0.2s ease, padding 0.25s ease;
  }

  #controls:not(.collapsed) .panel-peek {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    pointer-events: none;
  }

  .peek-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.78rem;
    color: var(--text);
    white-space: nowrap;
  }

  .peek-add-chip {
    color: var(--accent);
    border-color: rgba(255, 0, 111, 0.25);
  }

  .peek-plus {
    font-weight: 700;
    font-size: 0.95rem;
    line-height: 1;
  }

  .peek-expand-icon {
    margin-left: auto;
    color: var(--text-muted);
    flex-shrink: 0;
    animation: peek-nudge 2s ease-in-out 1s 3;
    transition: color 0.2s;
  }

  .panel-peek:hover {
    background: rgba(255, 255, 255, 0.04);
  }

  .panel-peek:hover .peek-expand-icon {
    color: var(--accent);
  }

  @keyframes peek-nudge {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
  }

  .panel-header {
    padding: 8px 20px 0;
  }

  .panel-header h1 {
    font-size: 1.25rem;
  }

  .panel-header .subtitle {
    font-size: 0.85rem;
    margin-top: 3px;
  }

  .panel-body {
    padding: 16px 20px;
  }

  .panel-footer {
    padding: 12px 20px;
  }

  .control-section {
    margin-bottom: 14px;
    padding-bottom: 14px;
  }

  .help-text {
    display: none;
  }

  /* Keyboard- and touch-accessible panel toggle */
  #panel-toggle {
    display: flex;
    top: 12px;
    right: 12px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
  }

  /* Overlay */
  #panel-overlay {
    display: block;
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 16;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
  }

  #panel-overlay.active {
    pointer-events: auto;
    opacity: 1;
  }

  /* Larger touch targets */
  select {
    padding: 12px 32px 12px 12px;
    font-size: 0.95rem;
  }

  #add-circle {
    padding: 14px;
    font-size: 0.88rem;
  }

  .segmented-option {
    padding: 11px 8px;
    font-size: 0.85rem;
  }

  input[type="range"] {
    height: 8px;
    margin: 10px 0 16px;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
  }

  input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }

  /* Light mode mobile overrides */
  [data-theme="light"] .panel-handle::after {
    background: rgba(0, 0, 0, 0.15);
  }

  [data-theme="light"] .panel-handle:hover::after {
    background: rgba(0, 0, 0, 0.35);
  }

  [data-theme="light"] .panel-peek:hover {
    background: rgba(0, 0, 0, 0.04);
  }

  [data-theme="light"] #mobile-header {
    background: linear-gradient(to bottom,
      rgba(240, 244, 248, 0.9) 0%,
      rgba(240, 244, 248, 0.5) 60%,
      transparent 100%);
  }

  [data-theme="light"] #mobile-header h1 {
    text-shadow: 0 1px 12px rgba(255, 255, 255, 0.5);
  }

  [data-theme="light"] #panel-overlay {
    background: rgba(0, 0, 0, 0.2);
  }

  [data-theme="light"] .peek-add-chip {
    border-color: rgba(212, 0, 90, 0.25);
  }

  .projection-popup-overlay {
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    padding: 0;
    align-items: flex-end;
    justify-content: center;
    pointer-events: auto;
  }

  .projection-popup {
    width: 100%;
    max-width: 100%;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    animation-name: popup-enter-mobile;
  }

  @keyframes popup-enter-mobile {
    from { opacity: 0; transform: translateY(100%); }
    to   { opacity: 1; transform: translateY(0); }
  }

  .projection-popup.popup-closing {
    animation-name: popup-exit-mobile;
    animation-duration: 0.2s;
  }

  @keyframes popup-exit-mobile {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(100%); }
  }

}
