:root {
  --navy: #101b2a;
  --steel: #34465a;
  --amber: #e0a348;
  --amber-ink: #8a5a12;
  --bg: #f4f5f3;
  --surface: #ffffff;
  --surface-2: #eef1f2;
  --ink: #172532;
  --muted: #5d6c76;
  --line: #d9dfe1;
  --focus: #2f6fb3;
  --danger: #a33a2a;
  --danger-bg: #fbecea;
  --radius: 10px;
  --font:
    "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  --base: 15px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-shop-floor="true"]) {
    --bg: #0d1520;
    --surface: #152233;
    --surface-2: #1b2b3f;
    --ink: #e8edf0;
    --muted: #9aa8b2;
    --line: #2a3b50;
    --amber-ink: #f0c070;
    --focus: #7fb3ec;
    --danger: #ff9b8a;
    --danger-bg: #3a1d1a;
    color-scheme: dark;
  }
}

/* Shop-floor mode: dark, high contrast, bigger type and touch targets. */
:root[data-shop-floor="true"] {
  --bg: #05090e;
  --surface: #0f1a27;
  --surface-2: #16263a;
  --ink: #ffffff;
  --muted: #c3ced6;
  --line: #3a4f66;
  --amber-ink: #ffc46b;
  --focus: #ffc46b;
  --danger: #ffb0a3;
  --danger-bg: #3a1d1a;
  --base: 19px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  font-size: var(--base);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

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

[hidden] {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-mark {
  background: var(--amber);
  color: var(--navy);
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.segmented {
  display: inline-flex;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  overflow: hidden;
}

.segmented button,
.shop-toggle {
  border: 0;
  background: transparent;
  color: #fff;
  padding: 6px 14px;
  min-height: 36px;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  background: var(--amber);
  color: var(--navy);
  font-weight: 700;
}

.shop-toggle {
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
}

.shop-toggle[aria-pressed="true"] {
  background: #fff;
  color: var(--navy);
  font-weight: 700;
}

.home-link {
  color: #fff;
  padding: 6px 4px;
  text-underline-offset: 3px;
}

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

.layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  min-height: calc(100vh - 56px);
}

.menu {
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  background: var(--surface);
}

.menu-group + .menu-group {
  margin-top: 16px;
}

.menu-heading {
  margin: 0 10px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.menu-link {
  display: block;
  padding: 7px 10px;
  border-radius: 7px;
  color: var(--ink);
  text-decoration: none;
}

.menu-link:hover {
  background: var(--surface-2);
}

.menu-link[aria-current="page"] {
  background: var(--surface-2);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--amber);
}

.workspace {
  padding: 24px 28px 48px;
  min-width: 0;
}

.calc {
  max-width: 1100px;
}

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

.calc-header h1 {
  margin: 2px 0 6px;
  font-size: 1.6rem;
  line-height: 1.2;
}

.summary {
  margin: 0 0 20px;
  color: var(--muted);
  max-width: 70ch;
}

.calc-body {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.inputs {
  grid-template-columns: minmax(0, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 12px;
}

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

.control {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
}

.control:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

.control input,
.control select {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  min-height: 40px;
  outline: none;
  font-variant-numeric: tabular-nums;
}

.control select option,
.control select optgroup {
  background: var(--surface);
  color: var(--ink);
}

.unit {
  display: flex;
  align-items: center;
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.85rem;
  border-left: 1px solid var(--line);
  background: var(--surface-2);
  white-space: nowrap;
}

.field.invalid .control {
  border-color: var(--danger);
}

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

.field-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-check label {
  margin: 0;
  font-weight: 500;
}

.field-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--amber);
}

.reset {
  justify-self: start;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 8px;
  padding: 6px 12px;
  color: var(--muted);
  cursor: pointer;
}

.reset:hover {
  color: var(--ink);
}

.outputs {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.figure {
  margin: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  max-width: 360px;
}

.figure svg {
  width: 100%;
  height: auto;
  display: block;
}

.figure text {
  fill: currentColor;
  font-size: 16px;
  font-weight: 700;
  font-style: italic;
}

.figure text.angle {
  fill: var(--amber-ink);
}

.message {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-weight: 600;
}

.field.solved input::placeholder {
  color: var(--amber-ink);
  opacity: 1;
  font-weight: 700;
}

.cards.power .card {
  border-top-color: var(--steel);
  background: var(--surface-2);
}

.message.needed {
  background: var(--surface-2);
  color: var(--ink);
}

.card-other {
  margin: 2px 0 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.message p {
  margin: 0;
}

.message p + p {
  margin-top: 4px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--amber);
  border-radius: var(--radius);
  padding: 12px 16px;
}

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

.card-value {
  margin: 2px 0 0;
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.card-unit {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--muted);
}

.details {
  display: grid;
  grid-template-columns: minmax(0, max-content) minmax(0, 1fr);
  gap: 6px 20px;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.details dt {
  color: var(--muted);
}

.details dd {
  margin: 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--muted);
  font-weight: 400;
}

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

caption {
  text-align: left;
  font-weight: 700;
  padding: 12px 16px 6px;
}

th,
td {
  text-align: left;
  padding: 7px 16px;
  border-top: 1px solid var(--line);
  white-space: nowrap;
}

thead th {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  border-top: 0;
}

tbody th {
  font-weight: 600;
}

tr.highlight th,
tr.highlight td {
  background: color-mix(in srgb, var(--amber) 22%, transparent);
}

.code {
  background: var(--navy);
  color: #e8edf0;
  border-radius: var(--radius);
  overflow: hidden;
}

.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 8px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.code-head p {
  margin: 0;
  font-size: 0.85rem;
  color: #c3ced6;
}

.copy {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  color: #fff;
  border-radius: 6px;
  padding: 4px 12px;
  cursor: pointer;
}

.code pre {
  margin: 0;
  padding: 12px 16px 16px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.55;
}

.notes {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 0.9rem;
}

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

.cta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--navy);
  color: #fff;
  border-radius: var(--radius);
  padding: 14px 18px;
}

.cta p {
  margin: 0;
  font-weight: 600;
}

.cta-link {
  background: var(--amber);
  color: var(--navy);
  text-decoration: none;
  font-weight: 700;
  border-radius: 8px;
  padding: 8px 16px;
}

@media (max-width: 980px) {
  .calc-body {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    padding: 10px 16px;
  }

  .shop-toggle {
    display: none;
  }

  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .menu {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 16px;
  }

  .menu-group {
    display: contents;
  }

  .menu-heading {
    display: none;
  }

  .menu-link {
    white-space: nowrap;
    border: 1px solid var(--line);
  }

  .menu-link[aria-current="page"] {
    box-shadow: none;
    border-color: var(--amber);
  }

  .workspace {
    padding: 18px 16px 40px;
  }

  .calc-header h1 {
    font-size: 1.35rem;
  }
}
