/* PENNYFORGE — Growth Observatory
   Dark "data observatory" aesthetic. Self-contained, no framework. */

:root {
  --bg: #05070d;
  --bg-2: #080b14;
  --panel: rgba(13, 18, 30, 0.72);
  --panel-solid: #0b1018;
  --border: rgba(120, 160, 220, 0.14);
  --border-bright: rgba(0, 255, 65, 0.35);
  --text: #e7eef7;
  --muted: #8595ad;
  --dim: #5a6679;
  --accent: #00ff41;       /* PENNY green */
  --cyan: #22d3ee;         /* newborn */
  --green: #34f06f;        /* growing */
  --gold: #fbbf24;         /* established */
  --violet: #a78bfa;
  --danger: #ff5470;
  --mono: "SF Mono", "JetBrains Mono", "Fira Code", ui-monospace, Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --r: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: radial-gradient(1200px 800px at 70% -10%, #0d1730 0%, var(--bg) 55%) fixed;
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#city { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; z-index: 0; }
#grid-overlay {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background-image:
    linear-gradient(rgba(120,160,220,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120,160,220,0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 50% 40%, black 0%, transparent 78%);
  opacity: 0.5;
}
#audio-bars {
  position: fixed; left: 0; right: 0; bottom: 86px; height: 120px; width: 100vw;
  z-index: 2; pointer-events: none; opacity: 0; transition: opacity .4s ease;
}
#audio-bars.live { opacity: 0.9; }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 58px; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  background: linear-gradient(180deg, rgba(5,7,13,0.9), rgba(5,7,13,0.0));
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { color: var(--accent); font-size: 18px; transform: translateY(1px); letter-spacing: -2px; }
.brand-name { font-weight: 800; letter-spacing: 1px; font-size: 18px; }
.brand-name .accent { color: var(--accent); }
.brand-sub { color: var(--muted); font-size: 11px; letter-spacing: 2px; text-transform: uppercase; }
.brand-tag {
  margin-left: 8px; font-family: var(--mono); font-size: 9px; letter-spacing: 1.5px;
  color: var(--accent); border: 1px solid var(--border-bright); border-radius: 999px;
  padding: 3px 9px; background: rgba(0,255,65,0.06);
}
.topnav { display: flex; align-items: center; gap: 8px; }
.export-group { display: flex; gap: 4px; padding: 0 4px; border-left: 1px solid var(--border); border-right: 1px solid var(--border); margin: 0 4px; }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--sans); font-size: 12px; font-weight: 600; letter-spacing: .3px;
  color: var(--text); background: rgba(255,255,255,0.04);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px;
  cursor: pointer; transition: all .15s ease; white-space: nowrap;
}
.btn:hover { background: rgba(255,255,255,0.09); border-color: rgba(120,160,220,0.3); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; }
.btn.primary {
  color: #04210d; background: var(--accent); border-color: var(--accent);
  box-shadow: 0 0 24px rgba(0,255,65,0.35);
}
.btn.primary:hover { background: #19ff55; }
.btn.round { width: 40px; height: 40px; border-radius: 50%; font-size: 16px; display: grid; place-items: center; padding: 0; }
.btn.round.playing { background: var(--accent); color: #04210d; border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Panels ---------- */
.panel {
  position: fixed; top: 70px; bottom: 98px; width: 340px; z-index: 15;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r);
  backdrop-filter: blur(14px); box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  display: flex; flex-direction: column; overflow: hidden;
}
.panel.left { left: 16px; }
.panel.right { right: 16px; width: 380px; }
.panel.hidden { display: none; }
.panel-scroll { overflow-y: auto; padding: 16px; height: 100%; }
.panel-scroll::-webkit-scrollbar { width: 8px; }
.panel-scroll::-webkit-scrollbar-thumb { background: rgba(120,160,220,0.2); border-radius: 8px; }
.panel-close {
  position: absolute; top: 10px; right: 12px; z-index: 2; background: transparent; border: none;
  color: var(--muted); font-size: 16px; cursor: pointer; width: 28px; height: 28px; border-radius: 8px;
}
.panel-close:hover { color: var(--text); background: rgba(255,255,255,0.06); }

.block { margin-top: 18px; }
.block-title {
  font-size: 10px; letter-spacing: 2px; text-transform: uppercase; color: var(--muted);
  margin-bottom: 10px; font-weight: 700;
}

/* ---------- Stat grid ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  border: 1px solid var(--border); border-radius: 12px; padding: 12px;
  background: linear-gradient(180deg, rgba(255,255,255,0.03), transparent);
}
.stat .label { font-size: 9.5px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--muted); }
.stat .value { font-family: var(--mono); font-size: 22px; font-weight: 700; margin-top: 4px; line-height: 1; }
.stat .delta { font-size: 10px; margin-top: 5px; font-family: var(--mono); }
.delta.up { color: var(--green); } .delta.down { color: var(--danger); } .delta.flat { color: var(--dim); }
.stat.hero { grid-column: 1 / -1; }
.stat.hero .value { font-size: 28px; color: var(--accent); }

/* ---------- Insights ---------- */
.insights { display: flex; flex-direction: column; gap: 8px; }
.insight {
  font-size: 12px; line-height: 1.5; color: var(--text);
  border-left: 2px solid var(--accent); padding: 7px 10px;
  background: rgba(0,255,65,0.05); border-radius: 0 8px 8px 0;
}
.insight.cyan { border-color: var(--cyan); background: rgba(34,211,238,0.06); }
.insight.gold { border-color: var(--gold); background: rgba(251,191,36,0.06); }
.insight b { color: var(--accent); font-weight: 700; }

/* ---------- Charts ---------- */
.chart { width: 100%; display: block; border-radius: 8px; }

/* ---------- Leaderboard ---------- */
.leaderboard { display: flex; flex-direction: column; gap: 6px; }
.lb-row {
  display: grid; grid-template-columns: 18px 1fr auto; gap: 8px; align-items: center;
  padding: 7px 9px; border-radius: 9px; cursor: pointer; border: 1px solid transparent;
  transition: all .12s ease;
}
.lb-row:hover { background: rgba(255,255,255,0.05); border-color: var(--border); }
.lb-rank { font-family: var(--mono); color: var(--dim); font-size: 11px; }
.lb-name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-name small { color: var(--muted); }
.lb-growth { font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--green); }

