/* BBMA Tracker: hand-written dark theme. */
:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c232d;
  --border: #2a323d;
  --text: #e6edf3;
  --muted: #8b949e;
  --sell: #f0616d;
  --sell-bg: rgba(240, 97, 109, 0.14);
  --buy: #3fcf8e;
  --buy-bg: rgba(63, 207, 142, 0.14);
  --accent: #58a6ff;
  --warn: #e3b341;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 0.6rem; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
.page-title { margin: 0 0 0.75rem; }
h3 { font-size: 0.95rem; margin-top: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
small, .small { font-size: 0.8rem; }
code { font-family: var(--mono); background: var(--panel-2); padding: 0 0.3em; border-radius: 4px; }
.muted { color: var(--muted); }
.sell { --side: var(--sell); --side-bg: var(--sell-bg); }
.buy { --side: var(--buy); --side-bg: var(--buy-bg); }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.5rem;
  padding: 0.55rem 1rem;
  background: rgba(14, 17, 22, 0.85);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 12px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(10px);
}
.brand { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand img { border-radius: 6px; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 0.25rem; }
.nav a { color: var(--muted); font-weight: 500; padding: 0.35rem 0.75rem; border-radius: 999px; transition: color 0.15s, background 0.15s; }
.nav a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--text); background: var(--panel-2); box-shadow: inset 0 0 0 1px var(--border); }
.topbar-actions { display: flex; align-items: center; gap: 0.6rem; margin-left: auto; }
.refresh-form { display: flex; margin: 0; }
.bar-btn { display: inline-flex; align-items: center; gap: 0.35rem; }
.icon-btn { display: inline-grid; place-items: center; width: 2rem; height: 2rem; padding: 0; color: var(--muted); background: none; border: 1px solid var(--border); border-radius: 999px; cursor: pointer; }
.icon-btn:hover, .icon-btn:focus-visible { color: var(--accent); border-color: var(--accent); }
.icon-btn:disabled { color: var(--accent); border-color: var(--accent); cursor: progress; }
.icon-btn:disabled svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .icon-btn:disabled svg { animation: none; } }
.signout { font: inherit; font-size: 0.85rem; color: var(--muted); background: none; border: 0; padding: 0.35rem 0.5rem; border-radius: var(--radius); cursor: pointer; }
.signout:hover, .signout:focus-visible { color: var(--sell); background: var(--sell-bg); }

