/* ============================= */
/* Base reset and layout frame   */
/* ============================= */

/* Lock the viewport and let only the layout’s children scroll */
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

/* Global font variable */
:root {
  --app-font: "Georgia", "Times New Roman", serif;
}

/* Apply the app font to main containers, headings, sidebar and the toggle */
body,
#page-content-wrapper,
#sidebar,
#sidebar h1, #sidebar h2, #sidebar h3, #sidebar h4, #sidebar h5, #sidebar h6,
#page-content-wrapper h1, #page-content-wrapper h2, #page-content-wrapper h3,
#page-content-wrapper h4, #page-content-wrapper h5, #page-content-wrapper h6,
#font-toggle {
  font-family: var(--app-font);
  line-height: 1.6;
}

/* Keep h5 inline flow trick */
h5 {
  display: inline;          /* make it inline instead of block */
  font-size: 1.05em;
  font-weight: bold;        /* bold for emphasis */
  margin: 0;                /* remove default margins */
  padding-right: 0.5rem;    /* optional spacing before the following text */
}

h5 + p {
  display: inline;       /* make the paragraph start inline */
  margin: 0;             /* remove top margin so it flows */
}

h5::before {
  content: "\A";       /* line break before heading */
  white-space: pre;    /* respect the newline */
}

/* The two‑column app layout: sidebar + content */
.layout {
  display: flex;
  height: 100vh; /* full viewport height */
  background: var(--app-bg, #0a140a);
}

/* Sidebar column */
#sidebar {
  background-color: var(--sidebar-bg, #0d1a0d);
  color: var(--sidebar-text, #e6f2e6);
  padding: 1rem;
  overflow-y: auto;
  overflow-x: visible;       /* prevent tooltip clipping horizontally */
  position: relative;        /* anchor tooltips inside sidebar */
  box-shadow: 2px 0 6px rgba(0,0,0,0.35);
  width: 300px;
}

/* Main content column */
#page-content-wrapper {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
  background: var(--content-bg, #0f1f0f);
  color: var(--content-text, #e6f2e6);
}

/* ============================= */
/* Title, byline, and footer     */
/* ============================= */

.dd-title {
  display: block;
  margin: 2rem auto;
  height: auto;
  width: 100%;
  max-width: 100%;
}

.dd-byline {
  text-align: center;
  margin-bottom: 2rem;
}
.dd-byline .title {
  font-size: 1.5rem;
  font-weight: bold;
  letter-spacing: 2px;
}
.dd-byline .subtitle {
  font-size: 1.2rem;
  font-style: italic;
}

.credit {
  font-size: 0.95rem;
  margin: 0.25rem 0;
}
.Main-Text {
  font-size: 0.9rem;
}
.Basic-Text-Frame {
  border-top: 1px solid;
  margin-top: 1rem;
  padding-top: 0.5rem;
  text-align: center;
}
.copyright {
  font-size: 0.8rem;
}

/* ============================= */
/* Headings, glossary, lists     */
/* ============================= */

h1, h2, h3, h4, h5 {
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
}
h1 {
  border-bottom: 2px solid;
  padding-bottom: 0.25rem;
}
h2 {
  border-bottom: 1px solid;
  padding-bottom: 0.25rem;
}

.common-term {
  font-weight: bold;
  margin-top: 1rem;
}
.common-term + p {
  margin-left: 1rem;
}

/* Document lists (inside content) */
#page-content-wrapper ul {
  margin-left: 1.5rem;
  list-style-type: square;
}
#page-content-wrapper li {
  margin: 0.25rem 0;
}

/* ============================= */
/* Tables                        */
/* ============================= */

div[id^="table"] {
  margin: 1rem 0;
  border: 1px solid;
  padding: 0.5rem;
}

.table-wrapper {
  width: 100%;
}
.table-wrapper table {
  width: 100%;
  table-layout: auto;
}
.table-wrapper table th {
  text-align: left;
}

/* Zebra striping */
.table-wrapper table tbody tr:nth-child(odd) {
  background-color: var(--row-odd);
}
.table-wrapper table tbody tr:nth-child(even) {
  background-color: var(--row-even);
}

/* ============================= */
/* Links                         */
/* ============================= */

/* Preserve original link styling and hover behavior */
a {
  text-decoration: none;
  color: inherit;
}
a:hover {
  text-decoration: underline;
}

/* ============================= */
/* Sidebar TOC behaviors         */
/* ============================= */

#sidebar ul {
  list-style: none;
  margin: 0;
  padding-left: 0;
}

