/* --- 1. Root Variables (Aesthetic Light Mode) --- */
:root {
  /* -- Typography -- */
  --font-serif: 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --font-display: "Source Serif 4 Display", serif;
  --font-mono: Consolas, Menlo, Monaco, "DejaVu Sans Mono", "Lucida Console", monospace;

  /* -- Core Colors -- */
  --c-bg: #fbf9f3; /* A warm, parchment-like off-white for comfort */
  --c-text: #2c2a2e; /* A soft, deep charcoal instead of harsh black */
  --c-text-soft: #6d6a70; /* A muted, gentle gray for secondary text */
  --c-link: #3a5c8d; /* A sophisticated, dusty indigo for links */
  --c-link-hover: #1e3250; /* A deeper, richer indigo for hover */
  --c-border: #e0dce5; /* A soft, warm gray for subtle borders */
  --c-border-strong: #bfbac9; /* A more prominent, but still soft, gray */
  --c-bg-offset: #f2f0f5; /* A slightly cooler, gentle gray for contrast */
  --c-bg-inline-code: #e9e6ed;

  /* -- UI & Other Colors -- */
  --c-button-bg: var(--c-link);
  --c-button-text: var(--c-bg);
  --c-menu-border: var(--c-bg);
  --c-menu-outline: var(--c-text);
  --c-grid-line: rgba(0, 0, 0, 0.15); /* Faint black for the grid */
}

/* --- 2. Dark Mode Overrides (Aesthetic Dark Mode) --- */
@media (prefers-color-scheme: dark) {
  :root {
    /* -- Core Colors -- */
    --c-bg: #191c23; /* A deep, cool navy blue for the background */
    --c-text: #d1d1d6; /* A soft, light gray for main text */
    --c-text-soft: #888ca0; /* A muted, cool gray for secondary text */
    --c-link: #82aaff; /* Brighter, more saturated blue for clear links */
    --c-link-hover: #b3c5ff; /* A gentle highlight for hover */
    --c-border: #333644; /* A subtle border that blends with the theme */
    --c-border-strong: #4d5163; /* A clearer, more defined border */
    --c-bg-offset: #222630; /* A slightly lighter navy for depth */

    /* -- UI Component Colors -- */
    --c-button-bg: var(--c-bg-offset);
    --c-button-text: var(--c-text);
    --c-menu-border: #fbf9f3;
    --c-grid-line: rgba(255, 255, 255, 0.15); /* Faint white for the grid */
  }
}

