/* ================================
   THEME VARIABLES
   ================================ */

:root {
  --bg: #f5f5f5;
  --bg-soft: #f2f2f0;
  --border-subtle: #dddddd;
  --text-main: #111111;
  --text-muted: #666666;
  --link: #333333;
  --link-hover: #000000;

  --header-height: 60px; /* used conceptually, header is natural height */
}

/* Dark mode overrides */
:root[data-theme="dark"] {
  --bg: #050505;
  --bg-soft: #1c1f22;
  --border-subtle: #333333;
  --text-main: #f5f5f5;
  --text-muted: #aaaaaa;
  --link: #f5f5f5;
  --link-hover: #ffffff;
}

/* ================================
   GLOBAL RESET / BASE
   ================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;

  var(--bg);

  color: var(--text-main);

  display: flex;
  flex-direction: column;
  overflow: hidden; /* no page scroll; scroll only inside frames */
}

:root[data-theme="light"] body {
  background-image: url("images/tonesbg3.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

:root[data-theme="dark"] body {
  background-image: url("images/tonesbg2.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}


a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}


/* ================================
   LAYOUT
   ================================ */

main {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 0 0 80px;

  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* allow children to shrink and scroll */
}

/* Page containers: index + chapters */

.chapter-page,
.chapter-index {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* critical for flex scrolling */
}

/* Shared rectangular frame: grows to fill vertical space,
   scrolls internally only.
*/
.chapter-page .chapter-frame,
.chapter-index .chapter-frame {
  border: 1px solid var(--border-subtle);
  background: var(--bg-soft);
  padding: 24px 20px;
  margin-top: 10px;

  flex: 1 1 auto;
  min-height: 0;      /* allow inner scroll area */
  overflow-y: auto;   /* INTERNAL SCROLL ONLY */
}

/* ================================
   HEADER + NAV + THEME TOGGLE
   ================================ */

.site-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 12px 16px 0 16px;
  flex-shrink: 0; /* keep header at natural height */
}

.site-header-left {
  justify-self: start;
visibility: hidden;
}

.site-header-center {
  justify-self: center;
}

.site-header-right {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 16px;
}

.site-header h1 {
  margin: 0;
  font-size: 20px;
}

.site-header-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.top-nav a {
  margin-left: 16px;
  font-size: 14px;
}

#theme-toggle {
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-main);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
}

#theme-toggle:hover {
  background: var(--bg-soft);
}

/* Center circle icon */
.home-circle {
  width: 26px;
  height: 26px;
  border: 2px solid var(--text-main);
  border-radius: 50%;
  display: block;
  position: relative;
}

/* Dot inside */
.home-circle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  background: var(--text-main);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

/* ================================
   INDEX (CHAPTER LIST) PAGE
   ================================ */

.tones-title {
  text-align: center;
  font-size: 67px;
  margin: 0 0 8px 0; /* no top gap under header */
  font-weight: 700;
}

/* Lists inside the frame */
.chapter-list {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: center;
}

.chapter-list li {
  margin: 8px 0;
}

.chapter-list a {
  font-size: 20px;
}

/* Toggle visibility */
.chapter-list-positive,
.chapter-list-negative {
  display: none;
}

.chapter-list-positive.is-active,
.chapter-list-negative.is-active {
  display: block;
}

/* Optional container (if ever used) for fixed toggle */
.chapter-toggle-container {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg);
  z-index: 50;
}

.chapter-list-label {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* Index bottom controls use same centered +/- styling as chapters */

.chapter-index .chapter-bottom-controls {
  margin-top: 20px;
  position: relative;
  height: 32px;
  flex-shrink: 0;
}

.chapter-index #chapter-toggle {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: none;
  border: none;
  font-size: 28px;     /* match chapter pages */
  font-weight: 900;    /* bold */
  line-height: 1;
  cursor: pointer;
  color: var(--text-main);
  padding: 0;
  text-decoration: none;
}

.chapter-index #chapter-toggle:hover {
  text-decoration: none !important;
}

/* ================================
   CHAPTER PAGE
   ================================ */

/* Big TONES title centered above the frame */
.tones-main-title {
  text-align: center;
  font-size: 67px;
  margin: 0 0 8px 0; /* no top space under header */
  font-weight: 700;
}

/* Chapter title and meta live inside the frame */
.chapter-page h2 {
  font-size: 24px;
  margin: 0 0 8px 0;
}

