:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-alt: #f3ede2;
  --ink: #1d1b18;
  --muted: #645d52;
  --accent: #8b2e2e;
  --accent-soft: #f5e6e6;
  --border: #e2d9c8;
  --shadow: 0 4px 20px rgba(29, 27, 24, 0.06);
  --serif: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body.dark {
  --bg: #151412;
  --surface: #1e1c19;
  --surface-alt: #282520;
  --ink: #ece6db;
  --muted: #a69d8f;
  --accent: #d97878;
  --accent-soft: #352323;
  --border: #35312b;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.55;
  transition: background 0.2s ease, color 0.2s ease;
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

.eyebrow {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}

.brand h1 {
  font-family: var(--serif);
  font-size: clamp(1.5rem, 2.5vw, 2.1rem);
  margin: 0.15rem 0 0.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
  max-width: 68ch;
}

.header-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.main-tabs {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  gap: 0.25rem;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.65rem 1rem;
  cursor: pointer;
}

.tab-btn:hover {
  color: var(--ink);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.btn {
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.5rem 0.95rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-ghost {
  background: var(--surface-alt);
  color: var(--ink);
}

.btn-ghost:hover {
  border-color: var(--accent);
}

.btn-sm {
  padding: 0.32rem 0.65rem;
  font-size: 0.82rem;
}

.full-width {
  width: 100%;
}

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.5rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

#view-explore.active {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.75rem;
  align-items: start;
}

.filters-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.15rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: 145px;
}

.filter-group {
  margin-bottom: 0.95rem;
}

.filter-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.32rem;
}

.filter-group input,
.filter-group select,
.poets-toolbar input,
.sort-wrap select {
  width: 100%;
  padding: 0.48rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.9rem;
}

.results-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.results-count {
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 500;
}

.sort-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.sort-wrap select {
  width: auto;
}

.poem-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.poem-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.2rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.poem-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--muted);
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.poem-card h3 {
  font-family: var(--serif);
  font-size: 1.12rem;
  margin: 0 0 0.2rem;
  line-height: 1.3;
}

.card-author {
  font-size: 0.88rem;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.65rem;
}

.card-snippet {
  font-family: var(--serif);
  font-size: 0.92rem;
  color: var(--muted);
  white-space: pre-line;
  margin: 0 0 0.85rem;
  line-height: 1.48;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 0.55rem;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.poets-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.1rem;
  flex-wrap: wrap;
}

.poets-toolbar input {
  max-width: 420px;
}

.poet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.poet-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.2rem;
  cursor: pointer;
}

.poet-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.poet-card h3 {
  font-family: var(--serif);
  margin: 0 0 0.2rem;
  font-size: 1.1rem;
}

.poet-meta {
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.poet-bio {
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0;
}

.stats-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1.25rem;
}

.stat-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.stat-panel h2 {
  font-family: var(--serif);
  font-size: 1.18rem;
  margin: 0 0 0.9rem;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  grid-column: 1 / -1;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
}

.kpi-value {
  font-family: var(--serif);
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}

.kpi-label {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.bar-row {
  margin-bottom: 0.6rem;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.84rem;
  margin-bottom: 0.2rem;
}

.bar-track {
  background: var(--surface-alt);
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  background: var(--accent);
  height: 100%;
  border-radius: 999px;
}

/* Modal */
.modal.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 16, 14, 0.65);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.75rem 2rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.modal-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.modal-nav {
  display: flex;
  gap: 0.4rem;
}

#modalTitle {
  font-family: var(--serif);
  font-size: 1.65rem;
  margin: 0 0 0.45rem;
  line-height: 1.25;
}

.modal-meta {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 1.35rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.modal-verse {
  font-family: var(--serif);
  font-size: 1.08rem;
  line-height: 1.7;
  white-space: pre-wrap;
  margin: 0 0 1.4rem;
}

.version-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.9rem;
}

.version-tabs.hidden {
  display: none;
}

.version-tab {
  font: inherit;
  font-size: 0.82rem;
  padding: 0.25rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: inherit;
  cursor: pointer;
}

.version-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.editorial-box {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding: 0.75rem 1rem;
  border-radius: 0 6px 6px 0;
  font-size: 0.88rem;
  margin-bottom: 1.15rem;
}

