/* Exploring the Analects - Classical Academic Style */

:root {
  --bg-warm-white: #f5f5f0;
  --bg-section: #e8e8e0;
  --text-primary: #2c3e50;
  --text-secondary: #5d6d7e;
  --accent-blue-grey: #5d7a8c;
  --accent-bronze: #8b7355;
  --accent-light-bronze: #b89968;
  --border-color: #d0d0c8;
  --hover-bg: #fafaf5;
}

/* Dark mode colors */
[data-theme="dark"] {
  --bg-warm-white: #1a1a1a;
  --bg-section: #252525;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0a0;
  --accent-blue-grey: #7a9bb0;
  --accent-bronze: #c9a873;
  --accent-light-bronze: #d4b87a;
  --border-color: #3a3a3a;
  --hover-bg: #2a2a2a;
}

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

body {
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 18px;
  line-height: 1.8;
  color: var(--text-primary);
  background-color: var(--bg-warm-white);
  padding: 0;
  margin: 0;
}

/* Typography */
h1, h2, h3, h4 {
  font-family: 'Garamond', 'Baskerville', serif;
  font-weight: 400;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

h1 {
  font-size: 2.8rem;
  letter-spacing: 0.5px;
}

h2 {
  font-size: 2rem;
  margin-top: 2.5rem;
}

h3 {
  font-size: 1.5rem;
  margin-top: 2rem;
}

/* Header */
header {
  background: linear-gradient(135deg, #4a6374 0%, #5d7a8c 50%, #7d95a8 100%);
  color: white;
  padding: 3rem 2rem 2.5rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

header.scrolled {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: 0;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.header-image {
  display: none;
}

.header-content {
  max-width: 1100px;
  margin: 0 auto;
  text-align: center;
}

header.scrolled .header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  padding: 0.8rem 2rem;
  max-width: 100%;
}

.site-title-link {
  text-decoration: none;
  color: inherit;
  display: block;
  cursor: pointer;
}

.site-title-link:hover .site-title {
  opacity: 0.85;
}

.site-title {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  font-weight: 300;
  letter-spacing: 2px;
  line-height: 1.2;
}

header.scrolled .site-title {
  font-size: 1.5rem;
  margin-bottom: 0;
  letter-spacing: 1px;
  line-height: 1.4;
}

.site-subtitle {
  font-size: 1.3rem;
  font-weight: 300;
  opacity: 0.95;
  font-style: italic;
  line-height: 1.5;
}

header.scrolled .site-subtitle {
  display: none;
}

/* Navigation */
nav {
  background-color: var(--bg-section);
  border-bottom: 2px solid var(--border-color);
  padding: 1rem 0;
}

header.scrolled nav {
  background-color: transparent;
  border-bottom: none;
  padding: 0;
}

nav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 2rem;
}

header.scrolled nav ul {
  gap: 2rem;
  padding: 0;
  margin: 0;
}

nav a {
  text-decoration: none;
  color: var(--accent-blue-grey);
  font-weight: 500;
  transition: color 0.3s;
  font-size: 1.1rem;
  display: inline-block;
  padding: 0.3rem 0.5rem;
  margin: -0.3rem -0.5rem;
}

header.scrolled nav a {
  color: white;
  font-size: 1rem;
}

nav a:hover {
  color: var(--accent-bronze);
}

header.scrolled nav a:hover {
  color: var(--accent-light-bronze);
}

/* Nav buttons group (Listen Now + toggles) */
.nav-buttons {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: nowrap;
}

.listen-now-link {
  background-color: var(--accent-blue-grey);
  color: white !important;
  padding: 0 1.2rem;
  border-radius: 4px;
  transition: background-color 0.3s;
  height: 2.1rem;
  display: inline-flex;
  align-items: center;
}

.listen-now-link:hover {
  background-color: var(--accent-bronze) !important;
  color: white !important;
}

header.scrolled .listen-now-link {
  background-color: rgba(255,255,255,0.2);
  padding: 0.4rem 1rem;
}

header.scrolled .listen-now-link:hover {
  background-color: rgba(255,255,255,0.3) !important;
}

/* Navigation Dropdown */
.nav-dropdown {
  position: relative;
}

.nav-dropdown-toggle {
  cursor: pointer;
}

.dropdown-arrow {
  font-size: 0.7em;
  margin-left: 0.2em;
}

.nav-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background-color: white;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 150px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 99999;
  padding: 0.5rem 0;
}

nav ul.nav-dropdown-menu {
  display: block;
  gap: 0;
}

.nav-dropdown:hover .nav-dropdown-menu {
  opacity: 1;
  visibility: visible;
}

.nav-dropdown-menu li {
  display: block;
}

.nav-dropdown-menu a {
  display: block;
  padding: 0.5rem 1rem;
  color: var(--text-primary);
  font-size: 1rem;
}

.nav-dropdown-menu a:hover {
  background-color: var(--bg-section);
}

.nav-dropdown-menu a.active {
  color: var(--accent-bronze);
}

header.scrolled .nav-dropdown-menu {
  background-color: var(--text-primary);
}

header.scrolled .nav-dropdown-menu a {
  color: white;
}

header.scrolled .nav-dropdown-menu a:hover {
  background-color: rgba(255,255,255,0.1);
}

/* Spacer for fixed header */
body.header-fixed {
  padding-top: 0;
}

.header-spacer {
  height: 0;
}

body.header-fixed .header-spacer {
  height: 60px;
}

/* Main Container */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 3rem 2rem;
}

