:root {
  --bg: #0d1017;
  --panel: #151a24;
  --panel2: #1b2130;
  --border: #262e40;
  --text: #e8ecf4;
  --muted: #8b94a7;
  --accent: #7c5cff;
  --accent2: #37d4a0;
  --warn: #f2b84b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  font-size: 26px;
  color: var(--accent);
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 48px; height: 48px;
  display: grid; place-items: center;
}
h1 { margin: 0; font-size: 20px; }
.tagline { margin: 0; color: var(--muted); font-size: 13px; }
.viewer { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }

nav {
  display: flex; gap: 4px; flex-wrap: wrap;
  padding: 10px 24px; border-bottom: 1px solid var(--border);
}
nav button {
  background: none; border: none; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
nav button.active { background: var(--panel2); color: var(--text); }
nav button:hover { color: var(--text); }

main { padding: 20px 28px 60px; max-width: 1100px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h2 { margin: 0 0 10px; font-size: 16px; }
.muted { color: var(--muted); font-size: 13px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px 16px;
}
.stat .num { font-size: 22px; font-weight: 650; margin-top: 2px; }
.stat .num.accent { color: var(--accent2); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
input, select {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; font-size: 14px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
#prompt { flex: 1; min-width: 240px; }
textarea {
  flex: 1; min-width: 240px; resize: vertical;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; font-size: 14px; font-family: inherit;
}
textarea:focus { outline: none; border-color: var(--accent); }

button.primary {
  background: var(--accent); color: #fff; border: none;
  padding: 9px 18px; border-radius: 8px; font-size: 14px; cursor: pointer;
}
button.primary:hover { filter: brightness(1.1); }
button.primary:disabled { opacity: .5; cursor: default; }
button.ghost {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  padding: 7px 14px; border-radius: 8px; font-size: 13px; cursor: pointer;
}

.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; background: var(--panel2);
  border: 1px solid var(--border); border-radius: 22px; cursor: pointer; transition: .15s;
}
.slider:before {
  content: ""; position: absolute; width: 16px; height: 16px;
  left: 2px; top: 2px; background: var(--muted); border-radius: 50%; transition: .15s;
}
.switch input:checked + .slider { background: var(--accent2); border-color: var(--accent2); }
.switch input:checked + .slider:before { transform: translateX(18px); background: #0d1017; }

.badge {
  display: inline-block; font-size: 11px; padding: 2px 8px;
  border-radius: 999px; border: 1px solid var(--border); color: var(--muted);
}
.badge.in { color: var(--accent2); border-color: var(--accent2); }

.gen {
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.gen:last-child { border-bottom: none; }
.gen .info { flex: 1; min-width: 200px; }
.gen .prompt { font-weight: 550; }
audio { height: 36px; }

#playerBar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: none; align-items: center; gap: 14px;
  padding: 10px 24px;
  background: var(--panel2); border-top: 1px solid var(--border);
  z-index: 10;
}
#playerTitle { font-size: 13px; color: var(--muted); max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#playerBar audio { flex: 1; }
button.play { padding: 3px 9px; font-size: 11px; }

.viz-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; margin-bottom: 18px; }
.viz-grid .card { margin-bottom: 0; }
.viz-donut { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.viz-legend { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.viz-donut .viz-legend { margin-top: 0; }
.viz-key { display: inline-flex; align-items: center; gap: 7px; }
.viz-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.viz-split { display: flex; height: 30px; border-radius: 6px; overflow: hidden; gap: 2px; background: var(--bg); }
.viz-split div { display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; min-width: 0; }
.viz-seg { cursor: default; }
svg text { font-family: inherit; }
#chartTip {
  position: fixed; display: none; z-index: 30; pointer-events: none;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; font-size: 12px; color: var(--text); max-width: 220px;
}

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: 1; }
#toast.error { border-color: #e05b5b; }

details.dist { margin: 6px 0; }
details.dist summary { cursor: pointer; padding: 6px 0; }

@media (max-width: 640px) {
  header, nav, main { padding-left: 16px; padding-right: 16px; }
}

/* Full-page auth gate (sign-in / no-access) */
#authGate { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: var(--bg); }
#authGate .gateCard { background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 36px 44px; text-align: center; max-width: 420px; }
#authGate .gateCard h2 { margin: 0 0 8px; }
#authGate .gateCard button { margin-top: 16px; }
