:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --faint: #a1a1a6;
  --line: #e6e6e1;
  --line-strong: #d6d6d0;
  --accent: #2f5bea;
  --accent-soft: #ebf0ff;
  --accent-text: #1f45c4;
  --danger: #c7372f;
  --focus: #2f5bea;
  --radius: 16px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC",
    "Noto Sans CJK SC", "Source Han Sans SC", "Microsoft YaHei", "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --bar-h: 56px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #1b1b1e;
    --surface-2: #242428;
    --text: #f2f2f4;
    --muted: #a0a0a8;
    --faint: #6c6c74;
    --line: #2b2b30;
    --line-strong: #3a3a40;
    --accent: #7c9cff;
    --accent-soft: rgba(124, 156, 255, 0.14);
    --accent-text: #a9bdff;
    --danger: #ff6b61;
    --focus: #7c9cff;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.wrap {
  width: 100%;
  max-width: 780px;
  margin-inline: auto;
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

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

/* ---------- Masthead ---------- */

.masthead {
  padding-top: max(40px, calc(env(safe-area-inset-top) + 24px));
  padding-bottom: 20px;
}

.masthead h1 {
  margin: 0;
  font-size: clamp(28px, 7vw, 36px);
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tag {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1;
  padding: 4px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--muted);
}

.intro {
  margin-top: 20px;
  color: var(--muted);
  font-size: 15px;
}

.intro p {
  margin: 0 0 6px;
  text-wrap: pretty;
}

/* ---------- Sticky progress bar ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 96%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

@supports not (background: color-mix(in srgb, red 50%, transparent)) {
  .bar {
    background: var(--bg);
  }
}

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

.progress {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-text {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.progress-text b {
  color: var(--text);
  font-weight: 600;
}

.progress-track {
  height: 4px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  border-radius: inherit;
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 240ms ease;
}

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 11px 16px;
  min-height: 44px;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
  touch-action: manipulation;
}

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

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn.primary {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.btn.primary:hover {
  opacity: 0.88;
}

.btn.quiet {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn.quiet:hover {
  color: var(--text);
  background: var(--surface-2);
}

.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn.small {
  font-size: 14px;
  padding: 7px 12px;
  min-height: 36px;
  border-radius: 10px;
}

/* ---------- Parts & sections ---------- */

#parts {
  padding-top: 8px;
}

.part {
  margin-top: 28px;
}

.part-head {
  margin: 0 2px 12px;
}

.part-eyebrow {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}

