:root {
  --ink: #182026;
  --muted: #65717d;
  --line: #d8e0e7;
  --paper: #f7f9fb;
  --panel: #ffffff;
  --green: #2f8f62;
  --blue: #2878b8;
  --red: #d94b42;
  --yellow: #f2b84b;
  --shadow: 0 14px 36px rgba(28, 42, 56, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 190px;
}

.brand strong {
  font-size: 18px;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.nav a,
.button-row a,
button,
.file-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font: inherit;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}

.nav a[aria-current="page"],
.button-row a.primary,
button.primary {
  border-color: #1d6fa5;
  background: #1d6fa5;
  color: #fff;
}

button.is-active {
  border-color: #2f8f62;
  background: #2f8f62;
  color: #fff;
}

button.danger {
  border-color: #d7a19d;
  color: #a72b23;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 11px;
  font: inherit;
  background: #fff;
}

textarea {
  min-height: 72px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

label span {
  color: var(--muted);
}

label.checkbox-field.point-label-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}

.point-label-text {
  flex: 1;
}

.point-distance,
.point-item-distance {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  font-weight: 600;
}

.point-item-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.point-item-row strong {
  min-width: 0;
}

.route-arrow.leaflet-div-icon {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
}

.route-arrow-svg {
  display: block;
  transform-origin: center center;
  pointer-events: none;
}

label.checkbox-field input {
  width: auto;
  margin: 0;
}

label.checkbox-field:not(.point-label-toggle) {
  display: flex;
  align-items: center;
  gap: 8px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  min-height: calc(100vh - 64px);
  align-items: start;
}

.layout.runner {
  grid-template-columns: minmax(0, 1fr) 330px;
}

.map-wrap {
  position: relative;
  height: calc(100vh - 64px);
  min-height: 0;
  overflow: hidden;
  background: #dfe8ee;
}

.map {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  touch-action: manipulation;
  cursor: grab;
}

.map.is-panning {
  cursor: grabbing;
}

.map-bg {
  fill: #f2f4f5;
}

.map-tile {
  image-rendering: auto;
}

.tile-layer {
  display: none;
}

.tile-layer.is-active {
  display: block;
}

.tile-soften {
  fill: rgba(255, 255, 255, 0.13);
  pointer-events: none;
}

.area-water {
  fill: #93c7df;
  stroke: #6eb0ce;
  stroke-width: 2;
}

.area-green {
  fill: #cfe7ce;
  stroke: #8bbb84;
  stroke-width: 2;
}

.base-path-context {
  fill: none;
  stroke: #b7c0c8;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.55;
}

.base-path-walk {
  fill: none;
  stroke: #6f9d68;
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 9 8;
}

.map-label {
  fill: #26323b;
  font-size: 17px;
  font-weight: 650;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 4px;
}

.label-dot {
  fill: #fff;
  stroke: #40515d;
  stroke-width: 2;
}

.label-park {
  stroke: var(--green);
}

.label-station {
  stroke: var(--blue);
}

.label-landmark {
  stroke: var(--yellow);
}

.map-attribution {
  fill: #53606b;
  font-size: 12px;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 3px;
}

.course-line {
  fill: none;
  stroke: #e33f34;
  stroke-width: 9;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 4px 2px rgba(120, 25, 20, 0.18));
}

.course-dot {
  fill: #fff;
  stroke: #e33f34;
  stroke-width: 5;
}

.course-dot.has-photo {
  fill: #ffe7a8;
}

.course-number {
  fill: #17212a;
  font-size: 12px;
  font-weight: 800;
  text-anchor: middle;
  pointer-events: none;
}

.user-dot {
  fill: #1d6fa5;
  stroke: #fff;
  stroke-width: 5;
}

.side-panel {
  height: calc(100vh - 64px);
  min-height: 0;
  overflow: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 16px;
}

