/* ---------- Tokens ---------- */
:root {
  /* GitHub Light */
  --bg: #ffffff;
  --canvas-subtle: #f6f8fa;
  --border: #d0d7de;
  --border-muted: #d8dee4;
  --text: #1f2328;
  --muted: #656d76;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --danger: #cf222e;

  --heat-0: #ebedf0;
  --heat-1: #9be9a8;
  --heat-2: #40c463;
  --heat-3: #30a14e;
  --heat-4: #216e39;

  /* SPY gradient endpoints (light) — continuous interpolation in JS */
  --spy-neutral: #ebedf0;
  --spy-up-soft: #9be9a8;
  --spy-up-strong: #216e39;
  --spy-dn-soft: #ffc1ba;
  --spy-dn-strong: #82071e;

  --sq-size: 11px;
  --sq-gap: 3px;
  --sq-radius: 2px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans",
               Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;

  color-scheme: light;
}

html.dark {
  /* GitHub Dark */
  --bg: #0d1117;
  --canvas-subtle: #161b22;
  --border: #30363d;
  --border-muted: #21262d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #2f81f7;
  --accent-hover: #4184e4;
  --danger: #f85149;

  --heat-0: #161b22;
  --heat-1: #0e4429;
  --heat-2: #006d32;
  --heat-3: #26a641;
  --heat-4: #39d353;

  /* SPY gradient endpoints (dark) */
  --spy-neutral: #161b22;
  --spy-up-soft: #033a16;
  --spy-up-strong: #3fb950;
  --spy-dn-soft: #3c0d14;
  --spy-dn-strong: #f85149;

  color-scheme: dark;
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
button { font-family: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}
.brand:hover { text-decoration: none; }

.logo {
  display: block;
  flex-shrink: 0;
}

.wordmark {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--canvas-subtle);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.btn:hover {
  background: var(--border-muted);
}
html.dark .btn:hover {
  background: #21262d;
}

.btn-primary {
  background: #1f883d;
  border-color: rgba(31, 35, 40, 0.15);
  color: #ffffff;
}
.btn-primary:hover {
  background: #1a7f37;
}
html.dark .btn-primary {
  background: #238636;
  border-color: rgba(240, 246, 252, 0.1);
}
html.dark .btn-primary:hover {
  background: #2ea043;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--canvas-subtle);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s;
}
.icon-btn:hover { background: var(--border-muted); }
html.dark .icon-btn:hover { background: #21262d; }
.icon-btn.small { width: 24px; height: 24px; border: none; background: transparent; }
.icon-btn.small:hover { background: var(--canvas-subtle); }

.icon-sun { display: none; }
.icon-moon { display: block; }
html.dark .icon-sun { display: block; }
html.dark .icon-moon { display: none; }

/* ---------- Container ---------- */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Summary ---------- */
.summary {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 8px 0 0;
}
.summary h1 {
  font-size: 20px;
  font-weight: 400;
  color: var(--text);
  margin: 0;
}
.summary h1 strong {
  font-weight: 600;
}
.year-picker {
  font-size: 14px;
  color: var(--muted);
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.year-picker select {
  padding: 4px 24px 4px 8px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16' fill='%23656d76'><path d='M4.427 7.427l3.396 3.396a.25.25 0 0 0 .354 0l3.396-3.396A.25.25 0 0 0 11.396 7H4.604a.25.25 0 0 0-.177.427z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 6px center;
}
.year-picker select:disabled { opacity: 0.5; cursor: not-allowed; }
html.dark .year-picker select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16' fill='%238b949e'><path d='M4.427 7.427l3.396 3.396a.25.25 0 0 0 .354 0l3.396-3.396A.25.25 0 0 0 11.396 7H4.604a.25.25 0 0 0-.177.427z'/></svg>");
}

/* ---------- Card ---------- */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.card-header h3 {
  font-size: 14px;
  font-weight: 600;
}

/* ---------- Heatmap ---------- */
.heatmap-card { padding: 16px; }

.heatmap-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.heatmap-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.heatmap-title #heatmapTitle {
  font-size: 14px;
  font-weight: 600;
}
.heatmap-title #heatmapSubtitle {
  font-size: 12px;
}

.metric-toggle {
  display: inline-flex;
  background: var(--canvas-subtle);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}
.metric-btn {
  background: transparent;
  border: none;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  border-radius: 4px;
  cursor: pointer;
}
.metric-btn:hover { color: var(--text); }
.metric-btn.is-active {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border);
}

.heatmap-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
  /* Firefox */
  scrollbar-width: thin;
}
.heatmap-scroll::-webkit-scrollbar { height: 8px; }
.heatmap-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.heatmap {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto 1fr;
  column-gap: 4px;
  row-gap: 4px;
  min-width: 760px;
  font-size: 11px;
  color: var(--muted);
}

.heatmap-months {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  height: 14px;
}
.heatmap-months .month-label {
  position: absolute;
  top: 0;
  font-size: 11px;
  color: var(--muted);
}

