:root {
  color-scheme: light;
  --app-bg: #f5f5f7;
  --panel-bg: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --panel-subtle: #f7f7fa;
  --text: #17181c;
  --text-muted: #60636d;
  --border: rgba(17, 24, 39, 0.12);
  --shadow: 0 20px 60px rgba(15, 23, 42, 0.16);
  --accent: #007aff;
  --accent-strong: #0065d0;
  --accent-soft: rgba(0, 122, 255, 0.13);
  --danger: #d92d20;
  --control-bg: rgba(255, 255, 255, 0.78);
  --control-hover: rgba(0, 0, 0, 0.05);
  --map-filter: none;
  --marker-bg: #007aff;
  --marker-ring: rgba(255, 255, 255, 0.92);
  --arrow-color: #007aff;
  --focus: 0 0 0 3px rgba(0, 122, 255, 0.24);
}

[data-theme="dark"] {
  color-scheme: dark;
  --app-bg: #101114;
  --panel-bg: rgba(30, 31, 36, 0.82);
  --panel-solid: #1e1f24;
  --panel-subtle: #282a31;
  --text: #f5f5f7;
  --text-muted: #b4b7c0;
  --border: rgba(255, 255, 255, 0.14);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  --accent: #64d2ff;
  --accent-strong: #33bff5;
  --accent-soft: rgba(100, 210, 255, 0.16);
  --danger: #ff6961;
  --control-bg: rgba(33, 34, 40, 0.82);
  --control-hover: rgba(255, 255, 255, 0.08);
  --map-filter: saturate(0.8) brightness(0.82) contrast(1.08);
  --marker-bg: #64d2ff;
  --marker-ring: rgba(16, 17, 20, 0.9);
  --arrow-color: #64d2ff;
  --focus: 0 0 0 3px rgba(100, 210, 255, 0.28);
}

[data-theme="macaron"] {
  color-scheme: light;
  --app-bg: #fbf8f2;
  --panel-bg: rgba(255, 253, 247, 0.88);
  --panel-solid: #fffdf7;
  --panel-subtle: #f4f9f7;
  --text: #232323;
  --text-muted: #6c6864;
  --border: rgba(86, 75, 66, 0.16);
  --shadow: 0 24px 64px rgba(83, 72, 61, 0.16);
  --accent: #3aa6a2;
  --accent-strong: #23817d;
  --accent-soft: rgba(58, 166, 162, 0.16);
  --danger: #cf4d6f;
  --control-bg: rgba(255, 253, 247, 0.82);
  --control-hover: rgba(58, 166, 162, 0.1);
  --map-filter: saturate(0.92) brightness(1.02);
  --marker-bg: #ff8fab;
  --marker-ring: rgba(255, 253, 247, 0.94);
  --arrow-color: #3aa6a2;
  --focus: 0 0 0 3px rgba(58, 166, 162, 0.26);
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--app-bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--app-bg);
}

