:root {
  color-scheme: light;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  --ag-canvas: #f4f1eb;
  --ag-surface: #fffefa;
  --ag-surface-soft: #ebe8e0;
  --ag-ink: #202a31;
  --ag-muted: #586a70;
  --ag-teal: #286d67;
  --ag-teal-dark: #1d5752;
  --ag-border: #cbd4d0;
  --ag-error: #a52f36;
  --ag-focus: #bb4e76;
  background: var(--ag-canvas);
  color: var(--ag-ink);
}

:root[data-theme="calm"] {
  --ag-canvas: #f0eee8;
  --ag-surface: #fdfbf5;
  --ag-surface-soft: #e6e4dd;
  --ag-ink: #18272b;
  --ag-muted: #455a5d;
  --ag-teal: #205f5b;
  --ag-teal-dark: #164d49;
  --ag-border: #bfcac5;
  --ag-focus: #9a3e64;
}

:root[data-theme="high-contrast"] {
  color-scheme: light;
  --ag-canvas: #fff;
  --ag-surface: #fff;
  --ag-surface-soft: #eee;
  --ag-ink: #000;
  --ag-muted: #111;
  --ag-teal: #00514c;
  --ag-teal-dark: #003b37;
  --ag-border: #000;
  --ag-error: #8c0011;
  --ag-focus: #9d004b;
}

* { box-sizing: border-box; }

html,
body {
  min-width: 0;
  min-height: 100%;
  margin: 0;
  background: var(--ag-canvas);
  color: var(--ag-ink);
}

body { min-height: 100vh; }

button,
input,
textarea { font: inherit; }

button,
a,
input,
textarea { touch-action: manipulation; }

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

.agreement-app {
  width: min(100% - 1.25rem, 50rem);
  margin-inline: auto;
  padding: max(0.75rem, env(safe-area-inset-top)) 0 calc(2.5rem + env(safe-area-inset-bottom));
}

.agreement-header {
  display: flex;
  min-height: 3rem;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.back-to-tools,
.clear-button,
.text-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  border: 0;
  border-radius: 0.7rem;
  background: transparent;
  color: var(--ag-teal-dark);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 0.18em;
  cursor: pointer;
}

.clear-button { padding: 0.5rem 0.65rem; color: var(--ag-error); }

.agreement-intro { padding: 1.25rem 0 1rem; }
.eyebrow { margin: 0 0 0.45rem; color: var(--ag-muted); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(2rem, 8vw, 3rem); line-height: 1.08; letter-spacing: -0.04em; }
.intro-copy { max-width: 40rem; margin: 0.75rem 0 0; color: var(--ag-muted); font-size: 1.05rem; line-height: 1.55; }

.progress-panel,
.step-card {
  border: 1px solid var(--ag-border);
  border-radius: 1rem;
  background: var(--ag-surface);
  box-shadow: 0 0.4rem 1.5rem rgb(32 42 49 / 5%);
}

.progress-panel { padding: 1rem; }
.progress-copy { margin-bottom: 0.6rem; color: var(--ag-ink); font-weight: 750; }
.progress-copy span { padding-inline: 0.2rem; color: var(--ag-muted); }
progress { display: block; width: 100%; height: 0.55rem; overflow: hidden; border: 0; border-radius: 999px; background: var(--ag-surface-soft); accent-color: var(--ag-teal); }
progress::-webkit-progress-bar { border-radius: 999px; background: var(--ag-surface-soft); }
progress::-webkit-progress-value { border-radius: 999px; background: var(--ag-teal); }
progress::-moz-progress-bar { border-radius: 999px; background: var(--ag-teal); }

.step-list { display: flex; gap: 0.45rem; margin: 0.8rem 0 0; padding: 0; list-style: none; }
.step-list li { display: flex; min-width: 0; flex: 1; align-items: center; justify-content: center; gap: 0.4rem; color: var(--ag-muted); }
.step-number { display: inline-grid; width: 1.6rem; height: 1.6rem; flex: 0 0 auto; place-items: center; border: 1px solid var(--ag-border); border-radius: 50%; font-size: 0.75rem; font-weight: 750; }
.step-list li.is-current-or-complete .step-number { border-color: var(--ag-teal); background: var(--ag-teal); color: white; }
.step-list li[aria-current="step"] .step-number { box-shadow: 0 0 0 3px color-mix(in srgb, var(--ag-teal) 20%, transparent); }
.step-name { display: none; }

.step-card { margin-top: 1rem; padding: 1.1rem; }
.step-card > h2 { margin: 0 0 1rem; font-size: clamp(1.45rem, 5vw, 1.9rem); line-height: 1.2; }
.step-card > h2:focus { outline-offset: 5px; }
.step-content { display: grid; gap: 1.1rem; }
.step-description { margin: 0; color: var(--ag-muted); font-size: 1rem; line-height: 1.6; }

