/* ============================================================
   SHATTERED EARTH: FANTASY ERA — Parchment & Greenwood theme
   Light parchment default · "night in the greenwood" dark mode
   ============================================================ */

:root {
  --parchment:      #f4ecd9;
  --parchment-deep: #ece1c6;
  --card:           #faf5e8;
  --ink:            #372c1f;
  --ink-soft:       #5c4d38;
  --moss:           #4a6741;
  --pine:           #2d4a32;
  --gold:           #9c7c2c;
  --gold-bright:    #b8963a;
  --bark:           #7a5c3e;
  --blood:          #7c3a2d;
  --rule:           #c9b98f;
}

body.night-mode {
  --parchment:      #1e241c;
  --parchment-deep: #171c15;
  --card:           #252e22;
  --ink:            #d9cfb2;
  --ink-soft:       #b3a888;
  --moss:           #8fae7e;
  --pine:           #9dc28a;
  --gold:           #c9a84c;
  --gold-bright:    #ddbd63;
  --bark:           #a98a63;
  --blood:          #c96a56;
  --rule:           #4a5442;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: Georgia, 'Times New Roman', serif;
  background: var(--parchment);
  color: var(--ink);
  line-height: 1.65;
  transition: background 0.3s, color 0.3s;
}

/* ---------- layout ---------- */
.container { display: flex; min-height: 100vh; }