#sidebar li {
  margin: 0.25rem 0;
}

#sidebar a {
  color: inherit;
  text-decoration: none;
  display: block;
  padding: 0.25rem 0;
}

#sidebar a:hover {
  text-decoration: underline;
}

/* Submenus are hidden by default; shown when the parent is expanded */
#sidebar li ul {
  padding-left: 1rem;
  margin: 0.25rem 0 0;
  display: none;
}
#sidebar li.expanded > ul {
  display: block;
}

/* Toggle arrows only on parents with children */
#sidebar li > a::after {
  content: "";
  float: right;
}
#sidebar li:has(ul) > a::after {
  content: "▶";
  font-size: 0.8em;
}
#sidebar li.expanded > a::after {
  content: "▼";
}

/* ============================= */
/* Scrollbar styling (dark)      */
/* ============================= */

/* Firefox */
#sidebar, #page-content-wrapper {
  scrollbar-color: #3a5c3a #0d1a0d; /* thumb, track */
  scrollbar-width: thin;
}

/* WebKit (Chrome/Edge/Safari) */
#sidebar::-webkit-scrollbar,
#page-content-wrapper::-webkit-scrollbar {
  width: 5px;
}
#sidebar::-webkit-scrollbar-track,
#page-content-wrapper::-webkit-scrollbar-track {
  background: #0d1a0d;
}
#sidebar::-webkit-scrollbar-thumb,
#page-content-wrapper::-webkit-scrollbar-thumb {
  background-color: #3a5c3a;
  border-radius: 6px;
  border: 2px solid #0d1a0d;
}
#sidebar::-webkit-scrollbar-thumb:hover,
#page-content-wrapper::-webkit-scrollbar-thumb:hover {
  background-color: #4b7a4b;
}

/* ============================= */
/* Font toggle button            */
/* ============================= */

#font-toggle {
  position: absolute;
  bottom: 10px;
  left: 10px;
  padding: 6px 12px;
  font-size: 1.2rem;
  cursor: pointer;
  border: none;
  border-radius: 4px;
  transition: background-color 0.3s, color 0.3s, transform 0.12s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 50; /* sit above sidebar content */
}

/* Focus/active affordances */
#font-toggle:focus {
  outline: 2px solid rgba(255,255,255,0.12);
  outline-offset: 2px;
}
#font-toggle:active {
  transform: translateY(1px);
}

#font-toggle::after {
  content: "Toggle dyslexic friendly fonts";
  position: absolute;
  bottom: 120%;
  left: 0;
  transform: translateX(0);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
  white-space: nowrap;
  max-width: calc(100vw - 24px); /* clamp to screen */
  box-sizing: border-box;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  z-index: 1000;
  line-height: 1.2;
}

#font-toggle::before {
  content: "";
  position: absolute;
  bottom: 110%;
  left: 12px;
  width: 8px;
  height: 8px;
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  opacity: 0;
  pointer-events: none;
  z-index: 1001;
  transition: opacity 0.18s ease;
}

/* Show tooltip on hover/focus */
#font-toggle:hover::after,
#font-toggle:focus::after {
  opacity: 1;
  transform: translateY(-4px);
}
#font-toggle:hover::before,
#font-toggle:focus::before {
  opacity: 1;
}

/* ============================= */
/* 🌿 Light Forest Theme         */
/* ============================= */

