/* Tokens: neutral UI, the data is the only colour. Series colours validated with the dataviz checker. */
:root {
  color-scheme: light dark;
  --page: #f9f9f7; --surface: #fcfcfb; --ink: #0b0b0b; --ink2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --axis: #c3c2b7; --hair: rgba(11, 11, 11, 0.12); --slot: #efeee9; --wash: rgba(11, 11, 11, 0.05);
  --up: #006300; --down: #c23030;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --hair: rgba(255, 255, 255, 0.12); --slot: #262624; --wash: rgba(255, 255, 255, 0.07);
    --up: #2fbf2f; --down: #f0716f;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 16px/1.5 var(--font); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
:focus-visible { outline: 2px solid var(--s1); outline-offset: 2px; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.top { border-bottom: 1px solid var(--hair); }
.bar { display: flex; align-items: center; justify-content: space-between; min-height: 56px; }
.brand { font-weight: 700; letter-spacing: -0.01em; color: var(--ink); text-decoration: none; font-size: 1.05rem; }
.lang select { background: transparent; border: 1px solid var(--hair); border-radius: 8px; padding: 6px 10px; min-height: 36px; }

/* layout: tool card left, result + chart right */
.intro { padding: 28px 0 18px; }
h1 { margin: 0; font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.1rem); font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; }
.lede { margin: 6px 0 0; color: var(--ink2); max-width: 62ch; }
.top-grid { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 20px; align-items: start; }
.side { display: grid; gap: 20px; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--hair); border-radius: 12px; padding: 20px; min-width: 0; }
.card > h2 { margin: 0 0 16px; font-size: 1rem; font-weight: 650; }
.tool { position: sticky; top: 12px; }
.field { margin-bottom: 14px; min-width: 0; }
.lbl { display: block; margin-bottom: 6px; font-size: 0.85rem; color: var(--ink2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inp, .pick-btn {
  width: 100%; min-height: 44px; padding: 0 12px; background: var(--page); color: var(--ink); border: 1px solid var(--hair); border-radius: 8px; font: inherit; display: flex; align-items: center; gap: 8px;
}
select.inp { appearance: none; -webkit-appearance: none; padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }
.inp:focus-within, .inp:focus, .pick-btn:focus-visible { border-color: var(--ink2); outline: 2px solid var(--s1); outline-offset: 1px; }
.inp input { flex: 1; min-width: 0; width: 100%; background: transparent; border: 0; padding: 0; font: inherit; color: inherit; outline: 0; -moz-appearance: textfield; }
.inp input::-webkit-outer-spin-button, .inp input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.aff { color: var(--ink2); }
input[type="date"].inp { padding-right: 8px; }
.err { margin: 0 0 12px; color: var(--down); font-weight: 600; font-size: 0.9rem; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.chip, .btn { background: transparent; border: 1px solid var(--hair); border-radius: 999px; padding: 6px 13px; min-height: 36px; font-size: 0.9rem; }
.btn { border-radius: 8px; min-height: 38px; }
.chip:hover, .btn:hover { background: var(--wash); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--page); border-color: var(--ink); }

/* coin picker (logo + name) */
.picker { position: relative; }
.pick-btn { cursor: pointer; text-align: left; }
.pick-btn .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.pick-btn .sy, .pick-list .sy { color: var(--ink2); font-weight: 400; margin-left: 6px; }
.pick-btn::after { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translate(-2px, -2px); flex: none; }
.pick-list { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none; max-height: 320px; overflow: auto;
  background: var(--surface); border: 1px solid var(--hair); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16); }
.pick-list li { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 6px; cursor: pointer; min-height: 44px; }
.pick-list li[aria-selected="true"] { font-weight: 650; }
.pick-list li.act, .pick-list li:hover { background: var(--wash); }
.logo { width: 24px; height: 24px; border-radius: 50%; flex: none; display: inline-grid; place-items: center; overflow: hidden; color: #fff; font-size: 0.62rem; font-weight: 700; letter-spacing: -0.02em; }
.logo img { width: 100%; height: 100%; display: block; }

/* result */
.result { }
.hero-label { color: var(--ink2); }
.hero-value { font-size: clamp(2.4rem, 1.5rem + 3.2vw, 3.6rem); font-weight: 650; letter-spacing: -0.035em; line-height: 1.05; margin: 2px 0 4px; overflow-wrap: anywhere; }
.hero-delta { font-size: 1.1rem; font-weight: 600; }
.hero-delta .rest { color: var(--ink2); font-weight: 400; }
.up { color: var(--up); } .down { color: var(--down); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 20px 0 0; padding: 0; }
.stats > div { border-top: 1px solid var(--hair); padding: 12px 16px 12px 0; }
.stats dt { color: var(--ink2); font-size: 0.85rem; }
.stats dd { margin: 2px 0 0; font-size: 1.2rem; font-weight: 600; overflow-wrap: anywhere; }
.stats small { display: block; font-size: 0.82rem; color: var(--ink2); }
.notes { margin: 14px 0 0; color: var(--ink2); font-size: 0.9rem; }
.notes p { margin: 2px 0; }

/* chart */
.chartcard { padding: 16px 16px 8px; }
.chartcard .ct { margin: 0; font-size: 0.95rem; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 6px 0 4px; color: var(--ink2); font-size: 0.85rem; align-items: center; }
.legend .li { display: inline-flex; align-items: center; gap: 6px; }
.legend .key { width: 16px; height: 2px; border-radius: 1px; display: inline-block; }
.logt { margin-left: auto; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.logt input { width: 16px; height: 16px; accent-color: var(--ink); }
.plot { position: relative; }
.plot canvas { display: block; width: 100%; height: 320px; touch-action: pan-y; border-radius: 4px; }
.tip {
  position: absolute; pointer-events: none; z-index: 2; background: var(--surface); border: 1px solid var(--hair); border-radius: 6px;
  padding: 8px 10px; font-size: 0.85rem; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.14); white-space: nowrap;
}
.tip-t { color: var(--ink2); margin-bottom: 4px; }
.tip-r { display: flex; align-items: center; gap: 8px; line-height: 1.5; }
.tip-r .key { width: 14px; height: 2px; border-radius: 1px; flex: none; }
.tip-r strong { font-weight: 650; font-variant-numeric: tabular-nums; }
.tip-r .lab { color: var(--ink2); }

/* ledger */
.ledger { margin-top: 44px; }
.ledger-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 16px; }
.ledger-head h2 { margin: 0; font-size: 1.25rem; }
.ledger-head .count { margin: 0; color: var(--ink2); font-size: 0.9rem; }
.tools { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.tablewrap { margin-top: 12px; overflow-x: auto; border-top: 1px solid var(--hair); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 10px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--hair); font-variant-numeric: tabular-nums; }
thead th { color: var(--ink2); font-weight: 600; font-size: 0.82rem; background: var(--page); position: sticky; top: 0; z-index: 1; }
th.c-date, td.c-date { text-align: left; position: sticky; left: 0; background: var(--page); z-index: 1; font-weight: 500; }
thead th.c-date { z-index: 2; }
tbody tr:hover td, tbody tr:hover th { background: var(--wash); }
.pl { font-weight: 600; }
.xbtn { display: none; }
.detail-row { display: none; }
.detail-row dl { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 0; padding: 4px 0 6px; text-align: left; }
.detail-row dt { color: var(--ink2); font-size: 0.8rem; }
.detail-row dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.wide { width: 100%; margin-top: 12px; }
.empty { padding: 36px 0; color: var(--ink2); }

footer { margin: 56px 0 40px; border-top: 1px solid var(--hair); padding-top: 18px; color: var(--ink2); font-size: 0.85rem; max-width: 74ch; }
footer p { margin: 0 0 8px; }
.busy .result, .busy .chartcard, .busy .ledger { opacity: 0.55; transition: opacity 0.15s; }
.loading-note { color: var(--ink2); padding: 24px 0; }

@media (max-width: 960px) {
  .top-grid { grid-template-columns: 1fr; }
  .tool { position: static; }
  .plot canvas { height: 260px; }
}
@media (max-width: 480px) { .card { padding: 16px; } .stats { grid-template-columns: 1fr 1fr; } }
@media (max-width: 720px) {
  .x { display: none; }
  table { font-size: 0.82rem; }
  th, td { padding: 11px 4px; }
  th.c-date { text-align: left; padding-left: 0; }
  td:last-child, th:last-child { padding-right: 0; }
  .tablewrap { overflow-x: visible; }
  thead th { position: static; }
  th.c-date, td.c-date { position: static; }
  .c-date .d { display: none; }
  .xbtn { display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; padding: 4px 0; min-height: 36px; text-align: left; font-weight: 500; }
  .xbtn::after { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translate(-2px, -2px); transition: transform 0.15s; }
  .xbtn[aria-expanded="true"]::after { transform: rotate(225deg) translate(-2px, -2px); }
  .detail-row.open { display: table-row; }
  .detail-row td { padding-top: 0; white-space: normal; background: var(--wash); }
  .tools { margin-left: 0; width: 100%; }
  .tools .btn { flex: 1 1 auto; }
}
@media (min-width: 721px) { .detail-row { display: none !important; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .top, .tools, .presets, .tool { display: none; } }
