/* Rules section — the Rules tab hub on index.php (rules-hub.php) and the
   pre-built rulebook pages rules-<slug>.php (build-rules.php, rules-page.js). */

/* ── Hub (Rules tab) ─────────────────────────────────────────── */
.rules-hub {
  padding: 8px 4px 12px;
}

.rules-hub-title {
  margin: 0 0 4px;
  font-size: 1.4rem;
  color: var(--text);
}

.rules-hub-lead {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.92rem;
}

.rules-hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.rules-hub-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  background: rgba(8, 15, 29, 0.72);
  color: var(--text);
  text-decoration: none;
  transition: border-color 150ms ease, transform 150ms ease;
}

.rules-hub-card:hover,
.rules-hub-card:focus-visible {
  border-color: rgba(125, 211, 252, 0.45);
  transform: translateY(-2px);
}

.rules-hub-card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
}

.rules-hub-card-era {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.rules-hub-card-desc {
  font-size: 0.86rem;
  line-height: 1.55;
  color: #94a3b8;
}

/* ── Rulebook page ───────────────────────────────────────────── */
.rules-page {
  padding: 24px 28px 48px;
}

.rules-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.rules-switcher-link {
  padding: 6px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
  text-decoration: none;
}

.rules-switcher-link:hover {
  color: var(--text);
  border-color: rgba(125, 211, 252, 0.32);
}

.rules-switcher-link.is-active {
  color: var(--accent);
  border-color: rgba(125, 211, 252, 0.45);
  background: rgba(125, 211, 252, 0.08);
}

.rules-title {
  margin: 0 0 4px;
  font-size: 1.6rem;
  color: var(--text);
}

.rules-meta {
  margin: 0 0 24px;
  font-size: 0.82rem;
  color: var(--muted);
}

.rules-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

.rules-sidebar {
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 32px);
  min-height: 0;
}

