:root {
  color-scheme: dark;
  font: 14px/1.45 system-ui, "Microsoft YaHei", sans-serif;
  --panel: rgb(12 12 13 / .72);
  --line: rgb(255 255 255 / .19);
  --muted: #c6c6c6;
  --accent: #eeeef0;
  --ink: #f5f5f5;
  --control: rgb(255 255 255 / .08);
  --control-hover: rgb(255 255 255 / .16);
  --shadow: 0 12px 36px rgb(0 0 0 / .26);
  --glass: blur(14px) saturate(.9);
  --radius: 16px;
  --gutter: 20px;
  --edge-top: max(20px, env(safe-area-inset-top));
  --edge-bottom: max(20px, env(safe-area-inset-bottom));
  --float-bottom: calc(var(--edge-bottom) + 66px);
  color: var(--ink);
  background: #141415;
}

* { box-sizing: border-box; }
body { margin: 0; overflow: hidden; }
[hidden] { display: none !important; }
#tour, #view, #ground-boundary, #transition { position: absolute; inset: 0; }
#view { width: 100%; height: 100%; touch-action: none; cursor: grab; }
#ground-boundary { width: 100%; height: 100%; pointer-events: none; }
#view:active { cursor: grabbing; }
#view.measure { cursor: crosshair; }
#view.surface-hover:not(:active) { cursor: none; }
#view.pointer-ring-active:not(:active) { cursor: none; }
.pointer-ring {
  position: absolute;
  width: 24px;
  height: 24px;
  border: 2px solid rgb(255 255 255 / .76);
  border-radius: 50%;
  pointer-events: none;
}

button, select, textarea { font: inherit; }
button {
  min-height: 38px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--control);
  color: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
button:hover:enabled { background: var(--control-hover); }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
:is(.primary, .switches button[aria-current="true"], button[aria-pressed="true"]) {
  background: var(--accent);
  border-color: var(--accent);
  color: #161617;
  font-weight: 680;
}
:is(.primary, .switches button[aria-current="true"], button[aria-pressed="true"]):hover:enabled {
  background: #fff;
}

h1, h2, p { margin: 0; }
.panel, .heading, .actions, .route-nav, .map-control > button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: var(--glass);
}

.toolbar {
  position: absolute;
  z-index: 1;
  inset: var(--edge-top) var(--gutter) auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}
