:root {
  color-scheme: dark;
  --bg: #0a0c12;
  --bg-alt: #0f1219;
  --panel: #141824;
  --panel-2: #1a1f2e;
  --line: #242b3d;
  --line-2: #2f3850;
  --text: #e6ebf5;
  --muted: #8f9ab5;
  --faint: #5c6780;
  --brand: #4f8cff;
  --brand-2: #7c5cff;
  --brand-3: #00d4a0;
  --warn: #ffb020;
  --error: #ff5c7a;
  --ok: #34d399;
  --radius: 14px;
  --radius-sm: 9px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code", Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --shadow: 0 10px 30px -12px rgb(0 0 0 / 0.6);
  --max: 1200px;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f8fc;
  --bg-alt: #eef2f9;
  --panel: #ffffff;
  --panel-2: #f4f7fc;
  --line: #dfe5ef;
  --line-2: #cbd5e6;
  --text: #101728;
  --muted: #5a6580;
  --faint: #8b95ab;
  --brand: #2563eb;
  --brand-2: #6d40f5;
  --brand-3: #00916d;
  --shadow: 0 10px 30px -14px rgb(16 24 40 / 0.18);
}

* { box-sizing: border-box; }

/* `hidden` must win over the layout `display` values set on components below. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background:
    radial-gradient(1100px 620px at 82% -12%, color-mix(in oklab, var(--brand-2) 20%, transparent), transparent 62%),
    radial-gradient(900px 520px at 8% 0%, color-mix(in oklab, var(--brand) 16%, transparent), transparent 58%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100dvh;
  overflow-wrap: break-word;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }

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

.wrap { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 clamp(14px, 3vw, 28px); }

/* ── header ─────────────────────────────────────────────────────────────── */

.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in oklab, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  display: flex; align-items: center; gap: 14px;
  min-height: 62px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -0.02em; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  font: 800 15px/1 var(--mono);
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; box-shadow: 0 4px 14px -4px var(--brand);
}
.brand-name { font-size: 17px; }
.brand-name small { display: block; font-size: 10.5px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }

.nav-toggle {
  margin-left: auto; display: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; cursor: pointer;
}
.nav-toggle span { display: block; width: 18px; height: 2px; background: var(--text); border-radius: 2px; }
.nav-toggle span + span { margin-top: 4px; }

.site-nav { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.site-nav a {
  padding: 7px 11px; border-radius: 9px; color: var(--muted);
  font-size: 14px; font-weight: 600; white-space: nowrap;
}
.site-nav a:hover, .site-nav a[aria-current="page"] {
  background: var(--panel); color: var(--text); text-decoration: none;
}

@media (max-width: 860px) {
  .nav-toggle { display: block; }
  .site-nav {
    position: fixed; inset: 62px 0 auto 0; flex-direction: column; align-items: stretch;
    background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px; gap: 2px;
    max-height: calc(100dvh - 62px); overflow: auto;
  }
  .site-nav[hidden] { display: none; }
}

/* ── layout ─────────────────────────────────────────────────────────────── */

main { padding: clamp(18px, 3vw, 34px) 0 60px; }

.page-head { margin-bottom: 22px; }
.page-head h1 {
  margin: 0 0 8px; font-size: clamp(24px, 4.4vw, 36px);
  letter-spacing: -0.03em; line-height: 1.14;
}
.page-head p { margin: 0; color: var(--muted); max-width: 70ch; }

.crumbs { font-size: 13px; color: var(--faint); margin-bottom: 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs a { color: var(--muted); }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

/* ── panel ──────────────────────────────────────────────────────────────── */

.panel {
  background: color-mix(in oklab, var(--panel) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(14px, 2.2vw, 20px);
  box-shadow: var(--shadow);
}
.panel > h2, .panel > h3 { margin-top: 0; letter-spacing: -0.015em; }
.panel-title {
  display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.09em; color: var(--faint); margin: 0 0 12px;
}

/* ── converter ──────────────────────────────────────────────────────────── */

.conv-controls {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field-label {
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--faint);
}
.input, .select, .textarea {
  width: 100%; background: var(--bg-alt); border: 1px solid var(--line-2);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 15px;
  transition: border-color 0.14s, box-shadow 0.14s;
  min-width: 0;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in oklab, var(--brand) 22%, transparent); outline: none;
}
.textarea {
  font-family: var(--mono); font-size: 14px; line-height: 1.6;
  min-height: 120px; resize: vertical; tab-size: 4;
}
.input[readonly], .textarea[readonly] { background: color-mix(in oklab, var(--panel-2) 80%, transparent); }
.mono { font-family: var(--mono); }

.panes { display: grid; gap: 14px; grid-template-columns: 1fr auto 1fr; align-items: stretch; }
@media (max-width: 820px) { .panes { grid-template-columns: 1fr; } }

.swap-col { display: grid; place-items: center; }
@media (max-width: 820px) { .swap-col { order: -1; } }

.swap-btn {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--panel-2); border: 1px solid var(--line-2); cursor: pointer;
  display: grid; place-items: center; font-size: 17px; color: var(--text);
  transition: transform 0.18s, background 0.18s, border-color 0.18s;
}
.swap-btn:hover { background: var(--brand); border-color: var(--brand); color: #fff; transform: rotate(180deg); }
@media (max-width: 820px) { .swap-btn { width: 100%; height: 38px; border-radius: var(--radius-sm); } }

.pane { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pane-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--faint); }

.pane-output .textarea {
  flex: 1; min-height: 132px;
  background: linear-gradient(180deg, color-mix(in oklab, var(--brand) 7%, var(--bg-alt)), var(--bg-alt));
  border-color: color-mix(in oklab, var(--brand) 26%, var(--line-2));
}

.drop-hint { border: 2px dashed transparent; transition: border-color 0.15s, background 0.15s; border-radius: var(--radius-sm); }
.drop-hint.over { border-color: var(--brand); background: color-mix(in oklab, var(--brand) 10%, transparent); }

/* ── buttons ────────────────────────────────────────────────────────────── */

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; align-items: center; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  font-size: 14px; font-weight: 600; white-space: nowrap;
  transition: background 0.14s, border-color 0.14s, transform 0.08s;
}
.btn:hover { background: var(--line); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border-color: transparent; color: #fff;
}
.btn-primary:hover { filter: brightness(1.08); background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.btn-ghost { background: transparent; }
.btn-icon { padding: 9px 10px; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── stats ──────────────────────────────────────────────────────────────── */

.stats { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.stat {
  display: flex; flex-direction: column; gap: 1px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 12px; min-width: 84px;
}
.stat b { font-size: 16px; font-family: var(--mono); letter-spacing: -0.02em; }
.stat span { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--faint); }

/* ── table ──────────────────────────────────────────────────────────────── */

.table-scroll { overflow: auto; max-height: 62vh; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 7px 11px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--panel-2); font-size: 11.5px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--faint);
}
tbody tr:hover { background: color-mix(in oklab, var(--brand) 7%, transparent); }
td.mono, th.mono { font-family: var(--mono); }
.cell-char { font-family: var(--mono); font-weight: 700; }

