:root {
  --bg: #f6f1e8;
  --bg-deep: #ebe4d8;
  --ink: #1c1917;
  --muted: #78716c;
  --card: #fffdf8;
  --line: #e7e0d4;
  --accent: #b45309;
  --accent-soft: #fef3c7;
  --ok: #3f6212;
  --ok-soft: #ecfccb;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
}
body { overscroll-behavior: none; }

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(88px + var(--safe-b));
  position: relative;
}

.view {
  display: none;
  padding: calc(12px + var(--safe-t)) 16px 24px;
  animation: fade .25s ease;
}
.view.active { display: block; }

@keyframes fade {
  from { opacity: .4; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
  min-height: 40px;
}
.top h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  text-align: center;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.back-btn, .link-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: .9rem;
  padding: 8px 4px;
  min-width: 52px;
}
.back-btn { text-align: left; }
.link-btn { text-align: right; }

.hint {
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.55;
  margin: 0 0 16px;
}
.hint.small { font-size: .84rem; margin-bottom: 12px; }

.boot {
  min-height: 80dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.boot-brand {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: .08em;
  margin: 0;
}
.boot-sub { color: var(--muted); margin: 0; }

.book-list { display: flex; flex-direction: column; gap: 12px; }
.book-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
  width: 100%;
  color: inherit;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(28,25,23,.04);
}
.book-card:active { transform: scale(.99); }
.book-type {
  display: inline-block;
  font-size: .72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-bottom: 8px;
}
.book-card h3 { margin: 0 0 6px; font-size: 1.1rem; }
.book-card p { margin: 0; color: var(--muted); font-size: .88rem; line-height: 1.5; }
.book-card .meta { margin-top: 10px; font-size: .8rem; color: var(--ink); opacity: .75; }

.task-card {
  background: linear-gradient(145deg, #292524, #1c1917);
  color: #fafaf9;
  border-radius: 20px;
  padding: 20px;
  margin-bottom: 16px;
}
.task-label { margin: 0; opacity: .7; font-size: .8rem; }
.toc-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toc-item.reading {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.read-progress.minimal {
  opacity: .65;
  font-size: .8rem;
}
.read-article.read-plain {
  border: 0;
  background: transparent;
  padding: 8px 4px 24px;
  box-shadow: none;
}
.read-plain .plain-header h2 {
  margin: 0 0 20px;
  font-size: 1.35rem;
  line-height: 1.4;
  font-weight: 800;
}
.read-plain .read-body {
  font-size: 1.12rem;
  line-height: 2;
}
.read-plain .read-body p {
  margin: 0 0 1.15em;
  text-align: justify;
}

html[data-font="md"] .read-body { font-size: 1.05rem; }
html[data-font="lg"] .read-body { font-size: 1.14rem; }
html[data-font="xl"] .read-body { font-size: 1.26rem; }
html[data-font="lg"] .read-plain .read-body { font-size: 1.18rem; }
html[data-font="xl"] .read-plain .read-body { font-size: 1.3rem; }

html[data-theme="night"] {
  --bg: #171412;
  --bg-deep: #221e1a;
  --ink: #f5f0e8;
  --muted: #a8a29e;
  --card: #1f1b17;
  --line: #3f3a34;
  --accent: #fbbf24;
  --accent-soft: #3b2f14;
  --ok: #bef264;
  --ok-soft: #1f2a14;
}
html[data-theme="night"] body { background: var(--bg); color: var(--ink); }
html[data-theme="night"] .tabbar {
  background: rgba(31,27,23,.94);
}
html[data-theme="night"] .task-card {
  background: linear-gradient(145deg, #3f3a34, #1c1917);
}
.toc-item-top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: .75rem;
  color: var(--muted);
}
.toc-item strong {
  display: block;
  font-size: .98rem;
  line-height: 1.45;
}
.toc-meta {
  margin-top: 8px;
  font-size: .8rem;
  color: var(--muted);
}
.read-nav-chapters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.book-actions-hint {
  display: block;
  margin-top: 8px;
  font-size: .78rem;
  color: var(--accent);
}
.toc-mini {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 12px;
  margin-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.toc-chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: .78rem;
  color: var(--ink);
  white-space: nowrap;
}
.toc-chip:active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.task-main {
  margin: 8px 0;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.4;
}
.task-main strong { color: #fbbf24; }
.task-meta, .task-days { margin: 0; font-size: .88rem; opacity: .85; line-height: 1.5; }
.progress-bar {
  height: 6px;
  background: rgba(255,255,255,.15);
  border-radius: 999px;
  margin: 14px 0 10px;
  overflow: hidden;
}
#book-progress-fill {
  height: 100%;
  width: 0;
  background: #fbbf24;
  border-radius: inherit;
  transition: width .3s ease;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.panel-head h2, .panel h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}
.badge {
  font-size: .75rem;
  background: var(--bg-deep);
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.on {
  background: var(--ok-soft);
  color: var(--ok);
}

.q-list { display: flex; flex-direction: column; gap: 8px; }
.q-list.compact { margin-top: 8px; }
.q-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  text-align: left;
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  color: inherit;
  cursor: pointer;
}
.q-item.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.q-item.done {
  opacity: .55;
}
.q-check {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 1.5px solid #a8a29e;
  flex-shrink: 0;
  margin-top: 1px;
  display: grid;
  place-items: center;
  font-size: .75rem;
}
.q-item.selected .q-check {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.q-text { flex: 1; font-size: .92rem; line-height: 1.45; }
.q-tag {
  font-size: .68rem;
  color: var(--muted);
  margin-top: 4px;
}

.duration-hint {
  min-height: 1.4em;
  margin: 12px 0;
  font-size: .86rem;
  color: var(--accent);
}

.primary-btn, .ghost-btn {
  width: 100%;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 1rem;
  font-weight: 600;
  border: 0;
  cursor: pointer;
}
.primary-btn {
  background: var(--ink);
  color: #fff;
}
.primary-btn:disabled {
  opacity: .35;
  cursor: not-allowed;
}
.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.read-progress {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: .84rem;
  margin-bottom: 12px;
}
.read-article {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
}
.read-q {
  margin: 0 0 14px;
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.45;
  color: var(--accent);
}
.read-body {
  font-size: 1.08rem;
  line-height: 1.9;
  letter-spacing: .02em;
}
.read-body p { margin: 0 0 1em; }
.read-body p:last-child { margin-bottom: 0; }
.read-continuous .read-section {
  padding-bottom: 22px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--line);
}
.read-continuous .read-section:last-of-type {
  border-bottom: 0;
  margin-bottom: 0;
  padding-bottom: 8px;
}
.read-section-q {
  margin: 0 0 12px;
  font-size: 1.02rem;
  font-weight: 700;
  line-height: 1.5;
  color: var(--accent);
}
.read-section-tag {
  display: inline-block;
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.read-actions {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 8px;
  margin-top: 18px;
}
.add-more { margin-top: 16px; }

.done-wrap {
  min-height: 70dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  gap: 10px;
}
.done-label { margin: 0; color: var(--muted); letter-spacing: .2em; font-size: .8rem; }
.done-title { margin: 0; font-size: 2rem; font-weight: 800; }
.done-meta { margin: 0 0 12px; color: var(--muted); line-height: 1.6; }
.done-actions { display: grid; gap: 8px; margin-top: 12px; }

.quote-card, #done-quote {
  background: #1c1917;
  color: #fafaf9;
  border-radius: 14px;
  padding: 18px;
  text-align: left;
  font-size: 1.05rem;
  line-height: 1.7;
  margin: 8px 0 4px;
}

.map-list, .ach-list, .quote-list { display: flex; flex-direction: column; gap: 10px; }
.map-node, .ach-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}
.map-node.lit {
  border-color: #84cc16;
  background: var(--ok-soft);
}
.map-node .status { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.map-node.lit .status { color: var(--ok); }

.ach-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
}
.stat b { display: block; font-size: 1.3rem; }
.stat span { font-size: .72rem; color: var(--muted); }

.ach-item h3 { margin: 0 0 4px; font-size: .95rem; }
.ach-item p { margin: 0; font-size: .84rem; color: var(--muted); }
.ach-item.got { border-color: #84cc16; background: var(--ok-soft); }

.quote-list .quote-card {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: .95rem;
}
.empty { color: var(--muted); font-size: .9rem; padding: 8px 0; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(28,25,23,.45);
  display: grid;
  place-items: end center;
  padding: 16px;
  z-index: 50;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(480px, 100%);
  background: var(--card);
  border-radius: 20px 20px 16px 16px;
  padding: 18px;
  margin-bottom: var(--safe-b);
}
.modal-label { margin: 0 0 10px; font-weight: 700; }
#quote-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  resize: vertical;
  background: #fff;
}
.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(480px, 100%);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  background: rgba(255,253,248,.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + var(--safe-b));
  z-index: 40;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: .78rem;
  padding: 10px 4px;
  font-weight: 600;
}
.tab.on { color: var(--ink); }

