:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --ink: #1d1d1f;
  --sub: #6e6e73;
  --line: #e5e5ea;
  --blue: #007aff;
  --blue-deep: #005ecb;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.08);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
button, input { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-t);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px 8px;
}
.brand h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.brand p {
  margin: 1px 0 0;
  color: var(--sub);
  font-size: 13px;
  letter-spacing: 0.04em;
}
#locate {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--blue);
  color: white;
  font-size: 16px;
  font-weight: 600;
}
#locate:active { background: var(--blue-deep); }
#locate[data-on="1"] { background: #1d1d1f; }

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 12px;
  border-radius: 18px;
  overflow: hidden;
  background: #e7e7ed;
  box-shadow: var(--shadow);
}
#viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}
#viewport.picking { cursor: crosshair; }
#world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}
#basemap {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}
#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

#north {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
#north i {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 11px solid #c2410c;
  transform-origin: 50% 16px;
}
#north span {
  font-size: 13px;
  font-weight: 700;
  color: #1d1d1f;
}

.switch {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  padding: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.switch button {
  min-width: 64px;
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
}
.switch button[aria-selected="true"] {
  background: var(--ink);
  color: white;
}

.zoom {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.zoom button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  font-size: 26px;
  line-height: 1;
}

#banner {
  position: absolute;
  left: 12px;
  right: 68px;
  bottom: 12px;
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(29, 29, 31, 0.88);
  color: white;
  font-size: 14px;
  line-height: 1.4;
}

#sheet {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  max-height: 46%;
  margin-top: 10px;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: var(--card);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -1px 0 var(--line);
}
.search input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--bg);
  font-size: 17px;
}
.search input:focus {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}
.chips {
  display: flex;
  gap: 8px;
  padding: 10px 0 6px;
}
.chips button {
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
}
.chips button[aria-selected="true"] {
  background: var(--ink);
  color: white;
}

#panel {
  overflow: auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 8px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
}
.row .name {
  font-size: 17px;
  font-weight: 620;
  letter-spacing: -0.01em;
}
.row .meta, .quiet {
  margin-top: 2px;
  color: var(--sub);
  font-size: 14px;
  line-height: 1.35;
}
.phase {
  flex: 0 0 auto;
  min-width: 44px;
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
  font-weight: 650;
  text-align: center;
}
.phase.p1 { color: #6b3f86; }
.phase.p2 { color: #1f7a32; }
.phase.p3 { color: #b45309; }
.soon {
  display: inline-block;
  margin-left: 6px;
  color: #9a3412;
  font-size: 13px;
  font-weight: 600;
}

.actions {
  display: flex;
  gap: 8px;
  padding: 8px 0 4px;
}
.actions button, .back {
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
}
.actions .go {
  background: var(--blue);
  color: white;
}
.actions .from, .back {
  background: var(--bg);
  color: var(--ink);
}

.summary {
  padding: 4px 0 8px;
}
.summary strong {
  display: block;
  font-size: 20px;
  font-weight: 680;
  letter-spacing: -0.02em;
}
.summary span {
  color: var(--sub);
  font-size: 15px;
}
.steps { list-style: none; margin: 0; padding: 0 0 8px; }
.steps li {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 16px;
  line-height: 1.45;
}
.steps .n {
  width: 24px;
  height: 24px;
  margin-top: 1px;
  border-radius: 50%;
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.empty {
  padding: 18px 4px 8px;
  color: var(--sub);
  font-size: 16px;
}
.foot {
  margin: 8px 0 0;
  color: var(--sub);
  font-size: 12px;
  line-height: 1.4;
}

@media (min-width: 840px) {
  #app {
    flex-direction: row;
    padding: 16px;
    gap: 16px;
  }
  header {
    position: absolute;
    z-index: 2;
    left: 28px;
    top: 24px;
    right: auto;
    width: auto;
    padding: 0;
  }
  #stage {
    flex: 1 1 auto;
    margin: 0;
  }
  #sheet {
    flex: 0 0 380px;
    max-height: none;
    margin: 0;
    border-radius: 18px;
  }
}
