/* rules.css
   Styles for the Rules page only: its two-column layout (document + contents) and the
   typography for rendered markdown. Everything is scoped under .rules-*.
   Load after core.css. */

.rules-layout {
  /* Gap kept above anything scrolled to, and the contents list's resting position:
     clear of the pinned menu bar (--menu-bar-h, set by form-load.js). */
  --rules-offset: calc(var(--menu-bar-h, 0px) + 16px);

  max-width: 1280px;
  margin: 0 auto;
  padding: 8px 24px 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 22px;
  align-items: start;
}

/* ---------------------------------------------------------------- */
/* Contents list                                                      */
/* ---------------------------------------------------------------- */
.rules-toc-panel {
  position: sticky;
  top: var(--rules-offset);
}

.rules-toc {
  list-style: none;
  margin: 0;
  padding: 8px 0 12px;
  /* Leaves room below it, so at the very end of the page the pinned panel isn't pushed up
     past the top of the screen by the page's bottom padding. */
  max-height: calc(100vh - var(--rules-offset) - 205px); /* 150px + the search box above it */
  overflow-y: auto;
}

.rules-toc-link {
  display: block;
  padding: 5px 16px;
  border-left: 3px solid transparent;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.3;
  color: var(--text-dim);
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.rules-toc-link:hover {
  background: var(--panel-bg-soft);
  color: var(--text);
}

.rules-toc-link.active {
  background: var(--panel-bg-soft);
  border-left-color: var(--cyan);
  color: var(--cyan);
}

.rules-toc-level-0 {
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 13px;
  color: var(--text);
}
.rules-toc-level-1 { padding-left: 28px; }
.rules-toc-level-2 { padding-left: 40px; font-size: 13px; }
.rules-toc-level-3 { padding-left: 52px; font-size: 13px; color: var(--text-faint); }

/* (The search bar and its match highlight, .rules-search* and mark.rules-hit, are in core.css: the
   Notes modal uses them too.) */

/* ---------------------------------------------------------------- */
/* The document                                                       */
/* ---------------------------------------------------------------- */
.rules-content {
  padding: 8px 28px 28px;
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.6;
  color: var(--text);
  overflow-wrap: anywhere;
}

.rules-message {
  margin: 20px 0 0;
  font-family: var(--font-data);
  font-size: 13px;
  font-style: italic;
  color: var(--text-faint);
}

.rules-content > :first-child { margin-top: 20px; }

.rules-content h1,
.rules-content h2,
.rules-content h3,
.rules-content h4,
.rules-content h5,
.rules-content h6 {
  scroll-margin-top: var(--rules-offset);
  margin: 1.8em 0 0.5em;
  line-height: 1.2;
  font-weight: 700;
  color: var(--text);
}

.rules-content h1 {
  font-size: 30px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--accent-dim);
}

.rules-content h2 {
  font-size: 23px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.rules-content h3 {
  font-size: 19px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--cyan);
}

