:root {
  color-scheme: light;
  --ink: #1f2523;
  --muted: #69716d;
  --line: #d8dfda;
  --soft-line: #edf2ee;
  --paper: #f4f7f4;
  --panel: #fbfdfb;
  --ocean: #d8eef0;
  --land: #d7d0b2;
  --land-edge: #9d8f62;
  --forest: #61896a;
  --clay: #b66d52;
  --blue: #2f6f9f;
  --gold: #b7872a;
  --shadow: 0 14px 34px rgba(35, 47, 43, 0.12);
  --soft-shadow: 0 8px 24px rgba(35, 47, 43, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 11px;
  max-height: 100vh;
  overflow-y: auto;
  padding: 18px 16px;
  border-right: 1px solid var(--line);
  background: rgba(250, 252, 250, 0.94);
  backdrop-filter: blur(16px);
  z-index: 2;
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 2px 2px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.15;
}

h2 {
  font-size: 15px;
}

.status-pill,
.count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--soft-shadow);
}

.panel-title-row,
.search-row,
.share-grid {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-title-row {
  justify-content: space-between;
}

.marker-title-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fffefa;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 111, 159, 0.15);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f0;
}

.map-mode-tabs {
  grid-template-columns: repeat(2, 1fr);
  background: #edf3ef;
}

.segmented button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
}

.segmented button.active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 1px 6px rgba(31, 37, 35, 0.13);
}

.tool-button,
.primary-button,
.icon-button,
.mini-button,
.search-row button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #fffefa;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.tool-button:hover,
.primary-button:hover,
.icon-button:hover,
.search-row button:hover,
.marker-actions button:hover {
  border-color: rgba(47, 111, 159, 0.48);
  box-shadow: 0 2px 8px rgba(31, 37, 35, 0.08);
}

.tool-button.active {
  border-color: var(--blue);
  color: #fff;
  background: var(--blue);
}

.toolbar-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#toggleMarkersButton {
  grid-column: 1 / -1;
}

.primary-button {
  border-color: var(--blue);
  color: #fff;
  background: var(--blue);
}

.icon-button,
.search-row button {
  flex: 0 0 38px;
  width: 38px;
}

.mini-button {
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  color: var(--muted);
  font-size: 12px;
}

.measure-card,
.coordinate-line {
  min-height: 44px;
  margin: 0;
  border-radius: 7px;
  padding: 10px;
  color: #26312d;
  background: #eef5f1;
  font-size: 13px;
  line-height: 1.45;
}

.marker-list {
  display: grid;
  gap: 7px;
  max-height: 210px;
  overflow-y: auto;
}

.marker-item {
  width: 100%;
  display: grid;
  gap: 7px;
  border: 1px solid var(--soft-line);
  border-radius: 7px;
  padding: 9px;
  text-align: left;
  background: #fffefa;
}

.marker-item strong {
  font-size: 13px;
}

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

.marker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.marker-chip {
  min-width: 0;
  max-width: 62%;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--marker-color), #fff 56%);
  border-radius: 999px;
  padding: 3px 8px;
  color: #24302d;
  background: color-mix(in srgb, var(--marker-color), #fff 82%);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.marker-coord {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

.marker-note {
  margin: 0;
  color: #38433f;
  font-size: 13px;
  line-height: 1.42;
  word-break: break-word;
}

.marker-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.marker-actions button {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 12px;
}

.marker-fold-button {
  min-height: 34px;
  border: 1px dashed rgba(47, 111, 159, 0.35);
  border-radius: 7px;
  color: var(--blue);
  background: rgba(47, 111, 159, 0.06);
  font-size: 12px;
}

.map-stage {
  position: relative;
  min-width: 0;
  min-height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(115deg, rgba(97, 137, 106, 0.14), transparent 34%),
    linear-gradient(245deg, rgba(182, 109, 82, 0.16), transparent 36%),
    var(--ocean);
}

#map {
  display: block;
  width: 100%;
  height: 100%;
}

#globeCanvas {
  display: none;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 44% 36%, rgba(255, 255, 255, 0.42), transparent 32%),
    linear-gradient(135deg, #d8eef0, #dcebe3);
  touch-action: none;
}

.map-stage.globe-active #map {
  display: none;
}

.map-stage.globe-active #globeCanvas {
  display: block;
}

.map-stage.south-up #map {
  rotate: 180deg;
  transform-origin: 50% 50%;
}

