:root {
  color-scheme: light dark;
  --page-bg: #f4f7fb;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --surface-strong: #eef2f7;
  --text: #182230;
  --text-muted: #526071;
  --border: #d9e1ea;
  --link: #075fba;
  --link-hover: #034986;
  --accent: #2457d6;
  --accent-soft: #e8efff;
  --success: #1f6a44;
  --success-soft: #e5f6ec;
  --warning: #8a5200;
  --warning-soft: #fff3d6;
  --danger: #a1261d;
  --danger-soft: #fff0ef;
  --info: #365b7c;
  --info-soft: #e8f1f8;
  --code-bg: #172033;
  --code-text: #f4f7fb;
  --shadow: 0 12px 36px rgb(25 39 58 / 10%);
  --radius: 0.75rem;
  --content-width: 78rem;
}

html[data-color-scheme="dark"] {
  --page-bg: #10151d;
  --surface: #171e28;
  --surface-muted: #1d2632;
  --surface-strong: #263141;
  --text: #edf2f8;
  --text-muted: #a9b6c6;
  --border: #344255;
  --link: #82b9ff;
  --link-hover: #b6d5ff;
  --accent: #8ab4ff;
  --accent-soft: #203556;
  --success: #92ddb2;
  --success-soft: #193b2a;
  --warning: #ffd17c;
  --warning-soft: #493719;
  --danger: #ffaaa3;
  --danger-soft: #462226;
  --info: #a7c8e7;
  --info-soft: #203648;
  --code-bg: #0b1017;
  --code-text: #f2f5f8;
  --shadow: 0 16px 44px rgb(0 0 0 / 35%);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 2rem clamp(1rem, 3vw, 3rem) 5rem;
  background: var(--page-bg);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  font-size: 1rem;
  line-height: 1.65;
}

body > * {
  width: min(100%, var(--content-width));
  margin-right: auto;
  margin-left: auto;
}

a {
  color: var(--link);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

a:hover {
  color: var(--link-hover);
}

.theme-toggle {
  display: block;
  width: auto;
  margin: 0 0 1rem auto;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
  font: inherit;
  font-size: 0.875rem;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  border-color: var(--accent);
  outline: none;
}

#title-block-header {
  padding: clamp(1.5rem, 4vw, 3rem);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.25);
  background: linear-gradient(145deg, var(--surface), var(--accent-soft));
  box-shadow: var(--shadow);
}

#title-block-header .title {
  max-width: 25ch;
  margin: 0 0 0.75rem;
  font-size: clamp(2rem, 5vw, 3.6rem);
  line-height: 1.08;
  letter-spacing: -0.035em;
}

.subtitle {
  max-width: 76ch;
  margin: 0;
  color: var(--text-muted);
  font-size: 1.1rem;
}

.document-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: 1.25rem 0 0;
  padding: 0;
  color: var(--text-muted);
  list-style: none;
}

.document-meta li {
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.875rem;
}

#TOC {
  margin-top: 1.5rem;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

#TOC h2 {
  margin-top: 0;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#TOC ol {
  columns: 2 22rem;
  margin-bottom: 0;
  padding-left: 1.25rem;
}

#TOC li {
  break-inside: avoid;
  margin: 0.25rem 0;
}