/* --- 3. General & Typographic Styles --- */
@font-face {
  font-family: "Source Serif 4 Display";
  src: url("SourceSerif4Display-Light.ttf.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-family: var(--font-serif);
  font-size: 11pt;
  line-height: 1.4;
  color: var(--c-text);
  background: var(--c-bg);
  margin: 0;
}

.container {
  max-width: 700px;
  width: 90%;
  margin: 0 auto;
  padding: 1rem 0;
}

p {
  text-align: justify;
  margin: 0 0 8.5pt 0;
}

h1 {
  font-size: 17pt;
  font-weight: normal;
  line-height: 22pt;
  text-align: center;
  margin: 5em 0 0.2em 0;
}

h2, h3, h4 {
  font-size: 11pt;
  font-weight: bold;
  margin: 12pt 0 8.5pt 0;
}

h2 {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 18pt;
  text-align: center;
}

h3 { font-style: italic; text-align: center; }

.author { text-align: center; margin-bottom: 1em; }

a {
  color: var(--c-link);
  text-decoration: none;
  border-bottom: 1px dotted var(--c-link-hover);
}

a:hover, a:focus {
  color: var(--c-link-hover);
  border-bottom-style: solid;
}

blockquote {
  margin: 1em 0.5in;
  padding-left: 0.5em;
  border-left: 2px solid var(--c-border);
  font-style: italic;
  color: var(--c-text-soft);
}

ul {
  margin: 0 0 8.5pt 0.75in;
  padding: 0;
  list-style-position: outside;
}

ul li {
  padding-left: 0.25in;
  text-indent: -0.25in;
}

footer, .text-center, .text-center h1, .text-center h2,
.text-center h3, .text-center p, .text-center blockquote {
  text-align: center;
}

/* --- 4. Content & Thematic Styles --- */
.divine { font-variant: small-caps; font-weight: bold; }
.king { color: var(--c-king); }
.wisdom { color: var(--c-wisdom); }
.sibyl { font-size: min(2.5rem, 1.5rem); font-variant: small-caps; font-weight: normal; }

@keyframes shimmer-red-blue {
  0%, 100% { color: var(--c-logoscript-1); }
  50% { color: var(--c-logoscript-2); }
}

.logoscript {
  font-weight: bold;
  font-variant: small-caps;
  animation: shimmer-red-blue 6s infinite ease-in-out;
}

figure { margin: 1.5em auto; text-align: center; }
picture { display: block; margin: auto; width: 50%; }
img { max-width: 100%; height: auto; }
figure figcaption {
  font-size: 8.5pt;
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  margin: 4px auto;
  max-width: 90%;
}
figure figcaption strong { font-weight: bold; font-style: italic; }

footer, footer p { text-align:center; padding:1.25rem 0; }
footer nav a { margin: 0 0.25rem; text-decoration:none; }
footer picture { display:block; margin:0.75rem auto 0; }


.table-container { overflow-x: auto; margin: 1em auto; }
table {
  border-collapse: collapse;
  margin: 0 auto;
  width: 100%;
  max-width: 5.5in;
  border-bottom: 1px solid var(--c-border-strong);
}
table caption { font-size: 8.5pt; line-height: 14pt; margin-bottom: 4pt; text-align: center; }
table caption strong { font-weight: bold; font-style: italic; }
th, td { font-size: 8.5pt; padding: 4px; }
th { border-bottom: 1px solid var(--c-border-strong); }
table tbody tr:last-child td { border-bottom: 1px solid var(--c-border-strong); }

.scripture-title {
  font-family: var(--font-display);
  font-size: min(10vw, 5.2rem);
  font-weight: normal;
  text-transform: uppercase;
  letter-spacing: -0.02em;
  text-align: center;
  text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.25);
  margin: 0 auto;
  max-width: 90vw;
  display: block;
  overflow-wrap: break-word;
  white-space: normal;
}

.subtitle {
  font-size: min(0.55rem, 2vw);
  font-weight: normal;
  text-transform: uppercase;
  text-align: center;
  white-space: normal;
  word-wrap: break-word;
  display: block;
  margin-top: 0.25em;
}

.scripture-subtitle {
  font-size: min(1.25rem, 4vw);
  font-weight: normal;
  line-height: 22pt;
  text-align: center;
  margin: 0.2em 0;
}

.verse-num-primary { font-weight: bold; color: var(--c-text); margin-right: 6px; }
.verse-num-ref { font-style: italic; font-size: 0.85em; vertical-align: super; color: var(--c-text-soft); margin: 0 6px 0 2px; }
.verse-ref { font-variant: small-caps; font-weight: bold; color: var(--c-text-soft); margin: 0 2px 0 4px; }

/* --- 5. Component Styles --- */
#table-of-contents {
  max-width: 650px;
  margin: 2rem auto;
  padding: 1rem;
  border: 1px solid var(--c-border);
  background: var(--c-bg-offset);
  border-radius: 8px;
}
#table-of-contents ul { list-style: none; padding: 0; margin: 0; }
#table-of-contents > ul > li { font-size: 12pt; font-weight: bold; margin-bottom: 0.75rem; }
#table-of-contents ul ul { margin-top: 0.25rem; padding-left: 1.25rem; }
#table-of-contents ul ul li { font-size: 11pt; font-weight: normal; margin-bottom: 0.5rem; }
#table-of-contents a { color: var(--c-link); border-bottom-color: var(--c-link-hover); }
#table-of-contents a:hover { color: var(--c-link-hover); border-bottom-style: solid; }

