:root {
  --bg: #070510;
  --surface: rgba(12, 10, 20, 0.55);
  --surface-strong: rgba(13, 11, 22, 0.78);
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.18);
  --text: rgba(247, 245, 255, 0.94);
  --text-muted: rgba(235, 232, 248, 0.56);
  --text-faint: rgba(235, 232, 248, 0.36);
  --accent: #c86bff;
  --cyan: #5ee6ff;
  --amber: #e2a856;
  --font-sans: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, 'PingFang TC', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#city-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#city-canvas:active {
  cursor: grabbing;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(244, 242, 255, 0.6);
  line-height: 1.4;
}

/* Loading overlay */
.loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #070510;
  transition: opacity 0.65s ease, visibility 0.65s ease;
}

.loading.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-inner {
  width: min(300px, 80vw);
  text-align: left;
}

.loading-title {
  margin: 10px 0 18px;
  font-size: 24px;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: var(--text);
}

.loading-track {
  width: 100%;
  height: 1px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.loading-bar {
  width: 28%;
  height: 100%;
  background: var(--accent);
  transition: width 0.35s ease;
}

/* Top-left title block */
.site-header {
  position: fixed;
  top: max(24px, env(safe-area-inset-top));
  left: 28px;
  z-index: 20;
  pointer-events: none;
  max-width: 420px;
}

.site-title {
  margin: 5px 0 4px;
  font-size: 28px;
  font-weight: 400;
  letter-spacing: 0.06em;
  line-height: 1.2;
  color: var(--text);
}

.site-subtitle {
  margin: 0;
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

/* Top-right clock & legend */
.status-corner {
  position: fixed;
  top: max(24px, env(safe-area-inset-top));
  right: 28px;
  z-index: 20;
  text-align: right;
  pointer-events: none;
}

.clock-row {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 8px;
}

.clock-val {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--text);
}

.clock-label {
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.legend-row {
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  font-size: 11px;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.dot-live {
  background: var(--accent);
}

.dot-build {
  background: rgba(226, 168, 86, 0.75);
}

/* Floating 3D pins and landmark labels */
.pins-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  overflow: hidden;
}

.district-pin {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate3d(-9999px, -9999px, 0);
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px 5px 8px;
  border-radius: 999px;
  background: rgba(12, 10, 20, 0.62);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.11);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.04em;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.2s ease, background 0.2s ease, opacity 0.25s ease;
  will-change: transform, opacity;
}

.district-pin:hover,
.district-pin.is-selected {
  border-color: rgba(200, 107, 255, 0.55);
  background: rgba(20, 16, 34, 0.82);
}

.district-pin .pin-code {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}

.district-pin.is-live .pin-code {
  color: var(--accent);
}

.district-pin .pin-tag {
  font-size: 10px;
  color: var(--text-faint);
  padding-left: 5px;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.landmark-label {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate3d(-9999px, -9999px, 0);
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1.5px 6px;
  border-radius: 4px;
  background: rgba(10, 8, 18, 0.34);
  border: 1px solid rgba(255, 255, 255, 0.045);
  color: rgba(226, 222, 248, 0.56);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.07em;
  white-space: nowrap;
  will-change: transform, opacity;
  transition: opacity 0.2s ease;
}

.landmark-label::before {
  content: '';
  width: 2.5px;
  height: 2.5px;
  border-radius: 50%;
  background: rgba(94, 230, 255, 0.52);
}

/* Raccoon mascot label & speech bubble */
.raccoon-label {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate3d(-9999px, -9999px, 0);
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 3px 7px;
  border-radius: 999px;
  background: rgba(18, 13, 28, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(242, 163, 168, 0.36);
  color: rgba(252, 244, 246, 0.94);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  cursor: pointer;
  white-space: nowrap;
  will-change: transform, opacity;
  transition: opacity 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.raccoon-label:hover {
  border-color: rgba(242, 163, 168, 0.72);
  background: rgba(28, 19, 40, 0.88);
}

.raccoon-label:focus-visible {
  outline: 1px solid rgba(242, 163, 168, 0.8);
  outline-offset: 2px;
}

.raccoon-label .raccoon-emoji {
  font-size: 12px;
  line-height: 1;
}

.raccoon-bubble {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate3d(-9999px, -9999px, 0);
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(280px, calc(100vw - 32px));
  padding: 8px 10px 8px 13px;
  border-radius: 12px;
  background: rgba(16, 12, 26, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(242, 163, 168, 0.38);
  color: rgba(252, 247, 250, 0.96);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0.03em;
  white-space: nowrap;
  z-index: 15;
  will-change: transform, opacity;
  transition: opacity 0.22s ease;
}

.raccoon-bubble[hidden] {
  display: none;
}

.raccoon-bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 8px;
  height: 8px;
  background: rgba(16, 12, 26, 0.86);
  border-right: 1px solid rgba(242, 163, 168, 0.38);
  border-bottom: 1px solid rgba(242, 163, 168, 0.38);
  transform: translateX(-50%) rotate(45deg);
}

.raccoon-bubble-close {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s ease, background 0.15s ease;
}

.raccoon-bubble-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

/* Bottom-center control dock */
.control-dock {
  position: fixed;
  bottom: max(22px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.dock-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.dock-divider {
  width: 1px;
  height: 16px;
  margin: 0 4px;
  background: rgba(255, 255, 255, 0.1);
}

.dock-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: rgba(245, 243, 255, 0.55);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.04em;
  padding: 7px 10px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.18s ease, background 0.18s ease;
}

.dock-btn .num {
  font-size: 11px;
  opacity: 0.72;
}

.dock-btn .btn-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: transparent;
  transition: background 0.18s ease, transform 0.18s ease;
}

.dock-btn:hover {
  color: rgba(255, 255, 255, 0.86);
  background: rgba(255, 255, 255, 0.04);
}

.dock-btn.is-active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
}

.dock-btn.is-active .btn-dot {
  background: var(--accent);
}

.dock-btn:focus-visible,
.district-pin:focus-visible,
.icon-close:focus-visible,
.fly-btn:focus-visible {
  outline: 1px solid rgba(200, 107, 255, 0.7);
  outline-offset: 2px;
}

/* City Log Panel (left side desktop) */
.log-panel {
  position: fixed;
  left: 28px;
  bottom: 92px;
  z-index: 25;
  width: 300px;
  max-height: 40vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.log-panel[hidden] {
  display: none;
}

.log-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.panel-heading {
  margin: 3px 0 0;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: var(--text);
}

.icon-close {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, background 0.15s ease;
}

.icon-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
}

.log-list {
  margin: 0;
  padding: 8px 16px 14px;
  list-style: none;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
}

.log-item {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 12px;
  line-height: 1.45;
  animation: logFadeIn 0.35s ease;
}

.log-item:last-child {
  border-bottom: 0;
}

.log-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  padding-top: 1px;
}

.log-text {
  color: rgba(242, 240, 252, 0.84);
  font-weight: 300;
}

@keyframes logFadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* District Info Panel (right side desktop) */
.district-panel {
  position: fixed;
  top: 96px;
  right: 28px;
  z-index: 35;
  width: 332px;
  max-height: calc(100vh - 184px);
  overflow-y: auto;
  padding: 20px 22px 22px;
  background: var(--surface-strong);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 14px;
  animation: panelSlideIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.district-panel[hidden] {
  display: none;
}

@keyframes panelSlideIn {
  from {
    opacity: 0;
    transform: translateX(18px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.panel-close {
  position: absolute;
  top: 14px;
  right: 14px;
}

.panel-eyebrow-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 28px;
}

.panel-code {
  font-size: 11px;
  color: var(--accent);
}

.panel-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.panel-name {
  margin: 0;
  font-size: 24px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--text);
}

.status-chip {
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-muted);
}

.status-chip.is-live {
  color: #e6c4ff;
  border-color: rgba(200, 107, 255, 0.35);
  background: rgba(200, 107, 255, 0.1);
}

.status-chip.is-building {
  color: rgba(236, 189, 120, 0.92);
  border-color: rgba(226, 168, 86, 0.3);
  background: rgba(226, 168, 86, 0.08);
}

.panel-tagline {
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: 400;
  color: rgba(240, 237, 252, 0.86);
}

.panel-desc {
  margin: 10px 0 0;
  font-size: 12.5px;
  font-weight: 300;
  line-height: 1.65;
  color: var(--text-muted);
}

.panel-stats {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 14px;
}

.stat-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 10.5px;
  color: var(--text-faint);
  letter-spacing: 0.06em;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.panel-landmarks-wrap {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.landmarks-eyebrow {
  margin-bottom: 8px;
}

.panel-landmarks {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.panel-landmarks li {
  font-size: 11px;
  color: rgba(240, 238, 250, 0.78);
  padding: 3px 9px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.panel-actions {
  margin-top: 18px;
}

.fly-btn {
  width: 100%;
  appearance: none;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(200, 107, 255, 0.35);
  background: rgba(200, 107, 255, 0.12);
  color: #ffffff;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.fly-btn:hover {
  background: rgba(200, 107, 255, 0.22);
  border-color: rgba(200, 107, 255, 0.6);
}

/* Mobile responsive (<= 699px, tested at 390px) */
@media (max-width: 699px) {
  .site-header {
    top: max(14px, env(safe-area-inset-top));
    left: 14px;
    max-width: calc(100% - 140px);
  }

  .site-header .eyebrow {
    font-size: 9px;
    letter-spacing: 0.16em;
  }

  .site-title {
    margin: 3px 0 2px;
    font-size: 20px;
  }

  .site-subtitle {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .status-corner {
    top: max(14px, env(safe-area-inset-top));
    right: 14px;
  }

  .clock-row {
    gap: 5px;
  }

  .clock-val {
    font-size: 12px;
  }

  .clock-label {
    font-size: 10px;
  }

  .legend-row {
    margin-top: 4px;
    gap: 8px;
    font-size: 10px;
  }

  .control-dock {
    left: 12px;
    right: 12px;
    bottom: max(10px, env(safe-area-inset-bottom));
    transform: none;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 6px 8px;
  }

  .dock-divider {
    width: 100%;
    height: 1px;
    margin: 0;
  }

  .dock-group {
    justify-content: space-between;
  }

  .dock-btn {
    flex: 1 1 0;
    justify-content: center;
    padding: 6px 4px;
    font-size: 11.5px;
    gap: 4px;
  }

  .log-panel {
    left: 12px;
    right: auto;
    bottom: auto;
    top: max(104px, calc(env(safe-area-inset-top) + 90px));
    width: calc(100% - 24px);
    max-height: 34vh;
  }

  .district-panel {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: calc(max(10px, env(safe-area-inset-bottom)) + 92px);
    width: auto;
    max-height: calc(100vh - 216px);
    padding: 16px 18px 18px;
    animation: panelSlideUp 0.26s cubic-bezier(0.22, 1, 0.36, 1);
  }

  @keyframes panelSlideUp {
    from {
      opacity: 0;
      transform: translateY(16px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

/* Soft legibility: a quiet shadow instead of boxes or scrims */
.site-header, .status-corner { text-shadow: 0 1px 2px rgba(5, 3, 12, 0.55), 0 0 18px rgba(5, 3, 12, 0.6); }
