:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-muted: #eef1f5;
  --ink: #121417;
  --muted: #69707d;
  --line: #d9dee7;
  --red: #b42335;
  --red-soft: #f7e7ea;
  --teal: #146c63;
  --teal-soft: #e3f2ef;
  --gold: #b57f18;
  --gold-soft: #fbf0d8;
  --gold-ink: #7b4f07;
  --violet: #5b4b8a;
  --solid-badge-ink: #ffffff;
  --topbar-bg: rgba(246, 247, 249, 0.94);
  --focus-ring: rgba(20, 108, 99, 0.14);
  --red-border: rgba(180, 35, 53, 0.42);
  --brand-shadow: 0 6px 16px rgba(180, 35, 53, 0.18);
  --shadow: 0 14px 34px rgba(18, 20, 23, 0.08);
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111317;
  --panel: #191c22;
  --panel-muted: #232833;
  --ink: #eef1f5;
  --muted: #a7afbc;
  --line: #323845;
  --red: #ff7b8a;
  --red-soft: #3a2027;
  --teal: #6fd2c6;
  --teal-soft: #173532;
  --gold: #f0bf5f;
  --gold-soft: #392d18;
  --gold-ink: #f0bf5f;
  --violet: #8f83d8;
  --solid-badge-ink: #111317;
  --topbar-bg: rgba(17, 19, 23, 0.94);
  --focus-ring: rgba(111, 210, 198, 0.18);
  --red-border: rgba(255, 123, 138, 0.48);
  --brand-shadow: 0 6px 16px rgba(255, 123, 138, 0.18);
  --shadow: 0 18px 38px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(150px, 220px) minmax(220px, 620px) auto auto;
  gap: 20px;
  align-items: center;
  min-height: 72px;
  padding: 14px clamp(14px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
}

.seo-topbar {
  grid-template-columns: minmax(150px, 220px) minmax(220px, 620px) auto;
}

