:root {
  color-scheme: light;
  --theme-background: #f2efe8;
  --theme-text: #172234;
  --theme-divider: #9ba9ad;
  --theme-focus: #f0a34a;
  --theme-header: #19324a;
  font-family: Inter, "Noto Sans SC", system-ui, sans-serif;
  color: var(--theme-text);
  background: var(--theme-background);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
[hidden] { display: none !important; }
header {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.55rem;
  padding: 0 1.25rem;
  height: 3rem;
  min-height: 3rem;
  max-height: 3rem;
  color: #f8f4ea;
  background: var(--theme-header);
  box-sizing: border-box;
}
header > strong {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1;
}
header > small#collection-title {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border-radius: 0.25rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  white-space: nowrap;
  flex-shrink: 0;
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
header > input#search {
  width: 9rem;
  height: 2rem;
  padding: 0.25rem 0.65rem;
  border: 1px solid #91a8b8;
  border-radius: 999px;
  color: #172234;
  background: #fffdf8;
  font: inherit;
  font-size: 0.82rem;
  flex-shrink: 1;
  transition: width 0.2s ease;
}
header > input#search:focus {
  width: 13rem;
  outline: 2px solid var(--theme-focus, #f0a34a);
}
header nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0 auto;
  flex-shrink: 0;
}
.header-tools {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}
.header-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.15rem;
  height: 2.15rem;
  padding: 0 !important;
  border: 1px solid var(--theme-button-border, #91a8b8);
  border-radius: 0.45rem;
  background: transparent;
  color: var(--buttonFg, inherit);
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
  text-decoration: none;
}
.header-icon-btn:hover {
  border-color: var(--theme-focus, #f0a34a);
  color: var(--theme-focus, #f0a34a);
  background: rgba(255, 255, 255, 0.08);
}
.header-icon-btn[aria-pressed="true"] {
  border-color: var(--theme-focus, #f0a34a);
  color: #172234;
  background: var(--theme-focus, #f0a34a);
}
header select {
  max-width: min(16rem, calc(100vw - 2rem));
  cursor: pointer;
  color: var(--buttonFg, inherit);
  background: var(--theme-header, transparent);
  text-overflow: ellipsis;
}
header select optgroup {
  font-weight: 700;
  background: var(--theme-background, #fffdf8);
  color: var(--theme-text, #172234);
}
header select option {
  font-weight: normal;
  background: var(--theme-background, #fffdf8);
  color: var(--theme-text, #172234);
}
#auto-fit-toggle[aria-pressed="true"] {
  border-color: var(--theme-focus, #305f72);
  color: var(--buttonFg, inherit);
  background: rgba(48, 95, 114, 0.22);
  font-weight: 700;
}
#position {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--pageCounter, var(--theme-text));
  min-width: 3.2rem;
  text-align: center;
}
#reader {
  --mindmap-pane-percent: 60%;
  display: flex;
  padding: 1rem;
}
#mindmap, #sentences {
  min-height: calc(100vh - 5rem);
  padding: 1.25rem;
  border: 1px solid #d3ccbd;
  border-radius: 0.75rem;
  background: #fffdf8;
}
#mindmap { flex: 0 0 var(--mindmap-pane-percent); overflow: auto; align-content: start; }
#sentences { flex: 1 1 auto; }
#pane-divider {
  flex: 0 0 1rem;
  position: relative;
  cursor: col-resize;
  touch-action: none;
  outline: none;
}
#pane-divider::before {
  content: "";
  position: absolute;
  inset: 0.5rem 0.4rem;
  border-radius: 999px;
  background: var(--theme-divider);
}
#pane-divider:focus-visible::before { box-shadow: 0 0 0 3px var(--theme-focus); }
#graph { position: relative; min-height: 0; margin-inline: auto; }
#words, #connections, #canvas-notes { position: absolute; inset: 0; width: 100%; height: 100%; }
#connections line { stroke: #8aa1a8; stroke-width: 0.45; vector-effect: non-scaling-stroke; }
#words .word {
  position: absolute;
  transform: translate(-50%, -50%);
}
#canvas-notes { z-index: 4; pointer-events: none; }
.canvas-note-marker {
  position: absolute;
  width: 2.5rem;
  height: 2.5rem;
  transform: translate(-50%, -50%);
  border: 2px solid #a45d22;
  border-radius: 999px;
  background: #fff1b8;
  pointer-events: auto;
}
.canvas-note-marker::before { content: "N"; font-weight: 800; }
.annotation-mode .canvas-note-marker { cursor: grab; touch-action: none; }
.canvas-note-preview {
  position: absolute;
  z-index: 5;
  left: 2.7rem;
  top: 0;
  display: none;
  width: 14rem;
  max-width: 18rem;
  max-height: none;
  overflow: visible;
  padding: 0.55rem 0.75rem;
  border: 1px solid #a45d22;
  border-radius: 0.4rem;
  color: #172234;
  text-align: left;
  background: #fffdf8;
  box-shadow: 0 0.4rem 1rem rgb(23 34 52 / 18%);
  line-height: 1.5;
}
.canvas-note-marker:hover .canvas-note-preview,
.canvas-note-marker:focus .canvas-note-preview { display: block; }
#canvas-note-drawer {
  position: fixed;
  z-index: 30;
  top: 5rem;
  right: 1rem;
  display: grid;
  width: min(24rem, calc(100vw - 2rem));
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
  gap: 0.6rem;
  padding: 1rem;
  border: 1px solid var(--theme-divider);
  border-top: 0.35rem solid #a45d22;
  border-radius: 0.75rem;
  background: #fffdf8;
  box-shadow: 0 1rem 3rem rgb(23 34 52 / 22%);
}
#canvas-note-drawer textarea { width: 100%; }
#canvas-note-close { justify-self: end; }
#canvas-note-actions { display: flex; gap: 0.5rem; }
.word-note-preview img, .canvas-note-preview img {
  display: block;
  max-width: 100%;
  max-height: 8rem;
  margin-top: 0.4rem;
  object-fit: contain;
}
#edges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 1.5rem;
  color: #536575;
  font-size: 0.85rem;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.word {
  padding: 0.7rem 1rem;
  border: 2px solid #305f72;
  border-radius: 999px;
  text-align: center;
}
.word.center { color: white; background: #305f72; }
.word small { display: block; margin-top: 0.25rem; }
.word-controls { display: inline-flex; align-items: center; }
.dictionary-trigger {
  border: 0;
  padding: 0.15rem 0.25rem;
  color: inherit;
  font: inherit;
  background: transparent;
  cursor: pointer;
}
.dictionary-trigger:focus-visible { outline: 3px solid var(--theme-focus); outline-offset: 2px; }
.sentence-vocabulary { text-decoration: none; }
.pronunciation-trigger {
  display: inline-grid;
  place-items: center;
  min-width: 2rem;
  min-height: 2rem;
  margin: 0 0.1rem;
  border: 1px solid transparent;
  border-radius: 999px;
  color: inherit;
  background: transparent;
  cursor: pointer;
  vertical-align: middle;
}
.pronunciation-trigger::before { content: "\1f50a"; }
.pronunciation-trigger:hover { border-color: var(--theme-divider); }
.pronunciation-trigger:focus-visible { outline: 3px solid var(--theme-focus); outline-offset: 1px; }
.pronunciation-trigger:disabled { cursor: not-allowed; opacity: 0.45; }
#dictionary-card {
  position: fixed;
  z-index: 20;
  top: 5rem;
  right: 1rem;
  display: grid;
  width: min(25rem, calc(100vw - 2rem));
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
  padding: 1.25rem;
  border: 1px solid var(--theme-divider);
  border-top: 0.35rem solid var(--theme-focus);
  border-radius: 0.75rem;
  box-shadow: 0 1rem 3rem rgb(23 34 52 / 22%);
  background: #fffdf8;
}
#dictionary-card p, #dictionary-card h2 { margin: 0.25rem 0; }
#dictionary-close { justify-self: end; }
#dictionary-kind { color: #536575; font-size: 0.8rem; text-transform: uppercase; }
#dictionary-ipa { color: #305f72; font-weight: 700; }
#dictionary-meaning { font-size: 1.1rem; }
#dictionary-illustration {
  margin: 0.6rem 0 0.35rem;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}
