:root {
  color-scheme: light;
  --bg: #f7f8f2;
  --surface: #fffefa;
  --surface-2: #eef4ec;
  --surface-3: #f5efe5;
  --text: #1c241f;
  --muted: #5c675f;
  --faint: #7d877f;
  --line: #d7ded3;
  --line-strong: #aebbac;
  --green: #2d7a57;
  --green-strong: #155f40;
  --gold: #b57824;
  --red: #b6473d;
  --blue: #326cb3;
  --violet: #7257a7;
  --shadow: 0 14px 40px rgba(40, 50, 38, 0.12);
  --code-bg: #18221d;
  --code-text: #f4f7ec;
  --radius: 8px;
  --topbar-height: 74px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11150f;
  --surface: #181e18;
  --surface-2: #20291f;
  --surface-3: #2a251c;
  --text: #eef3ea;
  --muted: #b7c0b4;
  --faint: #8d998e;
  --line: #334033;
  --line-strong: #556453;
  --green: #75c795;
  --green-strong: #9ad6ae;
  --gold: #e4af55;
  --red: #ef7d71;
  --blue: #8dbaf4;
  --violet: #b59ce8;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
  --code-bg: #090d0a;
  --code-text: #f2f8ec;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-height) + 18px);
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(45, 122, 87, 0.08), transparent 22rem),
    linear-gradient(180deg, var(--bg), var(--bg));
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
}

a {
  color: inherit;
}

code {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--green-strong);
  padding: 0.08rem 0.28rem;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
}

pre code {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 0.95rem;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 20;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  padding: 0.65rem 0.9rem;
  text-decoration: none;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 1rem;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  padding: 0.8rem clamp(1rem, 3vw, 2.25rem);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 13rem;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--green) 50%, var(--line));
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--green-strong);
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  line-height: 1.1;
}

.brand small {
  color: var(--muted);
  font-size: 0.8rem;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  width: min(100%, 49rem);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: min(100%, 31rem);
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0 0.85rem;
  color: var(--faint);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.plain-button,
.filter-button,
.copy-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0.45rem 0.75rem;
}

.plain-button:hover,
.filter-button:hover,
.copy-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.layout {
  display: grid;
  grid-template-columns: 17rem minmax(0, 1fr);
  gap: clamp(1.25rem, 3vw, 3rem);
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 0 clamp(1rem, 3vw, 2.25rem) 4rem;
}

.sidebar {
  position: sticky;
  top: var(--topbar-height);
  align-self: start;
  height: calc(100vh - var(--topbar-height));
  border-right: 1px solid var(--line);
  padding: 2rem 1rem 2rem 0;
  overflow: auto;
}

.sidebar nav {
  display: grid;
  gap: 0.25rem;
}

.nav-link {
  border-left: 3px solid transparent;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--muted);
  padding: 0.58rem 0.75rem;
  text-decoration: none;
}

.nav-link:hover,
.nav-link.is-active {
  border-left-color: var(--green);
  background: var(--surface-2);
  color: var(--text);
}