.editorial-box.hidden {
  display: none;
}

.modal-footer {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  font-size: 0.88rem;
}

.bio-box {
  margin-bottom: 0.55rem;
  line-height: 1.5;
}

.source-line {
  color: var(--muted);
  font-size: 0.82rem;
}

/* Memorize & Play */
.play-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1.75rem;
  align-items: start;
}

.play-sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.15rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: 145px;
}

.play-quick-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

.mode-pills {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.mode-pill {
  text-align: left;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.55rem 0.75rem;
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mode-pill:hover {
  border-color: var(--accent);
}

.mode-pill.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.philosophy-note {
  margin-top: 1rem;
  font-size: 0.82rem;
  color: var(--muted);
  background: var(--surface-alt);
  padding: 0.75rem;
  border-radius: 8px;
  line-height: 1.45;
}

.game-stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem 1.75rem;
  box-shadow: var(--shadow);
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  padding-bottom: 1rem;
  margin-bottom: 1.2rem;
  border-bottom: 1px solid var(--border);
}

.game-header h2 {
  font-family: var(--serif);
  margin: 0 0 0.2rem;
  font-size: 1.45rem;
}

.game-subtitle {
  color: var(--muted);
  font-size: 0.88rem;
}

.game-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1.25rem;
}

.game-controls select {
  padding: 0.38rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.85rem;
}

.cloze-verse {
  font-family: var(--serif);
  font-size: 1.08rem;
  line-height: 2.05;
  margin-bottom: 1.25rem;
}

.cloze-line {
  min-height: 1.6em;
}

.cloze-stanza-break {
  height: 0.85rem;
}

.cloze-input {
  font-family: var(--serif);
  font-size: 1rem;
  padding: 0.12rem 0.35rem;
  margin: 0 0.12rem;
  border: 1.5px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.cloze-input:focus {
  border-color: var(--accent);
}

.cloze-input.is-exact {
  background: #e8f4ea;
  border-color: #4c8c5b;
  color: #1f4d2b;
}

.cloze-input.is-variant {
  background: #fdf3dc;
  border-color: #c88a2b;
  color: #6b430a;
}

body.dark .cloze-input.is-exact {
  background: #1d3523;
  border-color: #5ca66e;
  color: #bfe8c8;
}

body.dark .cloze-input.is-variant {
  background: #3a2d15;
  border-color: #d69d43;
  color: #f7d99c;
}

.word-reveal-pill {
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--muted);
  margin-left: 0.15rem;
  vertical-align: middle;
}

.scramble-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-bottom: 1.25rem;
}

.scramble-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  cursor: grab;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.scramble-item.dragging {
  opacity: 0.5;
  border-style: dashed;
}

.scramble-item.in-place {
  border-color: #4c8c5b;
  background: #eef7f0;
}

body.dark .scramble-item.in-place {
  background: #1d3523;
  border-color: #5ca66e;
}

.scramble-text {
  font-family: var(--serif);
  font-size: 1.02rem;
  flex: 1;
}

.scramble-actions {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.ghost-line-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  align-items: center;
  margin-bottom: 0.55rem;
}

.ghost-prompt {
  font-family: var(--serif);
  font-size: 0.98rem;
  color: var(--muted);
  background: var(--surface-alt);
  padding: 0.45rem 0.7rem;
  border-radius: 6px;
}

.ghost-input {
  width: 100%;
  font-family: var(--serif);
  font-size: 0.98rem;
  padding: 0.45rem 0.7rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
}

.ghost-input.is-exact {
  border-color: #4c8c5b;
  background: #e8f4ea;
}

.ghost-input.is-variant {
  border-color: #c88a2b;
  background: #fdf3dc;
}

body.dark .ghost-input.is-exact {
  background: #1d3523;
  color: #bfe8c8;
}

body.dark .ghost-input.is-variant {
  background: #3a2d15;
  color: #f7d99c;
}

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-top: 1.25rem;
  padding-top: 1.15rem;
  border-top: 1px solid var(--border);
}

.compare-box {
  background: var(--surface-alt);
  border-radius: 8px;
  padding: 1rem 1.15rem;
}

