:root {
  --yellow: #f7d417;
  --yellow-deep: #f0c400;
  --red: #e2231a;
  --red-deep: #b8160f;
  --ink: #1a1a1a;
  --card-bg: #ffffff;
  --card-border: #1a1a1a;
  --page-bg: #f4f2ea;
  --sidebar-bg: #1a1a1a;
  --sidebar-text: #cfcfcf;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--page-bg);
  color: var(--ink);
  min-height: 100vh;
}

/* ---- App shell: sidebar + main ---- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 240px;
  height: 100vh;
  overflow-y: auto;
  flex: none;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  border-right: 4px solid var(--red);
  z-index: 10;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px 22px;
  border-bottom: 1px solid #3a3a3a;
  margin-bottom: 18px;
}

.sidebar-brand .brand-mark {
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 26px;
  color: var(--yellow);
  transform: rotate(-6deg);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.brand-text strong {
  color: #fff;
  font-size: 15px;
}

.brand-text small {
  color: var(--yellow);
  font-size: 12px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  padding: 11px 12px;
  border-radius: 8px;
  font-size: 14.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.nav-item .nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: #2c2c2c;
  color: var(--sidebar-text);
  font-size: 13px;
  flex: none;
}

.nav-item .nav-icon svg {
  width: 16px;
  height: 16px;
  display: block;
}

.nav-item:hover:not(:disabled) {
  background: #2c2c2c;
  color: #fff;
}

.nav-item.active {
  background: var(--red);
  color: #fff;
}

.nav-item.active .nav-icon {
  background: var(--yellow);
  color: var(--ink);
}

.nav-item:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.nav-divider {
  height: 1px;
  background: #3a3a3a;
  margin: 10px 4px;
}

.sidebar-footer {
  font-size: 11px;
  color: #777;
  padding: 12px 6px 0;
}

/* ---- Main area ---- */
.main-area {
  flex: 1;
  min-width: 0;
  margin-left: 240px;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--card-bg);
  border-bottom: 1px solid #e3e0d4;
  padding: 18px 32px;
}

.topbar-row {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}

.topbar-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
}

.topbar-hint {
  font-size: 13px;
  color: #888;
}

.topbar-key-hint {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: #b8160f;
}

.topbar-key-hint[hidden] {
  display: none;
}

.content {
  flex: 1;
  padding: 24px 32px 40px;
}

.module-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.module-panel[hidden] {
  display: none;
}

.panel-card {
  background: var(--card-bg);
  border: 1px solid #e3e0d4;
  border-radius: 14px;
  padding: 24px 26px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.panel-head h2 {
  margin: 0 0 6px;
  font-size: 20px;
  color: var(--red-deep);
}

.panel-head .hint {
  margin: 0;
  color: #666;
  font-size: 14px;
}

.panel-head .hint strong {
  color: var(--red);
}

.pregenerate-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
}

.pregenerate-status {
  font-size: 13px;
  font-weight: 600;
  color: #666;
}

.pregenerate-status.ok { color: #1a7a2e; }
.pregenerate-status.error { color: var(--red-deep); }

.link-btn {
  border: none;
  background: none;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--red-deep);
  text-decoration: underline;
  cursor: pointer;
}

.link-btn:hover {
  color: var(--red);
}

.letter-card.practice-active {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 8px 18px rgba(226, 35, 26, 0.3);
  background: var(--yellow);
  border-color: var(--red);
}

.letter-card .regen-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.08);
  color: var(--ink);
  font-size: 13px;
  line-height: 22px;
  text-align: center;
  padding: 0;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.letter-card:hover .regen-btn {
  opacity: 1;
}

.letter-card .regen-btn:hover {
  background: var(--red);
  color: #fff;
}

.letter-card .regen-btn.loading {
  opacity: 1;
  animation: regen-spin 0.8s linear infinite;
}

@keyframes regen-spin {
  to { transform: rotate(360deg); }
}

/* ---- Letter grid ---- */
.letter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 14px;
}