.heatmap-days {
  grid-column: 1;
  grid-row: 2;
  display: grid;
  /* 7 rows, same height as squares */
  grid-template-rows: repeat(7, calc(var(--sq-size) + var(--sq-gap)));
  align-items: start;
  padding-right: 4px;
  font-size: 11px;
  color: var(--muted);
  /* Slight offset so labels align with square center */
  padding-top: 1px;
}
.heatmap-days span {
  line-height: calc(var(--sq-size) + var(--sq-gap));
  height: calc(var(--sq-size) + var(--sq-gap));
  text-align: right;
  visibility: hidden;
}
.heatmap-days span.show { visibility: visible; }

.heatmap-grid {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, var(--sq-size));
  grid-auto-columns: var(--sq-size);
  gap: var(--sq-gap);
}

.sq {
  width: var(--sq-size);
  height: var(--sq-size);
  border-radius: var(--sq-radius);
  background: var(--heat-0);
  outline: 1px solid rgba(27, 31, 35, 0.06);
  outline-offset: -1px;
  cursor: pointer;
  transition: transform 0.08s;
}
html.dark .sq { outline-color: rgba(255, 255, 255, 0.04); }
.sq[data-level="1"] { background: var(--heat-1); }
.sq[data-level="2"] { background: var(--heat-2); }
.sq[data-level="3"] { background: var(--heat-3); }
.sq[data-level="4"] { background: var(--heat-4); }

.sq.placeholder { visibility: hidden; cursor: default; }

.sq:hover {
  outline: 1px solid var(--accent);
}
.sq.is-selected {
  outline: 2px solid var(--accent);
}

.heatmap-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  font-size: 12px;
  flex-wrap: wrap;
}

.legend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.legend-sq {
  display: inline-block;
  width: var(--sq-size);
  height: var(--sq-size);
  border-radius: var(--sq-radius);
  background: var(--heat-0);
  outline: 1px solid rgba(27, 31, 35, 0.06);
  outline-offset: -1px;
}
html.dark .legend-sq { outline-color: rgba(255,255,255,0.04); }
.legend-sq[data-level="1"] { background: var(--heat-1); }
.legend-sq[data-level="2"] { background: var(--heat-2); }
.legend-sq[data-level="3"] { background: var(--heat-3); }
.legend-sq[data-level="4"] { background: var(--heat-4); }

/* ---------- Mock-data banner ---------- */
.mock-banner {
  margin-bottom: 16px;
  background: #ddf4ff;
  border: 1px solid #54aeff66;
  border-radius: 6px;
  padding: 10px 12px;
}
html.dark .mock-banner {
  background: #121d2f;
  border-color: #1f6feb66;
}
.mock-banner-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.mock-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  color: #ffffff;
  background: var(--accent);
  border-radius: 10px;
  letter-spacing: 0.02em;
}
.mock-text {
  font-size: 13px;
  color: var(--text);
  flex: 1 1 280px;
}
.btn-sm {
  padding: 3px 10px;
  font-size: 12px;
  line-height: 18px;
}