.map-root {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.map-root.is-offline-map {
  background:
    linear-gradient(rgba(0, 122, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 122, 255, 0.08) 1px, transparent 1px),
    var(--app-bg);
  background-size: 32px 32px;
}

.leaflet-container {
  width: 100%;
  height: 100%;
  background: var(--app-bg);
  font-family: inherit;
}

.leaflet-tile-pane {
  filter: var(--map-filter);
}

.app-topbar,
.sidebar,
.inspector,
.floating-card {
  border: 1px solid var(--border);
  background: var(--panel-bg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(1.35);
  -webkit-backdrop-filter: blur(24px) saturate(1.35);
}

.app-topbar {
  position: absolute;
  top: 16px;
  left: 16px;
  right: auto;
  z-index: 500;
  display: flex;
  flex-wrap: wrap;
  max-width: calc(100vw - 32px);
  width: fit-content;
  gap: 12px;
  align-items: center;
  min-height: 64px;
  padding: 10px 12px 10px 16px;
  border-radius: 16px;
}

.brand {
  min-width: 0;
}

.brand-title {
  margin: 0;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.18;
}

.brand-subtitle {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.25;
}

.toolbar-group,
.segmented-control,
.action-row,
.image-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-group {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.segmented-control {
  min-height: 36px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--control-bg);
}

.segmented-control button,
.control-button,
.icon-button,
.secondary-button,
.danger-button {
  min-height: 34px;
  border-radius: 10px;
  color: var(--text);
  background: transparent;
  cursor: pointer;
  transition:
    background 160ms ease,
    color 160ms ease,
    transform 160ms ease,
    border-color 160ms ease;
}

.segmented-control button {
  min-width: 64px;
  padding: 0 12px;
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
}

.segmented-control button.is-active {
  color: #ffffff;
  background: var(--accent);
}

.control-button,
.secondary-button,
.danger-button,
.select-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: var(--control-bg);
  font-size: 13px;
  white-space: nowrap;
}

.select-control {
  min-height: 34px;
  color: var(--text-muted);
  font-size: 12px;
}

.select-control select {
  height: 28px;
  min-width: 104px;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  cursor: pointer;
}

.control-button.is-primary {
  border-color: transparent;
  color: #ffffff;
  background: var(--accent);
}

.control-button.is-primary:hover,
.segmented-control button.is-active:hover {
  background: var(--accent-strong);
}

.control-button.is-active {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.danger-button {
  color: var(--danger);
}

.icon-button {
  display: inline-grid;
  width: 34px;
  min-width: 34px;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--control-bg);
}

.icon-button svg,
.control-button svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button:hover {
  background: var(--control-hover);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.sidebar {
  position: absolute;
  top: 92px;
  left: 16px;
  bottom: 16px;
  z-index: 450;
  display: flex;
  width: min(320px, calc(100vw - 32px));
  flex-direction: column;
  overflow: hidden;
  border-radius: 18px;
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    visibility 180ms ease;
}

.sidebar.is-collapsed {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-18px);
}

.panel-header,
.panel-section,
.inspector-header,
.inspector-section {
  border-bottom: 1px solid var(--border);
}

.panel-header,
.inspector-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 12px;
}

.panel-title,
.section-title,
.inspector-title {
  margin: 0;
  color: var(--text);
}

.panel-title {
  font-size: 15px;
  font-weight: 700;
}

