/* ───────────── tokens ───────────── */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --text: #141821;
  --muted: #5d6676;
  --border: #e2e6ee;
  --accent: #2f6fec;
  --accent-ink: #ffffff;
  --accent-soft: #e8f0fe;
  --hit: #fff4cc;
  --danger: #c5221f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 6px 20px rgba(16, 24, 40, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1117; --surface: #161b24; --surface-2: #1d2430; --text: #e8ebf1; --muted: #9aa4b5; --border: #283041;
    --accent: #6ea0ff; --accent-ink: #0b1020; --accent-soft: #1c2a45; --hit: #3b3420; --danger: #ff8a80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1117; --surface: #161b24; --surface-2: #1d2430; --text: #e8ebf1; --muted: #9aa4b5; --border: #283041;
  --accent: #6ea0ff; --accent-ink: #0b1020; --accent-soft: #1c2a45; --hit: #3b3420; --danger: #ff8a80;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

/* Script-specific font stacks */
:lang(zh-CN) { --font: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif; }
:lang(zh-TW) { --font: system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif; }
:lang(ja) { --font: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, "Noto Sans JP", sans-serif; }
:lang(ko) { --font: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif; }
:lang(ar) { --font: system-ui, -apple-system, "Segoe UI", Tahoma, "Geeza Pro", "Noto Sans Arabic", sans-serif; }

