:root {
  --navy: #161c4c;
  --blue: #2e6da4;
  --green: #52b08c;
  --red: #f23a3c;
  --bg: #f3f5fa;
  --card: #ffffff;
  --text: #1d2233;
  --muted: #5d6478;
  --line: #dde2ee;
  --tick: #e8f1fb;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1224;
    --card: #1a1f38;
    --text: #eef0f7;
    --muted: #a3aac2;
    --line: #2d3458;
    --tick: #22305a;
    --blue: #6aa6e0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--navy);
  color: #fff;
}
.top img { border-radius: 10px; background: #fff; }
.top h1 { font-size: 17px; margin: 0; letter-spacing: .02em; }

form { max-width: 640px; margin: 0 auto; padding: 12px 12px 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
}

details.card > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  min-height: 32px;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after {
  content: "";
  width: 9px; height: 9px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  margin: 0 4px 4px 12px;
  transition: transform .15s;
}
details.card[open] > summary::after { transform: rotate(-135deg); margin-bottom: -4px; }

.q-label { font-weight: 650; font-size: 17px; display: block; }
.count { margin-left: auto; font-size: 13px; color: #fff; background: var(--blue); border-radius: 999px; padding: 2px 10px; }
.count:empty { display: none; }
.sub { color: var(--muted); font-size: 13px; margin: 2px 0 8px; }

.options { margin-top: 6px; }
.group + .group { border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 6px; }

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 8px 10px;
  margin: 0 -10px;
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.option:has(input:checked) { background: var(--tick); font-weight: 600; }
.option input { width: 22px; height: 22px; flex: none; accent-color: var(--blue); margin: 0; }

.number .q-label { margin-bottom: 8px; }
.stepper { display: flex; gap: 8px; }
.stepper input {
  flex: 1;
  min-width: 0;
  height: 48px;
  font-size: 18px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
.stepper input[aria-invalid="true"] { border-color: var(--red); }
.step {
  width: 52px; height: 48px;
  flex: none;
  font-size: 24px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--blue);
  cursor: pointer;
}
.number .sub { margin: 6px 0 0; }
.error { color: var(--red); font-size: 13px; margin: 4px 0 0; }
.error:empty { display: none; }

.divider { border: 0; border-top: 3px solid #919ee2; margin: 10px 0 14px; }

.results .result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
}
.results .result + .result { border-top: 1px solid var(--line); }
.r-label { font-weight: 650; display: block; }
.results .sub { margin: 0; }
output { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.actions { text-align: center; padding: 8px 0 20px; }
.submit {
  width: 100%;
  height: 54px;
  border: 0;
  border-radius: 12px;
  background: var(--red);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .04em;
  cursor: pointer;
}
.submit:disabled { opacity: .6; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.status { margin: 10px 0 0; font-weight: 600; }
.status.ok { color: var(--green); }
.status.bad { color: var(--red); }

.totals-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: space-around;
  gap: 4px;
  padding: 10px 8px calc(10px + env(safe-area-inset-bottom));
  background: var(--navy);
  color: #fff;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, .2);
}
.totals-bar div { text-align: center; min-width: 0; }
.totals-bar span { display: block; font-size: 11px; opacity: .75; letter-spacing: .06em; }
.totals-bar b { font-size: 16px; font-variant-numeric: tabular-nums; }

.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input[type=number] { -moz-appearance: textfield; appearance: textfield; }
