:root {
  --bg: #10141c;
  --bg-panel: #171d29;
  --bg-panel-raised: #1e2635;
  --border: #2a3346;
  --text: #e8ecf4;
  --text-dim: #8b96ac;
  --accent: #4fb0a5;
  --accent-dim: #2c5c56;
  --warn: #d6a24f;
  --bad: #d6674f;
  --good: #4fd67a;

  --delta: #5b6fd6;
  --theta: #8c6fd6;
  --alpha: #4fb0a5;
  --beta: #d6a24f;
  --gamma: #d65f9e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 64px;
}

.app-shell {
  width: 100%;
  max-width: 640px;
}

header.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
}

header.top h1 {
  font-size: 1.3rem;
  font-weight: 600;
  margin: 0;
}

header.top .subtitle {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 16px;
}

.panel h2 {
  margin-top: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.hidden { display: none !important; }

p { line-height: 1.55; color: var(--text); }
p.dim, .dim { color: var(--text-dim); }
small { color: var(--text-dim); }

label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 6px;
  margin-top: 16px;
}
label:first-of-type { margin-top: 0; }

select, input[type="number"] {
  width: 100%;
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 1rem;
}

p.small, .small { font-size: 0.82rem; margin-top: 4px; }

/* Wheel picker, a scroll-snap rebuild of Samadhi Timer's rolling picker */
.wheel-row { display: flex; gap: 24px; justify-content: center; margin: 10px 0 4px; }
.wheel-row.compact { gap: 16px; margin: 0; }
.wheel-col { display: flex; flex-direction: column; align-items: center; }
.wheel-caption { font-size: 0.72rem; color: var(--text-dim); margin-top: 4px; }

.wheel-picker {
  position: relative;
  width: 78px;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.wheel-picker::-webkit-scrollbar { display: none; }
.wheel-picker::before,
.wheel-picker::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 44px;
  top: 50%;
  transform: translateY(-50%);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  pointer-events: none;
}
.wheel-picker-list { display: flex; flex-direction: column; }
.wheel-picker-row {
  scroll-snap-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  color: var(--text-dim);
}
.wheel-picker-row.active { color: var(--text); font-weight: 600; }

.wheel-picker-wrap { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.wheel-arrow {
  background: transparent;
  color: var(--text-dim);
  border: none;
  padding: 3px 16px;
  font-size: 0.65rem;
  line-height: 1;
  border-radius: 6px;
}
.wheel-arrow:hover { color: var(--text); background: var(--bg-panel-raised); }
.wheel-arrow:active { opacity: 0.6; }

.interval-add-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.interval-add-row .btn-secondary { margin-top: 0; padding: 12px 18px; }

.warning-text {
  background: rgba(214, 103, 79, 0.12);
  border: 1px solid var(--bad);
  color: var(--bad);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.85rem;
  margin-top: 12px;
}

.interval-list { list-style: none; padding: 0; margin: 12px 0 0; }
.interval-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 0.88rem;
}
.btn-remove {
  background: transparent;
  color: var(--bad);
  border: 1px solid var(--bad);
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 8px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}
.checkbox-row input { width: 18px; height: 18px; }
.checkbox-row label { margin: 0; color: var(--text); font-size: 0.95rem; }

.end-reason-banner {
  background: rgba(214, 162, 79, 0.12);
  border: 1px solid var(--warn);
  color: var(--warn);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.88rem;
  margin: 12px 0;
}

.chart-controls-row {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  margin-top: 20px;
  padding: 12px 14px;
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.chart-controls-row .checkbox-row { margin-top: 0; }
.smoothing-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 0.95rem;
}
.smoothing-row select {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-family: inherit;
  font-size: 0.9rem;
}

button {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  padding: 14px 20px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
button:hover { opacity: 0.9; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #06231f; width: 100%; margin-top: 20px; }
.btn-secondary { background: var(--bg-panel-raised); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: transparent; color: var(--bad); border: 1px solid var(--bad); }
.btn-link { background: transparent; color: var(--accent); padding: 6px 0; }
a.btn-link {
  display: inline-block;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
a.btn-link:hover { opacity: 0.9; }

.btn-donate {
  display: inline-block;
  margin: 10px 0 4px;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: #06231f;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.btn-donate:hover { opacity: 0.88; }

.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

/* Connect screen */
.quality-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 18px 0;
}
.quality-cell {
  background: var(--bg-panel-raised);
  border-radius: 10px;
  padding: 12px 6px;
  text-align: center;
  border: 1px solid var(--border);
}
.quality-cell .ch-name { font-size: 0.75rem; color: var(--text-dim); }
.quality-dot {
  width: 12px; height: 12px; border-radius: 50%;
  margin: 8px auto 4px;
  background: var(--text-dim);
}
.quality-dot.good { background: var(--good); }
.quality-dot.noisy { background: var(--bad); }
.quality-label { font-size: 0.7rem; color: var(--text-dim); }

.status-line {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 0.9rem;
}
.status-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--text-dim);
}
.status-dot.connecting { background: var(--warn); }
.status-dot.connected { background: var(--good); }
.status-dot.error { background: var(--bad); }

/* Session (live) screen, deliberately dim/minimal, eyes mostly closed */
.session-screen {
  text-align: center;
  padding: 48px 24px;
}
.timer-display {
  font-size: 3.2rem;
  font-weight: 200;
  letter-spacing: 0.02em;
  margin: 12px 0 8px;
}
.timer-sub { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 32px; }

.baseline-capture-block {
  max-width: 420px;
  margin: 0 auto 32px;
  padding: 14px 18px;
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.baseline-instruction { color: var(--text); font-size: 0.92rem; line-height: 1.6; margin: 0; }

.hr-badge {
  display: inline-block;
  margin: 4px auto 0;
  padding: 6px 16px;
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.95rem;
  color: var(--text-dim);
}

.live-chart-wrap { height: 300px; margin: 24px 0 4px; }

.chart-caption { font-size: 0.82rem; color: var(--text-dim); margin: 6px 0 0; line-height: 1.5; }

.live-band-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 18px 0 4px;
  text-align: left;
}
@media (max-width: 480px) {
  .live-band-grid { grid-template-columns: 1fr; }
}
.live-band-card {
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px 6px;
}
.live-band-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 4px;
}
.live-band-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.live-band-chart-wrap { position: relative; height: 100px; }