.panel-section {
  display: grid;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.panel-section:first-child {
  padding-top: 0;
}

.panel-section h2,
.panel-section h3 {
  margin: 0;
  font-size: 16px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfd;
}

.stat b {
  display: block;
  font-size: 17px;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.point-list {
  display: grid;
  gap: 8px;
}

.point-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfd;
}

.point-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.point-title-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.point-coords-edit-btn {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}

.point-coords-edit-btn:hover {
  background: #eef3f6;
}

.point-item-meta {
  margin-left: auto;
  margin-right: 8px;
  color: var(--muted);
  font-size: 12px;
}

.point-map-btn {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.point-item-editable label {
  margin-top: 8px;
}

.point-item-editable input,
.point-item-editable textarea {
  width: 100%;
}

.point-marker-options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  margin-top: 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.point-marker-options .checkbox-field {
  margin: 0;
}

.point-checkpoint-toggle {
  margin: 0;
  padding: 0;
  border: 0;
}

.point-details[hidden] {
  display: none;
}

.point-photo-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-top: 8px;
}

.point-photo-row .point-photo-btn {
  margin-top: 0;
  flex: 1;
}

.point-insert-btn {
  flex: 0 0 auto;
  width: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.point-insert-btn:hover {
  background: #eef3f6;
}

.point-photo-btn {
  margin-top: 8px;
}

.point-photo-preview {
  margin-top: 8px;
}

.point-delete-btn {
  margin-top: 10px;
  width: 100%;
}

.point-item.active {
  border-color: #e33f34;
  box-shadow: inset 3px 0 0 #e33f34;
}

.point-item strong {
  display: block;
  font-size: 14px;
}

.point-item span {
  color: var(--muted);
  font-size: 12px;
}

.photo-preview {
  width: 100%;
  max-height: 170px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: none;
}

.photo-preview[src] {
  display: block;
}

.notice {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.runner-status {
  padding: 12px;
  border-radius: 8px;
  background: #edf6ef;
  color: #245b35;
  font-weight: 700;
}

.runner-status.warning {
  background: #fff4df;
  color: #76500d;
}

.runner-status.danger {
  background: #ffebe9;
  color: #8c2018;
}

.floating-tools,
.edit-tools,
.course-slots {
  z-index: 1100;
  pointer-events: auto;
}

.floating-tools {
  position: absolute;
  left: 16px;
  top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.course-slots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.course-slots button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  font-weight: 800;
}

.course-slots button[aria-pressed="true"] {
  border-color: #2f8f62;
  background: #2f8f62;
  color: #fff;
}

.edit-tools {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.edit-tools button {
  min-height: 34px;
  padding: 0 11px;
}

.edit-tools button[aria-pressed="true"] {
  border-color: #2f8f62;
  background: #2f8f62;
  color: #fff;
}

.map.tool-pan {
  cursor: grab;
}

.map.tool-walk,
.map.tool-free {
  cursor: crosshair;
}

.map.tool-select {
  cursor: default;
}

.spot-edit-handle {
  background: transparent !important;
  border: 0 !important;
}

.spot-edit-handle span {
  display: block;
  width: 20px;
  height: 20px;
  border: 3px solid #1d6fa5;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.spot-edit-handle.is-selected span {
  width: 24px;
  height: 24px;
  margin: -2px;
  border-color: #e33f34;
  border-width: 4px;
}

.coords-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.coords-modal[hidden] {
  display: none;
}

.coords-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 32, 38, 0.45);
}

.coords-modal-dialog {
  position: relative;
  width: min(100%, 360px);
  padding: 20px;
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow);
}

.coords-modal-dialog h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.coords-modal-hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.coords-modal-dialog label {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
}

.coords-modal-actions {
  margin-top: 16px;
}

.leaflet-map {
  position: relative;
  z-index: 1;
  background: #eef3f6;
}

.course-number-marker {
  background: transparent !important;
  border: 0 !important;
  z-index: 1000 !important;
}

.course-number-marker-inner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  border: 3px solid #2ea043;
  border-radius: 50%;
  background: #fff;
  color: #17212a;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
}

.route-arrow.leaflet-div-icon {
  z-index: 100 !important;
}

.spot-popup {
  display: grid;
  gap: 6px;
  max-width: 220px;
}

.spot-popup img {
  width: 100%;
  max-height: 130px;
  object-fit: cover;
  border-radius: 6px;
}

.spot-popup strong {
  font-size: 14px;
}

.spot-popup p {
  margin: 0;
  color: #53606b;
  font-size: 13px;
}

.zoom-tools {
  position: absolute;
  right: 16px;
  top: 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  z-index: 1100;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.zoom-tools button {
  width: 36px;
  min-height: 34px;
  padding: 0;
  font-weight: 800;
}

.zoom-tools span {
  min-width: 48px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.hidden-input {
  display: none;
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .layout,
  .layout.runner {
    grid-template-columns: 1fr;
  }

  .map-wrap,
  .map {
    height: 58vh;
    min-height: 0;
  }

  .side-panel {
    height: auto;
    min-height: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}