.letter-card {
  position: relative;
  aspect-ratio: 1 / 1;
  border: 2px solid #e3e0d4;
  border-radius: 12px;
  background: var(--page-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.letter-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 14px rgba(226, 35, 26, 0.18);
  background: var(--yellow);
  border-color: var(--ink);
}

.letter-card .letter {
  font-size: 48px;
  font-weight: 800;
  line-height: 1;
  color: var(--ink);
  user-select: none;
}

.letter-card.speaking .letter {
  color: var(--red);
}

.letter-card .phonetic-zone {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 42%;
  height: 42%;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 6px 8px;
  cursor: pointer;
}

.letter-card .phonetic-mark {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--red);
  transition: opacity 0.15s ease;
}

.letter-card .phonetic-zone:hover .phonetic-mark {
  opacity: 0;
}

.letter-card .phonetic-text {
  position: absolute;
  right: 6px;
  bottom: 6px;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: var(--red-deep);
  padding: 2px 8px;
  border-radius: 6px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
  white-space: nowrap;
}

.letter-card .phonetic-zone:hover .phonetic-text {
  opacity: 1;
  transform: translateY(0);
}

/* ---- Settings panel ---- */
.settings-form {
  max-width: 480px;
}

.field-label {
  display: block;
  font-weight: 700;
  margin-bottom: 8px;
}

.key-input-row {
  display: flex;
  gap: 8px;
}

.key-input-row input {
  flex: 1;
  padding: 10px 12px;
  font-size: 15px;
  border: 2px solid #d8d4c2;
  border-radius: 8px;
  background: #fbfaf4;
}

.key-input-row input:focus {
  outline: 2px solid var(--red);
}

.field-note {
  margin: 8px 0 0;
  font-size: 13px;
  color: #666;
}

.field-note code {
  background: rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 12px;
}

.settings-subhead {
  margin: 0 0 4px;
  font-size: 16px;
  color: var(--red-deep);
}

.explain-prompt-input {
  width: 100%;
  margin-top: 10px;
  border: 1.5px solid #d8d4c2;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13.5px;
  font-family: "Consolas", "Courier New", monospace;
  resize: vertical;
}

.explain-prompt-input:focus {
  outline: 2px solid var(--red);
}

.settings-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.primary-btn,
.ghost-btn {
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

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

.primary-btn:hover {
  background: var(--red-deep);
}

.ghost-btn {
  background: var(--card-bg);
  color: var(--ink);
}

.ghost-btn:hover {
  background: var(--yellow);
}

.settings-status {
  margin: 14px 0 0;
  font-size: 14px;
  font-weight: 600;
  min-height: 20px;
}

.settings-status.ok { color: #1a7a2e; }
.settings-status.cleared { color: #8a6d00; }

/* ---- Phonetics module ---- */
.phonetics-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.phonetics-title {
  margin: 0;
  font-size: 17px;
  color: var(--red-deep);
}

.phonetics-text {
  margin: 0;
  font-size: 14px;
  color: #444;
  line-height: 1.6;
}

.phonetics-subtle {
  color: #888;
  font-size: 13px;
  margin-top: 6px;
}

.phonetics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.phonetics-table td {
  border-bottom: 1px solid #ececdf;
  padding: 9px 10px;
  vertical-align: top;
}

.phonetics-table .ipa-cell {
  font-weight: 700;
  color: var(--red-deep);
  white-space: nowrap;
  width: 70px;
}

.phonetics-table .combo-cell {
  color: #555;
  width: 38%;
}

.phonetics-table .words-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.word-chip {
  border: 1.5px solid #d8d4c2;
  background: var(--page-bg);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, transform 0.1s ease;
}

.word-chip:hover {
  border-color: var(--red);
  color: var(--red-deep);
}

.word-chip.playing {
  background: var(--yellow);
  border-color: var(--ink);
  transform: scale(1.04);
}

.word-chip.loading {
  opacity: 0.6;
  cursor: wait;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.pairs-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pair-row {
  display: flex;
  gap: 28px;
  flex-wrap: wrap;
}

.pair-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.h-rule-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 14px;
}

.h-rule-row strong {
  color: var(--ink);
}

/* ---- Lessons module: albums (list, not grid) ---- */
.album-grid {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.album-card {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  border: none;
  border-bottom: 1px solid #ececdf;
  background: none;
  padding: 12px 6px;
  cursor: pointer;
  width: 100%;
}

.album-card:hover {
  background: var(--page-bg);
}

.album-cover {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--red);
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.album-title {
  flex: 1;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink);
}

.album-count {
  font-size: 12.5px;
  color: #888;
  flex: none;
}

.album-arrow {
  flex: none;
  color: var(--red);
  font-size: 18px;
}

/* ---- Lessons module: track list ---- */
.track-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.track-row {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  border: none;
  border-bottom: 1px solid #ececdf;
  background: none;
  padding: 12px 6px;
  cursor: pointer;
  width: 100%;
}

.track-row:hover {
  background: var(--page-bg);
}

.track-num {
  font-size: 12px;
  font-weight: 700;
  color: var(--red-deep);
  flex: none;
  width: 70px;
}

.track-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ink);
}

.track-zh {
  font-size: 13px;
  color: #888;
  flex: 1;
}

.track-play {
  flex: none;
  color: var(--red);
}

.lesson-back-btn {
  margin-bottom: 14px;
}

.lesson-detail-title {
  margin: 0 0 14px;
  font-size: 18px;
  color: var(--red-deep);
}

.lesson-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #666;
  font-weight: 600;
}