.sticky-head { position: sticky; top: 62px; z-index: 20; }

/* ── chips / tags ───────────────────────────────────────────────────────── */

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12.5px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.chip:hover { color: var(--text); border-color: var(--line-2); text-decoration: none; }
.chip b { color: var(--text); font-family: var(--mono); font-weight: 600; }
.chip-accent { border-color: color-mix(in oklab, var(--brand) 45%, var(--line)); color: var(--brand); }

/* ── alerts ─────────────────────────────────────────────────────────────── */

.alert {
  border-radius: var(--radius-sm); padding: 10px 13px; font-size: 14px;
  border: 1px solid var(--line-2); background: var(--panel-2); margin-top: 12px;
}
.alert-error { border-color: color-mix(in oklab, var(--error) 50%, var(--line)); color: var(--error); background: color-mix(in oklab, var(--error) 10%, transparent); }
.alert-ok { border-color: color-mix(in oklab, var(--ok) 45%, var(--line)); color: var(--ok); }
.alert-info { color: var(--muted); }

.toast-host { position: fixed; right: 14px; bottom: 14px; z-index: 100; display: grid; gap: 8px; }
.toast {
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px;
  padding: 10px 14px; font-size: 14px; box-shadow: var(--shadow);
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ── steps ──────────────────────────────────────────────────────────────── */

.steps {
  font-family: var(--mono); font-size: 13px; line-height: 1.75;
  background: var(--bg-alt); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 14px; overflow: auto; max-height: 320px;
  white-space: pre-wrap; word-break: break-word;
}
.steps:empty::before { content: 'Results and working appear here.'; color: var(--faint); }

.result-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.result {
  background: var(--bg-alt); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 12px; display: flex;
  flex-direction: column; gap: 2px; min-width: 0;
}
.result-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); }
.result-value { font-family: var(--mono); font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.result-value + .result-unit { font-size: 11.5px; color: var(--faint); font-family: var(--mono); }

/* ── tool catalogue ─────────────────────────────────────────────────────── */

.tool-card {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; color: var(--text);
  transition: border-color 0.15s, transform 0.15s;
}
.tool-card:hover { border-color: var(--brand); transform: translateY(-2px); text-decoration: none; }
.tool-card h3 { margin: 0; font-size: 15.5px; letter-spacing: -0.01em; }
.tool-card p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.45; }

.search-box { position: relative; margin: 18px 0; }
.search-box .input { padding-left: 38px; font-size: 16px; }
.search-box::before {
  content: "⌕"; position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--faint); font-size: 19px; pointer-events: none;
}

/* ── family pair grid ───────────────────────────────────────────────────── */

.pair-table { width: 100%; font-size: 13.5px; }
.pair-table td { white-space: nowrap; }
.pair-table .unit-link { font-family: var(--mono); font-size: 12.5px; }

.inline-fieldset { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.inline-fieldset .field { flex: 1 1 140px; }

.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); }

details.disclosure { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel-2); margin-top: 14px; }
details.disclosure > summary {
  cursor: pointer; padding: 11px 14px; font-weight: 600; font-size: 14px;
  list-style: none; display: flex; align-items: center; justify-content: space-between;
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::after { content: "+"; color: var(--faint); font-size: 18px; }
details.disclosure[open] > summary::after { content: "−"; }
details.disclosure > .disclosure-body { padding: 0 14px 14px; }

/* ── footer ─────────────────────────────────────────────────────────────── */

.site-footer {
  border-top: 1px solid var(--line); background: var(--bg-alt);
  padding: 26px 0; margin-top: 40px; font-size: 14px; color: var(--muted);
}
.footer-grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.footer-grid h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); }
.footer-grid ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.footer-grid a { color: var(--muted); }
.footer-bottom { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--faint); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skeleton {
  background: linear-gradient(90deg, var(--panel-2) 25%, var(--line) 50%, var(--panel-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 6px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

@media print {
  .site-header, .site-footer, .btn-row, .swap-col, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .panel { border: 1px solid #ccc; box-shadow: none; }
}