.chapter-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
}

/* Chapter body text */
.chapter-body p {
  margin: 16px 0;
  font-size: 16px;
}

/* Images inside chapters */
.chapter-image {
  margin: 24px 0;
}

/* For black PNGs that need to stay visible in dark mode */
.chapter-image.dark-safe {
  padding: 8px;
  border-radius: 4px;
}

:root[data-theme="dark"] .chapter-image.dark-safe {
  background: #f5f5f5;
  border: 1px solid #cccccc;
}

.chapter-image img {
  display: block;
  margin: 0 auto;
  max-width: 300px;
  width: 100%;
  height: auto;
}

.chapter-image figcaption {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ================================
   BOTTOM CONTROLS (CHAPTER NAV)
   ================================ */

/* Shared bottom controls block under frame */
.chapter-bottom-controls {
  margin-top: 12px;
  position: relative;
  height: 32px;        /* enough vertical space for the buttons */
  flex-shrink: 0;      /* don't let it collapse */
}

/* Base style for buttons / arrows / spacers */
.chapter-nav-arrow,
.chapter-sign-button,
.chapter-nav-spacer {
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-main);
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* spacer is just invisible but keeps layout if used */
.chapter-nav-spacer {
  visibility: hidden;
}

.chapter-nav-arrow:hover,
.chapter-sign-button:hover {
  background: var(--bg-soft);
}

/* Center +/- switcher: always dead center of the control bar */
.chapter-sign-button {
  font-weight: 900;   /* bold */
  text-decoration: none;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: none;
  border: none;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-main);
  padding: 0;
}

.chapter-sign-button,
.chapter-nav-arrow {
  text-decoration: none;
}

.chapter-sign-button:hover,
.chapter-nav-arrow:hover {
  text-decoration: none !important;
  color: var(--link-hover);
}

/* Triangles positioned relative to the centered +/- */
.chapter-nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-main);
  padding: 0;
}

/* Distance from center; tweak 28px if you want them closer/farther */
.chapter-nav-arrow.left {
  right: 50%;
  margin-right: 28px;
}

.chapter-nav-arrow.right {
  left: 50%;
  margin-left: 28px;
}

/* ================================
   CHARACTERS PAGE
   ================================ */

.characters-page h2 {
  font-size: 22px;
  margin-bottom: 16px;
}

.character-card {
  border-bottom: 1px solid var(--border-subtle);
  padding: 16px 0;
}

.character-card:last-of-type {
  border-bottom: none;
}

.character-card h3 {
  margin: 0 0 8px 0;
  font-size: 18px;
}

.character-card p {
  margin: 4px 0;
  font-size: 14px;
}

/* ================================
   GALLERY PAGE
   ================================ */

.gallery-page h2 {
  font-size: 22px;
  margin-bottom: 16px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

/* Gallery items; .dark-safe works here too */
.gallery-grid figure {
  margin: 0;
  background: var(--bg-soft);
  padding: 8px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
}

:root[data-theme="dark"] .gallery-grid figure.dark-safe {
  background: #f5f5f5;
  border-color: #cccccc;
}

.gallery-grid img {
  width: 100%;
  height: auto;
  display: block;
}

.gallery-grid figcaption {
  font-size: 12px;
  margin-top: 4px;
}

/* ================================
   RESPONSIVE TWEAKS
   ================================ */

@media (max-width: 600px) {
  .site-header {
    grid-template-columns: 1fr;
    gap: 6px;
    justify-items: flex-start;
  }

  .site-header-right {
    width: 100%;
    justify-content: space-between;
  }

  .top-nav a {
    margin-left: 0;
    margin-right: 12px;
  }

  /* --- Add this --- */
  main {
    max-width: none;
    width: 100%;
    padding-left: 0;
    padding-right: 0;
    margin: 0;
  }

  .chapter-frame {
    border-left: none;
    border-right: none;
    border-radius: 0;
  }
}

/* ================================
   SCROLLBAR STYLING FOR FRAME
   ================================ */

.chapter-frame::-webkit-scrollbar {
  width: 8px;
}

.chapter-frame::-webkit-scrollbar-track {
  background: transparent;
}

.chapter-frame::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 4px;
}

.chapter-frame::-webkit-scrollbar-thumb:hover {
  background: var(--text-main);
}

/* Firefox */
.chapter-frame {
  scrollbar-width: thin;
  scrollbar-color: var(--text-muted) transparent;
}
