:root {
  color-scheme: light;
  --bg: #f7f3ea;
  --surface: #fffdf8;
  --surface-2: #ece6da;
  --ink: #172027;
  --muted: #687174;
  --line: #d9d0c1;
  --accent: #1d6f78;
  --accent-2: #8e3b46;
  --accent-3: #b7832f;
  --shadow: 0 14px 36px rgba(24, 31, 36, 0.12);
  --radius: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101820;
  --surface: #17222b;
  --surface-2: #202d36;
  --ink: #f4efe6;
  --muted: #aeb8bc;
  --line: #34434c;
  --accent: #61b8bf;
  --accent-2: #e18a77;
  --accent-3: #d6ac58;
  --shadow: 0 16px 42px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface-2), transparent 12%) 0, transparent 300px),
    var(--bg);
  color: var(--ink);
  font-family:
    ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
  font-size: 17px;
  line-height: 1.62;
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
}

button,
input {
  font: inherit;
}

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

.progress {
  position: fixed;
  z-index: 20;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: transparent;
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--accent-3));
}

.topbar {
  position: sticky;
  z-index: 15;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 18px 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--line), transparent 18%);
  background: color-mix(in srgb, var(--surface), transparent 8%);
  backdrop-filter: blur(18px);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent-2);
  font-family:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.05;
}

main {
  width: min(100%, 860px);
  margin: 0 auto;
  padding: 14px 14px calc(64px + var(--safe-bottom));
}

.icon-button,
.small-button,
.filter,
.back-top {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: none;
}

.icon-button {
  width: 44px;
  font-family:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 1.1rem;
}

.control-panel {
  position: sticky;
  z-index: 10;
  top: 73px;
  margin: 0 -14px 14px;
  padding: 12px 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--line), transparent 10%);
  background: color-mix(in srgb, var(--bg), transparent 6%);
  backdrop-filter: blur(18px);
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.search-box {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0 12px;
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-family:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.96rem;
}

.search-box input::placeholder {
  color: color-mix(in srgb, var(--muted), transparent 18%);
}

.small-button {
  padding: 0 13px;
  font-family:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
}

.filter-row,
.toc {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.filter-row::-webkit-scrollbar,
.toc::-webkit-scrollbar {
  display: none;
}

.filter {
  flex: 0 0 auto;
  padding: 0 13px;
  color: var(--muted);
  font-family:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.86rem;
  font-weight: 800;
}

.filter.is-active {
  border-color: color-mix(in srgb, var(--accent), var(--line) 20%);
  background: color-mix(in srgb, var(--accent), var(--surface) 86%);
  color: var(--ink);
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 9px;
  color: var(--muted);
  font-family:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.8rem;
}

.status-row p {
  margin: 0;
}

.overview {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.metric {
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric strong,
.metric span {
  display: block;
}

.metric strong {
  color: var(--accent-2);
  font-size: 1.05rem;
  line-height: 1.2;
}

.metric span {
  margin-top: 2px;
  color: var(--muted);
  font-family:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.76rem;
  line-height: 1.25;
}

.toc {
  position: relative;
  margin: 10px -14px 12px;
  padding: 0 14px 4px;
}

.toc a {
  flex: 0 0 auto;
  max-width: 74vw;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface), transparent 10%);
  color: var(--muted);
  font-family:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.78rem;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
  white-space: nowrap;
}

.content {
  display: grid;
  gap: 10px;
}

.loading,
.empty {
  padding: 28px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}

.section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: clip;
  scroll-margin-top: 190px;
}

.section summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 64px;
  padding: 14px 14px 13px;
  cursor: pointer;
  list-style: none;
}

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

.summary-title {
  display: block;
  min-width: 0;
}

.summary-kicker {
  display: block;
  margin-bottom: 2px;
  color: var(--accent);
  font-family:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.summary-main {
  display: block;
  color: var(--ink);
  font-size: 1.08rem;
  font-weight: 800;
  line-height: 1.16;
  overflow-wrap: anywhere;
}

.chevron {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-family:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.95rem;
  transition: transform 160ms ease;
}

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

.section-body {
  padding: 0 15px 18px;
  border-top: 1px solid color-mix(in srgb, var(--line), transparent 18%);
}

.section-body h3 {
  margin: 22px 0 8px;
  color: var(--accent-2);
  font-size: 1rem;
  line-height: 1.25;
}

.section-body p {
  margin: 13px 0 0;
}

.section-body ul,
.section-body ol {
  margin: 10px 0 0;
  padding-left: 1.25rem;
}

.section-body li {
  margin: 7px 0;
  padding-left: 0.1rem;
}

.section-body code {
  border: 1px solid color-mix(in srgb, var(--line), transparent 18%);
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface-2), transparent 28%);
  padding: 0.08em 0.28em;
  color: var(--accent-2);
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.88em;
}

.section-body strong {
  color: var(--accent-2);
}

.back-top {
  position: fixed;
  right: 14px;
  bottom: calc(14px + var(--safe-bottom));
  z-index: 18;
  width: 44px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.back-top.is-visible {
  opacity: 1;
  pointer-events: auto;
}

@media (min-width: 720px) {
  body {
    font-size: 18px;
  }

  .topbar {
    padding-left: 28px;
    padding-right: 28px;
  }

  main {
    padding-left: 22px;
    padding-right: 22px;
  }

  .control-panel {
    top: 76px;
    margin-left: -22px;
    margin-right: -22px;
    padding-left: 22px;
    padding-right: 22px;
  }

  .toc {
    margin-left: -22px;
    margin-right: -22px;
    padding-left: 22px;
    padding-right: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .chevron,
  .back-top {
    transition: none;
  }
}