/* ---------- Filters ---------- */
.filters, .genre-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.genre-filters { margin-top: 8px; }
.chip {
  font-size: 11px; padding: 5px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  transition: all .12s ease;
}
.chip:hover { color: var(--text); border-color: rgba(120,160,220,0.35); }
.chip.active { color: #04210d; background: var(--accent); border-color: var(--accent); font-weight: 700; }
.chip.genre.active { color: #fff; }

/* ---------- Detail panel ---------- */
.detail-head { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; padding-right: 24px; }
.detail-title { font-size: 19px; font-weight: 800; letter-spacing: -0.2px; }
.detail-artist { color: var(--muted); font-size: 13px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  font-size: 10px; letter-spacing: 1.4px; text-transform: uppercase; font-weight: 700;
  padding: 4px 10px; border-radius: 999px; margin-top: 6px;
}
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; }
.status-newborn { color: var(--cyan); background: rgba(34,211,238,0.1); }
.status-newborn::before { background: var(--cyan); }
.status-growing { color: var(--green); background: rgba(52,240,111,0.1); }
.status-growing::before { background: var(--green); }
.status-established { color: var(--gold); background: rgba(251,191,36,0.1); }
.status-established::before { background: var(--gold); }

.metric-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.metric { border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.metric .label { font-size: 9px; letter-spacing: 1.3px; text-transform: uppercase; color: var(--muted); }
.metric .value { font-family: var(--mono); font-size: 17px; font-weight: 700; margin-top: 3px; }

.projection {
  margin-top: 6px; font-size: 12px; line-height: 1.5; color: var(--muted);
  border: 1px dashed var(--border); border-radius: 10px; padding: 10px;
}
.projection b { color: var(--gold); }

/* ---------- Transport ---------- */
.transport {
  position: fixed; left: 0; right: 0; bottom: 0; height: 84px; z-index: 18;
  display: grid; grid-template-columns: 260px 1fr 260px; align-items: center; gap: 16px;
  padding: 0 18px;
  background: linear-gradient(0deg, rgba(5,7,13,0.95), rgba(5,7,13,0.35));
  backdrop-filter: blur(8px); border-top: 1px solid var(--border);
}
.transport-left { display: flex; align-items: center; gap: 14px; }
.speed { display: flex; align-items: center; gap: 8px; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.speed input { width: 90px; }
#speed-val { font-family: var(--mono); color: var(--text); min-width: 34px; }
.transport-center { display: flex; flex-direction: column; gap: 7px; }
.day-readout { display: flex; align-items: baseline; gap: 10px; justify-content: center; }
#day-label { font-family: var(--mono); font-weight: 700; letter-spacing: 2px; font-size: 13px; color: var(--accent); }
.muted { color: var(--muted); font-size: 11px; }
.transport-right { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; height: 4px; border-radius: 4px;
  background: rgba(120,160,220,0.2); outline: none; cursor: pointer;
}
#timeline { width: 100%; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 12px rgba(0,255,65,0.7); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; border: none;
  background: var(--accent); box-shadow: 0 0 12px rgba(0,255,65,0.7); cursor: pointer;
}

/* ---------- Modal ---------- */
.modal-scrim {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  background: rgba(2,4,8,0.72); backdrop-filter: blur(4px);
}
.modal-scrim.hidden { display: none; }
.modal {
  width: min(560px, 92vw); max-height: 82vh; overflow-y: auto;
  background: var(--panel-solid); border: 1px solid var(--border); border-radius: 18px;
  padding: 26px; box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
.modal h2 { font-size: 20px; margin-bottom: 12px; }
.modal h2 .accent { color: var(--accent); }
.modal p { color: var(--muted); line-height: 1.65; font-size: 14px; margin-bottom: 12px; }
.modal .legend { display: flex; flex-direction: column; gap: 12px; margin: 18px 0; }
.modal .legend-item { display: flex; gap: 12px; align-items: flex-start; }
.modal .swatch { width: 14px; height: 26px; border-radius: 4px; flex-shrink: 0; margin-top: 2px; }
.modal textarea {
  width: 100%; height: 160px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 12px; font-family: var(--mono); font-size: 12px;
}
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%) translateY(20px);
  z-index: 50; background: var(--panel-solid); border: 1px solid var(--border-bright);
  color: var(--text); padding: 11px 18px; border-radius: 12px; font-size: 13px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5); opacity: 0; transition: all .3s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.hidden { display: none; }

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed; z-index: 30; pointer-events: none;
  background: rgba(8,12,20,0.92); border: 1px solid var(--border-bright); border-radius: 10px;
  padding: 8px 11px; font-size: 12px; line-height: 1.4; max-width: 220px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5); backdrop-filter: blur(6px);
  transform: translate(-50%, calc(-100% - 14px)); transition: opacity .12s ease;
}
.tooltip.hidden { opacity: 0; display: none; }
.tooltip .tt-title { font-weight: 700; }
.tooltip .tt-artist { color: var(--muted); font-size: 11px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; margin-top: 5px; font-family: var(--mono); font-size: 11px; }
.tooltip .tt-row span:last-child { color: var(--accent); }