.starter-options,
.participant-list,
.section-chooser { min-width: 0; margin: 0; padding: 0; border: 0; }
.starter-options legend,
.participant-list legend,
.section-chooser legend { margin-bottom: 0.65rem; font-size: 1rem; font-weight: 750; }
.starter-options { display: grid; gap: 0.65rem; }
.starter-option {
  position: relative;
  display: flex;
  min-height: 4.25rem;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem;
  border: 1px solid var(--ag-border);
  border-radius: 0.8rem;
  background: var(--ag-surface);
  cursor: pointer;
}
.starter-option:has(input:checked) { border-color: var(--ag-teal); background: color-mix(in srgb, var(--ag-teal) 7%, var(--ag-surface)); box-shadow: inset 0 0 0 1px var(--ag-teal); }
.starter-option input { width: 1.25rem; height: 1.25rem; flex: 0 0 auto; margin: 0.1rem 0 0; accent-color: var(--ag-teal); }
.starter-option-copy { display: grid; gap: 0.25rem; }
.starter-title { font-weight: 800; }
.starter-description,.helper-copy,.example-copy { margin: 0; color: var(--ag-muted); font-size: 0.92rem; line-height: 1.5; }
.starter-sfw { color: var(--ag-teal-dark); font-size: 0.82rem; font-weight: 800; }

.participant-list { display: grid; gap: 0.75rem; }
.participant-row { display: grid; gap: 0.6rem; padding: 0.85rem; border: 1px solid var(--ag-border); border-radius: 0.8rem; }
.field-group { display: grid; gap: 0.4rem; min-width: 0; }
.field-group label { font-weight: 700; line-height: 1.4; }
.field-group label span { color: var(--ag-muted); font-size: 0.92em; font-weight: 500; }
.field-group input,
.field-group textarea { width: 100%; min-height: 3rem; border: 1px solid var(--ag-border); border-radius: 0.65rem; background: var(--ag-surface); color: var(--ag-ink); padding: 0.75rem; }
.field-group textarea { min-height: 8.5rem; line-height: 1.55; resize: vertical; }
.field-group input[aria-invalid="true"],
.field-group textarea[aria-invalid="true"] { border-color: var(--ag-error); }
.character-count { margin: 0; color: var(--ag-muted); font-size: 0.84rem; text-align: end; }
.field-error { margin: 0; color: var(--ag-error); font-size: 0.9rem; font-weight: 700; }
.secondary-button,
.primary-button {
  display: inline-flex;
  min-width: 44px;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ag-teal);
  border-radius: 0.75rem;
  padding: 0.7rem 1rem;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  cursor: pointer;
}
.secondary-button { background: var(--ag-surface); color: var(--ag-teal-dark); }
.primary-button { background: var(--ag-teal); color: #fff; }
.secondary-button:hover:not(:disabled) { background: color-mix(in srgb, var(--ag-teal) 8%, var(--ag-surface)); }
.primary-button:hover { background: var(--ag-teal-dark); }
button:disabled { border-color: var(--ag-border); background: var(--ag-surface-soft); color: var(--ag-muted); cursor: not-allowed; }
.remove-participant { justify-self: start; }
.wizard-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.7rem; margin-top: 1.25rem; }
.wizard-actions .primary-button { margin-inline-start: auto; }

.section-chooser { padding-bottom: 0.25rem; }
.recommendation-note { margin: -0.45rem 0 0; color: var(--ag-muted); font-size: 0.9rem; }
.recommended-label { display: inline-block; margin-inline-start: 0.25rem; border-radius: 999px; padding: 0.12rem 0.5rem; background: #dcebe7; color: #245650; font-size: 0.75rem; font-weight: 800; }
.section-options { display: grid; gap: 0.5rem; }
.section-choice { display: flex; min-height: 3rem; align-items: center; gap: 0.6rem; padding: 0.55rem 0.65rem; border: 1px solid var(--ag-border); border-radius: 0.65rem; cursor: pointer; }
.section-choice input { width: 1.15rem; height: 1.15rem; flex: 0 0 auto; accent-color: var(--ag-teal); }
.section-choice > span:first-of-type { flex: 1; font-weight: 650; }
.section-choice.is-selected { border-color: color-mix(in srgb, var(--ag-teal) 65%, var(--ag-border)); background: color-mix(in srgb, var(--ag-teal) 5%, var(--ag-surface)); }
.section-editor { display: grid; gap: 0.8rem; padding: 1rem; border-radius: 0.85rem; background: var(--ag-surface-soft); }
.section-editor-heading h3,.custom-section-control h3 { margin: 0; font-size: 1.15rem; }
.section-purpose { color: var(--ag-ink); }
.example-copy { border-inline-start: 3px solid var(--ag-teal); padding-inline-start: 0.65rem; }
.section-editor-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.55rem; }
.section-editor-actions .text-button { padding-inline: 0.5rem; }
.empty-sections { border: 1px dashed var(--ag-border); border-radius: 0.8rem; padding: 1rem; color: var(--ag-muted); }
.empty-sections p { margin: 0; line-height: 1.5; }
.custom-section-control { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; border-top: 1px solid var(--ag-border); padding-top: 1rem; }
.custom-section-control h3 { margin-bottom: 0.25rem; }
.custom-section-control > p { flex-basis: 100%; }

