:root {
  --night: #0b1222;      /* page background */
  --rule: #2a3756;       /* field underline */
  --text: #e6ecf5;
  --muted: #8592ab;
  --signal: #f7a23b;     /* bitcoin amber: chart line, focus, button */
  --error: #ff8f7a;
  --gutter: clamp(20px, 8vw, 128px);
}

* { box-sizing: border-box; margin: 0; }

html, body { height: 100%; }

body {
  background: var(--night);
  color: var(--text);
  font: 400 15px/1.5 "Sora", system-ui, sans-serif;
  color-scheme: dark;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Bitcoin price history, 2012 to today (log scale) ---------- */

.history {
  position: fixed;
  /* starts right of the form column so the two never overlap */
  inset: 16vh 16vw 14vh calc(var(--gutter) + 420px);
  pointer-events: none;
}

.history svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  animation: draw 1.8s cubic-bezier(.6, 0, .2, 1) both;
}

.history path {
  fill: none;
  stroke: var(--signal);
  stroke-width: 1.25;
  stroke-linejoin: round;
  opacity: .55;
}

.now {
  position: absolute;
  left: 100%;
  top: var(--now-y);
  display: flex;
  align-items: center;
  gap: 12px;
  transform: translate(-4px, -50%);
  animation: appear .5s ease-out 1.7s both;
  white-space: nowrap;
}

.now::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 0 4px rgb(247 162 59 / .18), 0 0 18px rgb(247 162 59 / .6);
}

.now b { display: block; font-weight: 500; font-size: 14px; }
.now span { display: block; color: var(--muted); font-size: 12px; }

@keyframes draw {
  from { clip-path: inset(0 100% 0 0); }
  to   { clip-path: inset(0 0 0 0); }
}

@keyframes appear {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---------- Layout ---------- */

.page {
  position: relative;
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 32px var(--gutter);
}

.brand {
  font: 400 15px/1 "Michroma", "Sora", sans-serif;
  letter-spacing: .14em;
  color: var(--text);
  text-decoration: none;
  justify-self: start;
}

/* ---------- Form ---------- */

.login {
  align-self: center;
  width: 100%;
  max-width: 340px;
  padding-bottom: 6vh;
}

.field { margin-bottom: 24px; }

.field label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 12px 2px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  transition: border-color .2s, box-shadow .2s;
}

.field input:focus {
  outline: none;
  border-bottom-color: var(--signal);
  box-shadow: 0 1px 0 0 var(--signal), 0 12px 24px -16px rgb(247 162 59 / .55);
}

.field input[aria-invalid] { border-bottom-color: var(--error); }

.submit {
  width: 100%;
  margin-top: 16px;
  padding: 14px 20px;
  font: 500 15px/1 "Sora", sans-serif;
  color: var(--night);
  background: var(--signal);
  border: 0;
  border-radius: 2px;
  cursor: pointer;
  transition: filter .15s, transform .15s;
}

.submit:hover { filter: brightness(1.08); }
.submit:active { transform: translateY(1px); }

.submit:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 4px;
}

.message {
  min-height: 1.5em;
  margin-top: 16px;
  font-size: 13px;
  color: var(--error);
}

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  /* chart moves to its own band below the form */
  .history { inset: auto 30vw 5vh 0; height: 22vh; }
  .now { gap: 8px; }
  .now b { font-size: 12px; }
  .now span { font-size: 11px; }
  .login { max-width: none; align-self: start; margin-top: 10vh; }
}

/* the chart draws once; a failed login re-renders the page without replaying it */
.no-intro .history svg, .no-intro .now { animation: none; }

@media (prefers-reduced-motion: reduce) {
  .history svg, .now { animation: none; }
  .field input, .submit { transition: none; }
}