.map-stage.south-up #map .leaflet-control-container,
.map-stage.south-up #map .leaflet-popup,
.map-stage.south-up #map .leaflet-tooltip,
.map-stage.south-up #map .zh-map-label {
  rotate: 180deg;
}

.zh-map-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: rgba(36, 48, 45, 0.86);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.1;
  text-align: center;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.82),
    1px 0 0 rgba(255, 255, 255, 0.78),
    0 2px 6px rgba(255, 255, 255, 0.72);
  white-space: nowrap;
}

.zh-map-label.country {
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: 999px;
  padding: 2px 7px;
  color: rgba(30, 42, 39, 0.88);
  background: rgba(255, 255, 255, 0.58);
  font-size: 13px;
  letter-spacing: 0;
  box-shadow: 0 2px 8px rgba(31, 37, 35, 0.08);
}

.zh-map-label.place {
  color: rgba(47, 73, 67, 0.82);
  font-size: 11px;
  font-weight: 600;
}

.zh-map-label.search {
  border-radius: 999px;
  padding: 3px 8px;
  color: #0f5d8a;
  background: rgba(255, 255, 255, 0.72);
  font-size: 14px;
  font-weight: 750;
}

.leaflet-container {
  color: var(--ink);
  font-family: inherit;
  background: #d8eef0;
}

.leaflet-control-attribution {
  font-size: 11px;
}

.search-marker,
.user-marker,
.marker-cluster {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 10px rgba(31, 37, 35, 0.24);
}

.search-marker {
  background: #2f6f9f;
}

.user-marker {
  background: #b7872a;
}

.search-marker::after,
.user-marker::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
}

.marker-cluster {
  width: 32px;
  height: 32px;
  border-color: rgba(255, 255, 255, 0.92);
  color: #fff;
  background: #2f6f9f;
  font-size: 13px;
  font-weight: 800;
}

.leaflet-popup-content {
  margin: 10px 12px;
  line-height: 1.5;
}

.map-hud {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.map-hud span {
  max-width: 50%;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 7px;
  padding: 8px 10px;
  color: #24302d;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reward-drawer {
  position: fixed;
  right: 0;
  bottom: 76px;
  z-index: 1000;
  display: flex;
  align-items: stretch;
  max-width: calc(100vw - 10px);
  filter: drop-shadow(0 8px 18px rgba(31, 37, 35, 0.1));
  transform: translateX(calc(100% - 30px));
  transition: transform 220ms ease;
}

.reward-drawer:hover,
.reward-drawer:focus,
.reward-drawer:focus-within {
  transform: translateX(0);
}

.reward-drawer:focus {
  outline: none;
}

.reward-drawer:focus-visible {
  outline: 2px solid rgba(47, 111, 159, 0.24);
  outline-offset: 3px;
}

.reward-handle {
  width: 30px;
  min-height: 88px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(216, 223, 218, 0.9);
  border-right: 0;
  border-radius: 7px 0 0 7px;
  color: #5f6b66;
  background: rgba(251, 253, 251, 0.88);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.1;
  writing-mode: vertical-rl;
}

.reward-drawer:hover .reward-handle,
.reward-drawer:focus-within .reward-handle {
  color: var(--blue);
  background: rgba(255, 255, 255, 0.96);
}

.reward-panel {
  width: min(174px, calc(100vw - 38px));
  border: 1px solid rgba(216, 223, 218, 0.88);
  border-radius: 7px 0 0 7px;
  padding: 8px;
  background: rgba(251, 253, 251, 0.94);
  backdrop-filter: blur(14px);
}

.reward-title {
  margin: 0 0 7px;
  color: #47534f;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.3;
  text-align: center;
}

.reward-codes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.reward-codes figure {
  display: grid;
  gap: 5px;
  margin: 0;
  min-width: 0;
}

.reward-codes img {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--soft-line);
  border-radius: 6px;
  background: #fff;
  object-fit: contain;
}

.reward-codes figcaption {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  text-align: center;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(56vh, 1fr) auto;
  }

  .sidebar {
    grid-row: 2;
    max-height: 44vh;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .map-stage {
    grid-row: 1;
    min-height: 56vh;
  }

  .map-hud {
    left: 10px;
    right: 10px;
    bottom: 10px;
    flex-direction: column;
  }

  .map-hud span {
    max-width: 100%;
  }

  .reward-drawer {
    bottom: 70px;
  }
}
