:root {
  --bg: #fbf7f2;
  --surface: #ffffff;
  --text: #2a2320;
  --muted: #675b54;
  --accent: #a8481f;
  --accent-soft: #f6e3d6;
  --accent-ink: #ffffff;
  --border: #e4d8ce;
  --result-bg: #fff6ee;
  --error: #a3222a;
  --radius: 12px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1816;
    --surface: #25201d;
    --text: #f1e9e2;
    --muted: #bcaea4;
    --accent: #ef9468;
    --accent-soft: #3b2a21;
    --accent-ink: #1b1816;
    --border: #3d342e;
    --result-bg: #2c231e;
    --error: #ff8a8f;
    color-scheme: dark;
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.6;
}

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

a:hover {
  text-decoration-thickness: 2px;
}

img,
svg {
  max-width: 100%;
}

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

.skip {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 8px 12px;
  z-index: 10;
}

.skip:focus {
  left: 8px;
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
  padding-top: 12px;
  padding-bottom: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--text);
  text-decoration: none;
}

.brand svg {
  width: 28px;
  height: 28px;
}

.site-header nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-header nav a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.site-header nav a:hover,
.site-header nav a[aria-current='page'] {
  color: var(--accent);
  text-decoration: underline;
}

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

h1 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  line-height: 1.2;
  margin: 0.4em 0 0.3em;
}

h2 {
  font-size: 1.35rem;
  line-height: 1.3;
  margin: 1.8em 0 0.5em;
}

h3 {
  font-size: 1.1rem;
  margin: 1.4em 0 0.4em;
}

.lede {
  font-size: 1.15rem;
  color: var(--muted);
  margin-top: 0;
  max-width: 44rem;
}

.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.breadcrumbs li + li::before {
  content: '›';
  margin-right: 4px;
}

.breadcrumbs a {
  color: var(--muted);
}

/* Calculator card */
.calc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 20px 0;
}

.calc fieldset {
  border: 0;
  margin: 0 0 16px;
  padding: 0;
  min-width: 0;
}

.calc .spaced {
  margin-top: 16px;
}

.calc legend {
  font-weight: 700;
  margin-bottom: 8px;
  padding: 0;
}

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 14px 18px;
}

.field label,
.field .label {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.field .hint {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}

input[type='number'],
input[type='text'],
select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  min-height: 44px;
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choices label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  background: var(--bg);
  font-weight: 500;
  min-height: 40px;
}

.choices input {
  accent-color: var(--accent);
}

.choices label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.inline-unit {
  display: flex;
  gap: 8px;
}

.inline-unit select {
  width: auto;
  flex: 0 0 auto;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

button {
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  padding: 9px 16px;
  min-height: 44px;
  cursor: pointer;
}

button.secondary {
  background: transparent;
  color: var(--accent);
}

/* Results */
.result {
  background: var(--result-bg);
  border: 1px solid var(--border);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 20px 0;
}

.result:empty {
  display: none;
}

.result h2 {
  margin-top: 0;
  font-size: 1.4rem;
}

.big {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.3;
  margin: 4px 0 8px;
}

.counter-wrap {
  margin: 20px 0;
}

.instruction {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 6px 0 8px;
  overflow-wrap: anywhere;
}

.error {
  color: var(--error);
  font-weight: 600;
  margin: 0;
}

.small,
.muted {
  font-size: 0.9rem;
  color: var(--muted);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  margin: 12px 0;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.95rem;
  background: var(--surface);
}

th,
td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-weight: 700;
  /* Headings may wrap on narrow screens; the values stay on one line. */
  white-space: normal;
  vertical-align: bottom;
}

tr.highlight td {
  background: var(--accent-soft);
  font-weight: 600;
}

/* Article text under a calculator */
.explain {
  max-width: 44rem;
}

.explain li {
  margin-bottom: 0.3em;
}

.formula {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  overflow-x: auto;
}

/* Tool lists */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 14px;
  list-style: none;
  margin: 14px 0 28px;
  padding: 0;
}

.tool-card {
  display: block;
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--text);
  text-decoration: none;
}

.tool-card:hover {
  border-color: var(--accent);
}

.tool-card strong {
  display: block;
  color: var(--accent);
  margin-bottom: 4px;
}

.tool-card span {
  font-size: 0.93rem;
  color: var(--muted);
}

.related {
  margin-top: 40px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.meta-line {
  font-size: 0.85rem;
  color: var(--muted);
}

/* Row counter */
.counter {
  text-align: center;
}

.counter-value {
  font-size: clamp(3.5rem, 18vw, 6rem);
  font-weight: 800;
  line-height: 1;
  margin: 8px 0 16px;
  font-variant-numeric: tabular-nums;
}

.counter-buttons {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.counter-buttons button {
  font-size: 1.6rem;
  min-width: 88px;
  min-height: 64px;
}

.counter-list {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
}

.counter-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.counter-card input[type='text'] {
  text-align: center;
  font-weight: 600;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 20px 0 28px;
  font-size: 0.93rem;
  color: var(--muted);
}

.site-footer p {
  margin: 4px 0;
}

@media (max-width: 520px) {
  .calc {
    padding: 16px;
  }

  .result {
    padding: 14px 16px;
  }
}

@media print {
  .site-header,
  .site-footer,
  .calc .actions,
  .related {
    display: none;
  }
}
