/* ==========================================================================
   rulebook.css — overview page (table of contents + all rules)
   Depends on base.css for tokens and shared components.
   ========================================================================== */

/* ---- Two-column page layout --------------------------------------------- */
.page-layout {
  max-width: 1240px;
  padding-top: 1.5rem;
  padding-bottom: 1rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  flex-grow: 1;
}

@media (min-width: 1000px) {
  .page-layout {
    grid-template-columns: 310px minmax(0, 1fr);
    align-items: start;
  }
}

/* ---- Main column header -------------------------------------------------- */
.page-intro {
  margin-bottom: 1.5rem;
}
.page-intro h1 {
  margin: 0 0 0.35rem;
  letter-spacing: -0.01em;
}
.page-intro .page-meta {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.98rem;
}

/* ---- Sidebar (search + TOC) --------------------------------------------- */
.toc-sidebar {
  min-width: 0;
}

@media (min-width: 1000px) {
  .toc-sidebar {
    position: sticky;
    top: calc(var(--header-h) + 1rem);
  }
}

.toc-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

@media (min-width: 1000px) {
  .toc-inner {
    max-height: calc(100vh - var(--header-h) - 2.5rem);
    overflow: hidden;
  }
  /* Bound the scroll on the element that actually scrolls. The flex/`<details>`
     chain doesn't propagate a height, so cap it against the viewport here. */
  .toc-scroll {
    max-height: calc(100vh - var(--header-h) - 8rem);
    overflow-y: auto;
  }
  /* On desktop the TOC is a permanent sidebar: hide the disclosure toggle.
     The <details> is force-opened via JS at this breakpoint (see template). */
  .toc-sidebar .toc-details > summary { display: none; }
}

/* Search field */
.toc-search {
  position: relative;
  flex-shrink: 0;
}
.toc-search input {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0.55rem 0.75rem 0.55rem 2.2rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.toc-search input::placeholder { color: var(--text-muted); }
.toc-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.toc-search .search-icon {
  position: absolute;
  left: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.05rem;
  height: 1.05rem;
  pointer-events: none;
  opacity: 0.6;
  color: var(--text-muted);
}

/* TOC collapsible wrapper */
.toc-details {
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.toc-details > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  padding: 0.35rem 0.25rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.toc-details > summary::-webkit-details-marker { display: none; }
.toc-details > summary::before {
  content: "▸";
  color: var(--accent);
  transition: transform 0.15s ease;
}
.toc-details[open] > summary::before { transform: rotate(90deg); }

/* TOC list */
.toc-scroll {
  overflow-y: auto;
  margin-top: 0.5rem;
  padding-right: 0.15rem;
}
#toc {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.toc-li a {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  padding: 0.4rem 0.55rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  line-height: 1.3;
  font-size: 0.95rem;
}
.toc-li a:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.toc-li a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.toc-num {
  flex-shrink: 0;
  min-width: 2ch;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.toc-li a:hover .toc-num,
.toc-li a.active .toc-num { color: var(--accent); }

.toc-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 0.5rem;
  display: none;
}

/* ---- Rule cards ---------------------------------------------------------- */
.rules-main { min-width: 0; }

.rule {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem 1.6rem;
  margin: 0 0 1.5rem;
  scroll-margin-top: calc(var(--header-h) + 12px);
}

.rule_name {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0 0 1rem;
  font-size: 1.4rem;
}
.rule-title { color: var(--text); font-weight: 700; }
.rule-actions {
  margin-left: auto;
  display: inline-flex;
  gap: 0.15rem;
  opacity: 0.55;
  transition: opacity 0.15s ease;
}
.rule:hover .rule-actions,
.rule-actions:focus-within { opacity: 1; }

/* Rule / subrule number badges */
.rule-badge,
.subrule-badge {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  font-weight: 700;
  border-radius: 999px;
  line-height: 1;
}
.rule-badge {
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  padding: 0.35rem 0.7rem;
}
.subrule-badge {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  padding: 0.28rem 0.6rem;
}

.rule_content {
  color: var(--text);
}

/* Subrules */
.subrule {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  scroll-margin-top: calc(var(--header-h) + 12px);
}
.subrule:first-of-type {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}
.subrule_name {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 0.6rem;
  font-size: 1.08rem;
  color: var(--text);
}
.subrule-title { color: var(--text); font-weight: 600; }
.subrule_content { color: var(--text); }

/* Ordered lists inside rule content */
.rule_content ol,
.subrule_content ol {
  list-style: decimal;
  margin: 0.5rem 0 1rem;
  padding-left: 1.5rem;
}
.rule_content li,
.subrule_content li { margin-bottom: 0.35rem; }

/* Cross-reference links inside content */
.rule_content a,
.subrule_content a {
  color: var(--link);
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: var(--accent-soft);
  text-underline-offset: 2px;
}
.rule_content a:hover,
.subrule_content a:hover {
  color: var(--link-hover);
  text-decoration-color: currentColor;
}

/* ---- "Link copied" toast ------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.75rem;
  transform: translate(-50%, 1rem);
  z-index: 100;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.1rem;
  background: var(--header-bg);
  color: #ffffff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  font-size: 0.95rem;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}
.toast::before {
  content: "✓";
  color: var(--accent);
  font-weight: 700;
}
.toast.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}
@media (prefers-reduced-motion: reduce) {
  .toast { transition: opacity 0.2s ease, visibility 0.2s; }
  .toast.is-visible { transform: translate(-50%, 0); }
}
