/* ── Reset & tokens ────────────────────────────────────────── */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}

:root{
  --bg:       #0a0a0f;
  --surface:  #12121a;
  --border:   #1e1e2a;
  --text:     #e0e0e8;
  --text-dim: #6e6e80;
  --accent:   #f7931a;          /* bitcoin orange */
  --green:    #22c55e;
  --red:      #ef4444;
  --cvdd:     #facc15;
  --cohort-lt-1:    #6d7cff;
  --cohort-1-10:    #ef553b;
  --cohort-10-100:  #00c896;
  --cohort-100-1k:  #a855f7;
  --cohort-1k-10k:  #22d3ee;
  --cohort-ge-10k:  #e879f9;
  --radius:   8px;
  --price-axis-width: 78px;
  --font:     Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html,body{
  height:100%;
  background:var(--bg);
  color:var(--text);
  font-family:var(--font);
  overflow:hidden;
  -webkit-font-smoothing:antialiased;
}

/* ── Topbar ────────────────────────────────────────────────── */
#topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 20px;
  height:52px;
  background:var(--surface);
  border-bottom:1px solid var(--border);
  user-select:none;
}

.topbar-left{
  display:flex;
  align-items:center;
  gap:10px;
}

.logo{
  font-size:22px;
  color:var(--accent);
  font-weight:700;
}

#topbar h1{
  font-size:15px;
  font-weight:600;
  letter-spacing:0.4px;
}

.topbar-right{
  display:flex;
  align-items:center;
  gap:8px;
  min-width:0;
}

/* ── Pills ─────────────────────────────────────────────────── */
.pill-group{
  display:flex;
  gap:2px;
  background:var(--bg);
  border-radius:var(--radius);
  padding:3px;
}

.pill{
  background:transparent;
  border:none;
  color:var(--text-dim);
  font-family:var(--font);
  font-size:12px;
  font-weight:500;
  padding:4px 12px;
  border-radius:6px;
  cursor:pointer;
  transition:all .15s ease;
}

.pill:hover{
  color:var(--text);
}

.pill.active{
  background:var(--surface);
  color:var(--text);
  box-shadow:0 1px 3px rgba(0,0,0,.4);
}

.series-pill-group .pill{
  min-width:54px;
}

#series-pills .cvdd.active{
  color:#fff4a3;
}

#series-pills .bottom-dates.active{
  color:#ffc66d;
}

#series-pills .cohort-lt-1.active{ color:var(--cohort-lt-1) }
#series-pills .cohort-1-10.active{ color:var(--cohort-1-10) }
#series-pills .cohort-10-100.active{ color:var(--cohort-10-100) }
#series-pills .cohort-100-1k.active{ color:var(--cohort-100-1k) }
#series-pills .cohort-1k-10k.active{ color:var(--cohort-1k-10k) }
#series-pills .cohort-ge-10k.active{ color:var(--cohort-ge-10k) }

.cohort-pill{
  display:flex;
  align-items:center;
  gap:5px;
}

.pill-swatch{
  width:8px;
  height:8px;
  border-radius:50%;
  background:currentColor;
  flex:0 0 auto;
}

/* ── Legend overlay ────────────────────────────────────────── */
#legend{
  position:absolute;
  top:62px;
  left:20px;
  z-index:10;
  pointer-events:none;
  display:flex;
  flex-direction:column;
  gap:4px;
}

.legend-row{
  display:flex;
  align-items:center;
  gap:12px;
  font-size:13px;
  font-weight:500;
}

.legend-label{
  color:var(--text);
  font-weight:600;
}

.legend-ohlc{
  color:var(--text-dim);
  font-variant-numeric:tabular-nums;
}

.legend-overlay-row{
  font-size:12px;
  flex-wrap:wrap;
  max-width:min(1180px, calc(100vw - 120px));
}

.legend-overlay{
  font-variant-numeric:tabular-nums;
}

.cvdd{ color:var(--cvdd) }
.cohort-lt-1{ color:var(--cohort-lt-1) }
.cohort-1-10{ color:var(--cohort-1-10) }
.cohort-10-100{ color:var(--cohort-10-100) }
.cohort-100-1k{ color:var(--cohort-100-1k) }
.cohort-1k-10k{ color:var(--cohort-1k-10k) }
.cohort-ge-10k{ color:var(--cohort-ge-10k) }

#series-pills .pill:not(.active){
  color:var(--text-dim);
}

#series-pills .pill:not(.active):hover{
  color:var(--text);
}

/* ── Chart container ───────────────────────────────────────── */
#chart-shell{
  position:relative;
  width:100%;
  height:calc(100vh - 52px);   /* minus topbar */
}

#chart-container{
  position:absolute;
  inset:0;
}

#cycle-projection-layer{
  position:absolute;
  top:0;
  right:var(--price-axis-width);
  bottom:28px;
  left:0;
  z-index:8;
  pointer-events:none;
  overflow:hidden;
}