#dictionary-illustration[hidden] {
  display: none !important;
}
#dictionary-image {
  max-width: 100%;
  max-height: 11rem;
  height: auto;
  object-fit: contain;
  border-radius: 0.5rem;
  border: 1px solid var(--theme-divider, #d3ccbd);
  background: #ffffff;
  box-shadow: 0 0.2rem 0.6rem rgba(0, 0, 0, 0.08);
}
.dictionary-source { margin-top: 0.75rem !important; font-size: 0.8rem; }
#dictionary-card nav { display: flex; gap: 1rem; margin-top: 0.6rem; }
#profile-panel {
  position: fixed;
  z-index: 25;
  top: 5rem;
  right: 1rem;
  display: grid;
  width: min(26rem, calc(100vw - 2rem));
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
  padding: 1.25rem;
  border: 1px solid var(--theme-divider);
  border-top: 0.35rem solid #305f72;
  border-radius: 0.75rem;
  box-shadow: 0 1rem 3rem rgb(23 34 52 / 22%);
  background: #fffdf8;
}
#profile-panel h2 { margin: 0.25rem 0; font-size: 1.2rem; }
#profile-panel-close { justify-self: end; }
.profile-notice {
  margin: 0.5rem 0;
  padding: 0.6rem;
  border-radius: 0.4rem;
  background: #f7f3ea;
  font-size: 0.82rem;
  color: #435260;
  line-height: 1.45;
}
.profile-id-row {
  margin: 0.5rem 0;
  font-size: 0.85rem;
  word-break: break-all;
}
.profile-id-row code {
  padding: 0.15rem 0.35rem;
  border-radius: 0.25rem;
  background: #ece7dc;
  font-family: monospace;
  font-size: 0.82rem;
}
.profile-package-actions {
  display: grid;
  gap: 0.65rem;
  margin-top: 0.75rem;
}
.profile-package-actions button {
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--theme-divider);
  border-radius: 0.4rem;
  background: #fffdf8;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