section {
  margin-top: 1.5rem;
  padding: clamp(1.25rem, 3vw, 2rem);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

h1,
h2,
h3,
h4 {
  line-height: 1.25;
  letter-spacing: -0.015em;
}

h2 {
  margin-top: 0;
  font-size: clamp(1.45rem, 3vw, 2rem);
}

h3 {
  margin-top: 1.5rem;
  font-size: 1.25rem;
}

h4 {
  margin-bottom: 0.35rem;
  font-size: 1rem;
}

p,
ul,
ol,
table,
pre,
blockquote {
  margin-top: 0.75rem;
  margin-bottom: 1rem;
}

li + li {
  margin-top: 0.35rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  font-size: 0.94rem;
}

caption {
  margin-bottom: 0.5rem;
  color: var(--text-muted);
  text-align: left;
  font-weight: 700;
}

th,
td {
  padding: 0.72rem 0.82rem;
  border: 1px solid var(--border);
  vertical-align: top;
  text-align: left;
}

th {
  background: var(--surface-strong);
  font-weight: 700;
}

tbody tr:nth-child(even) td {
  background: var(--surface-muted);
}

code,
kbd,
samp {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
}

code {
  padding: 0.12em 0.32em;
  border-radius: 0.3rem;
  background: var(--surface-strong);
}

pre {
  overflow-x: auto;
  padding: 1rem 1.1rem;
  border-radius: 0.6rem;
  background: var(--code-bg);
  color: var(--code-text);
}

pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.callout,
.business-logic-block {
  margin: 1rem 0;
  padding: 0.85rem 1rem;
  border-left: 0.3rem solid var(--accent);
  border-radius: 0 0.5rem 0.5rem 0;
  background: var(--accent-soft);
}

.callout > :first-child,
.business-logic-block > :first-child {
  margin-top: 0;
}

.callout > :last-child,
.business-logic-block > :last-child {
  margin-bottom: 0;
}

.business-logic,
.business-rule,
[data-doc-role="business-logic"] {
  color: var(--danger);
  font-weight: 680;
}

.business-logic-block {
  border-left-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.implementation-status,
.task-status,
.label {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.35;
  letter-spacing: 0.035em;
  text-transform: uppercase;
}

.implementation-status {
  margin: 0 0 1rem;
}

.implementation-status--done,
.task-status--done,
.label--success {
  background: var(--success-soft);
  color: var(--success);
}

.implementation-status--partial,
.implementation-status--pending,
.task-status--pending,
.label--warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.label--info {
  background: var(--info-soft);
  color: var(--info);
}

.label--danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.metric-grid,
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0.8rem;
  margin: 1rem 0;
}

.metric,
.card {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  background: var(--surface-muted);
}

.metric strong {
  display: block;
  font-size: 1.65rem;
  line-height: 1.15;
}

.metric span,
.muted {
  color: var(--text-muted);
}

.card h3,
.card h4 {
  margin-top: 0;
}

.task-list {
  padding-left: 1.4rem;
}

.task-list li {
  padding: 0.4rem 0;
}

.task-list .task-status {
  margin-right: 0.45rem;
}

.nowrap {
  white-space: nowrap;
}

.back-link {
  margin-top: 1.5rem;
  text-align: right;
}

@media (max-width: 48rem) {
  body {
    padding-right: 0.75rem;
    padding-left: 0.75rem;
  }

  #TOC ol {
    columns: 1;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  td:last-child {
    min-width: 20rem;
    white-space: normal;
  }
}

@media print {
  :root,
  html[data-color-scheme="dark"] {
    --page-bg: #ffffff;
    --surface: #ffffff;
    --surface-muted: #f7f7f7;
    --surface-strong: #eeeeee;
    --text: #000000;
    --text-muted: #3c3c3c;
    --border: #bdbdbd;
    --link: #000000;
    --link-hover: #000000;
    --accent: #1f4b99;
    --accent-soft: #eef3fb;
    --success: #155636;
    --success-soft: #e6f3eb;
    --warning: #6f4200;
    --warning-soft: #fff1cf;
    --danger: #8f130b;
    --danger-soft: #fae9e7;
    --info: #244a6b;
    --info-soft: #e9f0f6;
    --code-bg: #eeeeee;
    --code-text: #000000;
    --shadow: none;
  }

  body {
    padding: 0;
    font-size: 10pt;
  }

  .theme-toggle {
    display: none;
  }

  #title-block-header,
  #TOC,
  section,
  .card,
  .metric {
    break-inside: avoid-page;
    box-shadow: none;
  }

  a {
    text-decoration: none;
  }

  a[href^="http"]::after {
    content: " (" attr(href) ")";
    overflow-wrap: anywhere;
    font-size: 0.8em;
  }
}