.cycle-projection-line{
  position:absolute;
  top:0;
  bottom:0;
  border-left:1px dashed rgba(248,250,252,.45);
}

.cycle-projection-line.early{
  border-left-color:rgba(148,163,184,.36);
}

.cycle-projection-line.average{
  border-left-color:rgba(247,147,26,.72);
}

.cycle-projection-label{
  position:absolute;
  top:28px;
  left:0;
  transform:translateX(10px);
  padding:7px 9px;
  border:1px solid rgba(42,43,54,.94);
  border-radius:6px;
  background:rgba(10,10,15,.86);
  color:#d8dce8;
  font-size:11px;
  font-weight:600;
  line-height:1.2;
  white-space:nowrap;
  box-shadow:0 8px 24px rgba(0,0,0,.28);
}

.cycle-projection-label-title{
  color:#d8dce8;
}

.cycle-projection-label-range{
  margin-top:4px;
  color:#ffc66d;
}

.cycle-projection-label-detail{
  display:grid;
  gap:2px;
  margin-top:7px;
  color:#aeb6c9;
  font-size:10px;
  font-weight:500;
  line-height:1.45;
}

.cycle-projection-detail-row{
  display:grid;
  grid-template-columns:34px max-content;
  column-gap:7px;
}

.cycle-projection-line.average .cycle-projection-label{
  color:#ffc66d;
}

.scale-settings{
  position:absolute;
  right:0;
  bottom:0;
  width:var(--price-axis-width);
  z-index:12;
}

.scale-settings-button{
  display:grid;
  place-items:center;
  width:100%;
  height:28px;
  border:0;
  border-left:1px solid var(--border);
  border-top:1px solid var(--border);
  background:rgba(10,10,15,.9);
  color:#cfd2dc;
  cursor:pointer;
  transition:background .15s ease,color .15s ease;
}

.scale-settings-button:hover,
.scale-settings-button[aria-expanded="true"]{
  background:var(--surface);
  color:var(--text);
}

.scale-settings-button svg{
  width:18px;
  height:18px;
  fill:none;
  stroke:currentColor;
  stroke-width:1.7;
}

.scale-menu{
  position:absolute;
  right:4px;
  bottom:32px;
  display:grid;
  gap:2px;
  min-width:96px;
  padding:5px;
  border:1px solid #2a2b36;
  border-radius:7px;
  background:rgba(15,15,22,.98);
  box-shadow:0 12px 32px rgba(0,0,0,.48);
}

.scale-menu[hidden]{
  display:none;
}

.scale-option{
  border:0;
  border-radius:5px;
  background:transparent;
  color:var(--text-dim);
  cursor:pointer;
  font:inherit;
  font-size:12px;
  line-height:1;
  padding:8px 10px;
  text-align:left;
  transition:background .15s ease,color .15s ease;
}

.scale-option:hover{
  color:var(--text);
}

.scale-option.active{
  background:#252733;
  color:var(--text);
}

@media (max-width:520px){
  #topbar{
    height:48px;
    padding:0 10px;
  }

  .topbar-left{
    gap:7px;
    min-width:0;
  }

  .logo{
    font-size:19px;
  }

  #topbar h1{
    font-size:13px;
    white-space:nowrap;
  }

  .topbar-right{
    gap:5px;
    overflow-x:auto;
    scrollbar-width:none;
  }

  .topbar-right::-webkit-scrollbar{
    display:none;
  }

  .pill-group{
    padding:2px;
  }

  .pill{
    font-size:11px;
    padding:4px 8px;
  }

  .series-pill-group .pill{
    min-width:44px;
  }

  #legend{
    top:58px;
    left:12px;
    right:12px;
    gap:5px;
  }

  .legend-row{
    gap:8px;
    font-size:12px;
    flex-wrap:wrap;
  }

  .legend-overlay-row{
    font-size:11px;
    max-width:calc(100vw - 24px);
  }

  .cycle-projection-label{
    top:22px;
  }

  #chart-shell{
    height:calc(100vh - 48px);
  }
}

@media (max-width:420px){
  #topbar h1{
    display:none;
  }

  .pill{
    padding:4px 7px;
  }

  .series-pill-group .pill{
    min-width:40px;
  }
}

/* ── Loading splash ────────────────────────────────────────── */
.loading-overlay{
  position:absolute;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  background:var(--bg);
  z-index:20;
  transition:opacity .4s ease;
}

.loading-overlay.hidden{
  opacity:0;
  pointer-events:none;
}

.spinner{
  width:28px;height:28px;
  border:3px solid var(--border);
  border-top-color:var(--accent);
  border-radius:50%;
  animation:spin .7s linear infinite;
}

@keyframes spin{to{transform:rotate(360deg)}}