.profile-package-actions button:hover:not(:disabled) {
  border-color: var(--theme-focus);
}
.profile-package-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.profile-import-label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: #305f72;
}
#profile-status {
  margin-top: 0.5rem;
  font-size: 0.82rem;
  color: #536575;
  min-height: 1.2rem;
}
.word-note-preview {
  margin: 0.75rem 0;
  padding: 0.65rem 0.75rem;
  border: 1px solid #d3ccbd;
  border-radius: 0.5rem;
  background: #f7f3ea;
  font-size: 0.9rem;
}
.word-note-preview.is-empty {
  margin: 0.35rem 0;
  padding: 0;
  border: none;
  background: transparent;
}
.word-note-preview h3 { margin: 0 0 0.35rem; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; }
.word-note-preview p, .word-note-preview ul, .word-note-preview ol { margin: 0.25rem 0; line-height: 1.6; }
#word-note-content {
  height: auto;
  max-height: none;
  overflow: visible;
  line-height: 1.6;
}
.word-note-editor {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  border-left: 0.3rem solid var(--theme-focus);
  background: #f7f3ea;
}
.word-note-editor label { display: grid; gap: 0.35rem; font-size: 0.85rem; font-weight: 700; }
.word-note-editor textarea { width: 100%; resize: vertical; padding: 0.55rem; font: inherit; }
.word-note-help, .word-note-status { margin: 0 !important; color: #536575; font-size: 0.75rem; }
.word-note-actions { display: flex; gap: 0.5rem; }
.word-note-actions button { padding: 0.4rem 0.65rem; }
.sentence-item {
  margin: 0.75rem 0;
  transition: all 0.2s ease;
}

#reader.auto-fit-active {
  min-height: calc(100vh - 8rem);
}

#reader.auto-fit-active .word {
  padding: 0.65rem 1rem;
}
#reader.auto-fit-active .word strong {
  font-size: calc(var(--node-en-size, 20px) * 1.15);
}
#reader.auto-fit-active .word small {
  font-size: calc(var(--node-zh-size, 14px) * 1.15);
}
#reader.auto-fit-active .word.center {
  padding: 0.85rem 1.35rem;
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.12);
}
#reader.auto-fit-active .word.center strong {
  font-size: calc(var(--node-en-size, 20px) * 1.3);
}

#reader.auto-fit-active #sentences {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.6rem;
  padding: 1.5rem;
}