/* ---------- Loading ---------- */
.boot {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: radial-gradient(900px 600px at 50% 40%, #0a1426, var(--bg)); transition: opacity .6s ease;
}
.boot.gone { opacity: 0; pointer-events: none; }
.boot-inner { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.boot .ring { width: 54px; height: 54px; border-radius: 50%; border: 2px solid rgba(0,255,65,0.18); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
.boot-title { font-weight: 800; letter-spacing: 2px; font-size: 16px; }
.boot-title .accent { color: var(--accent); }
.boot-sub { color: var(--muted); font-size: 11px; letter-spacing: 2px; text-transform: uppercase; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Live data tag ---------- */
.brand-tag.live {
  color: #04210d; background: var(--accent); border-color: var(--accent);
  box-shadow: 0 0 14px rgba(0,255,65,0.45); font-weight: 800;
  animation: live-pulse 2.6s ease-in-out infinite;
}
@keyframes live-pulse { 0%,100% { box-shadow: 0 0 10px rgba(0,255,65,0.35); } 50% { box-shadow: 0 0 18px rgba(0,255,65,0.7); } }

/* ---------- City's Pulse toggle ---------- */
#btn-city-sound.on {
  color: #04210d; background: var(--accent); border-color: var(--accent);
  box-shadow: 0 0 16px rgba(0,255,65,0.55);
  animation: live-pulse 2.2s ease-in-out infinite;
}

/* ---------- Built-in player ---------- */
.now-playing {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 96px; z-index: 22;
  display: flex; align-items: center; gap: 12px;
  width: min(560px, calc(100vw - 32px)); padding: 10px 14px;
  background: linear-gradient(180deg, rgba(10,14,22,0.96), rgba(7,10,16,0.96));
  border: 1px solid var(--border-bright); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5), 0 0 0 1px rgba(0,255,65,0.06);
  backdrop-filter: blur(10px);
}
.now-playing.hidden { display: none; }
.btn.round.sm { width: 32px; height: 32px; font-size: 13px; }
.np-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.np-title { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#np-seek { width: 100%; }
.np-time { font-family: var(--mono); font-size: 11px; color: var(--muted); white-space: nowrap; }
.np-close {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px;
  width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center;
}
.np-close:hover { color: var(--text); background: rgba(255,255,255,0.06); }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .panel.left { width: 280px; }
  .panel.right { width: 300px; }
  .transport { grid-template-columns: 1fr; height: auto; padding: 10px; gap: 8px; }
  .transport-left, .transport-right { justify-content: center; }
  #audio-bars { bottom: 150px; }
}
@media (max-width: 680px) {
  .panel { display: none; }
  .brand-sub, .brand-tag { display: none; }
}
