:root {
  --bg: #f7f5ff;
  --surface: #ffffff;
  --text: #1e1b4b;
  --muted: #54627a;
  --accent: #7c3aed;
  --accent-dark: #6d28d9;
  --soft: #ede9fe;
  --border: #e2e8f0;
  --danger: #9f1239;
  --danger-bg: #fff1f2;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(30, 27, 75, 0.08);
  --nav-h: 64px;
  --pad: 18px;
  color-scheme: light;
}

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

html {
  scroll-padding-top: calc(var(--nav-h) + env(safe-area-inset-top) + 8px);
}

body.menu-open {
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  overflow-wrap: break-word;
}

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

.wrap,
.stack,
.card,
.hero,
.hero > *,
.field,
.tool,
.prose,
.metrics > div {
  min-width: 0;
}

.wrap {
  width: 100%;
  max-width: 1100px;
  margin-inline: auto;
  padding-left: calc(var(--pad) + env(safe-area-inset-left));
  padding-right: calc(var(--pad) + env(safe-area-inset-right));
}

.skip {
  position: absolute;
  left: calc(var(--pad) + env(safe-area-inset-left));
  top: calc(8px + env(safe-area-inset-top));
  z-index: 90;
  padding: 10px 14px;
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  transform: translateY(-150%);
}

.skip:focus {
  transform: none;
}

/* Do not add transform, filter, perspective, or will-change on header, body, or .wrap.
   #site-menu uses position:fixed and must stay attached to the viewport. */
.site-header {
  position: sticky;
  top: 0;
  z-index: 80;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.header-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--nav-h);
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.logo::before {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 5px;
  background: var(--accent);
  flex: none;
}

.menu-toggle {
  margin-left: auto;
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
}

.burger {
  display: grid;
  gap: 5px;
}

.burger span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
}

.primary-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.primary-nav a,
.footer-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.primary-nav a[aria-current="page"],
.footer-nav a[aria-current="page"] {
  background: var(--soft);
  color: var(--accent-dark);
  font-weight: 800;
}

.no-js .menu-toggle {
  display: none;
}