.source-path {
  margin-top: 2rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

.source-path span {
  display: block;
  color: var(--faint);
  font-size: 0.8rem;
  text-transform: uppercase;
}

.source-path code {
  display: block;
  margin-top: 0.4rem;
  overflow-wrap: anywhere;
}

.content {
  min-width: 0;
}

.wiki-section {
  border-bottom: 1px solid var(--line);
  padding: clamp(2.25rem, 5vw, 4.5rem) 0;
}

.wiki-section:last-child {
  border-bottom: 0;
}

.wiki-section.is-hidden {
  display: none;
}

.section-heading {
  max-width: 58rem;
  margin-bottom: 1.4rem;
}

.section-kicker {
  margin: 0 0 0.3rem;
  color: var(--green-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 52rem;
  margin-bottom: 0.75rem;
  font-size: clamp(2rem, 6vw, 4.3rem);
  line-height: 0.98;
}

h2 {
  margin-bottom: 0.6rem;
  font-size: clamp(1.65rem, 3vw, 2.4rem);
  line-height: 1.08;
}

h3 {
  margin-bottom: 0.45rem;
  font-size: 1rem;
}

p {
  color: var(--muted);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 1.25rem 0 2rem;
  padding: 0;
  list-style: none;
}

.metrics li {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.metrics strong {
  display: block;
  color: var(--green-strong);
  font-size: clamp(1.35rem, 2.5vw, 2rem);
  line-height: 1;
}

.metrics span {
  display: block;
  margin-top: 0.4rem;
  color: var(--muted);
}

.overview-grid,
.rules-grid,
.permissions,
.notes-grid,
.build-details {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
}

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

.fact-panel,
.rule-item,
.permission-item,
.note-item,
.source-card,
.check-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1rem;
}

.fact-panel {
  border-top: 4px solid var(--green);
}

.rule-item:nth-child(2n),
.note-item:nth-child(2n),
.source-card:nth-child(2n) {
  background: var(--surface-3);
}

.check-toolbar,
.config-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.filter-button.is-active {
  border-color: var(--green);
  background: var(--green);
  color: #ffffff;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
}

.check-card {
  min-height: 19rem;
  display: grid;
  gap: 0.7rem;
  align-content: start;
  border-top: 4px solid var(--green);
}

.check-card[data-category="Combat"] {
  border-top-color: var(--red);
}

.check-card[data-category="World"] {
  border-top-color: var(--gold);
}

.check-card[data-category="Utility"] {
  border-top-color: var(--blue);
}

.check-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.check-title h3 {
  margin: 0;
  font-size: 1.2rem;
}

.badge {
  min-width: 5.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  padding: 0.18rem 0.45rem;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
}

.check-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  padding: 0.15rem 0.45rem;
  font-size: 0.78rem;
}

.check-card dl {
  display: grid;
  grid-template-columns: 5rem minmax(0, 1fr);
  gap: 0.45rem 0.75rem;
  margin: 0;
}

.check-card dt {
  color: var(--faint);
  font-size: 0.8rem;
  font-weight: 700;
}

.check-card dd {
  margin: 0;
  color: var(--text);
}

.flow-map {
  display: grid;
  grid-template-columns: minmax(9rem, 1fr) 3rem minmax(9rem, 1fr) 3rem minmax(9rem, 1fr);
  align-items: center;
  gap: 0.8rem;
  margin: 1rem 0 1.25rem;
}

.flow-node {
  min-height: 150px;
  display: grid;
  align-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1rem;
}

.flow-node strong,
.flow-branches strong {
  display: block;
  color: var(--text);
}

.flow-node span,
.flow-branches span {
  color: var(--muted);
}

.flow-arrow {
  height: 2px;
  background: var(--green);
  position: relative;
}

.flow-arrow::after {
  content: "";
  position: absolute;
  right: -1px;
  top: 50%;
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--green);
  border-top: 2px solid var(--green);
  transform: translateY(-50%) rotate(45deg);
}

.flow-branches {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.7rem;
  margin-top: 0.4rem;
}

.flow-branches div {
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 0.8rem;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.8rem 0.9rem;
  text-align: left;
  vertical-align: top;
}

tr:last-child td {
  border-bottom: 0;
}

th {
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.82rem;
  text-transform: uppercase;
}

td {
  color: var(--muted);
}

.permissions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 1rem;
}

.source-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.source-card {
  min-height: 12rem;
}

.source-card header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.source-card h3 {
  margin: 0;
  overflow-wrap: anywhere;
}

.source-card .path {
  display: block;
  margin-top: 0.5rem;
  color: var(--faint);
  overflow-wrap: anywhere;
}

.code-panel {
  position: relative;
  border-radius: var(--radius);
  background: var(--code-bg);
  color: var(--code-text);
  overflow: hidden;
}

.code-panel pre {
  margin: 0;
  padding: 1.2rem;
  overflow: auto;
}

.copy-button {
  position: absolute;
  right: 0.75rem;
  top: 0.75rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  color: var(--text);
}

.build-details {
  margin-top: 1rem;
}

.empty-state {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  padding: 1rem;
}

mark {
  border-radius: 4px;
  background: color-mix(in srgb, var(--gold) 35%, transparent);
  color: inherit;
  padding: 0 0.08rem;
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 1rem 0;
  }

  .sidebar nav {
    display: flex;
    flex-wrap: wrap;
  }

  .nav-link {
    border-left: 0;
    border-bottom: 3px solid transparent;
    border-radius: var(--radius);
  }

  .nav-link:hover,
  .nav-link.is-active {
    border-bottom-color: var(--green);
    border-left-color: transparent;
  }

  .source-path {
    display: none;
  }

  .check-grid,
  .overview-grid,
  .rules-grid,
  .notes-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  :root {
    --topbar-height: auto;
  }

  body {
    background: var(--bg);
  }

  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    align-items: stretch;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .search-box {
    width: 100%;
  }

  .metrics,
  .check-grid,
  .overview-grid,
  .rules-grid,
  .permissions,
  .notes-grid,
  .build-details,
  .source-grid,
  .flow-branches {
    grid-template-columns: 1fr;
  }

  .flow-map {
    grid-template-columns: 1fr;
  }

  .flow-arrow {
    width: 2px;
    height: 34px;
    justify-self: center;
  }

  .flow-arrow::after {
    right: 50%;
    top: auto;
    bottom: -1px;
    transform: translateX(50%) rotate(135deg);
  }

  h1 {
    font-size: 2.45rem;
  }
}