.heading { padding: 10px 15px; }
.heading h1 { font-size: clamp(17px, 1.6vw, 24px); font-weight: 680; line-height: 1.18; }
.heading p { margin-top: 3px; font-size: .82rem; color: var(--muted); }
.toolbar-start { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.toolbar-start .heading { min-width: 0; }
.view-switch {
  display: flex;
  flex: none;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
  pointer-events: auto;
}
.view-switch a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 6px 13px;
  border-radius: 9px;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.4;
  text-decoration: none;
  white-space: nowrap;
  touch-action: manipulation;
}
.view-switch a:hover { background: var(--control-hover); color: var(--ink); }
.view-switch a[aria-current="page"] { background: var(--accent); color: #161617; font-weight: 680; }
.view-switch a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.map-control { display: flex; gap: 6px; pointer-events: auto; }
.map-control > button { display: flex; align-items: center; gap: 7px; min-height: 42px; }
#map-toggle[aria-expanded="true"] { border-color: rgb(255 255 255 / .36); }

#transition { background: #141415; opacity: 0; transition: opacity .32s ease; pointer-events: none; }
#transition.active { opacity: .97; }
.loading {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  max-width: calc(100% - 32px);
}
.loader {
  flex: none;
  width: 15px;
  height: 15px;
  border: 2px solid rgb(255 255 255 / .3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .85s linear infinite;
}
.loading.error .loader { display: none; }
@keyframes spin { to { transform: rotate(1turn); } }

#settings {
  position: absolute;
  z-index: 5;
  bottom: var(--float-bottom);
  left: 50%;
  transform: translateX(-50%);
  width: min(316px, calc(100% - 2 * var(--gutter)));
  max-height: calc(100% - var(--float-bottom) - var(--edge-top));
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#settings label { display: block; margin-bottom: 10px; }
#settings label:is([for="travel-mode"], [for="render-quality"]) {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
#settings select {
  min-height: 36px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control);
  color: var(--ink);
}
select option { background: #1f1f20; color: var(--ink); }
#settings input { accent-color: var(--accent); }
#settings p { color: var(--muted); font-size: .86rem; }
#settings #flight-help { margin: -4px 0 10px; }
#settings #flight-floor-help { margin: -5px 0 12px; font-size: .8rem; }
#settings input[type="number"] { width: 82px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; color: inherit; background: rgba(255,255,255,.06); font: inherit; }
#settings #speed-help { margin: -4px 0 10px; }

#map-panel {
  position: absolute;
  bottom: var(--float-bottom);
  right: var(--gutter);
  width: min(320px, 33vw);
  padding: 12px;
}
.map-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 9px; }
.map-header h2 { font-size: .93rem; font-weight: 650; }
.map-tools { display: flex; gap: 4px; }
.map-tools button { width: 32px; min-height: 32px; padding: 2px; }
#map {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  cursor: crosshair;
  touch-action: none;
}
#map:active { cursor: grabbing; }
.map-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 7px 8px; margin-top: 8px; }
.map-legend { display: flex; flex: 1 1 120px; flex-wrap: wrap; gap: 4px 10px; margin: 0; color: var(--muted); font-size: .77rem; }
.map-legend span { display: flex; align-items: center; gap: 5px; }
.map-legend span::before { content: ""; width: 10px; height: 10px; border: 1px solid #bdbdbd; border-radius: 2px; background: #ffffff24; }
.map-legend span + span::before { border: 0; border-radius: 0; background: #fafafa; clip-path: polygon(50% 0, 100% 100%, 50% 78%, 0 100%); }
.map-travel-mode { display: flex; flex: 0 0 auto; gap: 2px; margin-left: auto; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: rgba(0,0,0,.15); }
.map-travel-mode button { min-height: 28px; padding: 3px 8px; border-color: transparent; border-radius: 5px; background: transparent; font-size: .78rem; white-space: nowrap; }
.map-travel-mode button[aria-pressed="true"] { color: #161617; background: #eeeef0; }
.map-travel-mode button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.dock {
  position: absolute;
  z-index: 4;
  inset: auto var(--gutter) var(--edge-bottom);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: end;
  column-gap: 14px;
  pointer-events: none;
}
.route-nav {
  grid-column: 1;
  justify-self: start;
  min-width: 0;
  max-width: 100%;
  padding: 5px;
  pointer-events: auto;
}
.switches { display: flex; gap: 3px; min-width: 0; max-width: 100%; overflow-x: auto; scrollbar-width: thin; }
.switches:empty { display: none; }
.switches + .switches:not(:empty) { margin-top: 3px; }
.switches button { flex: none; min-height: 32px; background: transparent; border-color: transparent; font-size: .84rem; }
.actions {
  grid-column: 2;
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 5px;
  pointer-events: auto;
}
.actions button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  border-color: transparent;
  font-size: .92rem;
  background: transparent;
}
.actions :is(.primary, [aria-pressed="true"]) { background: var(--accent); border-color: var(--accent); }
.actions button::before, #map-toggle::before {
  content: "";
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  background: currentColor;
  mask: var(--icon) center / contain no-repeat;
}
#stage-button { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M11 1.5c1.5 6.5 3 8 9.5 9.5-6.5 1.5-8 3-9.5 9.5C9.5 14 8 12.5 1.5 11 8 9.5 9.5 8 11 1.5ZM20 14.5l1 2.5 2.5 1-2.5 1-1 2.5-1-2.5-2.5-1 2.5-1Z'/%3E%3C/svg%3E"); }
#guide { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linejoin='round'%3E%3Cpath d='M9 5.5 19 12 9 18.5z'/%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3C/svg%3E"); }
#measure { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M2.5 16.5 16.5 2.5l5 5-14 14zM8 11l2 2m2-6 2 2m2-6 2 2'/%3E%3C/svg%3E"); }
#settings-toggle { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M3 6h7m4 0h7M3 12h12m4 0h2M3 18h2m4 0h12'/%3E%3Ccircle cx='12' cy='6' r='2'/%3E%3Ccircle cx='17' cy='12' r='2'/%3E%3Ccircle cx='7' cy='18' r='2'/%3E%3C/svg%3E"); }
#fullscreen { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 3H3v6m12-6h6v6M3 15v6h6m12-6v6h-6'/%3E%3C/svg%3E"); }
#map-toggle { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linejoin='round'%3E%3Cpath d='M3 5.5 9 3l6 2.5L21 3v15.5l-6 2.5-6-2.5L3 21zm6-2.5v15.5m6-13v15.5'/%3E%3C/svg%3E"); }

#notice {
  position: absolute;
  z-index: 2;
  bottom: var(--float-bottom);
  left: 50%;
  max-width: calc(100% - 2 * var(--gutter));
  transform: translateX(-50%);
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  backdrop-filter: var(--glass);
  text-align: center;
  pointer-events: none;
}
#joystick {
  display: none;
  position: absolute;
  bottom: calc(var(--float-bottom) + 86px);
  left: var(--gutter);
  width: 78px;
  height: 78px;
  padding: 0;
  border-radius: 50%;
  background: var(--panel);
  touch-action: none;
}
#joystick span {
  display: block;
  margin: auto;
  width: 31px;
  height: 31px;
  border-radius: 50%;
  background: var(--accent);
  transform: translate(var(--x, 0px), var(--y, 0px));
}
@media (pointer: coarse) {
  #joystick { display: block; }
}