#floating-menu, #menu-toggle {
  background: var(--c-button-bg);
  color: var(--c-button-text);
  border: 2px solid var(--c-menu-border);
  font-family: inherit;
  font-size: 12pt;
}
#floating-menu {
  position: fixed;
  bottom: 70px; right: 15px;
  width: 200px;
  border-radius: 6px;
  box-shadow: 0 0 0 2px var(--c-menu-outline), 2px 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 999;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease-out, transform 0.2s ease-out;
  pointer-events: none;
}
#menu-toggle {
  position: fixed;
  bottom: 15px; right: 15px;
  padding: 10px 15px;
  border-radius: 5px;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
  pointer-events: none;
}
#floating-menu:not(.hidden) { opacity: 1; transform: translateY(0); pointer-events: auto; }
#floating-menu ul { list-style: none; margin: 0; padding: 0.5rem; }
#floating-menu li { margin: 0.25rem 0; }
#floating-menu button, #floating-menu a {
  display: block; width: 100%; padding: 6px 12px;
  color: inherit; background: none; border: none;
  text-align: left; cursor: pointer; text-decoration: none;
}
#floating-menu button:hover, #floating-menu a:hover { background-color: rgba(255, 255, 255, 0.2); }

.verse-tts-button {
  background: none; border: 1px solid var(--c-text-soft); border-radius: 3px;
  padding: 2px 6px; margin-right: 0.5em; font-size: 0.85em;
  font-variant: small-caps; color: var(--c-wisdom); cursor: pointer;
}

/* --- 5a. Additional Component Styles --- */
.chapter, .subchapter {
  position: relative; /* Allows positioning of the TTS button */
}

.verse {
  position: relative;
}

/* --- 6. Interactive Diagram Styles --- */
/* Common container for all diagrams */
.interactive-wheel, .triangle-container, .heptagon-container, .dodecagon-container,
.cuboctahedron-container, .octahedron-container, .cube-container, .nested-container {
  background-color: var(--c-bg-offset);
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 1rem;
  margin: 1.5em auto;
  text-align: center;
  position: relative;
}

/* Specific Diagram Elements */
#creationWheel { cursor: pointer; width: 100%; height: auto; }
.line { stroke: var(--c-grid-line); stroke-width: 0.5px; }
.point { fill: var(--c-text); transition: fill 0.2s ease-out, r 0.2s ease-out; }
.label-text { fill: var(--c-text-soft); font-family: var(--font-serif); font-size: 18px; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.line.path-delight { stroke: var(--c-path-delight); stroke-width: 2px; }
.point.selected-delight { r: 8; fill: var(--c-path-delight); }
.line.path-plague { stroke: var(--c-path-plague); stroke-width: 2px; }
.point.selected-plague { r: 8; fill: var(--c-path-plague); }
.line.path-default { stroke: var(--c-path-default); stroke-width: 2px; }
.point.selected-default { r: 8; fill: var(--c-path-default); }

#word-display-container { display: flex; justify-content: center; align-items: center; gap: 20px; margin-bottom: 1rem; }
#word-display { font-family: var(--font-serif); font-size: 1.8em; letter-spacing: 0.2em; color: var(--c-text); background-color: var(--c-bg); border: 1px solid var(--c-border); border-radius: 3px; padding: 5px 15px; }
#clearButton { font-family: var(--font-serif); font-size: 11pt; background-color: var(--c-bg-offset); color: var(--c-text); border: 1px solid var(--c-border); border-radius: 3px; padding: 8px 15px; cursor: pointer; }
#clearButton:hover { background-color: var(--c-wisdom); color: var(--c-bg); border-color: var(--c-wisdom); }
#triangle-svg { cursor: pointer; border-radius: 10px; }
#triangle-readout { margin-top: 20px; font-size: 1.2em; min-height: 5em; }

#cuboctahedron-canvas-container, #nested-canvas-container,
#octahedron-canvas-container, #cube-canvas-container {
  width: 100%; /* Allow the container to shrink on small screens */
  height: auto; /* Adjust height automatically */
  aspect-ratio: 1 / 1; /* Maintain a square shape */
  margin: 0 auto;
  cursor: grab;
}

/* Set the maximum size for each group */
#cuboctahedron-canvas-container, #nested-canvas-container {
  max-width: 500px;
}
#octahedron-canvas-container, #cube-canvas-container {
  max-width: 400px;
}
.label { color: var(--c-text-soft); font-family: var(--font-serif); font-size: 20px; }

/* --- 6a. Interactive Diagram Specifics --- */

/* Creation Wheel Portal */
#portal-gate {
  visibility: hidden;
  border-radius: 50%;
  overflow: hidden; /* Ensures the iframe content is clipped to the circle */
}