.btn {
  background: var(--accent);
  color: #0b1220;
  border: 0;
  border-radius: var(--radius);
  padding: 0.45rem 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:disabled { background: var(--panel-2); color: var(--muted); cursor: progress; }
.btn.small { padding: 0.25rem 0.6rem; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn.danger { background: var(--sell); }
.btn.ghost.danger { background: transparent; color: var(--sell); border-color: var(--sell); }
.confirm { max-width: 22rem; background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; }
.confirm::backdrop { background: rgba(0, 0, 0, 0.6); }
.confirm p { margin: 0 0 1rem; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

/* iOS "Add to Home Screen" hint */
.install-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.hint-close { background: none; border: 0; color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 0 0.25rem; }

.container { max-width: 1600px; margin: 0 auto; padding: 1rem; }
.footer { text-align: center; padding: 1.5rem 1rem; font-size: 0.8rem; }
.footer p { margin: 0.4rem 0 0; }

/* Panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

/* Timeframe tabs */
.tabs { display: flex; align-items: center; gap: 0.25rem; margin-bottom: 1rem; }
.tab {
  flex: 0 0 auto;
  padding: 0.45rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 600;
}
.tab.active { background: var(--accent); border-color: var(--accent); color: #0b1220; }
.tab:hover { text-decoration: none; color: var(--text); }
.tab.active:hover { color: #0b1220; }

/* Filters */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.5rem; margin-bottom: 0.75rem; padding: 0.75rem 0.9rem; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.filter-group { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.6rem; margin: 0; }
.trend-filter { flex: 1 1 100%; }
.fl-label { color: var(--muted); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.filter-hint a { color: var(--muted); text-decoration: underline; }
.seg { display: inline-flex; gap: 2px; padding: 2px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); }
.seg-item { padding: 0.25rem 0.75rem; font-size: 0.85rem; font-weight: 600; color: var(--muted); border-radius: 6px; }
.seg-item:hover { text-decoration: none; color: var(--text); }
.seg-item.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.trend-filter .seg-item.active { background: rgba(88, 166, 255, 0.15); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.seg-item.sell.active { background: var(--sell-bg); color: var(--sell); box-shadow: inset 0 0 0 1px var(--sell); }
.seg-item.buy.active { background: var(--buy-bg); color: var(--buy); box-shadow: inset 0 0 0 1px var(--buy); }
.pair-search input { width: 8rem; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.3rem 0.5rem; }
.pair-search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.reset-filters { margin-left: auto; }
.reset-filters button { padding: 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: 0.8rem; cursor: pointer; }
.reset-filters button:hover { color: var(--accent); text-decoration: underline; }
.list-meta { margin: 0 0 0.75rem; }
.empty { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Re-entry table */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); -webkit-overflow-scrolling: touch; }
.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; white-space: nowrap; }
.grid thead th { background: var(--panel-2); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.grid tbody tr:hover { background: rgba(88, 166, 255, 0.05); }
.re-pair a { font-weight: 700; }
.re-row { border-left: 3px solid var(--side, transparent); }
.side-tag { font-weight: 700; color: var(--side); }
.lbl { display: none; }
.mono { font-family: var(--mono); }
.chip { display: inline-block; font-size: 0.7rem; color: var(--side, var(--muted)); background: var(--side-bg, var(--panel-2)); border-radius: 4px; padding: 0 0.3rem; white-space: nowrap; }
.trend-chips { display: flex; gap: 0.25rem; list-style: none; margin: 0; padding: 0; }
.trend-chips .chip { font-size: 0.72rem; padding: 0.05rem 0.35rem; opacity: 0.75; }
.trend-chips .chip.agrees { opacity: 1; box-shadow: inset 0 0 0 1px var(--side); }
.badge { display: inline-block; padding: 0.05rem 0.45rem; border-radius: 4px; font-size: 0.72rem; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }
.badge.warn { color: var(--warn); border-color: var(--warn); }

/* Pair page */
.page-head .chart-link { margin-left: auto; }
.topdown { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.6rem; }
.td-item { display: flex; flex-direction: column; gap: 0.3rem; padding: 0.6rem; background: var(--panel-2); border: 1px solid var(--border); border-left: 3px solid var(--side, var(--border)); border-radius: var(--radius); color: var(--text); }
.td-item:hover { text-decoration: none; border-color: var(--accent); }
.td-tf { font-weight: 700; font-size: 1.05rem; }
.trend { font-weight: 600; color: var(--side, var(--muted)); white-space: nowrap; }
.tf-panel h2 { display: flex; align-items: baseline; gap: 0.75rem; }

/* Chart */
.icon { vertical-align: -0.15em; }
.chart-link { display: inline-flex; align-items: center; gap: 0.3rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin-bottom: 0.75rem; }
.page-head h1 { margin: 0; font-size: 1.5rem; }
.back-icon { display: inline-grid; place-items: center; width: 2rem; height: 2rem; color: var(--muted); background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; }
.back-icon:hover { color: var(--text); border-color: var(--accent); }
.tabs.chart-tabs { gap: 2px; margin: 0 0 0 auto; padding: 0; background: none; }
.chart-tabs .tab { flex: 0 0 auto; padding: 0.3rem 0.55rem; font-size: 0.9rem; font-weight: 500; color: var(--muted); border: 0; border-radius: 4px; }
.chart-tabs .tab:hover { color: var(--text); background: var(--panel); }
.chart-tabs .tab.active, .chart-tabs .tab.active:hover { color: var(--text); background: var(--panel-2); }
.chart-panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem; }
.chart-toggles { display: flex; flex-wrap: wrap; gap: 0.45rem 0.9rem; font-size: 0.85rem; }
.tg { display: inline-flex; align-items: center; gap: 0.35rem; white-space: nowrap; }
.tg::before { content: ""; width: 0.9rem; height: 3px; border-radius: 2px; background: var(--tg); order: 1; }
.tg input { margin: 0; order: 0; }
.tg { --tg: var(--muted); }
.tg-bb { --tg: #e3b341; }
.tg-mah { --tg: #ff4d5e; }
.tg-mal { --tg: #3b9eff; }
.tg-ema { --tg: #b07cff; }
.tg-ev { --tg: #8b949e; }
.chart-prefs { display: flex; gap: 0.8rem; margin: 0 0 0.4rem; }
.chart-prefs a { color: var(--muted); }
.prefs-saved { transition: opacity 0.4s; }
.prefs-saved:empty { opacity: 0; }
.chart-side .side-head { margin: 1rem 0 0.45rem; font-size: 0.75rem; }
.chart-side .side-head:first-child { margin-top: 0; }
.chart-side .sig-row { font-size: 0.85rem; }
.chart-side .sig-row:first-of-type { margin-top: 0; }
.head-btn { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.3rem 0.7rem; font: inherit; font-size: 0.85rem; font-weight: 600; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; cursor: pointer; }
.head-btn:hover { border-color: var(--accent); text-decoration: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: 0.6rem; margin-bottom: 0.8rem; border-bottom: 1px solid var(--border); font-size: 1rem; }
.sheet-close { width: 2rem; height: 2rem; font-size: 1.3rem; line-height: 1; color: var(--muted); background: var(--panel-2); border: 0; border-radius: 999px; cursor: pointer; }
.sheet-foot { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1rem; }
.sheet-foot .chart-prefs { margin: 0; }
.sheet-backdrop { display: none; }
.sig-row { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.4rem; }
.sig { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.2rem 0.55rem; border: 1px solid var(--border); border-radius: 999px; white-space: nowrap; color: var(--side, var(--text)); cursor: pointer; user-select: none; }
.sig:has(input:checked) { background: var(--side-bg, var(--panel-2)); border-color: var(--side, var(--muted)); }
.sig input { margin: 0; }
.sig-btn { padding: 0.2rem 0.7rem; border: 1px solid var(--border); border-radius: 999px; background: none; color: var(--muted); font: inherit; cursor: pointer; }
.sig-btn:hover { color: var(--accent); border-color: var(--accent); }
/* Same colours as COLORS.band in js/chart.js. */
.chart-legend { display: flex; flex-wrap: wrap; gap: 0.2rem 0.8rem; margin-bottom: 0.35rem; }
.lg { display: inline-flex; align-items: center; gap: 0.3rem; }
.lg::before { content: ""; width: 0.75rem; height: 0.9rem; border-radius: 2px; background: var(--lg); outline: var(--lg-outline, none); outline-offset: -2px; }
.lg-csa-sell { --lg: rgba(255, 159, 67, 0.16); }
.lg-csa-buy { --lg: rgba(59, 158, 255, 0.16); }
.lg-csak-sell { --lg: rgba(240, 97, 109, 0.2); }
.lg-csak-buy { --lg: rgba(63, 207, 142, 0.2); }
.chart-box { position: relative; height: min(70vh, 640px); min-height: 320px; }
.chart-status { padding: 2rem 0; text-align: center; }
.chart-credit { margin: 0.25rem 0 0; }
@media (min-width: 1100px) {
  .chart-panel { display: grid; grid-template-columns: minmax(0, 1fr) 16rem; gap: 0 1rem; }
  .chart-side { order: 2; border-left: 1px solid var(--border); padding-left: 1rem; }
  .chart-toggles { flex-direction: column; }
  .chart-legend { display: grid; grid-template-columns: 1fr 1fr; }
  .chart-box { height: min(78vh, 760px); }
  .filter-btn, .sheet-head, .sheet-done { display: none; }
}
@media (max-width: 1099px) {
  .chart-side { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; flex-direction: column; max-height: 85dvh; padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--border); border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.5); transform: translateY(100%); visibility: hidden; transition: transform 0.25s ease, visibility 0.25s; }
  .sheet-body { overflow-y: auto; overscroll-behavior: contain; }
  .sheet-foot { padding-top: 0.8rem; border-top: 1px solid var(--border); }
  .chart-panel.filters-open .chart-side { transform: none; visibility: visible; }
  .chart-panel.filters-open .sheet-backdrop { display: block; position: fixed; inset: 0; z-index: 29; background: rgba(0, 0, 0, 0.55); }
  body:has(.filters-open) { overflow: hidden; }
}

@media (max-width: 760px) {
  body { font-size: 13px; }
  .chart-panel { padding: 0.4rem; margin: 0 -0.2rem; }
  .chart-box { height: calc(100dvh - 17rem); }
  .container { padding: 0.6rem; }
  .topbar { padding: 0.75rem 1rem 0.5rem; gap: 0.6rem 0.75rem; }
  .bar-label { display: none; }
  .topbar .bar-btn { justify-content: center; width: 2rem; height: 2rem; padding: 0; border-radius: 999px; }
  .topbar .signout { border: 1px solid var(--border); }
  .topbar-actions { gap: 0.5rem; }
  .nav { order: 3; width: 100%; }
  .nav a { flex: 1; text-align: center; }
  .page-head { gap: 0.5rem; }
  .page-head h1 { font-size: 1.25rem; }
  .chart-tabs .tab { padding: 0.3rem 0.35rem; }
  .filter-btn { width: 2rem; height: 2rem; padding: 0; justify-content: center; }
  .filter-label { display: none; }

  .toolbar { padding: 0.6rem; gap: 0.6rem; }
  .filter-group { flex: 1 1 100%; }
  .fl-label { min-width: 3.5rem; }
  .filter-group .seg { flex: 1 1 auto; }
  .filter-group .seg-item { flex: 1; padding: 0.45rem 0.4rem; text-align: center; }
  .pair-search input { flex: 1; }
  .reset-filters { margin-left: 0; }

  /* The re-entry table becomes a list of cards. */
  .table-wrap { overflow: visible; border: 0; }
  .grid thead { display: none; }
  .grid, .grid tbody { display: block; }
  .grid tr.re-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.4rem 0.6rem;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-left: 4px solid var(--side, var(--border));
    border-radius: var(--radius);
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.6rem;
  }
  .grid th, .grid td { display: block; padding: 0; border: 0; }
  .lbl { display: inline; color: var(--muted); font-family: system-ui, sans-serif; }
  /* Line 1: pair TF side grade ... chart; 2: time @ price ... age; 3: anchor zone; 4: trend chips. */
  .re-pair { font-size: 1.05rem; }
  .re-chart { order: 1; flex: 1 0 auto; text-align: right; }
  .re-chart .lbl { display: none; }
  .re-time { order: 2; min-width: 55%; }
  .re-price { order: 2; }
  .re-age { order: 3; margin-left: auto; }
  .re-anchor { order: 4; min-width: 55%; }
  .re-zone { order: 4; }
  .re-trends { order: 5; flex-basis: 100%; }
}

/* Auth pages */
.auth { max-width: 420px; margin: 2rem auto; }
.auth form { display: flex; flex-direction: column; gap: 0.5rem; margin: 1rem 0; }
.auth input { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem 0.6rem; }
.auth input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-error { color: var(--sell); }
.auth-notice { color: var(--buy); }
.auth-resend { margin-top: 0; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.recaptcha-note { margin-top: 1rem; }
.grecaptcha-badge { visibility: hidden; }
.user-menu { display: flex; margin: 0; }


/* Guide */
.guide { max-width: 52rem; margin: 0 auto; line-height: 1.6; font-size: 1rem; }
.guide h2 { margin-top: 2rem; font-size: 1.2rem; }
.guide-lang { margin-bottom: 1rem; }
.guide-note { padding: 0.6rem 0.8rem; border-left: 4px solid var(--warn); background: var(--panel); border-radius: var(--radius); }
.guide-terms dt { font-weight: 700; margin-top: 0.8rem; }
.guide-terms dd { margin: 0.15rem 0 0; }
.guide-side { color: var(--side); font-weight: 600; }
.guide-list { font-size: 1.1rem; }
.guide-steps li, .guide-stages li { margin-bottom: 0.6rem; }
.guide-stages .step { margin-right: 0.4rem; font-size: 0.85rem; }
.guide-example { margin: 1rem 0; line-height: 1.4; font-size: 0.9rem; }
.guide-example .grid { min-width: 0; }
.guide-num { display: inline-flex; align-items: center; justify-content: center; width: 1.3rem; height: 1.3rem; border-radius: 50%; background: var(--accent); color: #0b1220; font-size: 0.72rem; font-weight: 700; vertical-align: middle; }
.guide-shot { margin: 1.5rem 0; }
.guide-shot img { display: block; max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.guide-shot figcaption { margin-top: 0.4rem; font-size: 0.85rem; }
.guide-flow { align-items: center; gap: 0.3rem; margin: 0.6rem 0; font-size: 0.85rem; }
.guide-flow li[aria-hidden] { color: var(--muted); }

