:root {
  color-scheme: light dark;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-soft: #eef2fa;
  --text: #1b2333;
  --muted: #5b6577;
  --accent: #2f5bd3;
  --accent-soft: #dbe5ff;
  --border: #ccd5e4;
  --error: #b3261e;
  --error-soft: #fdeceb;
  --shadow: 0 18px 40px rgba(27, 35, 51, 0.08);
  --radius: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121620;
    --surface: #1b2130;
    --surface-soft: #232b3d;
    --text: #eef2fb;
    --muted: #a7b1c4;
    --accent: #8fb0ff;
    --accent-soft: #2b3a61;
    --border: #3a455c;
    --error: #ffb4ab;
    --error-soft: #44201d;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: clamp(1rem, 4vw, 3rem) 1rem 2rem;
  background:
    radial-gradient(circle at 15% 0%, var(--accent-soft), transparent 32rem),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.55;
}

.page-header,
main,
.page-footer {
  width: min(100%, 60rem);
  margin-inline: auto;
}

.page-header {
  margin-bottom: 1.5rem;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  line-height: 1.2;
}

h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(2rem, 5vw, 2.9rem);
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.lead {
  max-width: 45rem;
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.lead strong {
  color: var(--text);
  white-space: nowrap;
}

.calculator {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 1rem;
  margin: 0;
}

.control {
  min-width: 0;
  margin: 0;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.control legend {
  padding: 0 0.4rem;
  font-weight: 700;
  font-size: 1.05rem;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}

.control-row label {
  color: var(--muted);
  font-size: 0.95rem;
}

.input-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

input[type="number"] {
  width: 8rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

input[type="number"]:focus-visible,
input[type="range"]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

input[type="number"][aria-invalid="true"] {
  border-color: var(--error);
  background: var(--error-soft);
}

.unit {
  min-width: 2rem;
  color: var(--muted);
  font-size: 0.95rem;
}

input[type="range"] {
  display: block;
  width: 100%;
  height: 1.5rem;
  margin: 0.25rem 0 0.5rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.result-card {
  margin-top: 1rem;
  padding: 1.35rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.result {
  display: block;
  margin: 0;
  color: var(--accent);
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.result.is-empty {
  color: var(--muted);
}

.details {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.error {
  margin: 0.9rem 0 0;
  padding: 0.75rem 0.9rem;
  border-left: 4px solid var(--error);
  border-radius: 8px;
  background: var(--error-soft);
  color: var(--error);
  font-weight: 600;
}

.error[hidden] {
  display: none;
}

.theory {
  margin-top: 1rem;
  padding: 1.35rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.theory p {
  margin: 0 0 0.75rem;
  color: var(--muted);
}

.theory p:last-child {
  margin-bottom: 0;
}

.theory strong {
  color: var(--text);
}

.page-footer {
  margin-top: 1.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.page-footer p {
  margin: 0;
}

.noscript {
  width: min(100% - 2rem, 60rem);
  margin: 1rem auto 0;
  padding: 1rem;
  border-left: 4px solid var(--error);
  border-radius: 8px;
  background: var(--error-soft);
  color: var(--error);
}

@media (max-width: 30rem) {
  .control-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .input-wrap,
  input[type="number"] {
    width: 100%;
  }
}