/* Triangle Diagram Readouts */
.element-fire { color: var(--c-king); }
.element-water { color: var(--c-wisdom); }
.element-air { color: var(--c-text); }
@media (prefers-color-scheme: dark) {
  .element-air { color: var(--c-text); }
}

/* Heptagon Diagram */
.heptagon-controls {
  margin-bottom: 1rem;
}
.heptagon-controls button {
  font-family: var(--font-serif);
  font-size: 11pt;
  background-color: var(--c-bg-offset);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  border-radius: 3px;
  padding: 8px 15px;
  cursor: pointer;
  margin: 0 5px;
}
.heptagon-controls button.active {
  background-color: var(--c-wisdom);
  color: var(--c-bg);
  border-color: var(--c-wisdom);
}
.heptagon-point {
  fill: var(--c-text);
  transition: fill 0.2s;
  filter: drop-shadow(0 0 0px rgba(255, 255, 255, 0));
}
@keyframes heptagon-pulse {
  0% { filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.4)); }
  50% { filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.8)); }
  100% { filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.4)); }
}
.heptagon-point.active {
  animation: heptagon-pulse 2s infinite ease-in-out;
}
.heptagon-point.active:hover {
  fill: var(--c-wisdom);
}
.heptagon-point.selected {
  fill: var(--c-wisdom);
}
.heptagon-point.mirror {
  fill: var(--c-king);
}
.heptagon-point.hybrid {
  fill: var(--c-code-number); /* Using a distinct color */
}
.heptagon-path-line {
  stroke: var(--c-wisdom);
  stroke-width: 2px;
  pointer-events: none;
}
.heptagon-mirror-path-line {
  stroke: var(--c-king);
  stroke-width: 2px;
  stroke-dasharray: 5,5;
  pointer-events: none;
}
.heptagon-label-text {
  fill: var(--c-text-soft);
  font-family: var(--font-serif);
  font-size: 20px;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}
#heptagon-readout {
  margin-top: 20px;
  font-size: 1.2em;
  min-height: 4em;
}
#heptagon-calculation {
  font-family: var(--font-mono);
  color: var(--c-code-string);
}
.heptagon-button-container {
  display: flex;
  gap: 10px;
  justify-content: center;
}
#heptagon-resetButton {
  margin-top: 20px;
  font-family: var(--font-serif);
  font-size: 11pt;
  background-color: var(--c-bg-offset);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  border-radius: 3px;
  padding: 8px 15px;
  cursor: pointer;
}

/* Dodecagon (Hierarchy) Diagram */
.dodecagon-point {
  transition: r 0.2s ease-out;
  cursor: pointer;
}
.dodecagon-point:hover {
  r: 12;
}
.dodecagon-line {
  stroke: rgba(128, 128, 128, 0.2);
  stroke-width: 0.75px;
  pointer-events: none;
  transition: stroke 0.2s ease-out, stroke-opacity 0.2s ease-out;
}
.dodecagon-line.highlighted {
  stroke: var(--c-code-string); /* Yellow */
  stroke-opacity: 1.0;
  stroke-width: 1.5px;
}
.dodecagon-label-text {
  fill: var(--c-text-soft);
  font-family: var(--font-serif);
  font-size: 18px;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}
#dodecagon-readout {
  margin-top: 20px;
  font-size: 1.2em;
}
#dodecagon-edge-counter {
  font-style: italic;
  font-size: 0.9em;
  color: var(--c-text-soft);
  margin-top: 0.5em;
  min-height: 1.2em; /* Prevents layout shift */
}


/* --- 7. Reading Mode & Utility --- */
.hidden { display: none !important; }

body.reading-mode { font-size: 14pt; line-height: 1.6; }
body.reading-mode .container { max-width: 1000px; width: 95%; padding: 2rem 1rem; }
body.reading-mode h1, body.reading-mode h2, body.reading-mode h3, body.reading-mode img,
body.reading-mode figure, body.reading-mode header, body.reading-mode .verse-tts-button,
body.reading-mode .author, body.reading-mode .verse-ref, body.reading-mode .verse-num-ref,
body.reading-mode #toggle-toc, body.reading-mode nav, body.reading-mode #titlepage,
body.reading-mode #dedication, body.reading-mode .triangle-container,
body.reading-mode .heptagon-container, body.reading-mode .cube-container, 
body.reading-mode .octahedron-container, body.reading-mode .cuboctahedron-container,
body.reading-mode .dodecagon-container, body.reading-mode .nested-container,
body.reading-mode sup {
  display: none !important;
}
body.reading-mode a {
  pointer-events: none; cursor: default; color: inherit;
  text-decoration: none; border: none;
}
body.reading-mode .menu-button { display: block !important; }

