:root {
  color-scheme: light;
  --bg: #f3f2ee;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #76756f;
  --line: #e6e5df;
  --line-strong: #cfcec7;
  --accent: #2a78d6;
  --accent-soft: #e4eefb;
  --series: #2a78d6;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --hl: #fff3c4;
  --flash-up: #dff3df;
  --flash-down: #f8dede;
  --shadow: 0 1px 2px rgba(20, 20, 15, 0.05), 0 8px 24px -16px rgba(20, 20, 15, 0.18);
  --radius: 14px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, ui-serif, Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #222220;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --line: #2b2b29;
    --line-strong: #44443f;
    --accent: #3987e5;
    --accent-soft: #1b2a3f;
    --series: #3987e5;
    --hl: #4a3f12;
    --flash-up: #163a16;
    --flash-down: #472020;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
}

.wrap { max-width: 980px; margin: 0 auto; padding: 20px 20px 48px; }

a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- header ---------- */

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 650; letter-spacing: -0.01em; }
.brand-dim { color: var(--text-3); font-weight: 400; }
.mark { width: 28px; height: 28px; }
.mark-bg { fill: var(--text); }
.mark-fg { fill: none; stroke: var(--surface); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.status {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--text-2); text-decoration: none; font-size: 14px;
}
.status:hover { border-color: var(--line-strong); }
.status-icon { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); flex: none; }
.status[data-state="live"] .status-icon { background: var(--good); box-shadow: 0 0 0 0 rgba(12, 163, 12, 0.5); animation: pulse 2.4s infinite; }
.status[data-state="delayed"] .status-icon,
.status[data-state="offline"] .status-icon { background: var(--warning); border-radius: 2px; transform: rotate(45deg); }
.status[data-state="down"] .status-icon { background: var(--critical); border-radius: 2px; }
.status[data-state="closed"] .status-icon { background: transparent; border: 2px solid var(--text-3); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0.45); } 70% { box-shadow: 0 0 0 7px rgba(12, 163, 12, 0); } 100% { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0); } }

/* ---------- hero ---------- */

.hero { padding: 44px 0 30px; }
.hero h1 { margin: 0 0 6px; font: italic 400 20px/1.3 var(--serif); color: var(--text-2); }
.hero-rate { margin: 0; }
.hero-num { display: inline-flex; align-items: baseline; flex-wrap: wrap; gap: 0 14px; color: var(--text); text-decoration: none; border-radius: 10px; }
.hero-num .unit { font-size: clamp(18px, 3.4vw, 28px); color: var(--text-2); font-weight: 500; }
.hero-num .big { font-size: clamp(64px, 15vw, 128px); line-height: 1; font-weight: 680; letter-spacing: -0.035em; border-radius: 12px; padding: 0 4px; margin: 0 -4px; transition: background-color 0.9s ease; }
.hero-num:hover .big { text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 0.08em; text-decoration-color: var(--accent); }
.big.up { background: var(--flash-up); transition: none; }
.big.down { background: var(--flash-down); transition: none; }
.hero-sub { margin: 10px 0 0; color: var(--text-2); font-size: 17px; }
.sep { margin: 0 6px; color: var(--text-3); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--text); text-decoration: none; font-size: 14px;
}
.chip:hover { border-color: var(--accent); }
.chip .k { color: var(--text-2); }
.chip .arrow { font-size: 11px; }
.arrow.up { color: var(--good); }
.arrow.down { color: var(--critical); }
.hint { margin: 14px 0 0; font-size: 13px; color: var(--text-3); }

.num-link { color: inherit; text-decoration: underline dotted; text-decoration-color: var(--line-strong); text-underline-offset: 0.2em; }
.num-link:hover { text-decoration-style: solid; text-decoration-color: var(--accent); }

/* ---------- cards ---------- */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-top: 18px; scroll-margin-top: 12px; }
.card h2 { margin: 0 0 14px; font-size: 18px; letter-spacing: -0.01em; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.card-head h2 { margin: 0; }
.sub { margin: 0 0 14px; color: var(--text-2); font-size: 14px; }
.note { margin: 14px 0 0; color: var(--text-3); font-size: 13px; max-width: 70ch; }
.note + .note { margin-top: 6px; }
.note[hidden] { display: none; }
.lbl { display: block; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); margin-bottom: 6px; padding: 0; }

/* ---------- converter ---------- */

.conv { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 14px; align-items: end; }
.field { display: block; min-width: 0; }
.amt, .result {
  display: flex; align-items: baseline; gap: 10px;
  height: 58px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface);
  font-size: 26px; font-weight: 600; letter-spacing: -0.01em;
}
.amt { align-items: center; }
.amt:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.amt input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: inherit; font: inherit; font-variant-numeric: tabular-nums; padding: 0; }
.amt.bad { border-color: var(--critical); }
.code { font-size: 14px; font-weight: 600; color: var(--text-2); letter-spacing: 0.03em; }
.result { align-items: center; background: var(--surface-2); border-color: var(--line); color: var(--text); text-decoration: none; overflow: hidden; }
.result:hover { border-color: var(--accent); }
#result-num { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swapbtn { width: 44px; height: 44px; margin-bottom: 7px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); cursor: pointer; display: grid; place-items: center; }
.swapbtn:hover { border-color: var(--accent); color: var(--accent); }
.swapbtn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.basis { border: 0; margin: 18px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.basis legend { float: left; margin: 0 6px 0 0; padding: 7px 0; }
.basis label { cursor: pointer; }
.basis input { position: absolute; opacity: 0; pointer-events: none; }
.basis label span { display: inline-block; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-strong); font-size: 14px; color: var(--text-2); }
.basis input:checked + span { background: var(--text); border-color: var(--text); color: var(--surface); }
.basis input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.basis input:disabled + span { opacity: 0.45; cursor: not-allowed; }
.formula { margin: 14px 0 0; font-size: 15px; color: var(--text-2); }
.formula strong { color: var(--text); font-weight: 600; }