#reader.auto-fit-active .sentence-item {
  margin: 0;
  padding: 1.25rem 1.6rem;
  border-radius: 0.75rem;
  background: rgba(125, 150, 175, 0.06);
  border-left: 4px solid var(--theme-focus, #305f72);
  box-shadow: 0 0.25rem 1rem rgba(0, 0, 0, 0.04);
}

#reader.auto-fit-active .sentence-item p {
  font-size: clamp(1.65rem, 2.2vw, 2.25rem);
  line-height: 1.75;
  margin: 0 0 0.65rem 0;
}

#reader.auto-fit-active .sentence-audio-trigger {
  font-size: 0.95rem;
  padding: 0.35rem 0.85rem;
}

#sentences { font-size: var(--sentence-font-size, 1.5rem); line-height: 1.6; }
#error { margin: 2rem; color: #8b1e1e; }

@media (max-width: 760px) {
  #reader { flex-direction: column; }
  header {
    height: 3rem;
    min-height: 3rem;
    max-height: 3rem;
    padding: 0 0.5rem;
    gap: 0.35rem;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
  }
  header > strong .app-title-text {
    display: none;
  }
  header > input#search {
    width: 5.5rem;
  }
  header > input#search:focus {
    width: 8rem;
  }
  #mindmap, #sentences { min-height: auto; }
  #mindmap { flex-basis: auto; }
  #pane-divider { display: none; }
  #dictionary-card {
    inset: auto 0 0;
    width: 100%;
    max-height: 85vh;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 1rem 1rem 0 0;
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  }
  #canvas-note-drawer { inset: auto 0 0; width: 100%; max-height: 45vh; overflow: auto; border-radius: 1rem 1rem 0 0; }
  #profile-panel {
    inset: auto 0 0;
    width: 100%;
    max-height: 70vh;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 1rem 1rem 0 0;
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  }
  .canvas-note-marker { width: 2.75rem; height: 2.75rem; }
}