/* --- 8. Responsive Adjustments --- */

@media (max-width: 600px) {
  body { font-size: 12pt; }
  .container { width: 95%; }
  ul, ol { margin-left: 0.5in; }
}

/* --- 9. Additional Responsive Fixes --- */

/* Make SVG-based diagrams responsive */
#triangle-svg, #heptagon-svg {
  width: 100%;
  height: auto;
  max-width: 400px; /* Preserve original size on larger screens */
}

/* Make tables more compact on small screens to prevent overflow */
@media (max-width: 600px) {
  th, td {
    font-size: 7.5pt; /* Reduce font size to fit more content */
    padding: 3px;     /* Reduce cell padding */
  }

  table caption {
    font-size: 8pt; /* Adjust caption size as well */
  }
}

/* Planet ↔ Note mapping refinements */
.planet-note-table th.thin, .planet-note-table td.thin { width: 1%; white-space: nowrap; }
.planet-note-table tbody tr:hover td { background: var(--c-bg-offset); }
.pn-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--c-text-soft); margin-right: 8px; transform: translateY(-1px);
}
.pn-play {
  border: 1px solid var(--c-border); background: none; color: var(--c-text);
  padding: 2px 6px; border-radius: 3px; font-size: 10pt; cursor: pointer;
}
.pn-play:hover { background: var(--c-bg-offset); }

/* Planet glyph styling */
.pn-glyph{
  display:inline-block;
  width:1.25em;          /* consistent column width */
  text-align:center;
  margin-right:8px;
  font-size:1.1em;       /* a touch larger than text */
  line-height:1;
  color: var(--c-text-soft);
}
@media (prefers-color-scheme: dark){
  .pn-glyph{ color: var(--c-text); }
}

/* Diagram polish */
.label-text { font-size: 14px; }
.point { fill: var(--c-text); }
.triangle-container svg, .dodecagon-container svg { max-width: 100%; height: auto; }

/* ===== Genera table clarity ===== */
.table-container { overflow-x: auto; }

/* Sticky first two columns (name + tetrachord) so context doesn't scroll off */
#music #genera table th:nth-child(2),
#music #genera table td:nth-child(2),
#music #genera table th:nth-child(3),
#music #genera table td:nth-child(3) {
  position: sticky; left: 0; background: var(--c-bg);
  backdrop-filter: blur(1px);
  z-index: 1;
}
#music #genera table th:nth-child(3),
#music #genera table td:nth-child(3) { left: 12rem; } /* adjust if needed */

/* Narrow separators between the three genus columns */
#music #genera table th:nth-child(5),
#music #genera table td:nth-child(5) { border-left: 1px solid var(--c-border); }
#music #genera table th:nth-child(6),
#music #genera table td:nth-child(6) { border-left: 1px solid var(--c-border); }
#music #genera table th:nth-child(7),
#music #genera table td:nth-child(7) { border-left: 1px solid var(--c-border); }

/* Group headers */
.grouphead th {
  text-align: left;
  font-weight: 600;
  background: var(--c-bg-offset);
  border-top: 2px solid var(--c-border-strong);
  border-bottom: 1px solid var(--c-border);
}
.grouphead.tone th {
  background: transparent;
  color: var(--c-text-soft);
  font-style: italic;
}

/* Role badges (auto) */
#music #genera td:nth-child(4) { white-space: nowrap; }
#music #genera td:nth-child(4):has(> *), /* if you later wrap spans */
#music #genera td:nth-child(4) {
  position: relative;
  padding-left: 0.75rem;
}
#music #genera td:nth-child(4):before {
  content: "";
  position: absolute; left: 0.25rem; top: 0.8em;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--c-border);
}
#music #genera tr td:nth-child(4):where(:has(> :is(.role-fixed)), :contains("Fixed")):before {
  background: var(--c-text);           /* fixed = dark dot */
}
#music #genera tr td:nth-child(4):where(:has(> :is(.role-movable)), :contains("Movable")):before {
  background: var(--c-text-soft);      /* movable = lighter dot */
}