@media (prefers-color-scheme: light) {
  :root {
    --app-bg: #f5f9f4;
    --sidebar-bg: #d9e6d9;
    --sidebar-text: #1a2e1a;
    --content-bg: #f5f9f4;
    --content-text: #1a2e1a;
    --row-odd: #edf5ed;
    --row-even: #d9e6d9;
  }

  h1, h2, h3, h4, h5 {
    color: #2f5d2f;
    border-color: #4a7a4a;
  }

  .dd-byline .subtitle { color: #555; }
  .Main-Text { color: #444; }
  .Basic-Text-Frame { border-color: #ccc; }
  .copyright { color: #777; }

  a { color: #2f7a2f; }
  a:hover { color: #1a4d1a; }

  div[id^="table"] {
    border-color: #4a7a4a;
    background-color: #edf5ed;
  }

  .table-wrapper table,
  .table-wrapper table th,
  .table-wrapper table td {
    color: #000 !important; /* force black text */
  }

  /* Light scrollbars */
  #sidebar, #page-content-wrapper {
    scrollbar-color: #90b890 #e6efe6; /* thumb, track */
  }
  #sidebar::-webkit-scrollbar-track,
  #page-content-wrapper::-webkit-scrollbar-track { background: #e6efe6; }
  #sidebar::-webkit-scrollbar-thumb,
  #page-content-wrapper::-webkit-scrollbar-thumb {
    background-color: #90b890;
    border-color: #e6efe6;
  }

  /* Button colors for light theme */
  #font-toggle {
    background-color: #90b890;   /* soft green */
    color: #1a2e1a;              /* dark text */
  }
  #font-toggle:hover {
    background-color: #6fa86f;   /* darker green on hover */
  }

  /* Tooltip colors for light theme */
  #font-toggle::after {
    background-color: #1a2e1a;   /* dark green background */
    color: #e6f2e6;              /* light text */
    box-shadow: 0 6px 18px rgba(26,46,26,0.18);
  }
  #font-toggle::before {
    background-color: #1a2e1a;
  }
}

/* ============================= */
/* 🌌 Dark Forest Theme          */
/* ============================= */

@media (prefers-color-scheme: dark) {
  :root {
    --app-bg: #0d1a0d;
    --sidebar-bg: #0d1a0d;
    --sidebar-text: #e6f2e6;
    --content-bg: #0f1f0f;
    --content-text: #e6f2e6;
    --row-odd: #142414;
    --row-even: #1a2e1a;
  }

  h1, h2, h3, h4, h5 {
    color: #8fc48f;
    border-color: #4a7a4a;
  }

  .dd-byline .subtitle { color: #a3d9a3; }
  .Main-Text { color: #cfe6cf; }
  .Basic-Text-Frame { border-color: #4a7a4a; }
  .copyright { color: #a3d9a3; }

  a { color: #a3d9a3; }
  a:hover { color: #6fbf6f; }

  div[id^="table"] {
    border-color: #4a7a4a;
    background-color: #142414;
  }

  .table-wrapper table,
  .table-wrapper table th,
  .table-wrapper table td {
    color: #fff !important;
  }

  /* Button colors for dark theme */
  #font-toggle {
    background-color: #3a5c3a;   /* deep forest green */
    color: #e6f2e6;              /* light text */
  }
  #font-toggle:hover {
    background-color: #4b7a4b;   /* lighter green on hover */
  }

  /* Tooltip colors for dark theme */
  #font-toggle::after {
    background-color: #e6f2e6;   /* light tooltip background */
    color: #0d1a0d;              /* dark text */
    box-shadow: 0 6px 18px rgba(0,0,0,0.45);
  }
  #font-toggle::before {
    background-color: #e6f2e6;
  }
}

/* ============================= */
/* Accessibility helpers         */
/* ============================= */

/* Ensure tooltip text is readable at small sizes and never off-screen */
@media (max-width: 420px) {
  #font-toggle::after {
    font-size: 0.75rem;
    padding: 5px 8px;
    max-width: calc(100vw - 24px); /* clamp inside viewport */
  }
}

.char-fireball::before {
  content: "";
  display: inline-block;
  width: 1em;
  height: 1em;
  background-image: url("fireball.png");
  background-size: contain;
  background-repeat: no-repeat;
  image-rendering: auto;
  image-rendering: smooth;
  image-rendering: high-quality;
}
