:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-subtle: #f9faf8;
  --text: #1e2422;
  --muted: #5d6863;
  --border: #d7ded8;
  --accent: #1f6f64;
  --accent-dark: #184f49;
  --accent-soft: #e4f1ed;
  --warning: #8a4d12;
  --warning-bg: #fff5e5;
  --error: #9b2d2d;
  --error-bg: #fff0f0;
  --warning-border: #ebc277;
  --error-border: #e3a3a3;
  --on-accent: #ffffff;
  --tooltip-bg: #1e2422;
  --tooltip-text: #ffffff;
  --focus-subtle: rgba(31, 111, 100, 0.18);
  --focus-medium: rgba(31, 111, 100, 0.25);
  --focus-strong: rgba(31, 111, 100, 0.3);
  --shadow: 0 18px 48px rgba(35, 45, 42, 0.08);
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101513;
    --surface: #171d1b;
    --surface-subtle: #202825;
    --text: #eef4f1;
    --muted: #a8b8b2;
    --border: #34413d;
    --accent: #62c6b9;
    --accent-dark: #9edfd6;
    --accent-soft: #183832;
    --warning: #f0c47b;
    --warning-bg: #2a2114;
    --error: #f0aaaa;
    --error-bg: #2a1719;
    --warning-border: #6a5128;
    --error-border: #6a3236;
    --on-accent: #08110f;
    --tooltip-bg: #eef4f1;
    --tooltip-text: #101513;
    --focus-subtle: rgba(98, 198, 185, 0.2);
    --focus-medium: rgba(98, 198, 185, 0.28);
    --focus-strong: rgba(98, 198, 185, 0.34);
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.3);
  }
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-subtle: #f9faf8;
  --text: #1e2422;
  --muted: #5d6863;
  --border: #d7ded8;
  --accent: #1f6f64;
  --accent-dark: #184f49;
  --accent-soft: #e4f1ed;
  --warning: #8a4d12;
  --warning-bg: #fff5e5;
  --error: #9b2d2d;
  --error-bg: #fff0f0;
  --warning-border: #ebc277;
  --error-border: #e3a3a3;
  --on-accent: #ffffff;
  --tooltip-bg: #1e2422;
  --tooltip-text: #ffffff;
  --focus-subtle: rgba(31, 111, 100, 0.18);
  --focus-medium: rgba(31, 111, 100, 0.25);
  --focus-strong: rgba(31, 111, 100, 0.3);
  --shadow: 0 18px 48px rgba(35, 45, 42, 0.08);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101513;
  --surface: #171d1b;
  --surface-subtle: #202825;
  --text: #eef4f1;
  --muted: #a8b8b2;
  --border: #34413d;
  --accent: #62c6b9;
  --accent-dark: #9edfd6;
  --accent-soft: #183832;
  --warning: #f0c47b;
  --warning-bg: #2a2114;
  --error: #f0aaaa;
  --error-bg: #2a1719;
  --warning-border: #6a5128;
  --error-border: #6a3236;
  --on-accent: #08110f;
  --tooltip-bg: #eef4f1;
  --tooltip-text: #101513;
  --focus-subtle: rgba(98, 198, 185, 0.2);
  --focus-medium: rgba(98, 198, 185, 0.28);
  --focus-strong: rgba(98, 198, 185, 0.34);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  max-width: 100%;
  color-scheme: light dark;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  width: 100%;
  max-width: 100%;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

a {
  color: var(--accent-dark);
}

a:hover {
  color: var(--accent);
}

.content-wrap {
  width: min(1120px, calc(100% - 32px));
  max-width: 100%;
  margin: 0 auto;
}

.site-header {
  padding: 48px 0 24px;
}

.header-tools {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.header-tools .back-link {
  margin-bottom: 0;
}

.title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.title-row h1 {
  min-width: 0;
}

.theme-toggle {
  flex: 0 0 auto;
  margin-top: clamp(0px, calc(2.24vw - 18px), 13.4px);
  min-width: 112px;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--accent-dark);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 800;
  visibility: hidden;
}

html[data-theme-controls-ready="true"] .theme-toggle {
  visibility: visible;
}

.theme-toggle:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.12;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.5rem);
  letter-spacing: 0;
}

h2 {
  font-size: 1.35rem;
}

h3 {
  font-size: 1rem;
}

h4 {
  font-size: 0.92rem;
}

.intro {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 1.08rem;
}

.tool-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 20px;
  align-items: start;
  min-width: 0;
  max-width: 100%;
  margin: 24px 0;
}