/* ---------- SPY market heatmap ---------- */
.spy-card { margin-top: 16px; }
.spy-summary {
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.spy-summary strong { color: var(--text); font-weight: 600; }
.spy-summary .up { color: var(--spy-up-strong); }
.spy-summary .dn { color: var(--spy-dn-strong); }

/* SPY cells use inline background-color (continuous gradient); keep outline + hover behavior */
.sq-spy {
  width: var(--sq-size);
  height: var(--sq-size);
  border-radius: var(--sq-radius);
  background: var(--heat-0);
  outline: 1px solid rgba(27, 31, 35, 0.06);
  outline-offset: -1px;
  cursor: default;
  transition: transform 0.08s;
}
html.dark .sq-spy { outline-color: rgba(255, 255, 255, 0.04); }
.sq-spy.placeholder { visibility: hidden; }
.sq-spy.is-closed { background: var(--heat-0); }
.sq-spy:hover { outline: 1px solid var(--accent); }

/* SPY legend squares */
.spy-legend .legend-sq[data-spy="-2"] { background: var(--spy-dn-strong); }
.spy-legend .legend-sq[data-spy="-1"] { background: var(--spy-dn-soft); }
.spy-legend .legend-sq[data-spy="0"]  { background: var(--heat-0); }
.spy-legend .legend-sq[data-spy="1"]  { background: var(--spy-up-soft); }
.spy-legend .legend-sq[data-spy="2"]  { background: var(--spy-up-strong); }

/* ---------- Dropzone (empty state) ---------- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  background: var(--canvas-subtle);
  padding: 32px 24px;
  text-align: center;
  transition: background 0.15s, border-color 0.15s;
}
.dropzone.is-dragover {
  border-color: var(--accent);
  background: rgba(9, 105, 218, 0.06);
}
html.dark .dropzone.is-dragover {
  background: rgba(47, 129, 247, 0.12);
}
.dropzone.hidden { display: none; }
[hidden] { display: none !important; }

.dropzone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}
.dropzone-title {
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
}
.dropzone-sub {
  max-width: 520px;
  line-height: 1.5;
  font-size: 13px;
}
.dropzone-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

/* ---------- Stats row ---------- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}
.stat-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
.stat-value {
  margin-top: 2px;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.stat-sub {
  font-size: 12px;
  margin-top: 2px;
}

/* ---------- Bottom grid ---------- */
.bottom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Weekday chart */
.weekday-chart {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wd-row {
  display: grid;
  grid-template-columns: 36px 1fr 60px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.wd-label { color: var(--muted); font-weight: 500; }
.wd-bar {
  position: relative;
  height: 10px;
  background: var(--canvas-subtle);
  border-radius: 3px;
  overflow: hidden;
}
.wd-bar-fill {
  height: 100%;
  background: var(--heat-3);
  border-radius: 3px;
  transition: width 0.3s cubic-bezier(0.2, 0, 0, 1);
}
.wd-value { text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }

/* Time chart */
.time-chart {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 2px;
  height: 80px;
  align-items: end;
}
.tc-bar {
  position: relative;
  background: var(--heat-2);
  border-radius: 2px 2px 0 0;
  min-height: 2px;
}
.tc-bar[data-count="0"] {
  background: var(--canvas-subtle);
  min-height: 4px;
}
.time-axis {
  margin-top: 6px;
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 2px;
  font-size: 10px;
  color: var(--muted);
}
.time-axis span {
  text-align: center;
  visibility: hidden;
}
.time-axis span.show { visibility: visible; }

/* Top symbols */
.top-symbols {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.top-symbols li {
  display: grid;
  grid-template-columns: 24px 60px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
}
.top-symbols li:hover { background: var(--canvas-subtle); }
.top-symbols .rank {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.top-symbols .sym {
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 12px;
}
.top-symbols .bar {
  position: relative;
  height: 6px;
  background: var(--canvas-subtle);
  border-radius: 3px;
}
.top-symbols .bar-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: var(--heat-2);
  border-radius: 3px;
}
.top-symbols .count {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
}

/* Detail panel */
.detail-card { min-height: 220px; }
.detail-body { font-size: 13px; }
.detail-empty { margin: 0; }

.detail-summary {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.detail-summary .ds-item {
  display: flex;
  flex-direction: column;
}
.detail-summary .ds-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}
.detail-summary .ds-value {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.trades-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.trades-table th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  padding: 4px 8px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.trades-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-muted);
}
.trades-table tr:last-child td { border-bottom: none; }
.trades-table .t-sym {
  font-family: var(--font-mono);
  font-weight: 600;
}
.trades-table .t-side-buy  { color: #1f883d; font-weight: 600; }
.trades-table .t-side-sell { color: var(--danger); font-weight: 600; }
html.dark .trades-table .t-side-buy { color: #3fb950; }

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.9);
  color: #ffffff;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 0.08s;
  line-height: 1.35;
}
.tooltip.visible { opacity: 1; }
.tooltip::after {
  content: "";
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: rgba(0, 0, 0, 0.9);
  border-bottom: none;
}

/* ---------- Footer ---------- */
.page-footer {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  text-align: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .bottom-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .container { padding: 16px; }
  .header-inner { padding: 10px 16px; }
  .wordmark { display: none; }
  .summary h1 { font-size: 18px; }
  .stats-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat-value { font-size: 18px; }
  .heatmap-header { flex-direction: column; align-items: flex-start; }
  .dropzone { padding: 24px 16px; }
}

/* ---------- Password gate ---------- */
body.locked {
  overflow: hidden;
}

body.locked .site-header,
body.locked .container {
  filter: blur(14px) saturate(0.8);
  pointer-events: none;
  user-select: none;
  transition: filter 0.35s ease;
}

body:not(.locked) .site-header,
body:not(.locked) .container {
  filter: none;
  transition: filter 0.35s ease;
}

.gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  backdrop-filter: blur(2px);
  padding: 24px;
}

body:not(.locked) .gate {
  display: none;
}

.gate-card {
  width: 100%;
  max-width: 420px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25),
              0 4px 12px rgba(0, 0, 0, 0.1);
  padding: 32px 28px;
  text-align: center;
}

.gate-card .logo {
  margin: 0 auto 16px;
  display: block;
}

.gate-card h2 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.01em;
}

.gate-sub {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
}

.gate-form {
  display: flex;
  gap: 8px;
  margin: 0 0 10px;
}

.gate-form input {
  flex: 1;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  font-family: inherit;
  letter-spacing: 0.05em;
}

.gate-form input:focus {
  border-color: var(--accent, #2da44e);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #2da44e) 25%, transparent);
}

.gate-form input.shake {
  animation: gate-shake 0.4s cubic-bezier(.36,.07,.19,.97);
  border-color: #cf222e;
}

@keyframes gate-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}

.gate-error {
  min-height: 18px;
  margin: 0 0 16px;
  font-size: 13px;
  color: #cf222e;
}

.gate-privacy {
  margin: 16px 0 0;
  font-size: 12px;
  line-height: 1.5;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ---------- Privacy note ---------- */
.privacy-note {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 0;
  padding: 10px 14px;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.privacy-note svg {
  flex-shrink: 0;
  color: var(--muted);
}
