:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --ink: #17201d;
  --muted: #5b6763;
  --line: #dfe4e1;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3f0;
  --warm: #c2410c;
  --warm-soft: #fbe9df;
  --focus: #2563eb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 4px 16px rgba(16, 24, 22, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1413;
    --surface: #171e1c;
    --ink: #e7ecea;
    --muted: #9aa7a2;
    --line: #2a3431;
    --accent: #2dd4bf;
    --accent-ink: #062b27;
    --accent-soft: #123a35;
    --warm: #fb923c;
    --warm-soft: #3a2316;
    --focus: #93c5fd;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }

.skip {
  position: absolute; left: 8px; top: -60px; z-index: 10;
  background: var(--surface); color: var(--ink); padding: 8px 12px; border-radius: 8px;
}
.skip:focus { top: 8px; }

/* Header */
.top { background: var(--surface); border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; }
.brand-mark { width: 30px; height: 30px; fill: var(--accent); flex: none; }
.brand-mark .bm-screen, .brand-mark .bm-key { fill: var(--accent-ink); }
.brand-mark .bm-accent { fill: #fbbf24; }
.lang { font-size: .95rem; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; color: var(--ink); }
.lang:hover { border-color: var(--accent); }

.nav { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  flex: none; padding: 7px 12px; border-radius: 999px; text-decoration: none;
  color: var(--muted); font-weight: 500; white-space: nowrap;
}
.nav a:hover { color: var(--ink); background: var(--bg); }
.nav a[aria-current="page"] { color: var(--accent-ink); background: var(--accent); }

main { padding-top: 20px; padding-bottom: 40px; }

.crumbs { font-size: .9rem; color: var(--muted); margin: 0 0 8px; }
.crumbs ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs li + li::before { content: "/"; margin-right: 6px; color: var(--line); }
.crumbs a { color: var(--muted); }

.hero { margin: 8px 0 20px; }
.hero h1 { font-size: clamp(1.6rem, 4.5vw, 2.4rem); line-height: 1.15; margin: 0 0 10px; letter-spacing: -.02em; }
.lead { font-size: 1.08rem; color: var(--muted); margin: 0; max-width: 68ch; }

.section-h { font-size: 1.2rem; margin: 28px 0 12px; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin: 0 0 16px;
}
.card > h2:first-child { margin-top: 0; font-size: 1.15rem; }

.tiles { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: 1fr; }
.tile {
  display: flex; flex-direction: column; gap: 6px; height: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.tile:hover { border-color: var(--accent); transform: translateY(-1px); }
.tile strong { font-size: 1.05rem; }
.tile span:not(.tile-icon) { color: var(--muted); font-size: .95rem; }
.tile-icon {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 1.3rem; font-weight: 700;
}
.tiles-compact { margin-top: 24px; }

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips a {
  display: inline-block; padding: 7px 12px; border-radius: 999px; background: var(--surface);
  border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-size: .95rem;
}
.chips a:hover { border-color: var(--accent); color: var(--accent); }
.chips a[aria-current="page"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chips small { color: var(--muted); }

/* Form controls */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin: 0; }
.field > label, .field > legend { font-size: .9rem; color: var(--muted); font-weight: 500; }
input[type="text"], input[type="date"], select {
  width: 100%; min-height: 46px; padding: 10px 12px; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
input[type="date"] { min-width: 0; }
input:hover, select:hover { border-color: var(--muted); }
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
input[aria-invalid="true"] { border-color: var(--warm); box-shadow: 0 0 0 3px var(--warm-soft); }
.num { text-align: right; }

.pair { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.pair select { width: auto; }

.form-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
fieldset.radios { border: 0; padding: 0; gap: 8px; }
.radios label, .check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.radios input, .check input { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--accent); flex: none; }
.check { margin-top: 12px; }

.msg { color: var(--warm); margin: 12px 0 0; font-weight: 500; }

/* Converter */
.conv-grid { display: grid; gap: 12px; grid-template-columns: 1fr; align-items: end; }
.conv-value input { font-size: 1.1rem; padding-top: 8px; padding-bottom: 8px; }
.swap {
  justify-self: center; width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg); color: var(--accent);
  font-size: 1.3rem; cursor: pointer;
}
.swap:hover { border-color: var(--accent); }
.result-big {
  display: block; margin-top: 16px; padding: 14px 16px; border-radius: 12px;
  background: var(--accent-soft); color: var(--ink); font-size: 1.35rem; font-weight: 650;
  overflow-wrap: anywhere; min-height: 1.5em;
}
.result-big:empty { display: none; }

/* Tables */
.tbl-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .95rem; }
.tbl th, .tbl td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.tbl .r { text-align: right; white-space: nowrap; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl-num td { white-space: nowrap; }
.tbl tr.hl td { background: var(--accent-soft); }
.tbl td small { color: var(--muted); }

/* Percent cards */
.pc-grid { display: grid; gap: 14px; grid-template-columns: 1fr; margin-bottom: 16px; }
.pc-grid .card { margin: 0; }
.sentence { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; }
.sentence span:empty { display: none; }
.sentence input { width: 9.5em; }
.sentence input.short { width: 5.5em; }
.sentence select { width: auto; }
.answer { margin: 14px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 1.1rem; }
.answer span { color: var(--muted); font-size: .95rem; }
.answer output { font-weight: 650; }

/* Summary */
.summary { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; margin-top: 18px; }
.stat { background: var(--bg); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat span { color: var(--muted); font-size: .88rem; }
.stat output { font-size: 1.15rem; font-weight: 650; overflow-wrap: anywhere; }
.stat-main { grid-column: 1 / -1; background: var(--accent-soft); }
.stat-main output { font-size: 1.6rem; }

.split { display: flex; height: 10px; border-radius: 999px; overflow: hidden; margin-top: 16px; background: var(--line); }
.split-a { background: var(--accent); }
.split-b { background: var(--warm); }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: .9rem; color: var(--muted); margin: 8px 0 0; }
.legend output { color: var(--ink); font-weight: 600; }
.leg { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; margin-right: 10px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-a { background: var(--accent); }
.dot-b { background: var(--warm); }

details.sched { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
details.sched summary { cursor: pointer; font-weight: 600; color: var(--accent); }
details.sched[open] summary { margin-bottom: 8px; }
.more { margin-top: 10px; font: inherit; color: var(--accent); background: none; border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; cursor: pointer; }

/* Dates */
.two-col { display: grid; gap: 16px; grid-template-columns: 1fr; margin-bottom: 16px; }
.two-col .card { margin: 0; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.facts { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 14px; margin: 14px 0 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; text-align: right; white-space: nowrap; }

/* Prose */
.prose { max-width: none; }
.prose h1 { font-size: clamp(1.6rem, 4.5vw, 2.2rem); margin: 0 0 12px; }
.prose h2 { font-size: 1.15rem; margin: 22px 0 8px; }
.prose h2:first-child { margin-top: 0; }
.prose p, .prose li { max-width: 72ch; }
.prose ul { padding-left: 1.2em; }
.prose li { margin: 4px 0; }

.btn { display: inline-block; background: var(--accent); color: var(--accent-ink); text-decoration: none; padding: 10px 18px; border-radius: 999px; font-weight: 600; margin-top: 12px; }
.code-404 { font-size: 4.5rem; font-weight: 800; color: var(--accent); margin: 0; line-height: 1; letter-spacing: -.04em; }

/* Footer */
.foot { border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: .9rem; }
.foot-row { padding-top: 18px; padding-bottom: 24px; }
.foot p { margin: 4px 0; }
.foot a { color: var(--muted); }

@media (min-width: 640px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .radios { grid-column: 1 / -1; }
  .conv-grid { grid-template-columns: 1fr 1fr auto 1fr; }
  .conv-value { grid-column: 1 / -1; }
  .summary { grid-template-columns: repeat(3, 1fr); }
  .stat-main { grid-column: auto; }
  .summary-4 { grid-template-columns: 1fr 1fr; }
  .card { padding: 22px; }
}

@media (min-width: 900px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .pc-grid { grid-template-columns: 1fr 1fr; }
  .two-col { grid-template-columns: 1fr 1fr; }
  .conv-grid { grid-template-columns: 1.2fr 1fr auto 1fr; }
  .conv-value { grid-column: auto; }
  .summary-4 { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media print {
  .top, .foot, .swap, .skip { display: none; }
  .card { box-shadow: none; }
  details.sched { display: block; }
}