.rules-content h4 {
  font-family: var(--font-data);
  font-size: 16px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.rules-content h5,
.rules-content h6 {
  font-size: 16px;
  color: var(--text-dim);
}

.rules-content p { margin: 0 0 1em; }

.rules-content a {
  color: var(--cyan);
  text-decoration: underline;
  text-decoration-color: var(--cyan-dim);
  text-underline-offset: 3px;
}
.rules-content a:hover { text-decoration-color: var(--cyan); }

.rules-content strong { color: #fff; }
.rules-content em { color: var(--text); }

.rules-content ul,
.rules-content ol {
  margin: 0 0 1em;
  padding-left: 1.6em;
}
.rules-content li { margin: 0.25em 0; }
.rules-content li::marker { color: var(--accent); }
.rules-content li > ul,
.rules-content li > ol { margin: 0.25em 0 0; }

.rules-content blockquote {
  margin: 0 0 1em;
  padding: 10px 18px;
  background: var(--panel-bg-soft);
  border-left: 3px solid var(--cyan);
  color: var(--text-dim);
}
.rules-content blockquote > :last-child { margin-bottom: 0; }

/* Callout: a small inset panel for notes and sidebars. In the markdown:
     <div class="callout">

     **Note.** The text, with *normal* markdown. (The blank line after the opening tag is
     what lets markdown work inside it.)

     </div>
   Use a bold lead-in rather than a heading: headings inside it would join the contents. */
.rules-content .callout {
  margin: 1.4em 1.5em;
  padding: 12px 18px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-dim);
  background: rgba(9, 6, 13, 0.5);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.25);
}
.rules-content .callout > :first-child { margin-top: 0; }
.rules-content .callout > :last-child { margin-bottom: 0; }
.rules-content .callout strong:first-child {
  font-family: var(--font-data);
  font-size: 0.8em;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.rules-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

.rules-content code {
  font-family: var(--font-data);
  font-size: 0.85em;
  padding: 1px 6px;
  background: var(--panel-bg-soft);
  border: 1px solid var(--border-soft);
  color: var(--cyan);
}

.rules-content pre {
  margin: 0 0 1em;
  padding: 12px 16px;
  overflow-x: auto;
  background: var(--panel-bg-soft);
  border: 1px solid var(--border-soft);
}
.rules-content pre code {
  padding: 0;
  background: none;
  border: none;
  color: var(--text);
}

/* Tables scroll sideways on their own rather than stretching the page. */
.rules-content table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  margin: 0 0 1.2em;
  border-collapse: collapse;
  font-size: 15px;
}
.rules-content th,
.rules-content td {
  padding: 8px 14px;
  border: 1px solid var(--border-soft);
  text-align: left;
  vertical-align: top;
}
.rules-content th {
  background: var(--panel-bg-soft);
  font-family: var(--font-data);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.rules-content tbody tr:nth-child(even) td { background: rgba(255, 255, 255, 0.015); }

.rules-content img { max-width: 100%; height: auto; }

/* ---------------------------------------------------------------- */
/* Narrow screens: the contents list slides in from the right         */
/* ---------------------------------------------------------------- */
.rules-toc-toggle,
.rules-toc-backdrop,
.rules-toc-close {
  display: none;
}

body.rules-toc-open {
  overflow: hidden; /* the page behind the open sidebar doesn't scroll */
}

@media (max-width: 860px) {
  .rules-layout { grid-template-columns: minmax(0, 1fr); }
  .rules-content { padding: 4px 18px 22px; }
  .rules-content .callout { margin-left: 0; margin-right: 0; }

  /* The button that opens it, pinned bottom right. */
  .rules-toc-toggle {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 30;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    font-family: var(--font-ui);
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--cyan);
    background: var(--panel-bg);
    border: 1px solid var(--cyan-dim);
    border-radius: var(--radius);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    transition: border-color 0.12s ease, background 0.12s ease;
  }

  .rules-toc-toggle:hover {
    border-color: var(--cyan);
    background: var(--panel-bg-soft);
  }

  /* Dims the page while the sidebar is open; tapping it closes the sidebar. */
  .rules-toc-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(9, 6, 13, 0.72);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0s linear 0.2s;
  }

  .rules-layout.toc-open .rules-toc-backdrop {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.2s ease, visibility 0s;
  }

  /* The contents panel itself: parked off the right edge until opened. */
  .rules-toc-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    width: min(320px, 85vw);
    border-left: 1px solid var(--border);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
    transform: translateX(100%);
    visibility: hidden; /* keeps the off-screen links out of the tab order */
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
    outline: none;
  }

  .rules-layout.toc-open .rules-toc-panel {
    transform: none;
    visibility: visible;
    transition: transform 0.2s ease, visibility 0s;
  }

  .rules-toc-close {
    display: flex;
    width: 30px;
    height: 30px;
    background: var(--panel-bg);
  }

  .rules-toc {
    flex: 1;
    min-height: 0;
    max-height: none;
  }
}