:root {
  --paper: #F4F6F1;
  --surface: #ffffff;
  --surface-soft: #FAFBF7;
  --ink: #16241F;
  --muted: #5C6B66;
  --line: #E2E6DD;
  --green: #1F4E3D;
  --green-soft: #2C6A52;
  --gold: #C2853A;
  --gold-wash: #FBEFD9;
  --brick: #A45E3F;
  --blue: #365C86;
  --shadow: 0 1px 2px rgba(22, 36, 31, .05), 0 8px 28px rgba(22, 36, 31, .08);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, "PingFang SC", "Hiragino Sans GB", sans-serif;
  --serif: Georgia, "Times New Roman", "Songti SC", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

html {
  background: var(--paper);
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(54, 92, 134, .28);
  outline-offset: 2px;
}

::selection {
  background: var(--gold-wash);
}

.app {
  min-height: 100svh;
}

.library {
  min-height: 100svh;
  padding: calc(22px + env(safe-area-inset-top)) 18px calc(34px + env(safe-area-inset-bottom));
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 27px;
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: 0;
}

.brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
  flex: none;
}

.tagline {
  margin: 7px 0 21px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0;
  text-transform: uppercase;
}

.searchbar {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 36px;
  align-items: center;
  gap: 8px;
  min-height: 50px;
  margin: 0 0 12px;
  padding: 0 8px 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
}

.searchbar svg {
  width: 19px;
  height: 19px;
  stroke: var(--muted);
  stroke-width: 2;
  fill: none;
}

.searchbar input {
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.2;
}

.searchbar input::placeholder {
  color: #7d8782;
}

.searchbar:focus-within {
  border-color: var(--green-soft);
  box-shadow: 0 0 0 2px rgba(31, 78, 61, .12);
}

.searchbar input:focus-visible { outline: none; }
.searchbar input::-webkit-search-cancel-button { -webkit-appearance: none; }

.clear-search {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 22px;
  line-height: 1;
}

.clear-search:hover {
  background: #efe9dc;
  color: var(--ink);
}

.clear-search[hidden] {
  display: none;
}

.result-count {
  min-height: 18px;
  margin: 0 0 14px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.4;
}

.catgroup {
  margin: 0 0 20px;
}

