:root {
  color-scheme: dark;
  --bg: #0e1315;
  --panel: #171e21;
  --panel-2: #20282c;
  --line: #344047;
  --text: #f4f7f7;
  --muted: #a8b4b8;
  --teal: #08747b;
  --teal-bright: #21a6ad;
  --amber: #f2b544;
  --red: #ff786f;
  --green: #61c59b;
  --radius: 14px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}

button, select, input { font: inherit; }

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.app-icon { display: block; width: 56px; height: 56px; flex: 0 0 auto; border-radius: 13px; box-shadow: 0 5px 18px rgb(0 0 0 / 24%); }
.topbar-copy { flex: 1; min-width: 0; }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 2px; line-height: 1.15; }
h1 span { display: block; }
.product-name { font-size: clamp(1.65rem, 4vw, 2.35rem); font-weight: 900; letter-spacing: -.035em; }
.product-descriptor { margin-top: 3px; color: var(--muted); font-size: clamp(.92rem, 2.2vw, 1.05rem); font-weight: 700; letter-spacing: .01em; }
h2 { margin-bottom: 0; font-size: clamp(1.25rem, 2.5vw, 1.6rem); line-height: 1.25; }
.topbar p { margin-bottom: 0; color: var(--muted); }

.converter, .fit-panel, .measurement-guide, .notes {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.converter { overflow: hidden; }

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 24px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--teal-bright);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .12em;
}

.text-button {
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.text-button:hover, .text-button:focus-visible { border-color: var(--teal-bright); outline: none; }
.nav-button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; white-space: nowrap; }

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1.25fr;
  gap: 18px;
  padding: 24px;
  background: #12181b;
}

.controls label > span, legend {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 700;
}

select {
  width: 100%;
  min-height: 50px;
  padding: 10px 40px 10px 13px;
  border: 1px solid #46535a;
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--text);
}

select:focus-visible { border-color: var(--teal-bright); outline: 3px solid rgb(33 166 173 / 22%); }

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

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 50px;
  overflow: hidden;
  border: 1px solid #46535a;
  border-radius: 9px;
}

.segmented label { position: relative; }
.segmented label + label { border-left: 1px solid #46535a; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 48px;
  margin: 0;
  padding: 8px 12px;
  background: var(--panel-2);
  color: var(--muted);
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
}
.segmented input:checked + span { background: var(--teal); color: white; font-weight: 800; }
.segmented input:focus-visible + span { outline: 3px solid rgb(33 166 173 / 35%); outline-offset: -3px; }

.selected-summary {
  display: grid;
  grid-template-columns: minmax(180px, .9fr) 1.4fr;
  gap: 24px;
  align-items: center;
  padding: 26px 24px;
  border-top: 1px solid rgb(255 255 255 / 4%);
  border-bottom: 1px solid var(--line);
  background: var(--teal);
}