.speed-control select {
  border: 1.5px solid #d8d4c2;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  background: var(--card-bg);
  color: var(--ink);
}

.subtitle-mode-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
}

.subtitle-mode-label {
  font-size: 13px;
  color: #888;
  margin-right: 4px;
}

.mode-btn {
  border: 1.5px solid #d8d4c2;
  background: var(--card-bg);
  color: #666;
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.mode-btn.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

/* ---- Lessons module: left-aligned subtitle list ---- */
.dialogue-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.turn-row {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 10px;
  cursor: pointer;
  padding: 8px 6px;
  text-align: left;
  border-radius: 0;
  border-left: 3px solid transparent;
}

.turn-row:hover {
  background: var(--page-bg);
}

.turn-explain-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.turn-row:hover .turn-explain-btn {
  opacity: 1;
}

.turn-explain-btn:hover {
  background: var(--red);
  color: #fff;
  border-color: var(--red-deep);
}

.turn-tag {
  flex: none;
  width: 18px;
  font-size: 13px;
  font-weight: 800;
  color: var(--red);
}

.turn-row.speaker-b .turn-tag {
  color: #3a7ca5;
}

.turn-row.speaker-n .turn-tag {
  display: none;
}

.turn-body {
  flex: 1;
  min-width: 0;
}

.turn-row.speaker-n .turn-body {
  font-style: italic;
  color: #777;
}

.turn-row.turn-active {
  border-left-color: var(--red);
  background: var(--page-bg);
}

.turn-text {
  font-family: Verdana, Geneva, "Segoe UI", Tahoma, sans-serif;
  font-size: 18.5px;
  line-height: 1.6;
  color: var(--ink);
  text-align: left;
}

.turn-text .word {
  cursor: pointer;
  border-radius: 3px;
  padding: 0 1px;
  transition: background 0.1s ease;
}

.turn-text .word:hover {
  background: rgba(0, 0, 0, 0.08);
}

.turn-text .word.word-active {
  text-decoration: underline;
  text-decoration-color: var(--red);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

.turn-zh {
  margin-top: 3px;
  font-size: 16px;
  color: #555;
  text-align: left;
}

.turn-zh:empty {
  display: none;
}

.dialogue-list.mode-fr .turn-zh { display: none; }
.dialogue-list.mode-zh .turn-text { display: none; }

.word-popover {
  position: absolute;
  z-index: 50;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 160px;
}

.word-popover[hidden] {
  display: none;
}

.word-popover-word {
  font-weight: 800;
  font-size: 16px;
  color: var(--red-deep);
}

.word-popover-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.word-popover-tag {
  font-size: 10.5px;
  font-weight: 700;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.word-popover-ipa {
  font-size: 14px;
  color: #444;
}

.word-popover-pos {
  font-size: 14px;
  font-weight: 600;
  color: var(--red-deep);
}

.word-popover-zh {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ink);
}

.word-popover-example {
  font-size: 13px;
  color: #555;
  line-height: 1.4;
}

.word-popover-example:empty {
  display: none;
}

.word-popover {
  max-width: 320px;
}

/* ---- Words module: vocab grid ---- */
.vocab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.vocab-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1.5px solid #e3e0d4;
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--page-bg);
}