/* Introduction Section */
.intro-section {
  background-color: white;
  padding: 2.5rem;
  margin-bottom: 3rem;
  border: 1px solid var(--border-color);
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.intro-section p {
  margin-bottom: 1rem;
}

.intro-section p:last-child {
  margin-bottom: 0;
}

/* Sort Controls */
.sort-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.sort-btn {
  background: none;
  border: 1px solid var(--border-color);
  padding: 0.4rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.9rem;
  transition: all 0.2s;
}

.sort-btn:hover {
  border-color: var(--accent-blue-grey);
  color: var(--accent-blue-grey);
}

.sort-btn.active {
  background-color: var(--accent-blue-grey);
  border-color: var(--accent-blue-grey);
  color: white;
}

/* Episode List */
.episode-list {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.episode-card {
  background-color: white;
  border: 1px solid var(--border-color);
  padding: 2rem;
  transition: box-shadow 0.3s, transform 0.3s;
  text-decoration: none;
  color: inherit;
  display: block;
  position: relative;
}

.episode-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  transform: translateY(-2px);
}

.episode-card:hover .episode-listen {
  color: var(--accent-bronze);
}

.episode-number {
  color: var(--accent-bronze);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
}

.episode-title {
  font-size: 1.8rem;
  margin-bottom: 0.8rem;
  color: var(--text-primary);
}

.episode-passage {
  font-family: 'Noto Serif SC', 'SimSun', serif;
  font-size: 1.6rem;
  color: var(--accent-blue-grey);
  margin-bottom: 0.5rem;
  letter-spacing: 2px;
}

.episode-translation {
  font-style: italic;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  font-size: 1.05rem;
}

.episode-description {
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 0;
}

.episode-listen {
  color: var(--accent-blue-grey);
  font-weight: 600;
  font-size: 1rem;
  margin-top: 1rem;
  transition: color 0.3s;
}

/* Episode Page */
.episode-header {
  background-color: white;
  padding: 3rem 2.5rem;
  margin-bottom: 2rem;
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--accent-bronze);
}

.episode-meta {
  color: var(--accent-bronze);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-bottom: 1rem;
  text-transform: uppercase;
}

.passage-number {
  font-size: 1.1rem;
  color: var(--accent-bronze);
  font-weight: 600;
  margin: 2rem 0 0.5rem 0;
  text-align: center;
}

.passage-number:first-of-type {
  margin-top: 0;
}

/* Passage Reference Tooltips (only on episode pages, not full-text page) */
.content-section .passage-ref {
  position: relative;
  color: var(--accent-blue-grey);
  cursor: help;
  border-bottom: 1px dotted var(--accent-blue-grey);
}

.content-section .passage-ref:hover {
  color: var(--accent-bronze);
  border-bottom-color: var(--accent-bronze);
}

/* Passage reference modal backdrop */
.passage-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.passage-modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* Passage reference modal */
.passage-ref-tooltip {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  background-color: var(--bg-section);
  color: var(--text-primary);
  padding: 1.5rem;
  border-radius: 8px;
  font-size: 0.95rem;
  white-space: normal;
  width: 90vw;
  max-width: 450px;
  max-height: 70vh;
  overflow-y: auto;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 999;
  line-height: 1.6;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  text-align: left;
  border: 1px solid var(--border-color);
}

.passage-ref-tooltip.active {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.passage-ref-tooltip .modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  line-height: 1;
}

.passage-ref-tooltip .modal-close:hover {
  color: var(--text-primary);
}

.passage-ref-tooltip strong {
  color: var(--accent-bronze);
}

.passage-ref-chinese {
  font-family: 'Noto Serif SC', 'SimSun', serif;
  font-size: 1.1rem;
  display: block;
  margin: 0.5rem 0;
  line-height: 1.6;
  color: var(--accent-blue-grey);
}

.passage-ref-tooltip em {
  display: block;
  margin: 0.5rem 0;
  font-style: italic;
  color: var(--text-primary);
}

.passage-ref-tooltip small {
  color: var(--text-secondary);
}


.chinese-passage {
  font-family: 'Noto Serif SC', 'SimSun', serif;
  font-size: 2.2rem;
  line-height: 1.8;
  margin: 0.5rem 0 2rem 0;
  padding: 2rem;
  background-color: var(--bg-section);
  text-align: center;
  letter-spacing: 4px;
}

.chinese-char {
  position: relative;
  cursor: help;
  transition: color 0.2s;
}

.chinese-char:hover {
  color: var(--accent-bronze);
}

.char-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--text-primary);
  color: white;
  padding: 0.8rem 1.2rem;
  border-radius: 4px;
  font-size: 0.85rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  margin-bottom: 0.5rem;
  z-index: 999;
  font-family: 'Crimson Text', Georgia, serif;
  letter-spacing: 0;
  line-height: 1.4;
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
  user-select: none;
}

/* Mobile tooltip adjustments */
@media (max-width: 768px) {
  .char-tooltip {
    white-space: normal;
    word-break: keep-all;
    overflow-wrap: normal;
    max-width: 250px;
    text-align: center;
  }
}

.char-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--text-primary);
}

.chinese-char:hover .char-tooltip,
.chinese-char.active .char-tooltip {
  opacity: 1;
}