.panel {
  min-width: 0;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.calculator-form,
.results-panel {
  min-width: 0;
  max-width: 100%;
  padding: 24px;
}

.panel-heading {
  margin-bottom: 20px;
}

.panel-heading p {
  margin: 8px 0 0;
  color: var(--muted);
}

.field-group {
  padding: 0;
  margin: 0 0 18px;
  border: 0;
}

.field-group legend,
.field label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

.label-row {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.field label.label-row,
.field-group legend .label-row {
  display: flex;
}

.requirement,
.field-note {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--accent-dark);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  vertical-align: middle;
}

.requirement.optional {
  color: var(--muted);
}

.info-tooltip {
  position: relative;
  display: inline-grid;
  width: 20px;
  height: 20px;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--muted);
  cursor: help;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
  place-items: center;
}

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

.tooltip-text {
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  z-index: 20;
  width: min(260px, calc(100vw - 48px));
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--tooltip-bg);
  box-shadow: var(--shadow);
  color: var(--tooltip-text);
  font-size: 0.83rem;
  font-weight: 500;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  text-align: left;
  transform: translate(-50%, -4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.info-tooltip:hover .tooltip-text,
.info-tooltip:focus .tooltip-text {
  opacity: 1;
  transform: translate(-50%, 0);
}

.field {
  margin-bottom: 18px;
}

.optional-panel {
  margin: 0 0 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}

.optional-panel summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 800;
}

.optional-panel summary:focus-visible {
  outline: 3px solid var(--focus-subtle);
  outline-offset: 2px;
}

.optional-panel[open] summary {
  margin-bottom: 14px;
}

.optional-panel .field:last-child {
  margin-bottom: 0;
}

.field-row,
.unit-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.unit-fields {
  margin-bottom: 18px;
}

.unit-fields > .field > label,
.field-row > .field > label {
  min-height: 54px;
  align-content: flex-start;
}

#imperial-fields {
  grid-template-columns: 1fr;
}

#known-lean-mass-metric-fields,
#known-lean-mass-imperial-fields {
  grid-template-columns: 1fr;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.segmented-control label {
  position: relative;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-subtle);
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.segmented-control input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.segmented-control input:focus-visible + span {
  outline: 3px solid var(--focus-medium);
  outline-offset: 2px;
}

input,
select,
button {
  font: inherit;
  font-size: 16px;
  touch-action: manipulation;
}

.segmented-control span {
  font-size: 16px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

input:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid var(--focus-subtle);
}

input[aria-invalid="true"],
select[aria-invalid="true"] {
  border-color: var(--error);
  outline: 3px solid var(--error-bg);
}

.input-with-unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
}

.input-with-unit input {
  border-radius: var(--radius) 0 0 var(--radius);
}

.input-with-unit span {
  display: grid;
  min-width: 48px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-left: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--surface-subtle);
  color: var(--muted);
  font-weight: 700;
  place-items: center;
}

.button-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: stretch;
  margin-top: 22px;
}

.primary-button {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent-dark);
  color: var(--on-accent);
  cursor: pointer;
  font-weight: 800;
  white-space: normal;
}

.primary-button:hover {
  background: var(--accent);
}

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

.secondary-button {
  max-width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 800;
  white-space: normal;
}

.secondary-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

.button-row .secondary-button {
  min-height: 48px;
}

.messages {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.message-block {
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.message-block.warning {
  border: 1px solid var(--warning-border);
  background: var(--warning-bg);
  color: var(--warning);
}

.message-block.error {
  border: 1px solid var(--error-border);
  background: var(--error-bg);
  color: var(--error);
}

.message-block ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.results-placeholder {
  min-width: 0;
  max-width: 100%;
  color: var(--muted);
}

.results-placeholder:empty {
  display: none;
}

.results-placeholder p {
  margin: 0;
}

.result-highlight {
  min-width: 0;
  max-width: 100%;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--accent-soft);
}

.result-highlight p {
  margin: 0;
  color: var(--muted);
}

.result-highlight strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: clamp(2rem, 5vw, 3.25rem);
  line-height: 1;
  overflow-wrap: anywhere;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
  max-width: 100%;
  margin: 14px 0 20px;
}

.metric-box {
  min-width: 0;
  max-width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}

.metric-box span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
}

.metric-box strong {
  display: block;
  margin-top: 5px;
  font-size: 1.25rem;
  overflow-wrap: anywhere;
}

.result-actions {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 0.65fr) minmax(0, 0.55fr);
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  margin: 14px 0 0;
}

.compact-button {
  min-width: 0;
  padding-inline: 6px;
  font-size: 0.86rem;
  line-height: 1.15;
  overflow: hidden;
  text-align: center;
  white-space: nowrap;
}