.cathead {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 11px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.cathead .cn {
  flex-shrink: 0;
  color: var(--green);
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  text-transform: none;
}

.cathead .bar {
  min-width: 0;
  height: 1px;
  background: var(--line);
  flex: 1;
}

.cat-count {
  flex-shrink: 0;
  min-width: 18px;
  text-align: right;
  font-family: var(--mono);
}

.topiclist {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.topicbtn {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border-radius: 9px;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.35;
  text-align: left;
  overflow-wrap: anywhere;
}

.topicbtn .num {
  flex: 0 0 26px;
  min-width: 26px;
  padding-top: 2px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.4;
}

.topicbtn .topic-name {
  flex: 1;
  min-width: 0;
}

.topic-new {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 34px;
  height: 22px;
  border-radius: 4px;
  background: var(--gold-wash);
  color: #82501C;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
}

.topicbtn:hover {
  background: var(--paper);
}

.topicbtn.active {
  background: var(--green);
  color: #fff;
}

.topicbtn.active .num {
  color: rgba(255, 255, 255, .72);
}

.empty {
  margin: 20px 0 0;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 14px;
  text-align: center;
}

.player {
  display: none;
  min-height: 100svh;
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(36px + env(safe-area-inset-bottom));
}

body.viewing .library {
  display: none;
}

body.viewing .player {
  display: block;
}

.backbtn {
  position: sticky;
  top: env(safe-area-inset-top);
  z-index: 5;
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  margin: 0 0 18px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(244, 246, 241, .92);
  color: var(--green);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--gold);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0;
  text-transform: uppercase;
}

.cue {
  margin: 0 0 20px;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.bullets {
  margin: 0 0 20px;
  padding: 6px 0 6px 18px;
  border-left: 2px solid var(--line);
  list-style: none;
}

.bullets li {
  padding: 4px 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.45;
}

.transport {
  position: sticky;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
  padding: 14px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, .94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.playwrap {
  position: relative;
  width: 58px;
  height: 58px;
  flex: none;
}

.ring {
  position: absolute;
  inset: 0;
  transform: rotate(-90deg);
}

.ring circle {
  fill: none;
  stroke-width: 3;
}

.ring .track {
  stroke: var(--line);
}

.ring .prog {
  stroke: var(--gold);
  stroke-linecap: round;
  transition: stroke-dashoffset .2s linear;
}

.playbtn {
  position: absolute;
  inset: 6px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  transition: background .15s, transform .1s;
}

.playbtn:hover {
  background: var(--green-soft);
}

.playbtn:active {
  transform: scale(.96);
}

.playbtn svg {
  display: block;
}

.playhint {
  margin: 0;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.45;
}

.settings {
  display: grid;
  gap: 12px;
  margin: 0 0 28px;
}

.seg {
  display: grid;
  gap: 6px;
}

.seg > span {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
  text-transform: uppercase;
}

.voice-note {
  margin: 0;
  min-height: 42px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--green);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 800;
  padding: 8px 10px;
}

.fallback-voice {
  display: none;
}

.speeds {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.speeds button {
  min-height: 38px;
  border-radius: 9px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.speeds button.active {
  background: var(--green);
  color: #fff;
}

.voice-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: stretch;
}

select.voice {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  padding: 8px 10px;
}

.voice-refresh {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--green);
  font-family: var(--mono);
  font-size: 22px;
  line-height: 1;
}

.voice-refresh:active {
  transform: scale(.96);
}

.parttoggle {
  display: none;
  align-items: center;
  gap: 4px;
  width: fit-content;
  margin: 0 0 18px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.parttoggle button {
  min-height: 38px;
  padding: 7px 14px;
  border-radius: 7px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 800;
}

.parttoggle button.active {
  background: var(--green);
  color: #fff;
}

.answer {
  color: var(--ink);
  font-size: 18.5px;
  line-height: 1.82;
}

.content-section {
  margin: 0 0 34px;
}

.part2-section {
  padding-bottom: 8px;
}

.part3-section {
  padding-top: 26px;
  border-top: 1px solid var(--line);
}

.section-title {
  margin: 0 0 18px;
  color: var(--green);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: uppercase;
}

.answer p {
  margin: 0 0 18px;
}

.sentence {
  margin: -1px -2px;
  padding: 1px 2px;
  border-radius: 5px;
  cursor: pointer;
  transition: background .18s;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.sentence:hover {
  background: #ece7da;
}

.sentence.speaking {
  background: var(--gold-wash);
  box-shadow: -6px 0 0 var(--gold-wash);
}

.answer .kw {
  color: var(--green-soft);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: rgba(31, 78, 61, .28);
  text-underline-offset: 3px;
}

.vocab {
  margin-top: 34px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.inline-vocab {
  margin: 24px 0 4px;
}

.vocab h3 {
  margin: 0 0 10px;
  color: var(--green-soft);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.vlist {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.vrow {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 5px 6px;
  border-radius: 9px;
}

.vrow:hover {
  background: var(--surface-soft);
}

.vspeak {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--green);
}

.vspeak:hover {
  border-color: var(--green);
  background: var(--gold-wash);
}

.vtext {
  min-width: 0;
  line-height: 1.25;
}

.ven {
  font-size: 15px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.vzh {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 12px;
}

.qa {
  margin: 0 0 30px;
  padding-bottom: 6px;
}

.qa + .qa {
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.q-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 12px;
  padding-left: 12px;
  border-left: 3px solid var(--gold);
}

.q-line {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: var(--green);
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 700;
  line-height: 1.32;
}

.q-pause {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  margin-top: -3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .94);
  color: var(--green);
  box-shadow: 0 4px 14px rgba(30, 63, 48, .08);
}

.q-pause svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.q-pause:active {
  transform: scale(.96);
}

.a-line {
  margin: 0 0 16px;
}

.qa-vocab {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.mini-vocab-title {
  margin: 0 0 7px;
  color: var(--green-soft);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hint {
  display: none;
}

@media (min-width: 560px) {
  .library {
    padding-inline: 24px;
  }

  .player {
    padding-inline: 24px;
  }

  .settings {
    grid-template-columns: minmax(250px, 330px) minmax(220px, 1fr);
    align-items: end;
  }
}

@media (min-width: 861px) {
  .app {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    min-height: 100vh;
  }

  .library,
  body.viewing .library {
    display: block;
    position: sticky;
    top: 0;
    height: 100vh;
    min-height: 0;
    overflow-y: auto;
    border-right: 1px solid var(--line);
    padding: 28px 22px 56px;
  }

  .player,
  body.viewing .player {
    display: block;
  }

  .player {
    max-width: 920px;
    padding: 48px 64px 120px;
  }

  .backbtn {
    display: none;
  }

  .cue {
    font-size: 38px;
  }

  .transport {
    position: static;
    gap: 18px;
    padding: 16px;
  }

  .answer {
    font-size: 19px;
  }

  select.voice {
    max-width: 280px;
  }
}

.search-results {
  min-width: 0;
  max-width: 920px;
  padding: 22px 18px calc(48px + env(safe-area-inset-bottom));
}

.search-results[hidden],
body.viewing .search-results,
body.searching:not(.viewing) .player {
  display: none;
}

.search-results h2 {
  margin: 0 0 6px;
  font: 700 24px/1.3 var(--sans);
}

.search-summary {
  margin: 0 0 20px;
  color: var(--muted);
  font: 13px/1.5 var(--sans);
}

.search-match {
  display: block;
  width: 100%;
  padding: 19px 8px;
  border-top: 1px solid var(--line);
  text-align: left;
  overflow-wrap: anywhere;
}

.search-match:hover,
.search-match:focus-visible {
  background: var(--surface);
}

.match-source,
.match-question,
.match-sentence,
.match-translation {
  display: block;
}

.match-source {
  color: var(--green);
  font: 700 12px/1.6 var(--sans);
  margin-bottom: 7px;
}

.match-question {
  color: var(--muted);
  font: 13px/1.5 var(--sans);
  margin: 5px 0 9px;
}

.match-sentence {
  font: 19px/1.7 var(--serif);
}

.match-translation {
  color: var(--muted);
  font: 14px/1.6 var(--sans);
  margin-top: 5px;
}

.search-mark {
  color: inherit;
  background: #FFE59A;
  border-bottom: 2px solid var(--gold);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.search-target {
  scroll-margin-top: 72px;
}

.search-target:focus {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
}

.more-matches {
  display: block;
  margin: 20px auto 0;
  min-height: 44px;
  padding: 8px 20px;
  color: var(--green);
  font: 700 14px/1.5 var(--sans);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.more-matches[hidden] { display: none; }

@media (max-width: 860px) {
  body.searching:not(.viewing) .library {
    min-height: 0;
    padding-bottom: 0;
  }
  body.searching:not(.viewing) #index,
  body.searching:not(.viewing) #topicCount {
    display: none;
  }
}

@media (min-width: 560px) {
  .search-results { padding-inline: 24px; }
}

@media (min-width: 861px) {
  .search-results { padding: 48px 56px 100px; }
  body.searching.viewing .backbtn { display: inline-flex; }
}