.principles-list { display: grid; gap: 0.55rem; margin: 0; padding-inline-start: 1.3rem; line-height: 1.55; }
.safety-note { margin: 0; border-inline-start: 3px solid var(--ag-teal); padding: 0.55rem 0 0.55rem 0.8rem; color: var(--ag-muted); font-size: 0.92rem; line-height: 1.5; }
.review-content { gap: 1rem; }
.review-editor-heading { display: grid; gap: 0.55rem; }
.review-editor-heading h3 { margin: 0; font-size: 1.2rem; }
.review-editor-heading h3:focus { outline-offset: 5px; }
.review-state,.review-stale { margin: 0; font-size: 0.9rem; line-height: 1.45; }
.review-state { color: var(--ag-muted); font-weight: 750; }
.review-stale { border-inline-start: 3px solid var(--ag-teal); padding-inline-start: 0.7rem; color: var(--ag-ink); }
.review-textarea { width: 100%; min-height: 24rem; resize: vertical; border: 1px solid var(--ag-border); border-radius: 0.75rem; background: var(--ag-surface); color: var(--ag-ink); padding: 1rem; font: inherit; font-size: 0.97rem; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.review-actions { display: flex; flex-wrap: wrap; gap: 0.65rem; }
.regeneration-confirmation { display: grid; gap: 0.7rem; border: 1px solid var(--ag-border); border-radius: 0.8rem; background: var(--ag-surface-soft); padding: 1rem; }
.regeneration-confirmation h4,.regeneration-confirmation p { margin: 0; }
.regeneration-confirmation h4 { font-size: 1rem; }
.regeneration-confirmation p { line-height: 1.5; }
.review-status { min-height: 1.4em; margin: 0; color: var(--ag-teal-dark); font-weight: 700; }
.print-review { display: none; }
.error-summary { margin-bottom: 1rem; border: 2px solid var(--ag-error); border-radius: 0.75rem; padding: 0.85rem 1rem; }
.error-summary h3 { margin: 0 0 0.4rem; color: var(--ag-error); font-size: 1rem; }
.error-summary ul { display: grid; gap: 0.4rem; margin: 0; padding-inline-start: 1.2rem; }
.error-summary button { border: 0; background: transparent; color: var(--ag-error); font-weight: 700; text-align: start; text-decoration: underline; text-underline-offset: 0.15em; cursor: pointer; }
.agreement-footer { padding: 1rem 0; color: var(--ag-muted); font-size: 0.85rem; text-align: center; }
.agreement-footer p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }

@media (min-width: 600px) {
  .agreement-app { width: min(100% - 2rem, 50rem); padding-top: max(1.25rem, env(safe-area-inset-top)); }
  .agreement-intro { padding-block: 1.6rem 1.25rem; }
  .progress-panel,.step-card { border-radius: 1.15rem; padding: 1.35rem; }
  .step-name { display: inline; overflow: hidden; font-size: 0.72rem; line-height: 1.15; text-align: start; }
  .step-list li { justify-content: flex-start; }
  .section-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .participant-row { grid-template-columns: minmax(0, 1fr) auto; align-items: end; }
  .remove-participant { margin-bottom: 0.1rem; }
}

@media (min-width: 900px) {
  .agreement-app { width: min(100% - 3rem, 50rem); }
  .step-card { padding: 1.75rem; }
  .step-list { gap: 0.8rem; }
  .step-name { font-size: 0.78rem; }
}

@media (max-height: 480px) and (orientation: landscape) {
  .agreement-app { padding-top: 0.5rem; }
  .agreement-intro { padding-block: 0.75rem; }
  .agreement-intro h1 { font-size: 2rem; }
  .step-list { display: none; }
  .step-card { padding: 0.9rem; }
}

@media (prefers-reduced-motion: reduce) {
  *,*::before,*::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

@page { margin: 18mm; }

@media print {
  :root,html,body { min-height: 0; background: #fff !important; color: #000 !important; }
  .agreement-app { width: auto; margin: 0; padding: 0; }
  .agreement-header,.agreement-intro,.progress-panel,.agreement-footer { display: none !important; }
  .step-card { margin: 0; border: 0; border-radius: 0; background: #fff; box-shadow: none; padding: 0; color: #000; }
  .step-card > h2 { display: none !important; }
  .review-content > :not(.print-review) { display: none !important; }
  .print-review { display: block !important; overflow: visible; margin: 0; padding: 0; color: #000; font: 12pt/1.5 ui-sans-serif, system-ui, sans-serif; white-space: pre-wrap; overflow-wrap: anywhere; }
}
