:root {
  --cyan: #35c7d6;
  --cyan-deep: #168a9c;
  --ink: #0d2530;
  --ink-soft: #3c5b68;
  --panel: rgba(247, 252, 253, 0.82);
  --panel-line: rgba(120, 178, 194, 0.45);
  --panel-shadow: 0 12px 40px rgba(20, 60, 74, 0.22);
  --radius: 14px;
  --touch: 44px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #0b1c24;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app { position: fixed; inset: 0; }

#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#scene.dragging { cursor: grabbing; }

#vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 90% at 50% 45%, rgba(255,255,255,0) 55%, rgba(10,40,52,0.28) 100%);
  mix-blend-mode: multiply;
}

/* ---------- Loader ---------- */
#loader {
  position: absolute; inset: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: radial-gradient(90% 90% at 50% 40%, #eaf7fb 0%, #bfe0ea 60%, #9cc6d4 100%);
  transition: opacity 0.7s ease, visibility 0.7s ease;
}
#loader.hidden { opacity: 0; visibility: hidden; }
.loader-mark {
  width: 62px; height: 62px; border-radius: 16px;
  border: 2px solid rgba(22,138,156,0.5);
  background: conic-gradient(from 90deg, rgba(53,199,214,0.9), rgba(255,255,255,0.15), rgba(53,199,214,0.9));
  animation: spin 1.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-title { margin: 0; font-size: 26px; letter-spacing: 0.16em; text-transform: uppercase; color: #12414f; font-weight: 600; }
.loader-sub { margin: 0; font-size: 13px; letter-spacing: 0.06em; color: #35606e; }

/* ---------- Shared panel look ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(9px) saturate(1.1);
  -webkit-backdrop-filter: blur(9px) saturate(1.1);
}

/* ---------- Top bar ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 14px 16px calc(14px + env(safe-area-inset-top, 0px));
  pointer-events: none;
}
.brand { display: flex; align-items: center; gap: 12px; pointer-events: auto; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: linear-gradient(150deg, #ffffff 0%, #bfeef6 45%, var(--cyan) 100%);
  border: 1px solid rgba(255,255,255,0.8);
  box-shadow: 0 6px 18px rgba(22,138,156,0.35), inset 0 0 0 1px rgba(22,138,156,0.25);
}
.brand-text h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: 0.01em; color: #0b3441; text-shadow: 0 1px 0 rgba(255,255,255,0.6); }
.brand-text p { margin: 2px 0 0; font-size: 11.5px; letter-spacing: 0.04em; color: var(--ink-soft); }
.topbar-actions { display: flex; align-items: center; gap: 10px; pointer-events: auto; }

.icon-btn {
  width: var(--touch); height: var(--touch); min-width: var(--touch);
  border-radius: 12px; border: 1px solid var(--panel-line);
  background: var(--panel); color: var(--ink); font-size: 17px; font-weight: 700;
  cursor: pointer; box-shadow: var(--panel-shadow); backdrop-filter: blur(9px);
}
.icon-btn.small { width: 34px; height: 34px; min-width: 34px; font-size: 15px; position: absolute; top: 10px; right: 10px; }
.icon-btn:focus-visible, .layer-btn:focus-visible, .chip:focus-visible, .ghost-btn:focus-visible, .action-btn:focus-visible {
  outline: 3px solid rgba(53,199,214,0.85); outline-offset: 2px;
}

.clock {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 12px;
  padding: 8px 12px; box-shadow: var(--panel-shadow); backdrop-filter: blur(9px);
  font-variant-numeric: tabular-nums;
}
#clock-time { font-size: 17px; font-weight: 700; color: #0b3441; }
.phase { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--cyan-deep); }
.weather { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-soft); border-left: 1px solid var(--panel-line); padding-left: 10px; }

/* ---------- Layer bar ---------- */
#layerbar {
  position: absolute; top: 74px; left: 16px; z-index: 20;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 12px;
  padding: 7px; box-shadow: var(--panel-shadow); backdrop-filter: blur(9px);
}
.layer-btn {
  display: flex; align-items: center; gap: 9px; min-height: 36px; padding: 0 12px 0 9px;
  border: 1px solid transparent; border-radius: 9px; background: transparent;
  color: var(--ink-soft); font-size: 12.5px; font-weight: 600; letter-spacing: 0.02em; cursor: pointer;
  white-space: nowrap; text-align: left;
}
.layer-btn:hover { background: rgba(53,199,214,0.12); color: var(--ink); }
.layer-btn.active { background: rgba(53,199,214,0.2); color: #0b3441; border-color: rgba(53,199,214,0.55); }
.layer-dot { width: 9px; height: 9px; border-radius: 3px; flex: none; background: #8fb8c6; }
.layer-dot[data-k="street"] { background: #2f7d4f; }
.layer-dot[data-k="skyline"] { background: #2f7fc0; }
.layer-dot[data-k="underground"] { background: #6b4fa8; }
.layer-dot[data-k="infrastructure"] { background: #d0872f; }

/* ---------- District chips ---------- */
#districtbar {
  position: absolute; bottom: 46px; left: 16px; right: 16px; z-index: 20;
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
}
.chip {
  min-height: 38px; padding: 0 14px; border-radius: 19px;
  border: 1px solid var(--panel-line); background: var(--panel); color: var(--ink-soft);
  font-size: 12.5px; font-weight: 600; letter-spacing: 0.02em; cursor: pointer;
  box-shadow: var(--panel-shadow); backdrop-filter: blur(9px); white-space: nowrap;
}
.chip:hover { color: var(--ink); background: rgba(255,255,255,0.9); }
.chip.active { background: var(--cyan); color: #04333c; border-color: #1fa6b8; }

/* ---------- Help panel ---------- */
#help { position: absolute; top: 74px; right: 16px; z-index: 22; width: 250px; padding: 14px 16px 12px; }
#help.hidden { display: none; }
#help h2 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--cyan-deep); }
.keylist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.keylist li { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-soft); }
.keylist kbd {
  display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 5px;
  border-radius: 6px; border: 1px solid rgba(120,178,194,0.6); background: #ffffff;
  font-family: var(--font); font-size: 11px; font-weight: 700; color: #12414f; box-shadow: 0 1px 0 rgba(20,60,74,0.18);
}
.keylist .mouse { color: var(--ink-soft); font-size: 11.5px; font-style: italic; }
.ghost-btn {
  margin-top: 10px; width: 100%; min-height: 36px; border-radius: 9px;
  border: 1px solid var(--panel-line); background: transparent; color: var(--ink-soft);
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.ghost-btn:hover { background: rgba(53,199,214,0.12); }

/* ---------- Ticker ---------- */
#ticker {
  position: absolute; bottom: 96px; left: 16px; z-index: 19; max-width: min(420px, 40vw);
  display: flex; align-items: baseline; gap: 9px;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 12px;
  padding: 9px 13px; box-shadow: var(--panel-shadow); backdrop-filter: blur(9px);
  font-size: 12px; color: var(--ink-soft); transition: opacity 0.4s ease;
}
.ticker-tag { flex: none; font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--cyan-deep); font-weight: 700; }
#ticker-text { font-size: 12.5px; color: var(--ink); }

/* ---------- Info panel ---------- */
#info { position: absolute; top: 74px; right: 16px; z-index: 24; width: 300px; padding: 16px 18px 16px; }
#info[hidden] { display: none; }
.info-kind { margin: 0 0 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--cyan-deep); font-weight: 700; }
#info h2 { margin: 0 0 8px; font-size: 19px; color: #0b3441; letter-spacing: -0.01em; padding-right: 30px; }
.info-body { margin: 0 0 10px; font-size: 13px; line-height: 1.55; color: var(--ink-soft); }
.info-meta { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.info-meta li { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; border-bottom: 1px dashed rgba(120,178,194,0.4); padding-bottom: 5px; }
.info-meta li span:first-child { color: var(--ink-soft); }
.info-meta li span:last-child { color: var(--ink); font-weight: 600; text-align: right; }
.info-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.action-btn {
  min-height: var(--touch); padding: 0 14px; border-radius: 10px; border: 1px solid var(--panel-line);
  background: #ffffff; color: var(--ink); font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.action-btn:hover { background: rgba(53,199,214,0.16); }
.action-btn.primary { background: var(--cyan); border-color: #1fa6b8; color: #04333c; }

/* ---------- Footnote ---------- */
#footnote {
  position: absolute; bottom: 12px; left: 0; right: 0; z-index: 15; text-align: center;
  font-size: 11px; letter-spacing: 0.03em; color: rgba(12,52,65,0.72); pointer-events: none;
  text-shadow: 0 1px 0 rgba(255,255,255,0.5); padding: 0 16px;
}

/* ---------- Responsive / mobile ---------- */
@media (max-width: 860px) {
  #help { display: none; }
  #help.mobile-open { display: block; width: min(300px, 82vw); }
  #info { width: min(320px, 90vw); }
}

@media (max-width: 640px) {
  #topbar { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 10px calc(10px + env(safe-area-inset-top, 0px)); }
  .brand { min-width: 0; }
  .brand-text { min-width: 0; }
  .brand-text p { display: none; }
  .brand-text h1 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand-mark { width: 28px; height: 28px; border-radius: 8px; }
  .topbar-actions { justify-content: flex-end; }
  .clock { padding: 6px 9px; gap: 7px; }
  #clock-time { font-size: 15px; }
  .phase, .weather { font-size: 9.5px; }
  .weather { padding-left: 7px; }

  #layerbar {
    top: auto; bottom: 96px; left: 10px; right: 10px; flex-direction: row;
    justify-content: space-between; padding: 5px; gap: 4px;
  }
  .layer-btn { flex: 1 1 0; min-width: 0; flex-direction: column; gap: 3px; padding: 6px 2px; font-size: 10px; min-height: var(--touch); justify-content: center; }
  .layer-dot { width: 10px; height: 10px; }

  #districtbar {
    bottom: 50px; left: 0; right: 0; flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start;
    padding: 0 10px 6px; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  #districtbar::-webkit-scrollbar { display: none; }
  .chip { min-height: var(--touch); flex: none; }

  #ticker { left: 10px; right: 10px; max-width: none; bottom: 148px; }
  #info {
    top: auto; bottom: 0; left: 0; right: 0; width: 100%;
    border-radius: 18px 18px 0 0; max-height: 62vh; overflow-y: auto;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  }
  #footnote { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #loader, .loader-mark { animation: none; transition: none; }
}

@media (max-height: 520px) {
  #help { display: none; }
  #footnote { display: none; }
  #ticker { bottom: 44px; }
}