/* Pinyin annotations using native ruby elements for Safari/iOS compatibility */
.chinese-char {
  /* Using actual <ruby> elements now */
  ruby-position: under;
  -webkit-ruby-position: under; /* Safari/iOS */
}

.chinese-char rt {
  display: none;
}

[data-show-pinyin="true"] .passage-text,
[data-show-pinyin="true"] .chinese-passage {
  line-height: 3.2;
}

[data-show-pinyin="true"] .chinese-char {
  margin-right: 0.15em;
}

[data-show-pinyin="true"] .chinese-char rt {
  display: revert;
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 0.55em;
  color: var(--accent-blue-grey);
  font-weight: normal;
  ruby-align: center;
  text-align: center;
  padding-top: 0.4em;
  letter-spacing: -0.05em;
}

.hover-hint {
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 1rem;
  opacity: 0.8;
}

.translation-box {
  background-color: white;
  padding: 2rem;
  margin: 2rem 0;
  border-left: 3px solid var(--accent-blue-grey);
  font-style: italic;
  font-size: 1.15rem;
}

/* Content Sections */
.content-section {
  background-color: white;
  padding: 2.5rem;
  margin-bottom: 2rem;
  border: 1px solid var(--border-color);
}

.content-section h2 {
  margin-top: 0;
  color: var(--accent-blue-grey);
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0.8rem;
  margin-bottom: 1.5rem;
}

.content-section h3 {
  color: var(--accent-bronze);
  margin-top: 2rem;
}

.content-section p {
  margin-bottom: 1.2rem;
}

.content-section em {
  color: var(--accent-blue-grey);
}

/* Links in content sections */
.content-section a:not(.passage-ref):not(.episode-link) {
  color: var(--accent-bronze);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}

.content-section a:not(.passage-ref):not(.episode-link):hover {
  border-bottom-color: var(--accent-bronze);
}

/* Grammar (虛詞) Page */
.xuci-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 3rem 2rem;
}

.xuci-header {
  text-align: center;
  margin-bottom: 2rem;
}

.xuci-header h1 {
  font-size: 2.5rem;
  color: var(--accent-blue-grey);
  margin-bottom: 0.5rem;
}

.xuci-header .english-title {
  font-size: 1.2rem;
  font-weight: normal;
  color: var(--text-secondary);
}

.xuci-subtitle {
  font-style: italic;
  color: var(--text-secondary);
}

.xuci-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 2rem;
  position: sticky;
  top: 60px;
  background-color: var(--bg-main);
  padding: 1rem 0;
  z-index: 1;
}

.xuci-nav-btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  background-color: var(--bg-section);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--accent-blue-grey);
  text-decoration: none;
  font-size: 1.5rem;
  transition: all 0.2s;
}

.xuci-nav-btn:hover {
  background-color: var(--accent-blue-grey);
  color: white;
}

.xuci-intro {
  background-color: var(--bg-section);
  padding: 1.5rem;
  border-radius: 4px;
  margin-bottom: 2rem;
  border-left: 3px solid var(--accent-blue-grey);
}

.xuci-intro p {
  margin: 0 0 1rem 0;
}

.xuci-intro p:last-child {
  margin-bottom: 0;
}