/* ───────────── base ───────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 80px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.25rem); letter-spacing: -.01em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { unicode-bidi: isolate; direction: ltr; font-variant-numeric: tabular-nums; }
.mono, .mono .num { font-family: var(--mono); font-size: .95em; }
[hidden] { display: none !important; }

.skip { position: absolute; inset-inline-start: 8px; top: -60px; z-index: 100; padding: 8px 14px; background: var(--accent); color: var(--accent-ink); border-radius: 8px; }
.skip:focus { top: 8px; }

.ico { width: 20px; height: 20px; flex: none; }

/* ───────────── top bar ───────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.logo { flex: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 1px solid transparent; border-radius: 10px; background: transparent; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.small { width: 30px; height: 30px; font-size: 1.2rem; }
.menu-btn { display: none; }

.search { position: relative; flex: 1; max-width: 560px; margin-inline: auto; }
.search-ico { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
#q {
  width: 100%; height: 42px; padding-inline: 40px 14px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); outline: none;
}
#q:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
#q::-webkit-search-cancel-button { cursor: pointer; }
.results {
  position: absolute; inset-inline: 0; top: calc(100% + 6px); z-index: 40;
  max-height: min(60vh, 460px); overflow: auto; margin: 0; padding: 6px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.results a { display: flex; align-items: baseline; gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--text); }
.results a:hover, .results [aria-selected="true"] a { background: var(--accent-soft); text-decoration: none; }
.results .sym { color: var(--muted); font-size: .85em; }
.results .r-cat { margin-inline-start: auto; color: var(--muted); font-size: .8rem; white-space: nowrap; }
.results .empty { padding: 10px; color: var(--muted); }

.lang { position: relative; }
.lang summary {
  display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 10px;
  border-radius: 10px; cursor: pointer; color: var(--muted); list-style: none; white-space: nowrap;
}
.lang summary::-webkit-details-marker { display: none; }
.lang summary:hover, .lang[open] summary { background: var(--surface-2); color: var(--text); }
.lang-menu {
  position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: 40; min-width: 180px;
  margin: 0; padding: 6px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.lang-menu a { display: block; padding: 7px 12px; border-radius: 8px; color: var(--text); }
.lang-menu a:hover { background: var(--surface-2); text-decoration: none; }
.lang-menu a[aria-current] { color: var(--accent); font-weight: 600; }

.ico.sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ico.sun { display: block; }
  :root:not([data-theme="light"]) .ico.moon { display: none; }
}
:root[data-theme="dark"] .ico.sun { display: block; }
:root[data-theme="dark"] .ico.moon { display: none; }

.lang-banner {
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--accent-soft); font-size: .92rem;
}

/* ───────────── layout ───────────── */
.layout {
  display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 32px;
  max-width: 1240px; margin: 0 auto; padding: 24px 16px 56px;
}
.sidebar { position: sticky; top: 78px; align-self: start; max-height: calc(100vh - 96px); overflow: auto; padding-inline-end: 4px; scrollbar-width: thin; }
.nav-group + .nav-group { margin-top: 18px; }
.nav-h { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; padding-inline: 10px; font-size: .78rem; font-weight: 700; letter-spacing: .02em; color: var(--muted); }
.nav-h .ico { width: 16px; height: 16px; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a { display: block; padding: 5px 10px; border-radius: 8px; color: var(--text); font-size: .93rem; }
.sidebar a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.scrim { display: none; }

main { min-width: 0; transition: opacity .15s; }
body.loading main { opacity: .55; }
main > section, main > aside { margin-top: 24px; }

.crumbs { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0 0 10px; padding: 0; font-size: .85rem; color: var(--muted); }
.crumbs li + li::before { content: "›"; margin-inline-end: 6px; color: var(--border); }
[dir="rtl"] .crumbs li + li::before { content: "‹"; }
.lead { color: var(--muted); font-size: 1.02rem; max-width: 72ch; margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }

/* ───────────── converter ───────────── */
.conv-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 12px; align-items: end; }
.field label { display: block; margin-bottom: 6px; font-size: .82rem; font-weight: 600; color: var(--muted); }
.box { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); overflow: hidden; transition: border-color .15s, box-shadow .15s; }
.box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.num-in { width: 100%; min-width: 0; padding: 12px 14px; border: 0; background: transparent; font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; outline: none; }
[dir="rtl"] .num-in { text-align: right; }
.num-in[aria-invalid] { color: var(--danger); }
[data-kind="base"] .num-in { font-family: var(--mono); font-size: 1.3rem; }
.box select, .field > select {
  width: 100%; padding: 10px 12px; border: 0; border-top: 1px solid var(--border); background: var(--surface); cursor: pointer;
}
.field > select { border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); padding: 12px; }
.swap {
  display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: 30px;
  border: 1px solid var(--border); border-radius: 50%; background: var(--surface); color: var(--accent); cursor: pointer;
  transition: transform .2s, background .15s;
}
.swap:hover { background: var(--accent-soft); transform: rotate(180deg); }
.err { margin: 10px 0 0; color: var(--danger); font-size: .9rem; }
.result { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--border); }
.eq { margin: 0; font-size: 1.15rem; overflow-wrap: anywhere; }
.eq strong { color: var(--accent); }
.eq.sub { margin-top: 4px; font-size: .92rem; color: var(--muted); }
.eq small { color: var(--muted); font-weight: 400; }
[dir="rtl"] .eq, [dir="rtl"] .cap { text-align: right; }
.tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 14px; }
.prec { display: flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); }
.prec select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); cursor: pointer; font-size: .9rem;
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn.done { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.btn .ico { width: 16px; height: 16px; }
.btn.small { padding: 4px 10px; }

/* size charts */
.size-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.size-out { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 16px 0 0; }
.size-out > div { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.size-out > div.sel { border-color: var(--accent); background: var(--accent-soft); }
.size-out dt { font-size: .78rem; color: var(--muted); }
.size-out dd { margin: 2px 0 0; font-size: 1.25rem; font-weight: 700; }

/* ───────────── tables ───────────── */
.cap { margin: -4px 0 10px; color: var(--muted); }
.table-wrap { overflow-x: auto; margin-inline: -4px; padding-inline: 4px; }
table { width: 100%; border-collapse: collapse; font-size: .94rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: start; vertical-align: top; }
thead th { font-size: .78rem; font-weight: 600; color: var(--muted); border-bottom-width: 2px; }
tbody th { font-weight: 500; }
.r { text-align: end; }
tbody tr:last-child > * { border-bottom: 0; }
.sym { color: var(--muted); font-size: .85em; font-weight: 400; margin-inline-start: 4px; unicode-bidi: isolate; direction: ltr; }
table.all tbody tr, table.chart tbody tr { cursor: pointer; }
table.all tbody tr:hover, table.chart tbody tr:hover { background: var(--surface-2); }
table.all tr.is-from { color: var(--muted); }
table.all tr.is-to, table.chart tr.hit { background: var(--hit); }
table.all tr.is-to td { font-weight: 700; }
table.chart { white-space: nowrap; }
table.chart td { text-align: center; }
table.chart th { text-align: center; white-space: normal; min-width: 70px; }

.ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.ref { padding: 16px; }
.ref h3 a { color: var(--text); }
.ref h3 a:hover { color: var(--accent); }
.ref td, .ref th { padding: 5px 6px; }

.note { padding: 14px 18px; border-inline-start: 4px solid var(--accent); border-radius: 10px; background: var(--accent-soft); }
.note p { margin: 4px 0 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 0; padding: 0; }
.chips a { display: inline-block; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); font-size: .9rem; }
.chips a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

/* ───────────── home ───────────── */
.hero { padding: 8px 0 4px; }
.hero h1 { margin-bottom: .3em; }
.group h2 { display: flex; align-items: center; gap: 10px; }
.group h2 .ico { color: var(--accent); }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; list-style: none; margin: 0; padding: 0; }
.cat-grid a {
  display: block; height: 100%; padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s, transform .15s;
}
.cat-grid a:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); text-decoration: none; }
.cat-grid strong { display: block; font-weight: 600; }
.cat-grid span { display: block; margin-top: 2px; color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
[dir="rtl"] .cat-grid span { text-align: right; }

/* ───────────── footer ───────────── */
.footer { border-top: 1px solid var(--border); padding: 28px 16px 40px; text-align: center; color: var(--muted); font-size: .86rem; }
.footer p { max-width: 760px; margin: 0 auto 12px; }
.foot-langs { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; list-style: none; margin: 0 0 12px; padding: 0; }
.foot-langs a { color: var(--muted); }
.footer .copy { margin: 0; }

/* ───────────── responsive ───────────── */
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding-top: 16px; }
  .menu-btn { display: inline-grid; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; inset-inline-start: 0; z-index: 50; width: min(300px, 84vw); max-height: none;
    padding: 20px 12px; background: var(--surface); border-inline-end: 1px solid var(--border);
    transform: translateX(-105%); transition: transform .22s ease;
  }
  [dir="rtl"] .sidebar { transform: translateX(105%); }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(0, 0, 0, .35); }
}
@media (max-width: 680px) {
  .topbar { flex-wrap: wrap; row-gap: 8px; padding: 8px 12px; }
  .brand { flex: 1; }
  .search { order: 5; flex-basis: 100%; max-width: none; }
  .lang summary span { display: none; }
  .layout { padding-inline: 16px; }
  .card { padding: 16px; }
  .conv-grid { grid-template-columns: minmax(0, 1fr); }
  .swap { justify-self: center; margin: -2px 0; transform: rotate(90deg); }
  .swap:hover { transform: rotate(270deg); }
  .num-in { font-size: 1.4rem; }
  .size-grid { grid-template-columns: minmax(0, 1fr); }
  .tools { justify-content: space-between; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