/* Genus focus highlighting via data attribute on the table */
#music #genera table[data-focus="diatonic"] td:nth-child(5),
#music #genera table[data-focus="diatonic"] th:nth-child(5) {
  background: color-mix(in srgb, var(--c-bg-offset), transparent 60%);
  font-weight: 600;
}
#music #genera table[data-focus="chromatic"] td:nth-child(6),
#music #genera table[data-focus="chromatic"] th:nth-child(6) {
  background: color-mix(in srgb, var(--c-bg-offset), transparent 60%);
  font-weight: 600;
}
#music #genera table[data-focus="enharmonic"] td:nth-child(7),
#music #genera table[data-focus="enharmonic"] th:nth-child(7) {
  background: color-mix(in srgb, var(--c-bg-offset), transparent 60%);
  font-weight: 600;
}

/* Faint unit hints inside genus columns (readability) */
#music #genera td:nth-child(5),
#music #genera td:nth-child(6),
#music #genera td:nth-child(7) {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Responsive: increase row height and prevent crowding on mobile */
@media (max-width: 720px){
  #music #genera table th, #music #genera table td { padding: .5rem .4rem; }
  #music #genera table th:nth-child(2), #music #genera table td:nth-child(2){ left: 0; }
  #music #genera table th:nth-child(3), #music #genera table td:nth-child(3){ left: 8.5rem; }
}

.grouphead .tetra-play,
.grouphead .tone-play{
  float: right;
  font: inherit;
  font-size: 0.95em;
  padding: .15rem .45rem;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  background: none;
  color: var(--c-text);
}
.grouphead .tetra-play:hover,
.grouphead .tone-play:hover{ background: var(--c-bg-offset); }

.planet-ring { display:grid; gap:0.75rem; place-items:center; }
.planet-ring svg { width:min(420px, 90vw); height:auto; overflow:visible; }

.orbit { fill:none; stroke:var(--ink-20, #ccc); stroke-dasharray:1 2; }
.planet { cursor:pointer; }
.planet circle { r:2.8; }
.planet[aria-selected="true"] circle { r:4; stroke-width:1.2; stroke:currentColor; fill-opacity:.15; }

.planet-label { font-size:3px; text-anchor:middle; dominant-baseline:middle; pointer-events:none; }

.ring-controls button { font:inherit; padding:.4rem .6rem; border-radius:.75rem; border:1px solid var(--ink-20,#ccc); background:var(--paper,#fff); }
.ring-controls button[aria-pressed="true"] { outline:2px solid currentColor; }

@media (prefers-reduced-motion: reduce) {
  .planet-ring { --animate: 0; }
}

/* assistive-only text */
.sr-only{position:absolute!important;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}

/* highlight the linked table row */
.planet-note-table tbody tr.is-active td{
  background: color-mix(in srgb, var(--c-bg-offset), transparent 40%);
  outline: 1px dashed var(--c-border-strong);
}

.planet circle { r:2.8; }
.planet-img { image-rendering:auto; }
.planet[aria-selected="true"] .planet-img { filter: drop-shadow(0 0 2px currentColor); }

/* Center planet styling */
.planet-center .planet-img{ image-rendering:auto; }
.planet-center .planet-label{ font-size:5px; text-anchor:middle; dominant-baseline:middle; }
.planet-center { pointer-events:none; } /* purely decorative; doesn’t intercept clicks */
/* UNIVERSAL selection glow: apply to the whole planet group */
.planet[aria-selected="true"] {
  filter: drop-shadow(0 0 2px currentColor);
}

/* Keep the nice “bigger dot + stroke” effect for selected planets */
.planet circle { r: 2.8; }
.planet[aria-selected="true"] circle {
  r: 4;
  stroke-width: 1.2;
  stroke: currentColor;
  fill-opacity: .15;
}

/* Optional: dedicated halo (auto-inserted by JS below) */
.planet .planet-halo {
  fill: currentColor;
  fill-opacity: 0;
  transition: r .15s ease, fill-opacity .15s ease;
}
.planet[aria-selected="true"] .planet-halo {
  fill-opacity: .28;
  r: 5.2;
}

/* Make sure currentColor is defined on the group */
.planet { color: var(--c-text); }

/* If you want it slightly emphasized: add a soft glow */
.planet-center .planet-img,
.planet-center circle{
  filter: drop-shadow(0 0 2px rgba(0,0,0,.25));
}

/* ===== Three Genera table: robust sticky columns & mobile scroll ===== */
#music #genera .table-container {
  overflow-x: auto;            /* enable horizontal scroll on small screens */
  -webkit-overflow-scrolling: touch;
}

#music #genera table {
  table-layout: fixed;         /* predictable column widths */
  /* Define widths for the first three (label) columns */
  --col-1: 3rem;               /* “#” */
  --col-2: 12rem;              /* Note Name */
  --col-3: 9rem;               /* Tetrachord */
  min-width: calc(var(--col-1) + var(--col-2) + var(--col-3) + 24rem);
  /* (the +24rem leaves room for the remaining genus columns) */
}

/* Set explicit widths for the first three columns */
#music #genera table th:nth-child(1),
#music #genera table td:nth-child(1) { width: var(--col-1); }
#music #genera table th:nth-child(2),
#music #genera table td:nth-child(2) { width: var(--col-2); }
#music #genera table th:nth-child(3),
#music #genera table td:nth-child(3) { width: var(--col-3); }

/* Make the first three columns sticky and align them by accumulated widths */
#music #genera table th:nth-child(1),
#music #genera table td:nth-child(1),
#music #genera table th:nth-child(2),
#music #genera table td:nth-child(2),
#music #genera table th:nth-child(3),
#music #genera table td:nth-child(3) {
  position: sticky;
  background: var(--c-bg);
  z-index: 2;                  /* stay above scrolled cells */
}

/* Offsets */
#music #genera table th:nth-child(1),
#music #genera table td:nth-child(1) { left: 0; z-index: 3; } /* topmost */
#music #genera table th:nth-child(2),
#music #genera table td:nth-child(2) { left: var(--col-1); }
#music #genera table th:nth-child(3),
#music #genera table td:nth-child(3) { left: calc(var(--col-1) + var(--col-2)); }

/* Tighter sizes on narrow screens */
@media (max-width: 720px) {
  #music #genera table {
    --col-2: 9.5rem;
    --col-3: 7.5rem;
    min-width: calc(var(--col-1) + var(--col-2) + var(--col-3) + 22rem);
  }
  #music #genera table th, #music #genera table td {
    padding: .5rem .4rem;
  }
}