.session-quality { margin-top: 16px; font-size: 0.8rem; color: var(--text-dim); }

/* Summary screen */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 16px 0;
}
.stat-card {
  background: var(--bg-panel-raised);
  border-radius: 12px;
  padding: 14px;
  border: 1px solid var(--border);
}
.stat-card .stat-value { font-size: 1.4rem; font-weight: 600; }
.stat-card .stat-label { font-size: 0.75rem; color: var(--text-dim); }

.chart-wrap { position: relative; height: 300px; margin-bottom: 8px; }

.bell-list { font-size: 0.8rem; color: var(--text-dim); margin-top: 4px; }

.narrative { font-size: 1rem; line-height: 1.7; margin-top: 4px; }

.band-chart-card {
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px 8px;
  margin-bottom: 14px;
}
.band-chart-card .band-chart-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  margin-bottom: 8px;
}
.band-chart-card .band-chart-dot { width: 10px; height: 10px; border-radius: 50%; }
.band-chart-card .band-chart-canvas-wrap { position: relative; height: 200px; }
.band-chart-card p { margin: 8px 0 2px; color: var(--text-dim); font-size: 0.9rem; line-height: 1.55; }

.journal-textarea {
  width: 100%;
  min-height: 110px;
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.55;
  resize: vertical;
}
.journal-saved { align-self: center; }

.live-journal-block { margin-top: 8px; text-align: left; }
.live-journal-block label { margin-top: 0; }
.live-journal-block .journal-textarea { min-height: 70px; }

.journal-entries-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.journal-entries-list li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: 0.9rem;
  line-height: 1.5;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--bg-panel-raised);
  border-left: 2px dotted #8c6fd6;
}
.journal-entries-list .journal-entry-time {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.journal-entries-list .journal-entry-text { color: var(--text); }

.chart-toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 8px;
  flex-wrap: wrap;
}
.toggle-btn {
  background: var(--bg-panel);
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 8px;
}
.toggle-btn.active { background: var(--accent); color: #06231f; border-color: var(--accent); }
.centroid-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-left: auto;
  font-weight: 400;
}
.centroid-toggle input { width: 14px; height: 14px; margin: 0; }

.balance-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 480px) {
  .balance-grid { grid-template-columns: 1fr; }
}

.explain-section { margin-bottom: 20px; }
.explain-section h3 { font-size: 0.95rem; margin: 0 0 6px; }
.explain-section p { color: var(--text-dim); font-size: 0.9rem; line-height: 1.6; margin: 0; }

.no-data-note {
  color: var(--text-dim);
  font-size: 0.85rem;
  font-style: italic;
}

details.band-card {
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 10px;
}
details.band-card summary {
  cursor: pointer;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
details.band-card summary .band-dot { width: 10px; height: 10px; border-radius: 50%; }
details.band-card p { margin: 10px 0 2px; color: var(--text-dim); font-size: 0.92rem; }

.caveat-box {
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: 16px;
}

.history-list { list-style: none; padding: 0; margin: 12px 0 0; }
.history-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 0.88rem;
}
.history-list li:hover { border-color: var(--accent); }
.history-list .hist-dim { color: var(--text-dim); font-size: 0.78rem; }

footer.assumptions {
  margin-top: 32px;
  font-size: 0.75rem;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.6;
}

/* Export (PDF) prints the report screen as it's currently displayed, via
   the browser's own print-to-PDF, rather than a separate rendering path.
   Whichever screen is visible on the page prints, everything else already
   has .hidden (display:none) so this only needs to deal with the summary
   screen's own controls, and with the dark theme not being legible on
   white paper unless forced. */
@media print {
  :root {
    --bg: #ffffff;
    --bg-panel: #ffffff;
    --bg-panel-raised: #f2f2f4;
    --border: #ccc;
    --text: #111111;
    --text-dim: #444444;
  }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  @page { margin: 1.5cm; }
  body { padding: 0; }
  .app-shell { max-width: 100%; }
  header.top,
  footer.assumptions,
  #btnGoToExplain,
  #btnGoToResultsMeaning,
  .btn-donate,
  .chart-controls-row,
  #chartControlsNote,
  #btnSaveJournal,
  #journalSavedNote,
  #btnExportAi,
  #btnExportCsv,
  #btnExportPdf,
  #btnNewSession,
  .chart-toggle-row {
    display: none !important;
  }
  .panel { border: none; box-shadow: none; }
  .band-chart-card, .stat-card { break-inside: avoid; }
}