.seo-nav {
  display: inline-flex;
  justify-self: end;
  gap: 6px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.seo-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.seo-nav a:hover {
  background: var(--panel-muted);
  color: var(--ink);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  box-shadow: var(--brand-shadow);
}

.brand-text {
  font-size: 20px;
  font-weight: 800;
}

.search-wrap {
  position: relative;
  width: 100%;
  max-width: 620px;
}

.search-wrap input {
  width: 100%;
  height: 44px;
  padding: 0 46px 0 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

.search-wrap input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.search-wrap .icon-button {
  position: absolute;
  top: 6px;
  right: 7px;
}

.icon-button:hover {
  border-color: var(--line);
  background: var(--panel-muted);
  color: var(--ink);
}

.edition-toggle,
.theme-toggle {
  display: inline-flex;
  justify-self: end;
  min-width: 0;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.edition-option,
.theme-option {
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.edition-option:hover,
.theme-option:hover {
  color: var(--ink);
}

.edition-option.is-active,
.theme-option.is-active {
  background: var(--panel-muted);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}

.workspace {
  display: grid;
  grid-template-columns: 220px minmax(270px, 420px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px clamp(14px, 3vw, 32px) 32px;
}

.seo-main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px clamp(14px, 3vw, 32px) 42px;
}

.seo-breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.seo-breadcrumbs a {
  color: var(--muted);
  text-decoration: none;
}

.seo-breadcrumbs a:hover {
  color: var(--teal);
}

.seo-detail {
  max-width: 100%;
}

.seo-open-app {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.seo-open-app:hover {
  border-color: var(--red-border);
  color: var(--red);
}

.seo-content {
  margin-top: 20px;
}

.seo-link-list {
  display: grid;
  gap: 10px;
  margin: 24px 0 0;
  padding: 0;
  list-style: none;
}

.seo-link-list li {
  display: grid;
  gap: 5px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.seo-link-list a {
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  text-decoration: none;
}

.seo-link-list a:hover {
  color: var(--red);
}

.seo-link-list span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.seo-category-grid .home-tile {
  text-decoration: none;
}

.workspace.is-home {
  grid-template-columns: 220px minmax(0, 1fr);
}

.workspace.is-home .entry-list {
  display: none;
}

.sidebar {
  position: sticky;
  top: 90px;
  align-self: start;
  max-height: calc(100vh - 110px);
  overflow: auto;
  padding-right: 4px;
}

.category-tabs {
  display: grid;
  gap: 8px;
}

.category-button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
}

.category-button:hover {
  background: var(--panel-muted);
  color: var(--ink);
}

.category-button.is-active {
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.category-button .count {
  color: var(--muted);
  font-size: 12px;
}

.sidebar-meta {
  display: grid;
  gap: 6px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
}

.source-attribution {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.source-attribution a {
  color: var(--teal);
}

.entry-list,
.detail {
  min-width: 0;
}

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

.entry-card {
  display: grid;
  gap: 8px;
  width: 100%;
  min-height: 122px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.entry-card:hover,
.entry-card.is-active {
  border-color: var(--red-border);
  box-shadow: var(--shadow);
}

.entry-card.is-active {
  background: linear-gradient(90deg, var(--red-soft), var(--panel));
}

.entry-topline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--panel-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.badge.rules {
  background: var(--teal-soft);
  color: var(--teal);
}

.badge.legal,
.badge.character,
.badge.glossary,
.badge.gameplay {
  background: var(--panel-muted);
  color: var(--muted);
}

.badge.spells {
  background: var(--violet);
  color: var(--solid-badge-ink);
}

.badge.classes,
.badge.backgrounds,
.badge.species,
.badge.feats {
  background: var(--gold-soft);
  color: var(--gold-ink);
}

.badge.equipment,
.badge.magic-items {
  background: var(--red-soft);
  color: var(--red);
}

.badge.monsters {
  background: var(--teal);
  color: var(--solid-badge-ink);
}

.entry-card h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.22;
}

.entry-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.42;
}

.detail {
  min-height: calc(100vh - 122px);
  padding: clamp(18px, 3vw, 30px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.workspace.is-home .detail {
  min-height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.home-view {
  display: grid;
  gap: 22px;
  min-width: 0;
}

.home-header {
  display: grid;
  gap: 10px;
  min-width: 0;
  max-width: 900px;
}

.home-eyebrow {
  margin: 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

.home-header h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1.04;
}

.home-lead {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.home-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 2px;
}

.home-stat {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
  min-width: 0;
}

.home-tile {
  display: grid;
  gap: 10px;
  align-content: start;
  min-width: 0;
  min-height: 188px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
  overflow: hidden;
  cursor: pointer;
}

.home-tile .badge {
  justify-self: start;
  max-width: 100%;
  white-space: normal;
}

.home-tile:hover {
  border-color: var(--red-border);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.home-tile:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.home-tile h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.home-tile p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.home-examples {
  min-height: 38px;
}

.home-tile-footer {
  align-self: end;
  margin-top: auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.home-tile-footer strong {
  color: var(--ink);
  font-size: 16px;
}

.home-empty {
  min-height: 180px;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
}

.detail-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
}

.detail h1 {
  margin: 8px 0 10px;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.02;
}

.detail-summary {
  max-width: 850px;
  margin: 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.5;
}

.detail-subtitle {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 18px;
  font-weight: 700;
}

.detail-actions {
  display: flex;
  gap: 8px;
}

.action-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.action-button:hover,
.action-button.is-active {
  border-color: var(--red-border);
  background: var(--red-soft);
  color: var(--red);
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
  margin: 22px 0;
}

.meta-item {
  min-height: 70px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.meta-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.meta-value {
  display: block;
  margin-top: 6px;
  font-weight: 700;
}

.detail-body {
  display: grid;
  gap: 14px;
  max-width: 850px;
}

.detail-body p {
  margin: 0;
  font-size: 16px;
  line-height: 1.66;
}

.srd-content h2,
.srd-content h3,
.srd-content h4 {
  margin: 14px 0 0;
  line-height: 1.18;
}

.srd-content h2 {
  font-size: 25px;
}

.srd-content h3 {
  font-size: 21px;
}

.srd-content h4 {
  font-size: 18px;
}

.srd-content ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
}

.srd-content li {
  line-height: 1.55;
}

.srd-content blockquote {
  margin: 0;
  padding: 12px 14px;
  border-left: 4px solid var(--gold);
  background: var(--gold-soft);
}

.table-caption {
  color: var(--ink);
  font-weight: 800;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.srd-content table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  background: var(--panel);
}

.srd-content th,
.srd-content td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
  line-height: 1.42;
}

.srd-content th:last-child,
.srd-content td:last-child {
  border-right: 0;
}

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

.srd-content th {
  background: var(--panel-muted);
  font-weight: 800;
}

.srd-content code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--panel-muted);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 220px;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.not-found {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 100vh;
  padding: 24px;
  text-align: center;
}

.not-found-mark {
  width: 92px;
  height: 92px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.not-found h1 {
  margin: 24px 0 8px;
  font-size: clamp(30px, 5vw, 52px);
  line-height: 1.04;
}

.not-found p {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 17px;
}

.not-found a {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  box-shadow: var(--shadow);
}

.not-found a:hover {
  border-color: var(--red-border);
  color: var(--red);
}

@media (max-width: 1040px) {
  .workspace {
    grid-template-columns: 190px minmax(260px, 360px) minmax(0, 1fr);
  }

  .meta-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 860px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .seo-topbar {
    grid-template-columns: 1fr;
  }

  .seo-nav {
    justify-self: start;
  }

  .edition-toggle,
  .theme-toggle {
    justify-self: start;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .workspace.is-home {
    grid-template-columns: 1fr;
  }

  .workspace.is-home .detail {
    order: -1;
  }

  .sidebar {
    position: static;
  }

  .category-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail {
    min-height: auto;
  }
}

@media (max-width: 560px) {
  .workspace {
    max-width: 100vw;
    overflow-x: hidden;
  }

  .home-view,
  .home-header,
  .home-grid {
    width: 100%;
    max-width: calc(100vw - 28px);
  }

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

  .home-tile {
    width: 100%;
    max-width: calc(100vw - 28px);
  }

  .home-lead,
  .home-tile h2,
  .home-tile p {
    max-width: calc(100vw - 62px);
  }

  .category-tabs,
  .meta-grid {
    grid-template-columns: 1fr;
  }

  .detail-header {
    grid-template-columns: 1fr;
  }

  .seo-open-app {
    justify-self: start;
  }

  .detail-actions {
    justify-content: flex-start;
  }
}