/* ---------- Panel ---------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.link-button {
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 8px 0;
  cursor: pointer;
}

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

.link-button:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 4px;
}

.panel { align-self: center; padding-bottom: 6vh; }

.panel h1 {
  font-weight: 300;
  font-size: clamp(32px, 4vw, 44px);
  letter-spacing: -.02em;
  margin-bottom: 12px;
}

.panel p { color: var(--muted); }

.submit:disabled { opacity: .7; cursor: progress; }

/* ---------- Backtest pages ---------- */

:root {
  --up: #5fd39a;
  --down: var(--error);
  --line: #1c2740;
}

body.app { overflow: auto; }
.app .page { grid-template-rows: auto 1fr; gap: 40px; }

.results { min-width: 0; }

.results h1 {
  font-weight: 300;
  font-size: clamp(24px, 3vw, 32px);
  letter-spacing: -.01em;
  margin: 12px 0 8px;
}

.back, .results a { color: var(--text); text-decoration-color: var(--rule); text-underline-offset: 3px; }
.back { font-size: 13px; color: var(--muted); }
.results a:hover { text-decoration-color: var(--signal); }
.results a:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

.context { color: var(--muted); max-width: 72ch; margin-bottom: 24px; font-size: 14px; }
.empty { color: var(--muted); }
.empty code { color: var(--text); }

.controls { display: flex; flex-wrap: wrap; gap: 16px 24px; margin-bottom: 16px; }
.controls label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.controls select {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--night);
  border: 0;
  border-bottom: 1px solid var(--rule);
  padding: 6px 2px;
}
.controls select:focus { outline: none; border-bottom-color: var(--signal); }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 20px 32px;
  margin: 8px 0 32px;
}
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-size: 20px; font-weight: 300; font-variant-numeric: tabular-nums; }
.stats dd .muted { font-size: 13px; }

.table-wrap { overflow-x: auto; margin: 0 calc(var(--gutter) * -1); padding: 0 var(--gutter); }

table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th {
  text-align: left;
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
td { padding: 9px 12px 9px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:hover td { background: rgb(255 255 255 / .02); }
.num { text-align: right; }
.muted { color: var(--muted); }
.up, .buy { color: var(--up); }
.down, .sell { color: var(--down); }

/* ---------- Monthly view ---------- */

.results h2 { font-weight: 400; font-size: 16px; margin: 32px 0 12px; }
table.months { width: auto; min-width: 280px; }
.strip { display: block; }
.strip line { stroke: var(--rule); stroke-width: 1; }
.strip rect.up { fill: var(--up); }
.strip rect.down { fill: var(--down); }
.strip rect.flat { fill: var(--muted); }

/* ---------- Navigation and trend page ---------- */

.bar { gap: 24px; }
.nav { display: flex; gap: 20px; margin-right: auto; margin-left: 24px; }
.nav a { color: var(--muted); text-decoration: none; font-size: 14px; padding: 6px 0; border-bottom: 1px solid transparent; }
.nav a:hover { color: var(--text); }
.nav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--signal); }
.nav a:focus-visible { outline: 2px solid var(--signal); outline-offset: 4px; }

table.trend td a { text-decoration: none; }
table.trend td.num { padding-left: 12px; }
table.trend td.picked { outline: 1px solid var(--signal); outline-offset: -4px; padding-right: 10px; }
table.trend tfoot th, table.trend tfoot td { border-bottom: 0; padding-top: 12px; color: var(--muted); }
table.trend tfoot tr:first-child th, table.trend tfoot tr:first-child td { border-top: 1px solid var(--rule); color: var(--text); }
.note { margin-top: 12px; font-size: 13px; }

@media (max-width: 640px) {
  .nav { margin-left: 0; }
  .bar { flex-wrap: wrap; }
}

/* ---------- Research ---------- */

.status { display: inline-block; font-size: 12px; padding: 2px 8px; border: 1px solid var(--rule); border-radius: 2px; color: var(--muted); }
.status-in-progress { color: var(--signal); border-color: var(--signal); }
.status-done { color: var(--up); border-color: rgb(95 211 154 / .5); }
.status-blocked { color: var(--down); border-color: rgb(255 143 122 / .5); }
.research .context .status { margin-right: 8px; }