.xuci-list {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.xuci-card {
  background-color: white;
  border: 1px solid var(--border-color);
  padding: 2rem;
  scroll-margin-top: 120px;
}

.xuci-char {
  font-size: 3rem;
  color: var(--accent-blue-grey);
  margin: 0 0 0.5rem 0;
}

.xuci-summary {
  font-style: italic;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.xuci-functions {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.xuci-function h3 {
  color: var(--accent-bronze);
  margin: 0 0 0.5rem 0;
}

.function-explanation {
  margin-bottom: 1rem;
}

.xuci-examples {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.xuci-example {
  background-color: var(--bg-section);
  padding: 1rem;
  border-radius: 4px;
}

.xuci-example .chinese-passage {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.xuci-example .example-translation {
  font-style: italic;
  margin: 0.5rem 0;
}

.xuci-example .example-note {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin: 0;
}

/* Back Navigation */
.back-link {
  display: inline-block;
  margin-bottom: 2rem;
  color: var(--accent-blue-grey);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.3s;
}

.back-link:hover {
  color: var(--accent-bronze);
}

.back-link::before {
  content: '← ';
}

/* Episode Navigation Bar */
.episode-nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.5rem;
  background: transparent;
  background-color: transparent;
  border: none;
  border-bottom: none;
  padding: 0;
}

.back-link-icon {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--accent-blue-grey);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  transition: color 0.3s;
}

.back-link-icon:hover {
  color: var(--accent-bronze);
}

.back-link-icon svg {
  flex-shrink: 0;
}

.prev-next-links {
  display: flex;
  gap: 1.5rem;
}

.nav-link {
  color: var(--accent-blue-grey);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  transition: color 0.3s;
}

.nav-link:hover {
  color: var(--accent-bronze);
}

/* Bottom Episode Navigation */
.episode-nav-bottom {
  margin-top: 3rem;
  padding: 2rem;
  background-color: var(--bg-section);
  border: none;
  border-bottom: none;
  display: block;
}

.episode-nav-bottom .nav-link {
  display: block;
  margin-bottom: 0.75rem;
}

.episode-nav-bottom .nav-link:last-child {
  margin-bottom: 0;
}

/* Responsive episode nav */
@media (max-width: 550px) {
  .episode-nav-bar {
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
  }

  .prev-next-links {
    gap: 1rem;
  }
}

/* Listening Section */
.listening-section {
  background-color: white;
  padding: 0.75rem 1.5rem;
  margin: 1.5rem 0;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.listen-label {
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.listening-section h3 {
  margin-bottom: 1.5rem;
  color: var(--accent-blue-grey);
}

.listening-section iframe {
  max-width: 100%;
  margin: 0 auto;
  display: block;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.listen-links {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.listen-button {
  display: inline-block;
  padding: 0.8rem 2rem;
  background-color: var(--accent-blue-grey);
  color: white;
  text-decoration: none;
  border-radius: 4px;
  transition: background-color 0.3s;
  font-weight: 500;
}

.listen-button:hover {
  background-color: var(--accent-bronze);
}

/* Footer */
footer {
  background-color: var(--bg-section);
  border-top: 2px solid var(--border-color);
  padding: 2.5rem 2rem;
  margin-top: 4rem;
  text-align: center;
  color: var(--text-secondary);
}

footer p {
  margin-bottom: 0.5rem;
}

footer a {
  color: var(--accent-blue-grey);
  text-decoration: none;
}

footer a:hover {
  color: var(--accent-bronze);
  text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 768px) {
  body {
    overflow-x: hidden;
  }

  header {
    padding: 2rem 1.5rem 1.5rem;
  }

  header.scrolled {
    padding: 0;
  }

  .header-content {
    padding: 0;
  }

  .site-title-link {
    width: 100%;
  }

  header.scrolled .header-content {
    flex-direction: column;
    padding: 0.6rem 1rem;
    gap: 0.5rem;
  }

  header.scrolled .site-title-link {
    display: none;
  }

  .site-title {
    font-size: 2rem;
    letter-spacing: 1px;
    margin-bottom: 0.8rem;
    line-height: 1.1;
  }

  header.scrolled .site-title {
    font-size: 1.2rem;
    margin-bottom: 0;
    line-height: 1.3;
  }

  .site-subtitle {
    font-size: 1rem;
    line-height: 1.4;
  }

  nav {
    padding: 0.5rem 0;
  }

  nav ul {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.25rem 0.75rem;
    justify-content: center;
    align-items: center;
    padding: 0 0.5rem;
  }

  header.scrolled nav ul {
    gap: 0.25rem 1.5rem;
    padding: 0;
  }

  nav a {
    font-size: 0.9rem;
    white-space: nowrap;
  }

  header.scrolled nav a {
    font-size: 0.8rem;
  }

  body.header-fixed .header-spacer {
    height: 90px;
  }

  h1 {
    font-size: 2rem;
  }

  h2 {
    font-size: 1.6rem;
  }

  .container {
    padding: 2rem 1rem;
    overflow-x: hidden;
  }

  .episode-card,
  .content-section,
  .intro-section {
    padding: 1.5rem;
  }

  .chinese-passage {
    font-size: 1.6rem;
    padding: 1.5rem;
    letter-spacing: 2px;
  }

  .listen-links {
    flex-direction: column;
    align-items: center;
  }

  .listen-now-link {
    font-size: 0.85rem;
    padding: 0.35rem 0.75rem;
  }

  header.scrolled .listen-now-link {
    font-size: 0.75rem;
    padding: 0.3rem 0.65rem;
  }
}

/* Extra small screens */
@media (max-width: 400px) {
  nav ul {
    gap: 0.25rem 1rem;
  }

  header.scrolled nav ul {
    gap: 0.25rem 1.25rem;
  }

  nav a {
    font-size: 0.8rem;
  }

  header.scrolled nav a {
    font-size: 0.7rem;
  }

  .listen-now-link {
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
  }

  header.scrolled .listen-now-link {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
  }
}

/* Scroll margin for anchor targets to account for fixed header */
:target,
[id] {
  scroll-margin-top: 120px;
}

/* Additional spacing for mobile */
@media (max-width: 768px) {
  :target,
  [id] {
    scroll-margin-top: 100px;
  }
}

/* Audio Player Container */
.player-container {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  transform-origin: center bottom;
  width: 90%;
  max-width: 660px;
  height: auto;
  background: linear-gradient(135deg, #4a6374 0%, #5d7a8c 50%, #7d95a8 100%);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  z-index: 999;
  border-radius: 12px;
  padding: 0.5rem;
  transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
}

.player-container.hidden {
  display: none;
}

.player-container iframe {
  width: 100%;
  height: 175px;
  display: block;
  margin: 0 auto;
  border-radius: 12px;
}

/* Tablet sizing */
@media (min-width: 769px) and (max-width: 1024px) {
  .player-container {
    width: 85%;
    max-width: 600px;
  }
}

.close-player-btn {
  position: absolute;
  top: 0.5rem;
  left: 0.25rem;
  background: rgba(0, 0, 0, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.8);
  color: white;
  font-size: 1.25rem;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background 0.2s, border-color 0.2s;
  line-height: 1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.player-container.floating .close-player-btn {
  display: flex;
}

.close-player-btn:hover {
  background: rgba(0, 0, 0, 0.8);
  border-color: rgba(255, 255, 255, 1);
}

/* Player Selection Buttons */
.player-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.player-select-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  min-width: 150px;
  background: linear-gradient(135deg, #4a6374 0%, #5d7a8c 50%, #7d95a8 100%);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 1.1rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.player-select-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.player-select-btn:active {
  transform: translateY(0);
}

.player-select-btn svg {
  flex-shrink: 0;
}

.spotify-text {
  font-size: 1.2rem;
  letter-spacing: 0.02em;
}

@media (max-width: 768px) {
  .player-select-btn {
    padding: 0.65rem 1.25rem;
    font-size: 1rem;
  }
}

/* Mobile sizing */
@media (max-width: 768px) {
  .player-container {
    width: 95%;
    max-width: none;
    bottom: 0.5rem;
    padding: 0.5rem;
  }

  .close-player-btn {
    width: 24px;
    height: 24px;
    font-size: 1rem;
    left: 0.25rem;
  }
}

/* Small mobile devices */
@media (max-width: 480px) {
  .player-container {
    width: calc(100% - 1rem);
    bottom: 0.5rem;
  }
}

/* Analects Full Text Page */
.analects-page {
  max-width: 900px;
  margin: 0 auto;
}

.analects-header {
  text-align: center;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid var(--border-color);
}

.analects-header h1 {
  font-size: 2.5rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.analects-header .english-title {
  font-size: 1.5rem;
  color: var(--accent-blue-grey);
  font-weight: normal;
}

.analects-subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

/* Filter section - reorganized compact layout */
.filter-section {
  background-color: white;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  margin-bottom: 1.5rem;
}

/* Search row */
.search-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.search-row input {
  flex: 1;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 1rem;
}

.search-row button {
  padding: 0.6rem 1.25rem;
  background: var(--accent-blue-grey);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background 0.2s;
}

.search-row button:hover {
  background: var(--accent-bronze);
}

.help-btn {
  padding: 0.6rem 0.9rem !important;
  background: transparent !important;
  color: var(--text-secondary) !important;
  border: 1px solid var(--border-color) !important;
  font-weight: 600;
}

.help-btn:hover {
  background: var(--bg-section) !important;
  color: var(--accent-blue-grey) !important;
}

/* Search guide - hidden by default */
.search-guide {
  display: none;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-section);
  border-radius: 4px;
  line-height: 1.5;
}

.search-guide.visible {
  display: block;
}

/* Filter toggles row */
.filter-toggles {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.filter-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.filter-toggle-btn:hover {
  border-color: var(--accent-blue-grey);
  color: var(--accent-blue-grey);
}

.filter-toggle-btn.active {
  background: var(--bg-section);
  border-color: var(--accent-blue-grey);
  color: var(--accent-blue-grey);
}

.filter-toggle-btn .toggle-icon {
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.filter-toggle-btn.active .toggle-icon {
  transform: rotate(90deg);
}

.book-selection-indicator {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  background: var(--accent-bronze);
  color: white;
  border-radius: 10px;
  font-size: 0.75rem;
  margin-left: 0.25rem;
}

.book-selection-indicator:empty {
  display: none;
}

/* Display options - inline checkboxes */
.display-options {
  display: flex;
  gap: 1rem;
  margin-left: auto;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.toggle-label input {
  cursor: pointer;
}

.toggle-label:hover {
  color: var(--text-primary);
}

/* Quick filters - collapsible */
.quick-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border-color);
  margin-top: 0.5rem;
}

.quick-filters.collapsed {
  display: none;
}

/* Searchable dropdown component */
.searchable-dropdown {
  position: relative;
  min-width: 140px;
}

.dropdown-search {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: white;
  font-size: 0.85rem;
  color: var(--text-primary);
  transition: border-color 0.2s;
}

.dropdown-search:hover {
  border-color: var(--accent-blue-grey);
}

.dropdown-search:focus {
  outline: none;
  border-color: var(--accent-blue-grey);
  box-shadow: 0 0 0 2px rgba(107, 125, 138, 0.15);
}

.dropdown-search::placeholder {
  color: var(--text-secondary);
}

.dropdown-options {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 250px;
  overflow-y: auto;
  background: white;
  border: 1px solid var(--border-color);
  border-top: none;
  border-radius: 0 0 4px 4px;
  z-index: 100;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.dropdown-options.visible {
  display: block;
}

.dropdown-option {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-color);
}

.dropdown-option:last-child {
  border-bottom: none;
}

.dropdown-option:hover {
  background-color: var(--bg-secondary);
}

/* Active tag filters display */
.active-tags {
  display: none;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 0;
}

.active-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.5rem;
  background-color: var(--accent-blue-grey);
  color: white;
  border-radius: 3px;
  font-size: 0.85rem;
}

.remove-tag {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  margin-left: 0.2rem;
  opacity: 0.8;
}

.remove-tag:hover {
  opacity: 1;
}

/* Book navigation - collapsible */
.book-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border-color);
  margin-top: 0.5rem;
}

.book-nav.collapsed {
  display: none;
}

.book-nav-btn {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border-color);
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-primary);
  transition: all 0.15s;
}

.book-nav-btn:hover {
  border-color: var(--accent-blue-grey);
  background: var(--bg-section);
}

.book-nav-btn.active {
  background: var(--accent-blue-grey);
  color: white;
  border-color: var(--accent-blue-grey);
}

/* Filter status */
.filter-status {
  font-size: 0.85rem;
  color: var(--text-secondary);
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-color);
  margin-top: 0.5rem;
}

.search-guide code {
  background: var(--bg-section);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  font-family: monospace;
}

.filter-options {
  margin-bottom: 0.75rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.checkbox-label input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

.filter-status {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.search-highlight {
  background-color: #fff3cd;
  border-radius: 2px;
  box-shadow: 0 0 0 2px #fff3cd;
}

.english-highlight {
  background-color: #fff3cd;
  border-radius: 2px;
  padding: 0 2px;
}

.book-section {
  margin-bottom: 2.5rem;
}

.book-title {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.book-chinese {
  font-size: 1.5rem;
  color: var(--text-primary);
}

.book-english {
  font-size: 1rem;
  color: var(--accent-blue-grey);
  font-weight: normal;
}

.passages {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.passage {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  line-height: 1.8;
}

.passage-ref {
  flex-shrink: 0;
  font-size: 0.85rem;
  color: var(--accent-bronze);
  font-weight: 600;
  min-width: 3rem;
}

.passage-text {
  font-family: 'Noto Serif SC', serif;
  font-size: 1.1rem;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.passage-episode {
  width: 100%;
  padding-top: 0.5rem;
  margin-top: 0.25rem;
  border-top: 1px dashed var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.passage-translation {
  font-style: italic;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.legge-container {
  margin-top: 0.5rem;
}

.legge-toggle {
  background: none;
  border: none;
  color: var(--accent-bronze);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: 'Crimson Text', Georgia, serif;
  padding: 0.25rem 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legge-toggle:hover {
  color: var(--accent-blue-grey);
}

.toggle-icon {
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.legge-translation {
  display: none;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border-color);
  white-space: pre-line;
  line-height: 1.4;
}

.legge-translation.expanded {
  display: block;
}

/* Remove border when Legge is the only translation */
.passage-episode .legge-container:first-child .legge-translation {
  border-top: none;
  padding-top: 0;
}

.translation-source {
  font-size: 0.8rem;
  color: var(--accent-bronze);
}

.episode-link {
  font-size: 0.85rem;
  color: var(--accent-blue-grey);
  text-decoration: none;
  font-weight: 500;
}

.episode-link:hover {
  color: var(--accent-bronze);
  text-decoration: underline;
}

/* Passage action buttons */
.passage-actions {
  display: flex;
  gap: 1rem;
  width: 100%;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border-color);
}

/* Remove border when episode comes before actions */
.passage-episode + .passage-actions {
  border-top: none;
  padding-top: 0.25rem;
}

.action-btn {
  background: none;
  border: none;
  color: var(--accent-bronze);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: 'Crimson Text', Georgia, serif;
  padding: 0.25rem 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: color 0.2s;
}

.action-btn:hover {
  color: var(--accent-blue-grey);
}

.action-btn.active {
  color: var(--accent-blue-grey);
}

.action-btn .toggle-icon {
  font-size: 0.7rem;
}

.passage-extras {
  width: 100%;
}

.legge-content .legge-translation {
  display: block;
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.tags-content {
  padding-top: 0.5rem;
}

.passage-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.passage-tag {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
}

.passage-tag:hover {
  border-color: var(--accent-bronze);
  color: var(--accent-bronze);
}

/* Responsive Analects page */
@media (max-width: 768px) {
  .analects-page {
    width: 100%;
    overflow-x: hidden;
  }

  .analects-content {
    width: 100%;
    overflow-x: hidden;
  }

  .analects-header h1 {
    font-size: 2rem;
  }

  .analects-header .english-title {
    display: block;
    font-size: 1.2rem;
    margin-top: 0.25rem;
  }

  .book-nav {
    padding: 0.75rem;
    gap: 0.4rem;
  }

  .book-nav-btn {
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
    min-width: unset;
  }

  .book-nav-label {
    width: 100%;
    margin-bottom: 0.25rem;
  }

  .filter-section {
    padding: 1rem;
  }

  .book-title {
    flex-direction: column;
    gap: 0.25rem;
  }

  .book-chinese {
    font-size: 1.3rem;
  }

  .passages {
    width: 100%;
  }

  .passage {
    flex-direction: column;
    gap: 0.25rem;
    width: 100%;
    box-sizing: border-box;
    padding: 0.5rem 0.75rem;
  }

  .passage-ref {
    font-size: 0.8rem;
  }

  .passage-text {
    width: 100%;
    font-size: 1rem;
    line-height: 1.7;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
  }

  [data-show-pinyin="true"] .passage-text {
    line-height: 3.2;
  }

  .passage-episode {
    padding-top: 0.4rem;
  }

  .passage-translation {
    font-size: 0.9rem;
  }

  .episode-link {
    font-size: 0.8rem;
  }

  .search-row {
    flex-wrap: wrap;
  }

  .search-row input {
    flex: 1 1 100%;
    margin-bottom: 0.5rem;
  }

  .search-row button {
    flex: 1;
  }

  .filter-toggles {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .display-options {
    margin-left: 0;
    justify-content: flex-start;
  }

  .quick-filters {
    flex-direction: column;
  }

  .searchable-dropdown {
    width: 100%;
    min-width: unset;
  }

  .search-guide {
    font-size: 0.8rem;
  }

  .search-guide code {
    font-size: 0.75rem;
  }

  /* Ensure Chinese characters wrap properly - MUST be 'ruby' not 'inline' for pinyin to show */
  .passage-text .chinese-char {
    display: ruby;
    word-break: break-all;
  }
}

/* Dark mode overrides for hardcoded colors */
[data-theme="dark"] .intro-section,
[data-theme="dark"] .episode-card,
[data-theme="dark"] .episode-header,
[data-theme="dark"] .content-section,
[data-theme="dark"] .translation-box,
[data-theme="dark"] .listening-section,
[data-theme="dark"] .filter-section,
[data-theme="dark"] .book-nav,
[data-theme="dark"] .passage,
[data-theme="dark"] .book-nav-btn,
[data-theme="dark"] .dropdown-search,
[data-theme="dark"] .dropdown-options,
[data-theme="dark"] .search-row input {
  background-color: var(--bg-section);
}

[data-theme="dark"] .search-row input,
[data-theme="dark"] .dropdown-search {
  color: var(--text-primary);
}

[data-theme="dark"] .dropdown-option:hover {
  background-color: rgba(255,255,255,0.1);
}

[data-theme="dark"] .filter-toggle-btn {
  background-color: transparent;
}

[data-theme="dark"] .filter-toggle-btn.active {
  background-color: rgba(255,255,255,0.1);
}

[data-theme="dark"] .char-tooltip {
  background-color: #3a3a3a;
}

[data-theme="dark"] .char-tooltip::after {
  border-top-color: #3a3a3a;
}

[data-theme="dark"] .search-highlight {
  background-color: #5a4a20;
  box-shadow: 0 0 0 2px #5a4a20;
}

[data-theme="dark"] .english-highlight {
  background-color: #5a4a20;
}

[data-theme="dark"] .search-guide code {
  background-color: #333;
}

[data-theme="dark"] .nav-dropdown-menu,
[data-theme="dark"] header.scrolled .nav-dropdown-menu {
  background-color: var(--bg-section);
  border-color: var(--border-color);
}

[data-theme="dark"] .nav-dropdown-menu a,
[data-theme="dark"] header.scrolled .nav-dropdown-menu a {
  color: var(--text-primary);
}

[data-theme="dark"] .nav-dropdown-menu a:hover,
[data-theme="dark"] header.scrolled .nav-dropdown-menu a:hover {
  background-color: rgba(255,255,255,0.1);
}

/* Dark mode toggle button */
.theme-toggle,
.script-toggle,
.pinyin-toggle {
  background-color: var(--accent-blue-grey);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  width: 2.1rem;
  height: 2.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: background-color 0.3s;
}

.theme-toggle:hover,
.script-toggle:hover,
.pinyin-toggle:hover {
  background-color: var(--accent-bronze);
}

header .theme-toggle,
header .script-toggle,
header .pinyin-toggle {
  background-color: rgba(255,255,255,0.2);
}

header .theme-toggle:hover,
header .script-toggle:hover,
header .pinyin-toggle:hover {
  background-color: rgba(255,255,255,0.3);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

/* Show sun in dark mode, moon in light mode */
.theme-toggle .sun-icon {
  display: none;
}

.theme-toggle .moon-icon {
  display: block;
}

[data-theme="dark"] .theme-toggle .sun-icon {
  display: block;
}

[data-theme="dark"] .theme-toggle .moon-icon {
  display: none;
}

/* Script toggle button (traditional/simplified) */
.script-toggle,
.pinyin-toggle {
  font-size: 1.1rem;
  font-weight: 500;
  font-family: 'Noto Serif SC', Georgia, serif;
  line-height: 1;
}

/* Show 繁 when in simplified mode (click to go traditional) */
/* Show 简 when in traditional mode (click to go simplified) */
.script-toggle .trad-label {
  display: none;
}

.script-toggle .simp-label {
  display: inline;
}

[data-script="simplified"] .script-toggle .trad-label {
  display: inline;
}

[data-script="simplified"] .script-toggle .simp-label {
  display: none;
}

/* Bronze color when pinyin is OFF */
body:not(.show-pinyin) .pinyin-toggle {
  background-color: var(--accent-bronze);
}

/* Settings Button */
.settings-btn {
  background-color: var(--accent-blue-grey);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  width: 2.1rem;
  height: 2.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: background-color 0.3s;
}

.settings-btn:hover {
  background-color: var(--accent-bronze);
}

header .settings-btn {
  background-color: rgba(255,255,255,0.2);
}

header .settings-btn:hover {
  background-color: rgba(255,255,255,0.3);
}

.settings-btn svg {
  width: 18px;
  height: 18px;
}

/* Settings Modal */
.settings-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.settings-modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.settings-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  background-color: var(--bg-warm-white);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  z-index: 1001;
  width: 90%;
  max-width: 320px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.settings-modal.active {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.settings-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.settings-modal-header h3 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--text-primary);
}

.settings-modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.settings-modal-close:hover {
  background-color: var(--bg-section);
  color: var(--text-primary);
}

.settings-modal-body {
  padding: 0.5rem 0;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.25rem;
}

.settings-row:hover {
  background-color: var(--bg-section);
}

.settings-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.settings-label-text {
  font-size: 1rem;
  color: var(--text-primary);
}

.settings-label-icon {
  display: flex;
  align-items: center;
  color: var(--accent-blue-grey);
}

.settings-label-icon svg {
  width: 16px;
  height: 16px;
}

/* Show appropriate icon based on theme */
.settings-label-icon .sun-icon {
  display: none;
}

.settings-label-icon .moon-icon {
  display: block;
}

[data-theme="dark"] .settings-label-icon .sun-icon {
  display: block;
}

[data-theme="dark"] .settings-label-icon .moon-icon {
  display: none;
}

.settings-chinese-icon {
  font-family: 'Noto Serif SC', 'SimSun', serif;
  font-size: 1rem;
}

.settings-chinese-icon .trad-label {
  display: none;
}

.settings-chinese-icon .simp-label {
  display: inline;
}

[data-script="simplified"] .settings-chinese-icon .trad-label {
  display: inline;
}

[data-script="simplified"] .settings-chinese-icon .simp-label {
  display: none;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border-color);
  transition: 0.2s;
  border-radius: 26px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--accent-blue-grey);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(22px);
}

.toggle-switch input:focus + .toggle-slider {
  box-shadow: 0 0 0 2px rgba(93, 122, 140, 0.3);
}

/* Web Fonts Import */
@import url('https://fonts.googleapis.com/css2?family=Crimson+Text:ital,wght@0,400;0,600;1,400&family=Noto+Serif+SC:wght@400;500;600&display=swap');

/* Tone Coloring */
:root {
  --tone-1-color: #e67e22; /* Orange - flat tone */
  --tone-2-color: #27ae60; /* Green - rising tone */
  --tone-3-color: #3498db; /* Blue - dip tone */
  --tone-4-color: #e74c3c; /* Red - falling tone */
  --tone-5-color: #7f8c8d; /* Dark gray - neutral tone */
  /* Soft highlight versions (40% opacity) */
  --tone-1-bg: rgba(230, 126, 34, 0.35);
  --tone-2-bg: rgba(39, 174, 96, 0.35);
  --tone-3-bg: rgba(52, 152, 219, 0.35);
  --tone-4-bg: rgba(231, 76, 60, 0.35);
  --tone-5-bg: rgba(127, 140, 141, 0.3);
}

/* Text color mode - single characters */
[data-tone-color="text"] .chinese-char[data-tone="1"] { color: var(--tone-1-color); }
[data-tone-color="text"] .chinese-char[data-tone="2"] { color: var(--tone-2-color); }
[data-tone-color="text"] .chinese-char[data-tone="3"] { color: var(--tone-3-color); }
[data-tone-color="text"] .chinese-char[data-tone="4"] { color: var(--tone-4-color); }
[data-tone-color="text"] .chinese-char[data-tone="5"] { color: var(--tone-5-color); }

/* Text color mode - characters within compound words */
[data-tone-color="text"] .chinese-char [data-tone="1"] { color: var(--tone-1-color); }
[data-tone-color="text"] .chinese-char [data-tone="2"] { color: var(--tone-2-color); }
[data-tone-color="text"] .chinese-char [data-tone="3"] { color: var(--tone-3-color); }
[data-tone-color="text"] .chinese-char [data-tone="4"] { color: var(--tone-4-color); }
[data-tone-color="text"] .chinese-char [data-tone="5"] { color: var(--tone-5-color); }

/* Background color mode - single characters */
[data-tone-color="background"] .chinese-char[data-tone="1"] { background-color: var(--tone-1-bg); border-radius: 2px; padding: 0 1px; }
[data-tone-color="background"] .chinese-char[data-tone="2"] { background-color: var(--tone-2-bg); border-radius: 2px; padding: 0 1px; }
[data-tone-color="background"] .chinese-char[data-tone="3"] { background-color: var(--tone-3-bg); border-radius: 2px; padding: 0 1px; }
[data-tone-color="background"] .chinese-char[data-tone="4"] { background-color: var(--tone-4-bg); border-radius: 2px; padding: 0 1px; }
[data-tone-color="background"] .chinese-char[data-tone="5"] { background-color: var(--tone-5-bg); border-radius: 2px; padding: 0 1px; }

/* Background color mode - characters within compound words */
[data-tone-color="background"] .chinese-char [data-tone="1"] { background-color: var(--tone-1-bg); border-radius: 2px; padding: 0 1px; }
[data-tone-color="background"] .chinese-char [data-tone="2"] { background-color: var(--tone-2-bg); border-radius: 2px; padding: 0 1px; }
[data-tone-color="background"] .chinese-char [data-tone="3"] { background-color: var(--tone-3-bg); border-radius: 2px; padding: 0 1px; }
[data-tone-color="background"] .chinese-char [data-tone="4"] { background-color: var(--tone-4-bg); border-radius: 2px; padding: 0 1px; }
[data-tone-color="background"] .chinese-char [data-tone="5"] { background-color: var(--tone-5-bg); border-radius: 2px; padding: 0 1px; }

/* Override hover color when tone coloring is active */
[data-tone-color="text"] .chinese-char:hover {
  filter: brightness(0.85);
}

[data-tone-color="background"] .chinese-char:hover {
  filter: brightness(0.92);
}

/* Tone Colors Settings UI */
.settings-subsection {
  padding: 0 1.25rem 0.85rem;
  display: none;
}

.settings-subsection.visible {
  display: block;
}

.tone-mode-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.tone-mode-label {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.tone-mode-select {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--bg-warm-white);
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
}

.tone-colors-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
}

.tone-color-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.tone-color-item label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.tone-color-picker {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
  background: none;
}

.tone-color-picker::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.tone-color-picker::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}
