*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --text: #0f172a;
  --text-muted: #475569;
  --border: #e2e8f0;
  --accent: #1d4ed8;
  --accent-soft: #dbeafe;
  --radius: 8px;
  --shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
  --nav-bg: #ffffff;
  --footer-bg: #ffffff;
  --h1-color: var(--text);
  --h2-color: var(--text);
  --h3-color: var(--text);
  --h4-color: var(--text);
  --h5-color: var(--text);
  --h1-size: 2.2rem;
  --h2-size: 1.7rem;
  --h3-size: 1.35rem;
  --h4-size: 1.1rem;
  --h5-size: 1rem;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

body[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #0f172a;
  --surface-muted: #111827;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --border: #1f2937;
  --accent: #60a5fa;
  --accent-soft: #1d4ed8;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  --nav-bg: #0f172a;
  --footer-bg: #0f172a;
}

body {
  margin: 0;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1 { color: var(--h1-color); font-size: var(--h1-size); }
h2 { color: var(--h2-color); font-size: var(--h2-size); }
h3 { color: var(--h3-color); font-size: var(--h3-size); }
h4 { color: var(--h4-color); font-size: var(--h4-size); }
h5 { color: var(--h5-color); font-size: var(--h5-size); }

.shell {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.25rem;
}

.header-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  align-items: center;
}