.issue-body { max-width: 76ch; line-height: 1.65; }
.issue-body h2 { font-weight: 400; font-size: 18px; margin: 28px 0 8px; }
.issue-body h3, .issue-body h4 { font-weight: 500; font-size: 15px; margin: 20px 0 6px; }
.issue-body p, .issue-body ul, .issue-body ol { margin: 0 0 12px; }
.issue-body ul, .issue-body ol { padding-left: 20px; }
.issue-body li { margin-bottom: 4px; }
.issue-body code { font-size: .92em; background: rgb(255 255 255 / .05); padding: 1px 5px; border-radius: 2px; }
.issue-body pre { background: rgb(255 255 255 / .04); padding: 12px 14px; overflow-x: auto; border-radius: 2px; margin: 0 0 12px; }
.issue-body pre code { background: none; padding: 0; }
.issue-body .table-wrap { margin-bottom: 16px; }
.issue-body table { width: auto; }
.status-ongoing { color: var(--text); border-color: var(--muted); }

.data-status { margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.data-status.stale { color: var(--error); }
table.months tr.losing td:first-child { box-shadow: inset 2px 0 0 var(--down); padding-left: 8px; }
table.months td:first-child { padding-left: 8px; }

/* ---------- Heatmaps ---------- */

.heatmaps { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 480px), 1fr)); gap: 32px 48px; }
.heatmap { min-width: 0; overflow-x: auto; }
.heatmap table { width: auto; }
.heatmap th { padding-right: 16px; }
.heatmap td { padding: 0; border-bottom: 2px solid var(--night); border-right: 2px solid var(--night); }
.heatmap td a { display: block; padding: 10px 12px; color: var(--text); text-decoration: none; }
.heatmap td a:hover { outline: 1px solid var(--signal); outline-offset: -1px; }

/* ---------- Windows ---------- */

table.windows tr.group td { border-top: 1px solid var(--rule); }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.key { display: inline-block; width: 12px; height: 3px; margin-left: 8px; }
.key:first-child { margin-left: 0; }
.key-strategy { background: var(--signal); }
.key-bh { background: var(--muted); }
.chart { width: 100%; max-width: 760px; height: auto; display: block; margin-bottom: 24px; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .axis { stroke: var(--rule); }
.chart .zero { stroke: var(--rule); stroke-dasharray: 3 3; }
.chart .bar-strategy { fill: var(--signal); }
.chart .bar-bh { fill: var(--muted); opacity: .55; }
.chart .line-strategy { fill: none; stroke: var(--signal); stroke-width: 1; }
.chart .line-bh { fill: none; stroke: var(--muted); stroke-width: 1; opacity: .6; }

/* ---------- Hours and weekdays ---------- */

table.season { width: auto; font-size: 11px; }
table.season th, table.season td { padding: 6px 5px; border-bottom: 2px solid var(--night); border-right: 2px solid var(--night); }
table.season tr.all td, table.season tr.all th { border-top: 6px solid var(--night); }

/* ---------- Findings ---------- */

.controls input[type="date"], .controls input[type="number"] {
  font: inherit; font-size: 14px; color: var(--text); background: var(--night);
  border: 0; border-bottom: 1px solid var(--rule); padding: 6px 2px; color-scheme: dark;
}
.controls input:focus { outline: none; border-bottom-color: var(--signal); }
.submit.compact { width: auto; margin-top: 0; align-self: end; padding: 9px 18px; }
table.period tr.reference td { color: var(--muted); }
.findings .issue-body { margin-top: 40px; }
table.paper tr.reference td { color: var(--muted); }
.nav { flex-wrap: wrap; row-gap: 2px; }
.nav a, .link-button { white-space: nowrap; }