/* Filter box */
.rules-filter {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rules-filter-input {
  flex: 1;
  min-width: 0;
  height: var(--pill-height);
  padding: 0 12px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  background: rgba(3, 7, 18, 0.8);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
}

.rules-filter-input:focus {
  outline: none;
  border-color: rgba(125, 211, 252, 0.5);
}

.rules-filter-count {
  min-width: 3.5em;
  font-size: 0.76rem;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
}

.rules-filter-count:empty {
  display: none;
}

.rules-filter-step {
  width: 32px;
  height: var(--pill-height);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  background: rgba(8, 15, 29, 0.72);
  color: var(--text);
  cursor: pointer;
}

.rules-filter-step:disabled {
  opacity: 0.35;
  cursor: default;
}

mark.rules-hit {
  background: rgba(250, 204, 21, 0.28);
  color: inherit;
  border-radius: 2px;
}

mark.rules-hit.is-current {
  background: rgba(250, 204, 21, 0.75);
  color: #0a0f1a;
}

/* Table of contents */
.rules-toc {
  min-height: 0;
  overflow-y: auto;
  padding: 12px 10px 12px 14px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  background: rgba(3, 7, 18, 0.5);
}

.rules-toc-summary {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}

.rules-toc-list,
.rules-toc-sub {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rules-toc-list {
  margin-top: 8px;
}

.rules-toc-sub {
  padding-left: 12px;
  border-left: 1px solid rgba(148, 163, 184, 0.12);
  margin: 2px 0 6px 4px;
}

.rules-toc a {
  display: block;
  padding: 3px 4px;
  border-radius: 6px;
  color: #94a3b8;
  font-size: 0.82rem;
  line-height: 1.35;
  text-decoration: none;
}

.rules-toc-list > li > a {
  color: var(--text);
  font-weight: 600;
}

.rules-toc a:hover {
  color: var(--accent);
}

.rules-toc a.is-current {
  color: var(--accent);
  background: rgba(125, 211, 252, 0.08);
}

/* Body */
.rules-body {
  max-width: 780px;
  color: #b6c2d3;
  font-size: 0.93rem;
  line-height: 1.75;
}

.rules-body .rules-heading {
  position: relative;
  color: var(--text);
  scroll-margin-top: 16px;
}

.rules-body h2.rules-heading {
  margin: 40px 0 12px;
  padding-bottom: 8px;
  font-size: 1.3rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
}

.rules-body h2.rules-heading:first-child {
  margin-top: 0;
}

.rules-body h3.rules-heading {
  margin: 28px 0 8px;
  font-size: 1.06rem;
}

.rules-body h4.rules-heading {
  margin: 20px 0 6px;
  font-size: 0.95rem;
  color: var(--accent);
}

.rules-anchor {
  position: absolute;
  left: -1.1em;
  width: 1em;
  color: var(--muted);
  text-decoration: none;
  opacity: 0;
  transition: opacity 120ms ease;
}

.rules-heading:hover .rules-anchor,
.rules-anchor:focus-visible {
  opacity: 1;
}

.rules-anchor:hover {
  color: var(--accent);
}

.rules-body p,
.rules-body ul,
.rules-body ol {
  margin: 0 0 12px;
}

.rules-body ul,
.rules-body ol {
  padding-left: 22px;
}

.rules-body li {
  margin-bottom: 4px;
}

.rules-body li > ul,
.rules-body li > ol {
  margin: 4px 0 0;
}

.rules-body strong {
  color: var(--text);
}

.rules-body blockquote {
  margin: 0 0 14px;
  padding: 8px 16px;
  border-left: 3px solid rgba(125, 211, 252, 0.35);
  background: rgba(125, 211, 252, 0.04);
  color: #94a3b8;
  font-style: italic;
}

.rules-body blockquote p:last-child {
  margin-bottom: 0;
}

/* Obsidian Hand (OBH) rule changes: struck 20F text + amber callout boxes. */
.rules-body del {
  color: var(--muted);
  opacity: 0.7;
  text-decoration-color: rgba(251, 191, 36, 0.7);
}

.rules-body del strong {
  color: inherit;
}

.rules-obh {
  margin: 0 0 16px;
  padding: 10px 16px 4px;
  border-left: 3px solid #fbbf24;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: rgba(251, 191, 36, 0.07);
}

.rules-body .rules-obh h4.rules-heading {
  margin: 4px 0 8px;
  color: #fcd34d;
}

.rules-obh blockquote {
  font-style: normal;
}

.rules-obh-note {
  padding: 6px 14px 0;
  font-size: 0.92em;
}

.rules-body a:not(.rules-anchor) {
  color: var(--accent);
  text-decoration-color: rgba(125, 211, 252, 0.45);
  text-underline-offset: 3px;
}

.rules-body a:not(.rules-anchor):hover {
  color: #bae6fd;
  text-decoration-color: currentColor;
}

.rules-body .rules-obh a:not(.rules-anchor) {
  color: #fcd34d;
  text-decoration-color: rgba(252, 211, 77, 0.45);
}

.rules-body .rules-obh a:not(.rules-anchor):hover {
  color: #fde68a;
  text-decoration-color: currentColor;
}

/* Collapsed "20F original" panel inside an OBH box: the replaced text, struck. */
.rules-original {
  margin: 4px 0 12px;
  border-top: 1px solid rgba(251, 191, 36, 0.18);
  padding-top: 8px;
}

.rules-original > summary {
  cursor: pointer;
  width: fit-content;
  color: var(--muted);
  font-size: 0.88em;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.rules-original > summary:hover,
.rules-original > summary:focus-visible {
  color: var(--text);
}

.rules-original-body {
  margin-top: 8px;
  color: var(--muted);
  opacity: 0.75;
  text-decoration: line-through;
  text-decoration-color: rgba(251, 191, 36, 0.6);
}

.rules-original-body strong {
  color: inherit;
}

.rules-body hr {
  border: none;
  border-top: 1px solid rgba(148, 163, 184, 0.14);
  margin: 24px 0;
}

.rules-table-wrap {
  overflow-x: auto;
  margin: 0 0 16px;
}

.rules-body table {
  border-collapse: collapse;
  font-size: 0.86rem;
  line-height: 1.5;
}

.rules-body th,
.rules-body td {
  padding: 6px 12px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  text-align: left;
  vertical-align: top;
}

.rules-body th {
  background: rgba(125, 211, 252, 0.07);
  color: var(--text);
}

@media (max-width: 900px) {
  .rules-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }

  /* Flatten the sidebar so the finder's sticky range is the whole layout,
     not just the sidebar box. */
  .rules-sidebar {
    display: contents;
  }

  /* Compact finder pinned to the bottom of the screen while reading
     (just above the bottom tab bar on phones, see the 720px block). */
  .rules-filter {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 39;
    gap: 4px;
    padding: 5px 10px calc(5px + env(safe-area-inset-bottom, 0px));
    background: #050a16;
    border-top: 1px solid rgba(125, 211, 252, 0.18);
    box-shadow: 0 -6px 14px rgba(2, 6, 23, 0.55);
  }

  .rules-filter-input,
  .rules-filter-step {
    height: 32px;
  }

  /* 16px keeps iOS from zooming in when the field is focused. */
  .rules-filter-input {
    font-size: 16px;
    padding: 0 10px;
  }

  .rules-filter-count {
    min-width: 3em;
  }

  body:has(#rules-filter-input) {
    padding-bottom: 46px;
  }

  body:has(#rules-filter-input) .back-to-top-btn {
    bottom: 60px;
  }

  .rules-toc {
    max-height: 60vh;
  }

  .rules-body .rules-heading {
    scroll-margin-top: 64px;
  }

  .rules-anchor {
    position: static;
    margin-right: 6px;
    opacity: 0.5;
  }
}

@media (max-width: 720px) {
  .rules-page {
    padding: 18px 16px 40px;
  }

  /* Sit directly on top of the fixed bottom tab bar. rules-page.js sets
     --rules-nav-h to the bar's real height (incl. the safe-area inset). */
  body:has(#mobile-bottom-nav) .rules-filter {
    bottom: var(--rules-nav-h, calc(59px + env(safe-area-inset-bottom, 0px)));
    padding-bottom: 5px;
  }

  body:has(#mobile-bottom-nav):has(#rules-filter-input) {
    padding-bottom: calc(68px + 43px + env(safe-area-inset-bottom, 0px));
  }

  body:has(#mobile-bottom-nav):has(#rules-filter-input) .back-to-top-btn {
    bottom: calc(68px + 43px + 14px + env(safe-area-inset-bottom, 0px));
  }

  .rules-title {
    font-size: 1.3rem;
  }

  /* One swipeable row instead of six wrapped rows of pills. */
  .rules-switcher {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin: 0 -16px 18px;
    padding: 0 16px 4px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .rules-switcher::-webkit-scrollbar {
    display: none;
  }

  .rules-switcher-link {
    flex: none;
    white-space: nowrap;
  }
}
