:root {
  --ink: #25392a;
  --muted: #657368;
  --faded: #a7aea5;
  --paper: #f7f6ed;
  --line: #dbe1d3;
  --moss: #3d7353;
  --moss-pale: #e3eee0;
  --amber: #af7434;
  --control-height: 88px;
}

* { box-sizing: border-box; }

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

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, transparent 0, transparent 8%, #82917212 8.1%, transparent 8.2%),
    var(--paper);
  font-family: "Source Han Serif SC", "Noto Serif CJK SC", "Songti SC", "STSong", serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; }

.page-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: max(42px, env(safe-area-inset-top)) 20px calc(var(--control-height) + 42px + env(safe-area-inset-bottom));
}

.masthead { padding: 2px 2px 27px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 10px; color: var(--amber); font-family: "Microsoft YaHei", sans-serif; font-size: 13px; letter-spacing: 0; }
h1, h2 { margin: 0; font-weight: 700; letter-spacing: 0; }
h1 { font-size: 35px; line-height: 1.2; }
.intro { max-width: 32em; margin: 13px 0 0; color: var(--muted); font-size: 17px; line-height: 1.65; }

.section-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 24px 0 28px;
  padding: 4px;
  border: 1px solid var(--line);
  background: #eef1e7;
}

.section-tab {
  min-height: 46px;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 15px;
  cursor: pointer;
}

.section-tab[aria-current="page"] { color: #fff; background: var(--moss); box-shadow: 0 1px 2px #19372033; }
.section-tab:focus-visible, .sentence:focus-visible, .icon-button:focus-visible, .restart-button:focus-visible { outline: 3px solid #d69b54; outline-offset: 3px; }

.reading-header { margin-bottom: 11px; }
.section-number { margin: 0 0 8px; color: var(--amber); font-family: "Microsoft YaHei", sans-serif; font-size: 14px; }
h2 { font-size: 27px; line-height: 1.35; }
.status-message { min-height: 26px; margin: 0 0 7px; color: var(--moss); font-family: "Microsoft YaHei", sans-serif; font-size: 14px; line-height: 1.5; }
.status-message.is-error { color: #9c5236; }

.sentence-list { border-top: 1px solid var(--line); }
.sentence {
  position: relative;
  display: block;
  width: 100%;
  min-height: 64px;
  padding: 15px 12px 15px 47px;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  background: transparent;
  text-align: left;
  font-size: var(--reading-font-size, 28px);
  line-height: 1.62;
  cursor: pointer;
  transition: color 180ms ease, background-color 180ms ease;
}

.sentence::before {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 24px;
  height: 24px;
  transform: translateY(-50%);
  border: 1px solid #87a08b;
  border-radius: 50%;
  color: var(--moss);
  content: "▶";
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 11px;
  line-height: 22px;
  text-align: center;
}

.sentence:active { background: #edf2e8; }
.sentence.is-playing { color: #214e34; background: var(--moss-pale); }
.sentence.is-playing::before { border-color: var(--moss); content: "Ⅱ"; font-weight: 700; }
.sentence.is-completed { color: var(--faded); }
.sentence.is-completed::before { border-color: #a5b6a4; color: #93a593; content: "✓"; }

.voice-note { margin: 28px 0 0; color: var(--muted); font-family: "Microsoft YaHei", sans-serif; font-size: 13px; line-height: 1.6; }

.reading-controls {
  position: fixed;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 14px;
  min-height: var(--control-height);
  padding: 12px max(18px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  border-top: 1px solid #ccd8c7;
  background: #fbfcf7ee;
  box-shadow: 0 -8px 20px #42523a12;
  backdrop-filter: blur(14px);
  font-family: "Microsoft YaHei", sans-serif;
}

.progress-label { display: block; color: var(--muted); font-size: 12px; }
#progress-count { display: block; margin-top: 2px; color: var(--ink); font-size: 16px; }
.font-controls { display: flex; align-items: center; gap: 7px; }
.icon-button { width: 38px; height: 38px; border: 1px solid #bacabb; border-radius: 50%; color: var(--moss); background: #fff; font-size: 24px; line-height: 1; cursor: pointer; }
.font-size-label { width: 29px; color: var(--muted); font-size: 12px; text-align: center; }
.restart-button { min-height: 40px; padding: 0 11px; border: 1px solid #9eb69f; border-radius: 4px; color: var(--moss); background: transparent; font-size: 14px; cursor: pointer; }
.restart-button:active, .icon-button:active { background: var(--moss-pale); }

@media (min-width: 760px) {
  .page-shell { padding-right: 32px; padding-left: 32px; }
  .reading-controls { right: auto; left: 50%; width: min(100%, 760px); transform: translateX(-50%); border-right: 1px solid #ccd8c7; border-left: 1px solid #ccd8c7; }
}

@media (max-width: 390px) {
  .page-shell { padding-right: 15px; padding-left: 15px; }
  .reading-controls { gap: 9px; padding-right: 12px; padding-left: 12px; }
  .restart-button { padding: 0 8px; font-size: 13px; }
}

/* Sentence playback and character pronunciation are separate controls. */
.sentence {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  padding: 14px 4px 14px 8px;
  text-align: initial;
  cursor: default;
}

.sentence::before { display: none; content: none; }

.sentence-play-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  margin-top: 4px;
  padding: 0;
  border: 1px solid #87a08b;
  border-radius: 50%;
  color: var(--moss);
  background: #fffdf7;
  font-family: "Microsoft YaHei", sans-serif;
  cursor: pointer;
}

.sentence-play-icon { font-size: 13px; line-height: 1; }
.sentence-text { min-width: 0; margin: 0; }
.character-button {
  position: relative;
  min-width: 0.9em;
  min-height: 1.35em;
  padding: 0;
  border: 0;
  border-radius: 3px;
  color: inherit;
  background: transparent;
  font: inherit;
  line-height: inherit;
  cursor: pointer;
}

.character-button:active,
.character-button.is-active { color: var(--moss); background: #dfeadd; }
.character-button.is-unread { color: var(--ink); }
.character-button.is-read { color: var(--faded); }
.character-button.is-current { color: var(--moss); background: #dfeadd; }
.punctuation { white-space: pre-wrap; }
.pronunciation-popover {
  position: absolute;
  z-index: 4;
  bottom: calc(100% + 3px);
  left: 50%;
  padding: 3px 6px;
  border: 1px solid #bfceb9;
  border-radius: 4px;
  color: #214e34;
  background: #fffdf7;
  box-shadow: 0 2px 7px #42523a1f;
  font-family: "Microsoft YaHei", sans-serif;
  font-size: max(12px, calc(var(--reading-font-size, 28px) * 0.48));
  font-weight: 600;
  line-height: 1.2;
  transform: translateX(-50%);
  white-space: nowrap;
  pointer-events: none;
}

.sentence.is-playing .sentence-play-button { border-color: var(--moss); background: #f5fbf1; }
.sentence.is-completed .sentence-play-button { border-color: #a5b6a4; color: #93a593; }
.sentence-play-button:focus-visible,
.character-button:focus-visible { outline: 3px solid #d69b54; outline-offset: 3px; }