.part-title {
  margin: 2px 0 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.part-sections {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.legend {
  margin-top: 8px;
  font-size: 14px;
  color: var(--muted);
}

.legend > summary {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  color: var(--accent-text);
  min-height: 32px;
  list-style: none;
}

.legend > summary::-webkit-details-marker {
  display: none;
}

.legend > summary::after {
  content: "";
  width: 6px;
  height: 6px;
  margin-left: 4px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 160ms ease;
}

.legend[open] > summary::after {
  transform: translateY(1px) rotate(-135deg);
}

.legend dl {
  margin: 8px 0 0;
  padding: 4px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.legend-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.legend-row:last-child {
  border-bottom: 0;
}

.legend dt {
  color: var(--text);
  font-weight: 600;
}

.legend dd {
  margin: 2px 0 0;
  line-height: 1.5;
}

.section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  scroll-margin-top: calc(var(--bar-h) + env(safe-area-inset-top) + 12px);
}

.section > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 18px;
  min-height: 56px;
  cursor: pointer;
  user-select: none;
  border-radius: var(--radius);
}

.section > summary::-webkit-details-marker {
  display: none;
}

.section-code {
  flex: none;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 6px;
  padding: 3px 6px;
  line-height: 1;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
}

.section-count {
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.section.complete .section-count {
  color: var(--accent-text);
}

.chevron {
  width: 16px;
  height: 16px;
  flex: none;
  color: var(--faint);
  transition: transform 160ms ease;
}

.section[open] .chevron {
  transform: rotate(180deg);
}

.section-note {
  border-top: 1px solid var(--line);
  padding: 12px 18px;
  font-size: 14px;
  color: var(--muted);
  background: var(--surface-2);
}

.section-note p {
  margin: 0;
}

.questions {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
}

.q {
  padding: 14px 14px 16px;
  border-bottom: 1px solid var(--line);
}

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

.q legend {
  float: left;
  width: 100%;
  padding: 0;
  margin: 0 0 10px;
}

.q-text {
  display: flex;
  gap: 8px;
  padding-inline: 4px;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.45;
  text-wrap: pretty;
}

.q-num {
  flex: none;
  min-width: 1.5em;
  color: var(--faint);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.seg {
  clear: both;
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.opt {
  position: relative;
  display: block;
  cursor: pointer;
}

.opt input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.pill {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 100%;
  min-height: 44px;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  line-height: 1.3;
  color: var(--text);
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.seg-yesNoUnsure .pill {
  justify-content: center;
}

.pill .emo {
  flex: none;
  font-size: 16px;
  line-height: 1;
}

.opt:hover .pill {
  background: var(--surface-2);
}

.opt input:checked + .pill {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.opt input:focus-visible + .pill {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.section-foot {
  display: flex;
  justify-content: flex-end;
  padding: 8px 10px;
}

.end-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 28px 0 8px;
}

@media (min-width: 640px) {
  .q {
    padding: 16px 22px 18px;
  }

  .q-text {
    padding-inline: 0;
  }

  .section > summary {
    padding-inline: 22px;
  }

  .section-note {
    padding-inline: 22px;
  }

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

  .seg-exclusivity {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .seg-yesNoUnsure {
    max-width: 420px;
  }

  .end-actions {
    flex-direction: row;
    justify-content: space-between;
  }

  .end-actions .btn.primary {
    min-width: 200px;
  }
}

/* ---------- Results ---------- */

.result-head {
  padding: 28px 0 4px;
}

.result-head h2 {
  margin: 0;
  font-size: 22px;
  outline: none;
}

.result-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 16px 0;
}

@media (min-width: 640px) {
  .toolbar {
    grid-template-columns: repeat(4, auto);
    justify-content: start;
  }
}

#result .part {
  margin-top: 20px;
}

#result .part-sections,
#result .part {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#result .part-head {
  margin-bottom: 2px;
}

.r-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.r-head {
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
}

.r-head h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.r-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.r-row {
  display: grid;
  gap: 3px;
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
}

.r-row:last-child {
  border-bottom: 0;
}

.r-q {
  display: flex;
  gap: 8px;
  font-size: 15px;
  line-height: 1.45;
}

.r-value {
  padding-left: calc(1.5em + 8px);
  font-size: 15px;
  font-weight: 600;
}

.r-value.empty {
  color: var(--faint);
  font-weight: 400;
}

@media (min-width: 640px) {
  .r-head {
    padding-inline: 22px;
  }

  .r-row {
    grid-template-columns: minmax(0, 1fr) 220px;
    column-gap: 20px;
    padding-inline: 22px;
  }

  .r-value {
    padding-left: 0;
  }
}

/* ---------- Footer ---------- */

.privacy {
  padding-top: 32px;
  padding-bottom: max(32px, calc(env(safe-area-inset-bottom) + 20px));
  text-align: center;
  color: var(--faint);
  font-size: 12px;
}

.privacy p {
  margin: 0;
}

/* ---------- Dialogs ---------- */

dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

dialog h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.image-dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 16px;
}

.image-dialog[open] {
  display: flex;
  flex-direction: column;
}

.image-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.image-dialog-head h2 {
  margin: 0;
}

.image-frame {
  flex: 1;
  min-height: 160px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  -webkit-overflow-scrolling: touch;
}

.image-frame img {
  display: block;
  width: 100%;
  height: auto;
  -webkit-touch-callout: default;
}

.image-status {
  padding: 60px 16px;
  text-align: center;
}

.image-hint {
  margin-top: 10px !important;
  font-size: 13px !important;
  text-align: center;
}

.image-dialog .dialog-actions {
  margin-top: 12px;
}

.image-dialog .dialog-actions .btn {
  flex: 1;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px));
  transform: translate(-50%, 12px);
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 99px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 100;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
