:root {
  --bg: #0f1420;
  --panel-bg: rgba(255,255,255,0.96);
  --panel-ink: #1b2430;
  --panel-ink2: #4a5566;
  --accent: #c2410c;
  --border: #d9d4c7;
  --btn-bg: #f2efe6;
  --btn-active-bg: #1b2430;
  --btn-active-ink: #ffffff;
  --routeA: #e0393e;
  --routeB: #2477d4;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }

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

#viewport {
  position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none;
}

#labelLayer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.tag {
  position: absolute; transform: translate(-50%, -100%);
  background: rgba(27,36,48,0.86); color: #fff; font-size: 11px; line-height: 1.3;
  padding: 3px 7px; border-radius: 5px; white-space: nowrap; pointer-events: none;
  border: 1px solid rgba(255,255,255,0.18);
}
.tag .pid { font-weight: 700; color: #f4b71e; margin-right: 4px; }

#loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 14px; color: #e7e3d8; font-size: 15px; z-index: 50;
  background: var(--bg); transition: opacity .35s ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.25); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 52px; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; background: linear-gradient(to bottom, rgba(15,20,32,0.82), rgba(15,20,32,0));
  pointer-events: none;
}
#title { color: #fff; font-weight: 700; font-size: 17px; letter-spacing: 0.2px; pointer-events: none; }
#title .rev { font-weight: 500; opacity: 0.65; font-size: 13px; margin-left: 6px; }
#menuToggle {
  pointer-events: auto; width: 38px; height: 38px; border-radius: 10px; border: none;
  background: rgba(255,255,255,0.12); color: #fff; font-size: 18px; display: none;
}

#panel {
  position: absolute; top: 60px; right: 14px; width: 230px; z-index: 20;
  background: var(--panel-bg); border-radius: 14px; padding: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  max-height: calc(100vh - 80px); overflow-y: auto;
}
#panel section { margin-bottom: 12px; }
#panel h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--panel-ink2);
  margin: 0 0 6px 2px; font-weight: 700;
}
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid.views { grid-template-columns: 1fr 1fr; }
.grid.routes { grid-template-columns: 1fr 1fr; }
.grid.toggles { grid-template-columns: 1fr; }

#panel button {
  font-family: inherit; font-size: 12.5px; font-weight: 600; color: var(--panel-ink);
  background: var(--btn-bg); border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 6px; cursor: pointer; line-height: 1.15; min-height: 38px;
}
#panel button:active { transform: scale(0.97); }
#panel button.active { background: var(--btn-active-bg); color: var(--btn-active-ink); border-color: var(--btn-active-bg); }
#panel button.routeA.active { background: var(--routeA); border-color: var(--routeA); color: #fff; }
#panel button.routeB.active { background: var(--routeB); border-color: var(--routeB); color: #fff; }
#panel button#playMarble { grid-column: 1 / -1; background: var(--accent); color: #fff; border-color: var(--accent); }
#panel button#resetView { background: #fff; }

#hint { font-size: 10.5px; color: var(--panel-ink2); text-align: center; padding-top: 2px; }

@media (max-width: 900px) {
  #menuToggle { display: inline-flex; align-items: center; justify-content: center; }
  #panel {
    top: auto; bottom: 0; left: 0; right: 0; width: auto; border-radius: 16px 16px 0 0;
    max-height: 48vh; transform: translateY(100%); transition: transform .25s ease;
  }
  #panel.open { transform: translateY(0); }
}