.compare-box h3 {
  font-family: var(--serif);
  font-size: 1.02rem;
  margin: 0 0 0.6rem;
}

.compare-verse {
  font-family: var(--serif);
  white-space: pre-wrap;
  line-height: 1.65;
  font-size: 0.96rem;
}

.compare-verse .hl-variant {
  background: #fdf3dc;
  color: #6b430a;
  padding: 0.05rem 0.22rem;
  border-radius: 4px;
}

body.dark .compare-verse .hl-variant {
  background: #3a2d15;
  color: #f7d99c;
}

.notebook-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.15rem;
  margin-bottom: 0.9rem;
}

.notebook-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.status-banner {
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  background: var(--surface-alt);
  font-size: 0.88rem;
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

@media (max-width: 860px) {
  #view-explore.active,
  .play-layout,
  .ghost-line-row,
  .compare-grid {
    grid-template-columns: 1fr;
  }
  .filters-panel,
  .play-sidebar {
    position: static;
  }
  .modal-card {
    padding: 1.25rem;
  }
}

.game-header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.game-version-tabs {
  margin: 0;
}

.game-version-note {
  font-size: 0.8rem;
  color: var(--muted);
}

.game-progress-line {
  font-size: 0.82rem;
  color: var(--accent);
  margin-top: 0.25rem;
}

.result-banner {
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  border: 1px solid #c88a2b;
  background: #fdf3dc;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.result-banner.is-pass {
  border-color: #4c8c5b;
  background: #e8f4ea;
}

body.dark .result-banner {
  background: #3a2d15;
  color: #f7d99c;
}

body.dark .result-banner.is-pass {
  background: #1d3523;
  color: #bfe8c8;
}

.recite-input {
  width: 100%;
  font-family: var(--serif);
  font-size: 1.02rem;
  line-height: 1.7;
  padding: 0.8rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  resize: vertical;
  margin-bottom: 1rem;
}

.diff-miss {
  background: #f6d5d0;
  color: #8a2a1c;
  border-radius: 3px;
  padding: 0 0.15em;
}

body.dark .diff-miss {
  background: #4a211c;
  color: #f3b9b0;
}

.diff-key {
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--muted);
}

.diff-extras {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.75rem 0 0;
}

.diff-extra {
  text-decoration: line-through;
}

.progress-heading {
  font-size: 1rem;
  margin: 1.25rem 0 0.6rem;
}

.close-verse {
  font-family: var(--serif);
  font-size: 1.08rem;
  line-height: 1.8;
  white-space: pre-wrap;
}

.close-word,
.close-option,
.close-line-option {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
}

.close-word {
  padding: 0 0.12em;
  margin: 0 -0.12em;
}

.close-word:hover:not(:disabled),
.close-option:hover:not(:disabled),
.close-line-option:hover:not(:disabled) {
  border-color: var(--accent);
}

.close-word:disabled,
.close-option:disabled,
.close-line-option:disabled {
  cursor: default;
}

.close-option,
.close-line-option {
  border-color: var(--border);
  background: var(--bg);
  padding: 0.35rem 0.8rem;
}

.close-line-option {
  display: block;
  width: 100%;
  text-align: left;
  font-family: var(--serif);
  font-size: 1rem;
  margin-bottom: 0.45rem;
}

.close-question {
  margin-bottom: 1.1rem;
}

.close-question-line {
  font-family: var(--serif);
  font-size: 1.05rem;
  margin-bottom: 0.45rem;
}

.close-gap {
  color: var(--muted);
}

.close-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.close-summary {
  margin: 0 0 1rem 1.1rem;
  font-size: 0.92rem;
}

.is-picked {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.is-hit {
  background: #e8f4ea;
  border-color: #4c8c5b;
  color: #23512e;
}

.is-missed {
  background: #f6d5d0;
  border-color: #b4513f;
  color: #8a2a1c;
}

.is-false {
  background: #fdf3dc;
  border-color: #c88a2b;
  color: #7a5210;
}

body.dark .is-hit {
  background: #1d3523;
  color: #bfe8c8;
}

body.dark .is-missed {
  background: #4a211c;
  color: #f3b9b0;
}

body.dark .is-false {
  background: #3a2d15;
  color: #f7d99c;
}