.section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.section-note,
.empty-state,
.field-help {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.panel-content,
.inspector-content {
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
}

.panel-section,
.inspector-section {
  padding: 14px;
}

.panel-section:last-child,
.inspector-section:last-child {
  border-bottom: 0;
}

.list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.point-list-button,
.route-list-button {
  display: grid;
  width: 100%;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  background: var(--control-bg);
  text-align: left;
}

.point-list-button.is-selected,
.route-list-button.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.point-index {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: var(--point-color, var(--marker-bg));
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.list-title {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-meta {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 11px;
}

.badge {
  padding: 4px 7px;
  border-radius: 999px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 11px;
  font-weight: 650;
}

.inspector {
  position: absolute;
  top: 92px;
  right: 16px;
  bottom: 16px;
  z-index: 450;
  display: flex;
  width: min(360px, calc(100vw - 32px));
  flex-direction: column;
  overflow: hidden;
  border-radius: 18px;
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    visibility 180ms ease;
}

.inspector.is-collapsed {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateX(18px);
}

.inspector-title {
  overflow: hidden;
  font-size: 15px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-grid {
  display: grid;
  gap: 10px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 650;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--control-bg);
}

.field input,
.field select {
  height: 36px;
  padding: 0 10px;
}

.field textarea {
  min-height: 94px;
  resize: vertical;
  padding: 9px 10px;
  line-height: 1.45;
}

.color-picker {
  display: grid;
  grid-template-columns: repeat(5, 28px) 1fr;
  gap: 8px;
  align-items: center;
}

.color-swatch {
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: var(--swatch-color);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.color-swatch.is-selected {
  border-color: var(--text);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.32),
    0 0 0 3px var(--accent-soft);
}

.color-custom {
  display: inline-flex;
  min-width: 0;
  height: 32px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 8px 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  background: var(--control-bg);
  font-size: 12px;
  font-weight: 650;
}

.color-custom input {
  width: 30px;
  height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.marker-image-editor {
  display: flex;
  align-items: center;
  gap: 10px;
}

.marker-image-preview {
  display: grid;
  width: 48px;
  height: 48px;
  min-width: 48px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-subtle);
}

.marker-image-preview span {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: var(--point-color, var(--marker-bg));
  font-size: 12px;
  font-weight: 800;
}

.marker-image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.marker-image-actions {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  gap: 8px;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.image-tile {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-subtle);
  aspect-ratio: 1;
}

.image-tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-tile button {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  border-radius: 50%;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.58);
}

.image-tile .image-use-button {
  left: 5px;
  right: auto;
  width: auto;
  min-width: 42px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.map-marker {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 3px solid var(--marker-ring);
  border-radius: 50% 50% 50% 7px;
  color: #ffffff;
  background: var(--point-color, var(--marker-bg));
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
  font-size: 12px;
  font-weight: 800;
  transform: rotate(-45deg);
}

.map-marker span {
  max-width: 22px;
  overflow: hidden;
  line-height: 1;
  text-align: center;
  text-overflow: clip;
  transform: rotate(45deg);
}

.map-marker.is-selected {
  outline: 3px solid var(--accent-soft);
}

.map-marker-image {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  overflow: hidden;
  border: 3px solid var(--marker-ring);
  border-radius: 50% 50% 50% 10px;
  background: var(--point-color, var(--marker-bg));
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  transform: rotate(-45deg);
}

.map-marker-image img {
  width: 58px;
  height: 58px;
  object-fit: cover;
  transform: rotate(45deg);
}

.map-marker-image.is-selected {
  outline: 3px solid var(--accent-soft);
}

.arrow-head {
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 14px solid var(--arrow-color);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.24));
  transform-origin: 50% 50%;
}

.map-status {
  position: absolute;
  left: 50%;
  top: 92px;
  z-index: 420;
  max-width: min(420px, calc(100vw - 32px));
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  background: var(--panel-bg);
  box-shadow: var(--shadow);
  font-size: 12px;
  transform: translateX(-50%);
  backdrop-filter: blur(18px) saturate(1.3);
}

.map-status[data-status="error"] {
  color: var(--danger);
}

.leaflet-control-zoom,
.leaflet-control-scale-line,
.leaflet-control-attribution {
  border: 1px solid var(--border) !important;
  background: var(--panel-bg) !important;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(1.25);
}

.leaflet-control-zoom {
  overflow: hidden;
  border-radius: 12px;
}

.leaflet-control-zoom a {
  width: 38px !important;
  height: 38px !important;
  color: var(--text) !important;
  background: transparent !important;
  line-height: 38px !important;
}

.leaflet-control-zoom a:hover {
  background: var(--control-hover) !important;
}

.leaflet-control-scale-line {
  color: var(--text);
}

.leaflet-control-attribution {
  border-radius: 8px 0 0 0;
  color: var(--text-muted);
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  border: 1px solid var(--border);
  background: var(--panel-solid);
  color: var(--text);
  box-shadow: var(--shadow);
}

.leaflet-popup-content {
  width: 240px;
  margin: 12px;
}

.popup-title {
  margin: 0 0 6px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.popup-desc {
  margin: 0 0 8px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.popup-images {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.popup-images img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 7px;
  object-fit: cover;
}

.mode-hint {
  position: absolute;
  left: 50%;
  bottom: 22px;
  z-index: 440;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 999px;
  color: var(--text);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 13px;
  transform: translateX(-50%);
  backdrop-filter: blur(18px) saturate(1.3);
}

.connection-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.route-list-button {
  grid-template-columns: 1fr auto;
}

@media (max-width: 1080px) {
  .app-topbar {
    width: calc(100vw - 32px);
  }

  .toolbar-group {
    justify-content: flex-start;
  }

  .sidebar {
    top: 154px;
    bottom: 52%;
  }

  .inspector {
    top: auto;
    left: 16px;
    right: 16px;
    bottom: 16px;
    width: auto;
    height: calc(52% - 32px);
  }
}

@media (max-width: 720px) {
  .app-topbar {
    top: 10px;
    left: 10px;
    right: 10px;
    padding: 10px;
  }

  .brand-subtitle {
    display: none;
  }

  .segmented-control,
  .toolbar-group {
    width: 100%;
  }

  .segmented-control button {
    flex: 1;
    min-width: 0;
    padding: 0 8px;
  }

  .sidebar,
  .inspector {
    left: 10px;
    right: 10px;
    width: auto;
  }

  .sidebar {
    top: 150px;
    bottom: auto;
    max-height: 34%;
  }

  .inspector {
    height: 38%;
  }

  .connection-pair {
    grid-template-columns: 1fr;
  }

  .mode-hint {
    bottom: calc(38% + 24px);
    border-radius: 14px;
  }
}