/* ---------- official tiles ---------- */

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile { display: block; padding: 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); text-decoration: none; min-width: 0; }
.tile:hover { border-color: var(--accent); }
.tile .t-label { font-size: 13px; color: var(--text-2); }
.tile .t-value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; margin: 2px 0; }
.tile .t-meta { font-size: 12px; color: var(--text-3); overflow-wrap: anywhere; }
.tile.off .t-value { color: var(--text-3); }

/* ---------- history ---------- */

.tabs { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.tabs button { border: 0; background: transparent; color: var(--text-2); font: inherit; font-size: 14px; font-weight: 550; padding: 5px 12px; border-radius: 7px; cursor: pointer; }
.tabs button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.tabs button:disabled { opacity: 0.4; cursor: not-allowed; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 8px; }
.stat { text-align: left; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; min-width: 0; }
.stat:hover { border-color: var(--accent); }
.stat .s-label { display: block; font-size: 12px; color: var(--text-2); }
.stat .s-value { display: block; font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
.stat .s-meta { display: block; font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chart { position: relative; margin-top: 6px; min-height: 240px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; cursor: crosshair; border-radius: 8px; }
.chart-empty { margin: 0; padding: 90px 0; text-align: center; color: var(--text-3); }
.c-grid { stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
.c-axis { fill: var(--text-3); font: 11px var(--sans); font-variant-numeric: tabular-nums; }
.c-line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-end { fill: var(--text); font: 600 12px var(--sans); font-variant-numeric: tabular-nums; }
.c-end-dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.c-cross { stroke: var(--text-3); stroke-width: 1; shape-rendering: crispEdges; }
.c-dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.tip { position: absolute; top: 8px; left: 0; pointer-events: none; z-index: 2; padding: 8px 10px; border-radius: 8px; background: var(--text); color: var(--surface); font-size: 12px; line-height: 1.35; white-space: nowrap; box-shadow: 0 6px 20px -8px rgba(0, 0, 0, 0.5); }
.tip strong { display: block; font-size: 16px; font-weight: 650; }
.tip .tip-dim { opacity: 0.7; }

.table-title { margin: 18px 0 8px; font-size: 13px; font-weight: 600; color: var(--text-2); }

/* ---------- tables ---------- */

.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.tablewrap.tall { max-height: 380px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.st { white-space: normal; min-width: 104px; }
#src { font-size: 13.5px; }
#src tfoot td { white-space: normal; }
thead th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--text-2); letter-spacing: 0.02em; }
tbody th { font-weight: 550; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
tfoot td, tfoot th { border-top: 1px solid var(--line-strong); border-bottom: 0; background: var(--surface-2); font-weight: 600; }
.r { text-align: right; }
td.dim, .dim { color: var(--text-3); }
td a { color: inherit; text-decoration: underline dotted; text-decoration-color: var(--line-strong); text-underline-offset: 0.2em; }
td a:hover { text-decoration-style: solid; text-decoration-color: var(--accent); }
tr.unused td, tr.unused th { color: var(--text-3); }
.src-name { display: block; }
.src-kind { display: block; font-size: 12px; font-weight: 400; color: var(--text-3); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.badge.ok::before { background: var(--good); }
.badge.warn::before { background: var(--warning); border-radius: 2px; transform: rotate(45deg); }
.badge.bad::before { background: var(--critical); border-radius: 2px; }
.badge.info::before { background: transparent; border: 2px solid var(--text-3); }

.hl, tr.hl > td, tr.hl > th { background-color: var(--hl) !important; }
tr > td, tr > th, .card, .tile, .stat { transition: background-color 0.6s ease; }

/* ---------- about + footer ---------- */

.about ul { margin: 0; padding-left: 20px; color: var(--text-2); max-width: 75ch; }
.about li { margin: 6px 0; }
.about strong { color: var(--text); }
.foot { display: flex; flex-wrap: wrap; gap: 6px 20px; justify-content: space-between; margin-top: 22px; color: var(--text-3); font-size: 13px; }

/* ---------- small screens ---------- */

@media (max-width: 760px) {
  .wrap { padding: 14px 14px 36px; }
  .hero { padding: 30px 0 22px; }
  .card { padding: 16px; }
  .tiles, .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .conv { grid-template-columns: minmax(0, 1fr); }
  .swapbtn { margin: 0 auto; transform: rotate(90deg); }
  .amt, .result { font-size: 22px; }
}