/* === Tetrachord Species Slider === */
.tetra-controls { margin:.25rem 0 .35rem; }
.tetra-slider { width: min(380px, 80vw); vertical-align: middle; margin: 0 .5rem; }

.tetra-ticks {
  display:flex; justify-content:space-between;
  width:min(380px, 80vw); margin:.2rem auto 0; font-variant: small-caps;
  font-size: 10pt; color: var(--c-text-soft);
}

.tetra-species-label { margin-top:.35rem; font-style: italic; }

.tetra-bar {
  display:grid; grid-auto-flow:column; grid-auto-columns:1fr;
  gap: 2px; max-width:520px; margin:.5rem auto 0; border:1px solid var(--c-border);
  background: var(--c-bg-offset); border-radius:6px; overflow:hidden;
}
.tetra-seg { height: 16px; }
.seg-semi { background: color-mix(in srgb, var(--c-wisdom, #446), transparent 50%); }
.seg-tone { background: color-mix(in srgb, var(--c-king, #844), transparent 60%); }

@media (prefers-color-scheme: dark){
  .seg-semi { background: color-mix(in srgb, var(--c-wisdom, #ccd), transparent 65%); }
  .seg-tone { background: color-mix(in srgb, var(--c-king, #fcc), transparent 70%); }
}

/* === Means Calculator (Chapter 7) === */
.means-controls { margin:.25rem 0 .5rem; }
.means-input { width:6rem; padding:.2rem .35rem; border:1px solid var(--c-border); border-radius:4px; background:var(--c-bg-offset); color:var(--c-text); }

.means-grid{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap:.5rem;
  max-width:650px;
  margin:.5rem auto 0;
}
.means-card{
  border:1px solid var(--c-border);
  background: var(--c-bg-offset);
  border-radius:8px;
  padding:.5rem .6rem;
  text-align:center;
}
.means-title{ font-weight:bold; margin-bottom:.25rem; }
.means-value{ font-family:var(--font-mono); font-size:1.15rem; }
.means-note{ font-size:.9rem; color: var(--c-text-soft); }

.means-checks{
  max-width:650px; margin:.6rem auto 0;
  display:grid; gap:.25rem;
}
.means-checks code{ font-family:var(--font-mono); }
.badge{
  display:inline-block; margin-left:.4rem; padding:.05rem .4rem; border-radius:.4rem;
  border:1px solid var(--c-border);
  font-size:.85rem;
}
.badge.ok{ background: color-mix(in srgb, #38a169, transparent 70%); }
.badge.no{ background: color-mix(in srgb, #e53e3e, transparent 75%); }

@media (max-width: 720px){
  .means-grid{ grid-template-columns: 1fr; }
}

/* === Greater Perfect System Explorer === */
.gps-controls { margin:.25rem 0 .5rem; }
.gps-select { padding:.2rem .35rem; border:1px solid var(--c-border); border-radius:4px; background:var(--c-bg-offset); color:var(--c-text); }

.gps-legend{
  display:flex; gap:.75rem; justify-content:center; flex-wrap:wrap;
  font-size:.95rem; margin:.25rem auto .35rem; max-width:700px;
}
.gitem{ display:flex; align-items:center; gap:.35rem; border:1px solid var(--c-border); padding:.25rem .5rem; border-radius:.5rem; background:var(--c-bg-offset); }
.gchip{ width:10px; height:10px; border-radius:2px; display:inline-block; }
.gplay{ font:inherit; font-size:.85rem; padding:.1rem .4rem; border:1px solid var(--c-border); border-radius:.35rem; background:none; color:var(--c-text); }
.gplay:hover{ background:var(--c-bg-offset); }

.g-hypaton{ background: color-mix(in srgb, #8f7, transparent 75%); }
.g-meson{ background: color-mix(in srgb, #7bf, transparent 75%); }
.g-diazeuxis{ background: color-mix(in srgb, #bbb, transparent 70%); }
.g-diezeug{ background: color-mix(in srgb, #fc7, transparent 75%); }
.g-hyperb{ background: color-mix(in srgb, #f9a, transparent 75%); }


.gps-viz{ max-width:860px; margin:.25rem auto 0; }
.gps-node{
  cursor:pointer;
  transition: transform .15s ease, filter .15s ease;
}
.gps-node circle{ r:6; fill: var(--c-text); }
.gps-node:hover{ transform: translateY(-1px); filter: drop-shadow(0 0 2px rgba(0,0,0,.25)); }
.gps-node[aria-selected="true"] circle{ r:8; fill: var(--c-wisdom, #446); }

.gps-label{
  font-size:10px;
  text-anchor:middle;
  dominant-baseline:hanging;
  fill: var(--c-text-soft);
}
.gps-label.above{ dominant-baseline:auto; }
.gps-band{
  opacity:.35;
  stroke:none;
}

/* === GPS "Simon Says" ladder === */
#gpsSvg .gps-steps rect {
  opacity: .28;
  transition: opacity .15s ease, transform .12s ease;
  rx: 4px;
}
#gpsSvg .gps-steps rect.is-lit {
  opacity: .95;
  transform: translateY(-2px);
}

/* Hide node text labels so the ladder is the focus */
#gpsSvg .gps-label { display: none; }


/* small screens */
@media (max-width: 680px){
  .gps-label{ font-size:9px; }
}

/* === Beating a Fifth (Chapter 4) === */
.beats-controls { margin:.25rem 0 .35rem; }
.beats-slider { width:min(420px, 85vw); vertical-align:middle; margin:0 .5rem; }

.beats-grid{
  display:grid; gap:.5rem; grid-template-columns: repeat(3, 1fr);
  max-width:700px; margin:.25rem auto 0;
}
.beats-card{
  border:1px solid var(--c-border);
  background: var(--c-bg-offset);
  border-radius:8px; padding:.5rem .6rem; text-align:center;
}
.beats-title{ font-weight:bold; margin-bottom:.25rem; }
.beats-value{ font-family:var(--font-mono); font-size:1.1rem; }
.beats-note{ font-size:.9rem; color: var(--c-text-soft); }

@media (max-width: 720px){
  .beats-grid{ grid-template-columns: 1fr; }
}