.selected-size { font-size: clamp(2rem, 6vw, 4rem); font-weight: 900; line-height: 1; letter-spacing: -.04em; }
.selected-system { margin-top: 8px; font-size: .88rem; font-weight: 800; letter-spacing: .08em; opacity: .82; }
.measurement { display: flex; align-items: baseline; gap: 9px; }
.measurement strong { font-size: clamp(1.8rem, 5vw, 3.25rem); line-height: 1; }
.measurement span { font-size: 1.1rem; font-weight: 800; }
.summary-copy { margin: 10px 0 0; max-width: 60ch; color: #e5ffff; }

.results-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.result-card {
  min-height: 190px;
  padding: 20px 18px;
  background: var(--panel);
}

.result-card .system-name { color: var(--muted); font-size: .8rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.result-card h3 { margin: 9px 0 4px; font-size: 1.45rem; line-height: 1.2; }
.result-card .actual { margin-bottom: 17px; color: var(--muted); font-size: .9rem; }
.fit-badge { display: inline-flex; align-items: center; min-height: 29px; padding: 4px 9px; border: 1px solid currentColor; border-radius: 99px; font-size: .78rem; font-weight: 800; }
.fit-badge.exact { color: var(--green); }
.fit-badge.close { color: #7fd7d5; }
.fit-badge.caution { color: var(--amber); }
.fit-badge.nofit, .fit-badge.poor { color: var(--red); }
.difference { margin: 10px 0 0; color: var(--muted); font-size: .82rem; }

.fit-panel {
  display: grid;
  grid-template-columns: .6fr 1.4fr;
  gap: 28px;
  margin-top: 20px;
  padding: 24px;
}

.recommendations { display: grid; gap: 10px; }
.recommendation {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}
.recommendation .rec-system { color: var(--muted); font-size: .83rem; font-weight: 800; text-transform: uppercase; }
.recommendation strong { font-size: 1.06rem; }
.recommendation .rec-note { color: var(--muted); font-size: .86rem; text-align: right; }
.recommendation.warning { border-color: #765d2d; }
.no-recommendation { margin: 0; padding: 18px; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); }

.measurement-guide {
  margin-top: 20px;
  padding: 24px;
}

.measurement-heading {
  display: grid;
  grid-template-columns: minmax(260px, .8fr) 1.2fr;
  column-gap: 28px;
  align-items: end;
  margin-bottom: 20px;
}

.measurement-heading .eyebrow,
.measurement-heading h2 { grid-column: 1; }
.measurement-heading p { grid-column: 2; grid-row: 1 / span 2; margin: 0; color: var(--muted); }

.diagram-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.diagram-card {
  grid-column: span 2;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
}

.diagram-card.british-card { grid-column: span 3; }

.diagram-card figcaption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.diagram-card figcaption strong { font-size: 1.05rem; }
.diagram-card figcaption span { color: var(--muted); font-size: .78rem; font-weight: 700; text-align: right; }
.diagram-card svg { display: block; width: 100%; height: auto; background: #12181b; }
.diagram-card > p { min-height: 92px; margin: 0; padding: 14px 16px 16px; color: var(--muted); font-size: .9rem; }
.diagram-card > p b { color: var(--text); }

.part-fill { fill: #253237; stroke: var(--teal-bright); stroke-width: 3; stroke-linejoin: round; }
.recess-fill { fill: var(--bg); stroke: #66757c; stroke-width: 3; }
.guide-line { stroke: #68767d; stroke-width: 1.5; stroke-dasharray: 4 4; }
.dimension-line { stroke: var(--amber); stroke-width: 2.5; }
.arrow-fill { fill: var(--amber); }
.dimension-line.secondary { stroke: var(--teal-bright); }
.secondary-fill { fill: var(--teal-bright); }
.thread-lines { fill: none; stroke: #6f8087; stroke-width: 2; }
.diagram-value { fill: var(--text); font: 800 17px Inter, sans-serif; }
.diagram-label { fill: var(--muted); font: 700 10px Inter, sans-serif; letter-spacing: 1.2px; }
.diagram-small { fill: var(--text); font: 700 10px Inter, sans-serif; }

.notes { margin-top: 20px; padding: 24px; }
.note-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 18px; }
.note-grid article { padding: 16px; border-left: 4px solid var(--line); background: var(--panel-2); }
.note-grid article:nth-child(1) { border-color: var(--green); }
.note-grid article:nth-child(2) { border-color: #7fd7d5; }
.note-grid article:nth-child(3) { border-color: var(--amber); }
.note-grid p { margin: 4px 0 0; color: var(--muted); }
.technical-note { margin: 20px 0 0; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); }

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  margin-top: 24px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.app-footer > a {
  display: inline-flex;
  padding: 8px 12px;
  border-radius: 9px;
  background: #fdfbf9;
}

.app-footer > a:focus-visible { outline: 3px solid var(--teal-bright); outline-offset: 3px; }
.app-footer img { display: block; width: min(220px, 48vw); height: auto; }
.app-footer p { margin: 0; color: var(--muted); text-align: right; }

.help-shell { width: min(980px, calc(100% - 32px)); }
.icon-home { display: block; flex: 0 0 auto; border-radius: 13px; }
.icon-home:focus-visible { outline: 3px solid var(--teal-bright); outline-offset: 4px; }
.help-content { display: grid; gap: 20px; }
.help-section {
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.help-section h2 { margin-bottom: 8px; }
.help-lead { max-width: 72ch; margin-bottom: 0; color: var(--muted); }
.help-steps { margin: 22px 0 0; padding-left: 1.5rem; }
.help-steps li { padding: 0 0 16px 8px; }
.help-steps li:last-child { padding-bottom: 0; }
.help-steps strong { display: block; margin-bottom: 3px; }
.help-steps p { margin: 0; color: var(--muted); }
.fit-table { width: 100%; margin-top: 22px; border-collapse: collapse; }
.fit-table th, .fit-table td { padding: 12px 14px; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.fit-table th { width: 150px; background: var(--panel-2); }
.fit-table td { color: var(--muted); }
.help-callout { margin-top: 20px; padding: 17px 18px; border-left: 4px solid var(--amber); background: #292317; color: #f8e5bc; }
.help-callout p { margin: 0; }
.platform-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 22px; }
.platform-card, .system-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel-2);
}
.platform-card h3, .system-card h3 { margin: 0 0 8px; font-size: 1.05rem; }
.platform-card ol { margin: 0; padding-left: 1.25rem; color: var(--muted); }
.platform-card li + li { margin-top: 6px; }
.offline-note { margin: 18px 0 0; color: var(--muted); }
.system-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 22px; }
.system-card:last-child { grid-column: 1 / -1; }
.system-card .system-measure { display: inline-block; margin-bottom: 9px; color: var(--teal-bright); font-size: .82rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.system-card p { margin-bottom: 8px; color: var(--muted); }
.system-card p:last-child { margin-bottom: 0; }
.system-card b { color: var(--text); }
.support-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.support-panel { padding: 20px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-2); }
.support-panel h2 { margin-bottom: 10px; }
.support-panel p { color: var(--muted); }
.support-panel p:last-of-type { margin-bottom: 0; }
.primary-link { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; margin-top: 8px; padding: 9px 15px; border-radius: 9px; background: var(--teal); color: white; font-weight: 800; text-decoration: none; }
.primary-link:hover, .primary-link:focus-visible { background: var(--teal-bright); outline: none; }
.donation-actions { display: grid; gap: 10px; margin: 18px 0; }
.donation-actions .primary-link { margin-top: 0; }
.secondary-link { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; padding: 9px 15px; border: 1px solid #526168; border-radius: 9px; background: transparent; color: var(--text); font-weight: 800; text-align: center; text-decoration: none; }
.secondary-link:hover, .secondary-link:focus-visible { border-color: var(--teal-bright); color: var(--teal-bright); outline: none; }
.support-panel .donation-note { margin-top: 14px; font-size: .9rem; }
.help-footer-link { color: var(--teal-bright); }

@media (max-width: 900px) {
  .controls { grid-template-columns: 1fr 1fr; }
  .controls fieldset { grid-column: 1 / -1; }
  .results-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-card:last-child { grid-column: 1 / -1; }
  .fit-panel { grid-template-columns: 1fr; }
  .diagram-card, .diagram-card.british-card { grid-column: span 3; }
  .diagram-card:last-child { grid-column: 2 / span 4; }
  .platform-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .app-shell { width: min(100% - 20px, 1180px); padding-top: 16px; }
  .topbar { align-items: flex-start; }
  .app-icon { width: 48px; height: 48px; border-radius: 11px; }
  .topbar .nav-button { min-height: 40px; padding-inline: 11px; }
  .topbar p { font-size: .9rem; }
  .section-heading, .controls, .selected-summary, .fit-panel, .measurement-guide, .notes { padding: 18px; }
  .controls, .selected-summary, .note-grid { grid-template-columns: 1fr; }
  .results-grid { grid-template-columns: 1fr; }
  .result-card, .result-card:last-child { grid-column: auto; min-height: 0; }
  .recommendation { grid-template-columns: 1fr auto; }
  .recommendation .rec-system { grid-column: 1 / -1; }
  .recommendation .rec-note { text-align: right; }
  .measurement-heading { grid-template-columns: 1fr; }
  .measurement-heading .eyebrow,
  .measurement-heading h2,
  .measurement-heading p { grid-column: 1; grid-row: auto; }
  .measurement-heading p { margin-top: 10px; }
  .diagram-grid { grid-template-columns: 1fr; }
  .diagram-card, .diagram-card.british-card, .diagram-card:last-child { grid-column: 1; }
  .diagram-card > p { min-height: 0; }
  .app-footer { flex-direction: column; align-items: flex-start; }
  .app-footer p { text-align: left; }
  .help-shell { width: min(100% - 20px, 980px); }
  .help-section { padding: 20px; }
  .fit-table th, .fit-table td { display: block; width: 100%; }
  .fit-table tr + tr th { border-top-width: 0; }
  .fit-table td { border-top: 0; }
  .system-grid, .support-grid { grid-template-columns: 1fr; }
  .system-card:last-child { grid-column: auto; }
}

@media (prefers-reduced-motion: no-preference) {
  .result-card, .recommendation { animation: settle .22s ease-out; }
  @keyframes settle { from { opacity: .35; transform: translateY(3px); } }
}