@media (max-width: 1070px) {
  #map-panel { width: min(305px, 42vw); }
  .route-nav { position: absolute; bottom: calc(100% + 10px); left: 0; }
  #notice { max-width: min(44vw, 380px); }
}
@media (max-width: 620px) {
  :root {
    --gutter: 10px;
    --edge-top: max(12px, env(safe-area-inset-top));
    --edge-bottom: max(12px, env(safe-area-inset-bottom));
    --float-bottom: calc(var(--edge-bottom) + 63px);
    --glass: blur(10px) saturate(.9);
  }
  .heading { padding: 8px 11px; }
  .toolbar { gap: 8px; }
  .toolbar-start { flex: 1; flex-direction: column; gap: 7px; }
  .toolbar-start .heading { max-width: 100%; }
  .heading h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .view-switch a { min-height: 38px; padding-inline: 11px; }
  .dock { display: flex; justify-content: center; }
  .route-nav { max-width: 100%; }
  .switches button { min-height: 31px; padding-inline: 9px; }
  .actions { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); width: min(100%, 385px); gap: 3px; }
  .actions button { flex-direction: column; gap: 4px; min-height: 43px; padding: 4px 1px; font-size: .81rem; }
  .actions button::before { width: 15px; height: 15px; }
  #map-panel {
    bottom: calc(var(--float-bottom) + 86px);
    width: min(260px, calc(100vw - 151px));
    padding: 8px;
  }
  #settings {
    top: calc(var(--edge-top) + 112px);
    bottom: auto;
    max-height: calc(100% - var(--edge-top) - 112px - var(--edge-bottom));
  }
  .map-header { gap: 4px; margin-bottom: 6px; }
  .map-header h2 { font-size: .82rem; }
  .map-tools { gap: 3px; }
  .map-tools button { width: 25px; min-height: 26px; font-size: .87rem; }
  #notice { bottom: calc(var(--float-bottom) + 164px); max-width: calc(100% - 2 * var(--gutter)); }
}
@media (max-width: 340px) {
  .map-control { flex-direction: column; align-items: flex-end; }
  #map-panel { width: calc(100vw - 147px); }
}
@media (prefers-reduced-motion: reduce) {
  #transition, button { transition: none; }
}