.action-status {
  grid-column: 1/-1;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.section-block {
  min-width: 0;
  max-width: 100%;
  margin-top: 22px;
}

.section-block p {
  margin: 8px 0 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.definition-list {
  display: grid;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  margin: 12px 0 0;
}

.definition-row {
  display: grid;
  grid-template-columns: minmax(150px, 0.8fr) minmax(0, 1.2fr);
  gap: 12px;
  min-width: 0;
  max-width: 100%;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.definition-row dt {
  min-width: 0;
  color: var(--muted);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.definition-row dd {
  min-width: 0;
  margin: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.estimate-table {
  width: 100%;
  max-width: 100%;
  margin-top: 12px;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.estimate-table th,
.estimate-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.estimate-table th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.method-sensitivity {
  min-width: 0;
  max-width: 100%;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.method-sensitivity p {
  margin: 6px 0 0;
}

.basis-badge {
  display: inline-block;
  max-width: 100%;
  margin-top: 10px;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--surface-subtle);
  color: var(--accent-dark);
  font-size: 0.83rem;
  font-weight: 800;
  overflow-wrap: anywhere;
  white-space: normal;
}

.methodology-summary {
  width: 100%;
  max-width: 100%;
  margin: 32px 0 18px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.summary-content {
  min-width: 0;
  max-width: 850px;
}

.summary-content p {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.text-link {
  display: inline-block;
  margin-top: 4px;
  font-weight: 800;
}

.disclaimer {
  width: 100%;
  max-width: 100%;
  margin: 14px 0 32px;
  color: var(--muted);
  font-size: 0.92rem;
}

.disclaimer p {
  margin: 0;
  overflow-wrap: anywhere;
}

.doc-header {
  padding-bottom: 10px;
}

.doc-wrap {
  width: min(900px, calc(100% - 32px));
}

.back-link {
  display: inline-block;
  margin-bottom: 20px;
  font-weight: 800;
}

.doc-layout {
  padding-bottom: 48px;
}

.doc-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 20px;
}

.doc-toc a {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent-dark);
  font-size: 0.9rem;
  font-weight: 800;
  text-decoration: none;
}

.doc-toc a:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.doc-article {
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.doc-article section + section {
  margin-top: 34px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
}

.doc-article h2 {
  margin-bottom: 12px;
}

.doc-article h3 {
  margin-top: 22px;
  margin-bottom: 8px;
}

.doc-article h4 {
  margin-top: 16px;
  margin-bottom: 6px;
}

.doc-article p,
.doc-article li {
  color: var(--muted);
}

.doc-article ul {
  margin: 10px 0 0;
  padding-left: 22px;
}

.doc-article li + li {
  margin-top: 6px;
}

.reference-list {
  display: grid;
  gap: 18px;
  padding-left: 0;
  list-style: none;
}

.reference-list li + li {
  margin-top: 0;
}

.reference-list p {
  margin: 0;
}

.reference-list cite {
  font-style: normal;
}

.reference-list a {
  overflow-wrap: anywhere;
}

.source-use {
  margin-top: 6px !important;
}

.doc-article pre {
  margin: 12px 0 16px;
  padding: 14px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}

.doc-article code {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92rem;
}

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

[hidden] {
  display: none !important;
}

@media (max-width: 860px) {
  .site-header {
    padding-top: 32px;
  }

  .header-tools {
    margin-bottom: 16px;
  }

  .title-row {
    gap: 16px;
  }

  .tool-grid {
    grid-template-columns: 1fr;
  }

  .results-panel {
    order: -1;
  }
}

@media (max-width: 620px) {
  .content-wrap {
    width: calc(100% - 24px);
  }

  .calculator-form,
  .results-panel,
  .methodology-summary,
  .doc-article {
    padding: 18px;
  }

  .summary-content {
    max-width: none;
    width: 100%;
  }

  .title-row {
    flex-direction: column;
    gap: 12px;
  }

  .theme-toggle {
    margin-top: 0;
  }

  .field-row,
  .unit-fields,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .unit-fields > .field > label,
  .field-row > .field > label {
    min-height: 0;
  }

  .definition-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .estimate-table {
    table-layout: fixed;
    white-space: normal;
  }

  .result-actions {
    grid-template-columns: minmax(0, 1.9fr) minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 0.62fr) minmax(0, 0.5fr);
    gap: 4px;
  }

  .compact-button {
    padding-inline: 2px;
    font-size: 0.68rem;
  }
}

@media (max-width: 360px) {
  .compact-button {
    font-size: 0.64rem;
  }
}