.book-card.slot {
  border-style: dashed;
  background: transparent;
  color: var(--muted);
}
.book-card.slot h3 { color: var(--ink); }

.steps {
  margin: 0;
  padding-left: 1.2em;
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.7;
}
.steps code {
  background: var(--bg-deep);
  padding: 1px 6px;
  border-radius: 6px;
  color: var(--ink);
  font-size: .84rem;
}

.file-btn {
  display: block;
  text-align: center;
  background: var(--ink);
  color: #fff;
  border-radius: 12px;
  padding: 14px 16px;
  font-weight: 600;
  cursor: pointer;
}
.file-btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0;
}
.seg-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 12px 8px;
  font-weight: 600;
  color: var(--ink);
}
.seg-btn.on {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

#view-boot .tabbar,
#view-read .tabbar,
#view-done .tabbar,
#view-today .tabbar,
#view-map .tabbar { /* tabbar always in DOM */ }

.view-hide-tabs #tabbar { display: none; }

.toc-item {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
}
.toc-item .toc-main {
  text-align: left;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 14px;
  cursor: pointer;
}
.toc-item.done {
  border-color: #84cc16;
  background: var(--ok-soft);
}
.merge-btn {
  width: calc(100% - 28px);
  margin: 0 14px 12px;
  border: 1px dashed var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 10px;
  padding: 10px;
  font-weight: 600;
}
.shelf-group {
  margin: 18px 0 10px;
  font-size: .9rem;
  font-weight: 700;
}
.shelf-demos summary.shelf-group {
  cursor: pointer;
  list-style: none;
}
.shelf-demos summary::-webkit-details-marker { display: none; }
.listen-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1.4fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.listen-bar .ghost-btn { padding: 10px; font-size: .9rem; }
.listen-status {
  font-size: .78rem;
  color: var(--muted);
  text-align: right;
}
.select-tip { opacity: .75; }
.sel-toast {
  position: absolute;
  z-index: 60;
}
.voice-select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
html[data-theme="night"] .voice-select {
  background: var(--card);
  color: var(--ink);
}

@media (min-width: 768px) {
  #app {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    min-height: 100vh;
  }
}