#mindmap, #sentences, #dictionary-card, #canvas-note-drawer, #profile-panel, #settings-panel,
.word-note-preview, .word-note-editor, .profile-id-row code {
  background: var(--theme-background);
  color: var(--theme-text);
}
#mindmap, #sentences { min-width: 0; }
.word, .word.center {
  background: var(--mermaidPrimaryColor, transparent);
  color: var(--mermaidPrimaryTextColor, var(--theme-text));
  border-color: var(--mermaidPrimaryBorderColor, var(--theme-divider));
   overflow-wrap: normal;
}
.word u { color: var(--mermaidHighlightFg, inherit); text-decoration-color: var(--mermaidHighlightUl, currentColor); }
#sentences u { color: var(--highlightFg, inherit); text-decoration-color: var(--highlightUl, currentColor); }
#connections line { stroke: var(--mermaidLineColor, var(--theme-divider)); }
#edges, #dictionary-kind, #dictionary-ipa, #profile-status, .profile-import-label,
.word-note-help, .word-note-status { color: var(--theme-text); }
a { color: var(--highlightFg, #245a71); }
#topbar, header { color: var(--theme-text); }
#topbar button, header button { color: var(--buttonFg, var(--theme-text)); }
.word strong { font-size: var(--node-en-size, 1.2rem); white-space: nowrap; }
#words .word { width: max-content; }
header > strong { color: var(--lessonTitle, var(--theme-text)); }
.word small { font-size: var(--node-zh-size, .85rem); color: var(--mermaidPrimaryTextColorZh, var(--theme-text)); }
#graph [data-branch="0"] { --branch-color: #397b82; }
#graph [data-branch="1"] { --branch-color: #8765a3; }
#graph [data-branch="2"] { --branch-color: #a66a36; }
#graph [data-branch="3"] { --branch-color: #537e46; }
#words .word {
  padding: .45rem .6rem;
  border-radius: .65rem;
  border-color: var(--branch-color, var(--mermaidPrimaryBorderColor, #305f72));
  background: var(--mermaidPrimaryColor, var(--theme-background));
  box-shadow: 0 2px 5px rgb(23 34 52 / 6%);
  white-space: nowrap;
}
#words .word.center {
  padding: .8rem 1rem;
  border: 3px solid var(--mermaidPrimaryTextColor, #305f72);
  border-radius: 1rem;
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--mermaidPrimaryTextColor, #305f72) 14%, transparent);
}
#words .word[data-depth="1"] { border-width: 3px; }
#connections path { fill: none; stroke: var(--branch-color, var(--mermaidLineColor, var(--theme-divider))); stroke-width: 2; vector-effect: non-scaling-stroke; }
#connections .cross-link { stroke-dasharray: 5 4; stroke-width: 1.5; }
@media (max-width: 760px) {
  #mindmap { max-height: 65vh; padding: .75rem; align-content: normal; }
}

/* Toolbar visibility toggle */
body.toolbar-hidden header,
body.toolbar-hidden .teacher-notes-guide {
  display: none !important;
}
body.toolbar-hidden #reader {
  min-height: 100vh;
}
body.toolbar-hidden #mindmap,
body.toolbar-hidden #sentences {
  min-height: calc(100vh - 2rem);
}
.floating-toolbar-toggle {
  position: fixed;
  top: 0.6rem;
  right: 1.25rem;
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--theme-button-border, #9ba9ad);
  border-radius: 999px;
  background: var(--theme-header, #19324a);
  color: var(--buttonFg, #f8f4ea);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: all 0.15s ease;
}
.floating-toolbar-toggle:hover {
  border-color: var(--theme-focus, #f0a34a);
  color: var(--theme-focus, #f0a34a);
}

/* Settings Panel */
#settings-panel {
  position: fixed;
  z-index: 30;
  top: 4.5rem;
  right: 1rem;
  display: grid;
  width: min(24rem, calc(100vw - 2rem));
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
  padding: 1.25rem;
  border: 1px solid var(--theme-divider);
  border-top: 0.35rem solid var(--theme-focus, #305f72);
  border-radius: 0.75rem;
  box-shadow: 0 1rem 3rem rgb(23 34 52 / 22%);
  background: var(--theme-background, #fffdf8);
}
.settings-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}
.settings-panel-header h2 {
  margin: 0;
  font-size: 1.15rem;
}
#settings-panel-close {
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--theme-button-border, #aab8c2);
  border-radius: 0.35rem;
  background: transparent;
  color: var(--theme-text);
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
}
#settings-panel-close:hover {
  border-color: var(--theme-focus);
}
.settings-tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--theme-divider);
  margin-bottom: 0.85rem;
}
.settings-tab {
  padding: 0.35rem 0.75rem;
  border: none;
  background: transparent;
  color: var(--theme-text);
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.settings-tab.active {
  border-bottom-color: var(--theme-focus);
  color: var(--theme-focus);
}
.settings-checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.5rem;
  user-select: none;
}
.settings-checkbox-row input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--theme-focus, #305f72);
  cursor: pointer;
}
.settings-help {
  margin: 0.35rem 0 0.85rem 1.75rem;
  font-size: 0.8rem;
  color: var(--theme-text);
  opacity: 0.75;
  line-height: 1.5;
}
.settings-theme-group {
  margin-top: 0.85rem;
  display: grid;
  gap: 0.4rem;
}
.settings-field-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--theme-text);
}
.settings-theme-group select {
  width: 100%;
  padding: 0.45rem 0.65rem;
  border-radius: 0.4rem;
  border: 1px solid var(--theme-divider, #aab8c2);
  background: var(--theme-background, #fff);
  color: var(--theme-text);
  font: inherit;
  font-size: 0.88rem;
}
.settings-inline-toggle {
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--theme-button-border, #91a8b8);
  border-radius: 0.4rem;
  background: transparent;
  color: var(--theme-text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.settings-inline-toggle[aria-pressed="true"] {
  background: var(--theme-focus, #305f72);
  color: #fff;
  border-color: var(--theme-focus, #305f72);
}

/* Hide word bounding box (frameless mindmap words) */
body.hide-word-box #words .word,
body.hide-word-box #words .word.center {
  border-color: transparent !important;
  background: transparent !important;
  box-shadow: none !important;
}
body.hide-word-box #words .word:hover,
body.hide-word-box #words .word:focus-within {
  border-color: color-mix(in srgb, var(--branch-color, var(--theme-focus)) 35%, transparent) !important;
  background: color-mix(in srgb, var(--branch-color, var(--theme-focus)) 8%, transparent) !important;
}