.sidebar {
  width: 270px;
  min-width: 270px;
  background: linear-gradient(180deg, var(--pine) 0%, #1f3524 100%);
  color: #e8e0c8;
  padding: 28px 20px 40px;
  border-right: 4px double var(--gold);
  /* Own scroll container, so a long menu scrolls independently of the page
     and sidebar-memory.js can hold its position across chapters. Sticky
     rather than fixed: this is a flex child, and sticky keeps the column
     allocated so .main-content is not slid underneath it. */
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
body.night-mode .sidebar {
  background: linear-gradient(180deg, #131a12 0%, #0d120c 100%);
}

.sidebar h1 {
  font-variant: small-caps;
  letter-spacing: 2px;
  font-size: 1.5em;
  color: var(--gold-bright);
  text-align: center;
}
.sidebar h2 {
  font-size: 0.95em;
  font-weight: normal;
  font-style: italic;
  text-align: center;
  color: #cfc6a5;
  margin: 4px 0 18px;
}
.sidebar hr.leaf-rule {
  border: 0;
  border-top: 1px solid var(--gold);
  margin: 14px 10px;
  opacity: 0.5;
}
.nav-section h3 {
  font-variant: small-caps;
  letter-spacing: 1px;
  color: var(--gold-bright);
  font-size: 1em;
  margin: 16px 0 6px;
}
.nav-section ul { list-style: none; }
.nav-section li { margin: 2px 0; }
.nav-section a {
  color: #e8e0c8;
  text-decoration: none;
  display: block;
  padding: 4px 10px;
  border-radius: 3px;
  font-size: 0.95em;
}
.nav-section a:hover { background: rgba(184,150,58,0.25); color: #fff; }
.nav-section a.active {
  background: rgba(184,150,58,0.35);
  color: #fff;
  border-left: 3px solid var(--gold-bright);
}
.portal-link {
  display: block;
  margin-top: 26px;
  text-align: center;
  color: #cfc6a5 !important;
  font-style: italic;
  font-size: 0.85em !important;
}

.main-content {
  flex: 1;
  max-width: 900px;
  padding: 44px 56px 90px;
}

/* ---------- typography ---------- */
h2.page-title {
  font-variant: small-caps;
  letter-spacing: 2px;
  font-size: 2.1em;
  color: var(--pine);
  border-bottom: 3px double var(--gold);
  padding-bottom: 8px;
  margin-bottom: 6px;
}
.page-subtitle {
  font-style: italic;
  color: var(--ink-soft);
  margin-bottom: 26px;
}
h3 {
  font-variant: small-caps;
  letter-spacing: 1px;
  color: var(--moss);
  font-size: 1.45em;
  margin: 34px 0 10px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 4px;
}
h4 {
  color: var(--bark);
  font-size: 1.12em;
  margin: 20px 0 6px;
  font-variant: small-caps;
  letter-spacing: 0.5px;
}
p { margin: 0 0 12px; }
ul, ol { margin: 0 0 14px 26px; }
li { margin-bottom: 6px; }
strong { color: var(--pine); }
em { color: var(--ink-soft); }
a { color: var(--moss); }
a:hover { color: var(--gold); }

/* ---------- cards & boxes ---------- */
.rule-card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-left: 5px solid var(--moss);
  border-radius: 4px;
  padding: 16px 20px;
  margin: 18px 0;
  box-shadow: 1px 2px 4px rgba(60,45,25,0.12);
}
.rule-card h4 { margin-top: 0; color: var(--pine); font-size: 1.2em; }
.rule-citation {
  font-size: 0.82em;
  font-style: italic;
  color: var(--ink-soft);
  border-bottom: 1px dotted var(--rule);
  padding-bottom: 6px;
  margin-bottom: 10px;
}

.lore-box {
  background: linear-gradient(135deg, rgba(74,103,65,0.10), rgba(156,124,44,0.10));
  border: 1px solid var(--gold);
  border-radius: 4px;
  padding: 14px 18px;
  margin: 18px 0;
  font-style: italic;
}
.warning-box {
  background: rgba(124,58,45,0.08);
  border: 1px solid var(--blood);
  border-left: 5px solid var(--blood);
  border-radius: 4px;
  padding: 14px 18px;
  margin: 18px 0;
}
.formula-box {
  text-align: center;
  font-size: 1.08em;
  background: var(--parchment-deep);
  border: 1px dashed var(--bark);
  border-radius: 4px;
  padding: 10px;
  margin: 14px 0;
}

/* ---------- tables ---------- */
table {
  border-collapse: collapse;
  width: 100%;
  margin: 14px 0 20px;
  background: var(--card);
  font-size: 0.95em;
}
th {
  background: var(--pine);
  color: #f0e9d2;
  font-variant: small-caps;
  letter-spacing: 0.5px;
  padding: 7px 10px;
  text-align: left;
}
body.night-mode th { background: #101710; }
td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--rule);
}
tr:nth-child(even) td { background: rgba(122,92,62,0.06); }

/* ---------- controls ---------- */
.theme-toggle {
  position: fixed;
  top: 14px;
  right: 16px;
  background: var(--card);
  border: 1px solid var(--gold);
  border-radius: 20px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 0.85em;
  color: var(--ink);
  z-index: 1200;
  box-shadow: 1px 2px 5px rgba(0,0,0,0.2);
}
.theme-toggle:hover { border-color: var(--gold-bright); }

.search-box { margin: 12px 0 4px; }
.search-box input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 4px;
  border: 1px solid var(--gold);
  background: rgba(244,236,217,0.92);
  color: #33291c;
  font-family: inherit;
}

.menu-toggle { display: none; }

/* ---------- print ---------- */
@media print {
  .sidebar, .theme-toggle { display: none; }
  .main-content { max-width: 100%; padding: 0; }
  body { background: #fff; color: #000; }
}

/* ---------- small screens ---------- */
@media (max-width: 820px) {
  .container { flex-direction: column; }
  /* Stacked layout: the sidebar must flow above the content at its natural
     height. Without these resets it keeps height:100vh + position:sticky +
     overflow-y:auto from the base rule, filling the whole screen and eating
     scroll so the page content below it is never reachable. */
  .sidebar {
    width: 100%;
    min-width: 0;
    border-right: 0;
    border-bottom: 4px double var(--gold);
    position: static;
    height: auto;
    overflow-y: visible;
  }
  .main-content { padding: 24px 18px 60px; }
}