.site-header {
  background: var(--nav-bg);
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.brand {
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
  font-size: 1.1rem;
  background: linear-gradient(90deg, #f86816, #ff9a4d);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

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

.badge {
  background: #22c55e;
  color: #0f172a;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
}

.nav a:hover {
  color: var(--text);
}

.nav-toggle {
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius);
  cursor: pointer;
}

.nav-toggle:hover {
  background: var(--surface);
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1rem 0;
  background: var(--footer-bg);
  margin-top: auto;
}

.site-footer .shell {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}

.search {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

.search input[type="search"] {
  flex: 1;
  padding: 0.5rem;
}

.search button {
  padding: 0.5rem 0.75rem;
}

main h1, main h2, main h3 {
  margin-bottom: 0.25rem;
}

.page-hero {
  margin: 0 0 1rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.page-hero h1 {
  margin: 0 0 0.25rem 0;
  color: var(--h1-color);
}

.page-hero p {
  margin: 0;
  color: var(--text-muted);
}

.list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
}

.list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.muted {
  color: var(--text-muted);
  margin: 0.25rem 0 0;
}

.alert {
  background: #fee2e2;
  border: 1px solid #ef4444;
  color: #991b1b;
  padding: 0.75rem;
  margin: 1rem 0;
}

.alert-success {
  background: #dcfce7;
  border: 1px solid #16a34a;
  color: #14532d;
}

.back {
  display: inline-block;
  margin-bottom: 0.75rem;
  text-decoration: none;
  color: #1d4ed8;
}

.rich-text {
  white-space: normal;
}

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.home-cards {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.home-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.home-card h2 {
  margin: 0 0 0.2rem 0;
}

.home-card p {
  margin: 0;
  color: #475569;
  flex: 1;
}

.home-card .button-link {
  flex-shrink: 0;
}

.rule-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1.25rem;
}

.toc {
  position: sticky;
  top: 1rem;
  align-self: start;
  padding: 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #f8fafc;
}

.toc-toggle {
  display: none;
  margin-top: 0.35rem;
  padding: 0.45rem 0.7rem;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
  background: #fff;
  cursor: pointer;
}

.toc-label {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
}

.toc ol {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.toc-link {
  text-decoration: none;
  color: #0f172a;
  display: block;
  padding: 0.3rem 0.35rem;
  border-radius: 4px;
}

.toc-link:hover {
  background: #e2e8f0;
}

.toc-active {
  background: #e0e7ff;
  border-left: 3px solid #1d4ed8;
  padding-left: 0.5rem;
}

.section-block {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.section-header {
  display: grid;
  grid-template-columns: 120px 1fr;
  align-items: center;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  margin: 0.5rem 0;
}

.section-number {
  font-weight: 800;
  font-size: 1.2rem;
}

.section-title {
  font-weight: 700;
  font-size: 1.1rem;
}

.clauses {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
}

.clause-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 0.75rem;
  align-items: start;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.clause-number {
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.clause-body .rich-text {
  margin: 0.15rem 0;
}

.clause-title {
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.permalink {
  text-decoration: none;
  color: #475569;
  margin-left: 0.25rem;
}

.edit-icon {
  text-decoration: none;
  color: #0ea5e9;
  margin-left: 0.35rem;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.clause-row:hover .edit-icon {
  opacity: 1;
}

.history-icon {
  text-decoration: none;
  color: #475569;
  margin-left: 0.35rem;
  font-size: 0.9rem;
}

.clause-header {
  background: var(--surface);
}

.clause-subsection {
  background: var(--surface-muted);
  border-left: 4px solid var(--accent);
  font-weight: 700;
}

.clause-rule .clause-body {
  font-weight: 400;
}

.clause-subrule .clause-body {
  font-weight: 700;
}

.clause-note .clause-body {
  font-style: italic;
  background: #fffbeb;
  border-left: 3px solid #f59e0b;
  padding: 0.5rem;
  border-radius: 4px;
}

.clause-rule-bold .clause-body {
  font-weight: 700;
}

.clause-rule-bold .clause-number {
  font-weight: 800;
}

.clause-visual-header .clause-body {
  display: none;
}

.depth-1 .clause-number {
  padding-left: 0rem;
}

.depth-2 .clause-number {
  padding-left: 1rem;
  color: #1d4ed8;
}

.depth-3 .clause-number {
  padding-left: 2rem;
  color: #22c55e;
}

.depth-4 .clause-number {
  padding-left: 3rem;
  color: #f59e0b;
}

.depth-2 .clause-body {
  padding-left: 1rem;
  border-left: 2px solid #bfdbfe;
}

.depth-3 .clause-body {
  padding-left: 2rem;
  border-left: 2px solid #bbf7d0;
}

.depth-4 .clause-body {
  padding-left: 3rem;
  border-left: 2px solid #fef08a;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 520px;
}

.form.wide {
  max-width: 100%;
}

.form.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.form.two-col .form-actions {
  grid-column: 1 / -1;
}

.inline-form {
  display: inline;
}

.span-all {
  grid-column: 1 / -1;
}

.mt-1 {
  margin-top: 0.5rem;
}

.tabs {
  margin-top: 1rem;
}

.tab-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.tab-button {
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}

.tab-button.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.tab-panel {
  display: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  background: var(--surface);
}

.tab-panel.active {
  display: block;
}

.subtabs {
  margin: 0.5rem 0 1rem;
}

.subtab-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.subtab-button {
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}

.subtab-button.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.subtab-panel {
  display: none;
}

.subtab-panel.active {
  display: block;
}

.form input[type="text"],
.form input[type="password"],
.form textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font: inherit;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.form button,
.form .button-link {
  padding: 0.5rem 0.75rem;
  border: none;
  background: #1d4ed8;
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.form .button-link {
  background: #e2e8f0;
  color: #0f172a;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
  margin: 0.25rem 0;
}

.toolbar button {
  padding: 0.35rem 0.6rem;
  border: 1px solid #cbd5e1;
  background: #f1f5f9;
  border-radius: 4px;
  cursor: pointer;
}

.option-group {
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.75rem;
}

.option-group legend {
  padding: 0 0.35rem;
  font-weight: 600;
}

.option-group label {
  display: block;
  margin: 0.35rem 0;
}

.option-group label input[type="checkbox"] {
  margin-right: 0.35rem;
}

.small {
  font-size: 0.9rem;
}

.filters {
  margin: 1rem 0 1.25rem;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filters-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.75rem 1rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.filters .row-full {
  grid-column: 1 / -1;
  grid-template-columns: 1fr;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.95rem;
}

.filters input,
.filters select {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: 44px;
  background: var(--surface);
  color: var(--text);
}

.search-field {
  width: 100%;
}

.domain-toggles {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.filter-results-separator {
  height: 0;
  margin: 0;
}

.card-grid {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.75rem;
  width: 100%;
}

.card-tile {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.6rem 0.75rem;
  box-sizing: border-box;
  box-shadow: var(--shadow);
}

.card-tile a {
  text-decoration: none;
  color: inherit;
}

.tile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
}

.tile-image {
  width: 100%;
  padding-top: 140px;
  background-size: cover;
  background-position: center;
  border-radius: 4px;
  border: 1px solid #e2e8f0;
  margin: 0.35rem 0;
}

.card-full {
  padding: 0;
  border: none;
}

.tile-image-full img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
}

.filters-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.25rem;
}

.results-count {
  color: #475569;
}

.clear-filters {
  background: #e2e8f0;
  color: #0f172a;
  border: 1px solid #cbd5e1;
}

.domain-pill {
  border: 1px solid transparent;
}

.domain-pill[data-domain="fury"] { background: #8C2D29; color: #fff; }
.domain-pill[data-domain="calm"] { background: #387A57; color: #fff; }
.domain-pill[data-domain="mind"] { background: #2C576F; color: #fff; }
.domain-pill[data-domain="body"] { background: #A05721; color: #fff; }
.domain-pill[data-domain="chaos"] { background: #4C3B68; color: #fff; }
.domain-pill[data-domain="order"] { background: #957C27; color: #fff; }
.domain-pill[data-domain="colorless"] { background: #0f4aff; color: #fff; }

.pill-active {
  box-shadow: 0 0 0 2px #0f172a inset;
  opacity: 0.9;
}

.placeholder {
  background: var(--surface-muted);
  color: var(--text-muted);
  padding: 2rem;
  text-align: center;
  border-radius: 6px;
}

.tile-meta {
  display: flex;
  gap: 0.5rem;
  color: #475569;
  font-size: 0.9rem;
}

.empty-state {
  border: 1px dashed #cbd5e1;
  padding: 1rem;
  border-radius: 8px;
  background: #f8fafc;
  text-align: left;
}

.guide-card {
  padding: 0.75rem 0.85rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.guide-ref-pill {
  background: var(--surface-muted);
  color: var(--text);
  border: 1px solid var(--border);
  text-decoration: none;
}

.guide-ref-pill:focus,
.guide-ref-pill:hover {
  background: var(--surface-muted);
}

.guide-card .pill {
  background: transparent;
  padding: 0.2rem 0.55rem;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: 999px;
}

.guide-card.guide-penalty .pill {
  color: #f97316;
  border-color: rgba(249, 115, 22, 0.3);
  background: rgba(249,115,22,0.08);
}

.guide-card.guide-nopenalty .pill {
  color: #34d399;
  border-color: rgba(52,211,153,0.3);
  background: rgba(52,211,153,0.08);
}

.guide-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.guide-code {
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.guide-title {
  margin: 0.3rem 0 0.35rem 0;
  color: var(--h2-color);
}

.guide-desc {
  color: var(--text-muted);
  margin: 0.35rem 0 0.5rem;
}

.guide-remedy {
  border: 1px solid var(--border);
  background: var(--surface-muted);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  color: var(--text);
}

.guide-remedy-title {
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

.guide-title-accent {
  color: var(--h1-color);
}

.guide-grid {
  width: 100%;
  display: grid;
  gap: 1.25rem;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

@media (min-width: 1100px) {
  .guide-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.guide-card {
  padding: 0.75rem 0.85rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.guide-ref-pill {
  background: var(--surface-muted);
  color: var(--text);
  border: 1px solid var(--border);
  text-decoration: none;
}

.guide-ref-pill:focus,
.guide-ref-pill:hover {
  background: var(--surface-muted);
}

.guide-card .pill {
  background: transparent;
  padding: 0.2rem 0.55rem;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: 999px;
}

.guide-card.guide-penalty .pill {
  color: #f97316;
  border-color: rgba(249, 115, 22, 0.3);
  background: rgba(249,115,22,0.08);
}

.guide-card.guide-nopenalty .pill {
  color: #34d399;
  border-color: rgba(52,211,153,0.3);
  background: rgba(52,211,153,0.08);
}

.guide-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.guide-code {
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.guide-title {
  margin: 0.3rem 0 0.35rem 0;
  color: var(--text);
}

.guide-desc {
  color: var(--text-muted);
  margin: 0.35rem 0 0.5rem;
}

.guide-remedy {
  border: 1px solid var(--border);
  background: var(--surface-muted);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  color: var(--text);
}

.guide-remedy-title {
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

.tile-types,
.tile-domains {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.pill {
  background: var(--surface-muted);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  font-size: 0.85rem;
  border: 1px solid transparent;
}

.pill-domain {
  background: #dbeafe;
  color: #1e3a8a;
}

.pill-muted {
  background: var(--surface-muted);
  color: var(--text);
}

#search-results[hidden] {
  display: none;
}

#search-results .result {
  padding: 0.5rem 0;
  border-bottom: 1px solid #e2e8f0;
}

mark {
  background: #fef08a;
}

.diff-add {
  background: #bbf7d0;
  padding: 0 2px;
}

.diff-del {
  color: #ef4444;
  text-decoration: line-through;
  padding: 0 2px;
}

/* Ensure heading color/size overrides always win */
body h1 { color: var(--h1-color) !important; font-size: var(--h1-size) !important; }
body h2 { color: var(--h2-color) !important; font-size: var(--h2-size) !important; }
body h3 { color: var(--h3-color) !important; font-size: var(--h3-size) !important; }
body h4 { color: var(--h4-color) !important; font-size: var(--h4-size) !important; }
body h5 { color: var(--h5-color) !important; font-size: var(--h5-size) !important; }
.guide-title { color: var(--h2-color) !important; }
.guide-title-accent { color: var(--h1-color) !important; }

.card-detail {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.rule-page .section-block:last-of-type {
  border-bottom: none;
}

.card-header {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1rem;
  align-items: start;
}

.card-image {
  width: 100%;
  max-width: 260px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  display: block;
}

.changelog .list li {
  border-left: 3px solid #0ea5e9;
  padding-left: 0.5rem;
}

.card-hero {
  max-width: 260px;
}

.card-meta h1 {
  margin: 0 0 0.25rem 0;
}

.card-meta p {
  margin: 0.15rem 0;
}

.card-text {
  margin-top: 0.5rem;
  padding: 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  background: #eef2ff;
  border-radius: 999px;
  color: #312e81;
  font-size: 0.95rem;
}

.chip-clear {
  color: #1d4ed8;
  text-decoration: none;
  font-weight: 700;
}

.search-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.search-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.search-summary {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .header-bar {
    grid-template-columns: 1fr;
  }
  .card-header {
    grid-template-columns: 1fr;
  }
  .guide-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }
}

@media (max-width: 920px) {
  .rule-layout {
    grid-template-columns: 1fr;
  }
  .toc {
    position: relative;
    top: auto;
  }
  .toc-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
  }
  .toc {
    display: none;
  }
  .toc.toc-open {
    display: block;
    margin-bottom: 0.75rem;
  }
}

@media (max-width: 720px) {
  .clause-row {
    display: block;
    padding: 0.4rem 0.5rem;
  }
  .clause-number {
    margin-bottom: 0.25rem;
  }
  .clause-body {
    padding-left: 0;
    border-left: none;
  }
  .depth-2 {
    border-left: 3px solid #bfdbfe;
    padding-left: 0.5rem;
  }
  .depth-3 {
    border-left: 3px solid #bbf7d0;
    padding-left: 0.6rem;
  }
  .depth-4 {
    border-left: 3px solid #fef08a;
    padding-left: 0.7rem;
  }
}