main {
  padding-top: 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.stack {
  display: grid;
  gap: 16px;
}

.hero {
  display: grid;
  gap: 16px;
}

.hero-copy h1,
.page-intro h1,
.prose h1 {
  margin: 0 0 8px;
  font-size: 1.75rem;
  line-height: 1.2;
  font-weight: 800;
}

.lead {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.5;
}

.hero-actions,
.form-actions {
  display: grid;
  gap: 10px;
}

.hero-actions {
  margin-top: 12px;
}

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

.tool {
  padding: 16px;
}

.disclosure {
  padding: 0;
}

.disclosure summary {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 12px 16px;
  font-weight: 700;
  cursor: pointer;
}

.disclosure .prose {
  padding: 0 16px 16px;
}

.tool h2,
.prose h2,
.page-intro + .card h2 {
  margin: 0 0 12px;
  font-size: 1.25rem;
  line-height: 1.3;
}

.tool-form {
  display: grid;
  gap: 20px;
  max-width: 640px;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

legend {
  margin: 0 0 8px;
  padding: 0;
  font-weight: 800;
}

.choices,
.dimensions,
.presets {
  display: grid;
  gap: 10px;
}

.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
}

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

.choice input {
  width: 1.15rem;
  height: 1.15rem;
  min-height: 0;
  margin: 0;
  accent-color: var(--accent);
}

.choice input:focus {
  outline: none;
}

.choice:focus-within {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.field label {
  display: block;
  margin: 0 0 6px;
  font-weight: 700;
}

.text-input {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.text-input[aria-invalid="true"] {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.help,
.field .error {
  margin: 6px 0 0;
  font-size: 0.95rem;
}

.help {
  color: var(--muted);
}

.field .error {
  color: var(--danger);
  font-weight: 700;
}

.presets {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 12px;
}

.preset,
.btn {
  min-height: 48px;
  min-width: 48px;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.preset {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
}

.preset[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--soft);
  color: var(--accent-dark);
  font-weight: 800;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  text-decoration: none;
  text-align: center;
  border: 2px solid transparent;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-secondary {
  background: var(--surface);
  color: var(--accent-dark);
  border-color: var(--accent);
}

.btn:active,
.preset:active,
.choice:active,
.menu-toggle:active {
  opacity: 0.88;
}

.error-summary {
  padding: 12px 14px;
  border: 1px solid #fecdd3;
  border-left: 4px solid var(--danger);
  border-radius: 12px;
  background: var(--danger-bg);
}

.error-summary p {
  margin: 0 0 8px;
  font-weight: 800;
}

.error-summary ul {
  margin: 0;
  padding-left: 1.15rem;
}

.error-summary a {
  color: var(--danger);
  font-weight: 700;
}

.results h3,
.results h4 {
  margin: 0 0 8px;
  line-height: 1.3;
}

.results h3 {
  font-size: 1.15rem;
}

.results h4 {
  margin-top: 16px;
  font-size: 1.05rem;
}

#results-empty {
  margin: 0;
  color: var(--muted);
}

#out-summary,
.bag-line,
#out-raw,
.caveat,
.callout {
  margin: 0 0 10px;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 0 0 12px;
}

.metrics > div {
  padding: 12px;
  border-radius: 12px;
  background: var(--soft);
}

.metrics dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.metrics dd {
  margin: 4px 0 0;
  font-size: 1.35rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.callout {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--soft);
}

.prose p,
.prose li {
  margin: 0 0 10px;
}

.prose :last-child {
  margin-bottom: 0;
}

.steps,
.feature-list {
  display: grid;
  gap: 12px;
}

.steps {
  margin: 0;
  padding-left: 1.25rem;
}

.feature-list {
  gap: 16px;
}

.feature-list h3,
.prose h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding-top: 20px;
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
}

.footer-brand {
  margin: 0 0 8px;
  font-weight: 800;
}

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

.disclaimer {
  color: var(--muted);
}

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
}

.email-link {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  font-weight: 800;
  color: var(--accent-dark);
}

.noscript-card p {
  margin: 0;
}

.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;
}

input,
button,
a,
.choice,
.error-summary,
#results {
  scroll-margin-top: calc(var(--nav-h) + env(safe-area-inset-top) + 12px);
  scroll-margin-bottom: calc(16px + env(safe-area-inset-bottom));
}

:focus {
  outline: none;
}

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

@media (max-width: 800px) {
  .hero-copy,
  .page-intro {
    text-align: center;
  }

  .hero-actions {
    justify-items: stretch;
  }

  .tool,
  .tool label,
  .tool legend,
  .tool input,
  .tool .help {
    text-align: left;
  }

  .primary-nav:not([hidden]) {
    position: fixed;
    z-index: 70;
    top: calc(var(--nav-h) + env(safe-area-inset-top));
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin: 0;
    padding: 12px calc(var(--pad) + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom))
      calc(var(--pad) + env(safe-area-inset-left));
    background: var(--surface);
    overflow: auto;
    border-top: 1px solid var(--border);
  }

  .no-js .primary-nav {
    position: static;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0 0 12px;
    border-top: 0;
    background: transparent;
  }
}

@media (min-width: 360px) {
  .presets {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 480px) {
  .metrics {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 801px) {
  .menu-toggle {
    display: none;
  }

  #site-menu {
    display: flex !important;
    position: static;
    margin-left: auto;
  }

  .hero {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 28px;
    align-items: start;
  }

  .hero-copy h1,
  .page-intro h1 {
    font-size: 2.25rem;
  }

  .hero-actions {
    grid-template-columns: auto auto;
    justify-content: start;
  }

  .form-actions {
    grid-template-columns: 1fr 1fr;
  }

  .shape-choices {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .unit-choices {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover {
    background: var(--accent-dark);
  }

  .btn-secondary:hover,
  .preset:hover,
  .primary-nav a:hover,
  .footer-nav a:hover {
    background: var(--soft);
  }

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

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

[hidden] {
  display: none !important;
}

/* Release polish: keep long values readable on narrow screens. */
.metric-value, dd { overflow-wrap: anywhere; }
.related-tools { margin-block: 2rem; }
details.card > summary { cursor: pointer; font-weight: 650; padding: .75rem 0; min-height: 44px; box-sizing: border-box; }