.vocab-fr {
  font-family: Verdana, Geneva, "Segoe UI", Tahoma, sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}

.vocab-fr:hover {
  color: var(--red-deep);
  text-decoration: underline;
}

.vocab-zh {
  font-size: 13px;
  color: #666;
}

/* ---- Explain modal (per-sentence Q&A) ---- */
.explain-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}

.explain-modal[hidden] {
  display: none;
}

.explain-panel {
  position: relative;
  width: min(520px, 90vw);
  max-height: 80vh;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.explain-close-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: none;
  font-size: 22px;
  line-height: 1;
  color: #888;
  cursor: pointer;
}

.explain-close-btn:hover {
  color: var(--red);
}

.explain-sentence {
  font-family: Verdana, Geneva, "Segoe UI", Tahoma, sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--red-deep);
  padding-right: 24px;
  border-bottom: 1px solid #ececdf;
  padding-bottom: 10px;
}

.explain-thread {
  flex: 1;
  min-height: 80px;
  max-height: 40vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.explain-msg {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.5;
}

.explain-msg-q {
  align-self: flex-end;
  background: var(--yellow);
  color: var(--ink);
  white-space: pre-wrap;
}

.explain-msg-a {
  align-self: flex-start;
  background: var(--page-bg);
  color: var(--ink);
}

.explain-msg-a p {
  margin: 0 0 8px;
}

.explain-msg-a p:last-child {
  margin-bottom: 0;
}

.explain-msg-a ul,
.explain-msg-a ol {
  margin: 0 0 8px;
  padding-left: 20px;
}

.explain-msg-a ul:last-child,
.explain-msg-a ol:last-child {
  margin-bottom: 0;
}

.explain-msg-a li {
  margin-bottom: 3px;
}

.explain-msg-a .explain-heading {
  font-weight: 700;
  margin-bottom: 4px;
}

.explain-msg-a code {
  background: rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 13px;
}

.explain-status {
  margin: 0;
  font-size: 12.5px;
  color: #888;
  min-height: 16px;
}

.explain-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.explain-input {
  flex: 1;
  resize: vertical;
  border: 1.5px solid #d8d4c2;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
}

.explain-input:focus {
  outline: 2px solid var(--red);
}

/* ---- Grammar module ---- */
.grammar-explanation {
  font-size: 14.5px;
  line-height: 1.6;
  color: #444;
  background: var(--page-bg);
  border-left: 3px solid var(--red);
  padding: 10px 14px;
  margin: 0 0 16px;
}

.grammar-example-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.grammar-example {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 6px;
  border-bottom: 1px solid #ececdf;
}

.example-play-btn {
  flex: none;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  background: var(--card-bg);
  color: var(--ink);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.example-play-btn:hover {
  background: var(--red);
  color: #fff;
  border-color: var(--red-deep);
}

.example-regen-btn {
  flex: none;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  background: var(--card-bg);
  color: var(--ink);
  font-size: 12px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.grammar-example:hover .example-regen-btn {
  opacity: 1;
}

.example-regen-btn:hover {
  background: var(--red);
  color: #fff;
  border-color: var(--red-deep);
}

.example-regen-btn.loading {
  opacity: 1;
  animation: regen-spin 0.8s linear infinite;
}

.example-text-wrap {
  flex: 1;
  min-width: 0;
}

.example-fr {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.example-fr-text {
  font-family: Verdana, Geneva, "Segoe UI", Tahoma, sans-serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}

.example-fr-text .word {
  cursor: pointer;
  border-radius: 3px;
  padding: 0 1px;
}

.example-fr-text .word:hover {
  background: rgba(0, 0, 0, 0.08);
}

.example-speed-select {
  flex: none;
  border: 1.5px solid #d8d4c2;
  border-radius: 6px;
  padding: 2px 4px;
  font-size: 11.5px;
  background: var(--card-bg);
  color: var(--ink);
  opacity: 0;
  transition: opacity 0.12s ease;
}

.grammar-example:hover .example-speed-select {
  opacity: 1;
}

.example-zh {
  margin-top: 3px;
  font-size: 13.5px;
  color: #666;
}

.example-note {
  margin-top: 6px;
  font-size: 13px;
  color: var(--ink);
  background: var(--page-bg);
  border-left: 3px solid var(--ink);
  padding: 6px 10px;
  line-height: 1.5;
}

.example-note[hidden] {
  display: none;
}

.example-note-btn,
.example-explain-btn {
  flex: none;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.grammar-example:hover .example-note-btn,
.grammar-example:hover .example-explain-btn {
  opacity: 1;
}

.example-note-btn:hover:not(:disabled),
.example-explain-btn:hover {
  background: var(--red);
  color: #fff;
  border-color: var(--red-deep);
}

.example-note-btn:disabled {
  cursor: not-allowed;
}

.grammar-example:hover .example-note-btn:disabled {
  opacity: 0.35;
}

/* ============================================================
   Mobile / responsive layout
   ------------------------------------------------------------
   Desktop keeps the fixed left sidebar. On narrow screens the
   sidebar becomes an off-canvas drawer toggled by a "☰" button
   pinned to the top-right corner. The drawer slides in from the
   left over a dimming backdrop.
   ============================================================ */

/* Hamburger button + backdrop are desktop-hidden by default. */
.menu-toggle {
  display: none;
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 30;
  width: 44px;
  height: 44px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--red);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.menu-toggle:active {
  transform: scale(0.94);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(0, 0, 0, 0.45);
}

@media (max-width: 768px) {
  /* Sidebar -> off-canvas drawer (must sit above the backdrop, z-index 15) */
  .sidebar {
    width: 250px;
    max-width: 84vw;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.25);
    z-index: 20;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
  }
  .sidebar-backdrop[hidden] {
    display: none;
  }

  .menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Main column reclaims the full width */
  .main-area {
    margin-left: 0;
  }

  /* Leave room for the floating ☰ so it never overlaps the title */
  .topbar {
    padding: 16px 18px;
  }
  .topbar-row {
    padding-right: 52px;
  }

  .content {
    padding: 16px 14px 32px;
  }

  .panel-card {
    padding: 16px 16px;
    border-radius: 12px;
  }

  /* Tighter letter grid on small screens */
  .letter-grid {
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: 10px;
  }
  .letter-card .letter {
    font-size: 36px;
  }

  .vocab-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }

  /* Touch screens have no :hover — reveal the controls that are
     hover-gated on desktop so they're actually reachable. */
  .letter-card .regen-btn,
  .example-regen-btn,
  .example-speed-select,
  .example-note-btn,
  .example-explain-btn,
  .turn-explain-btn {
    opacity: 1;
  }

  /* Word IPA popover: keep it inside the viewport */
  .word-popover {
    max-width: min(320px, 92vw);
  }

  /* Tables / wide rows: allow horizontal scroll instead of overflow */
  .phonetics-table {
    display: block;
    overflow-x: auto;
  }

  /* Roomier tap targets for sentence rows */
  .turn-text {
    font-size: 17px;
  }
}

@media (max-width: 420px) {
  .letter-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .vocab-grid {
    grid-template-columns: 1fr 1fr;
  }
  .topbar-title {
    font-size: 18px;
  }
}
