:root {
  --bg: #0e0f13;
  --panel: #171a21;
  --panel2: #1e222c;
  --text: #eef1f6;
  --dim: #9aa3b2;
  --accent: #ff7a1a;
  --line: #262b36;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100dvh;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
.dim { color: var(--dim); }
.accent { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- library ---------- */
#view-library { max-width: 640px; margin: 0 auto; padding: calc(20px + env(safe-area-inset-top)) 18px calc(24px + env(safe-area-inset-bottom)); }
.lib-head h1 { font-size: 40px; margin: 8px 0 2px; letter-spacing: -0.5px; }
.tagline { color: var(--dim); margin: 0 0 20px; }
.lib-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
.primary {
  background: var(--accent); color: #14100c; font-weight: 700;
  padding: 12px 18px; border-radius: 12px;
}
.ghost {
  background: var(--panel); color: var(--text);
  padding: 12px 18px; border-radius: 12px; border: 1px solid var(--line);
}
.ghost.small { padding: 8px 14px; font-size: 14px; }
#empty-state {
  background: var(--panel); border: 1px dashed var(--line); border-radius: 14px;
  padding: 22px; text-align: center; margin-bottom: 18px;
}
.book-card {
  display: flex; align-items: stretch; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 14px 12px; margin-bottom: 10px;
}
.book-main { flex: 1; min-width: 0; cursor: pointer; }
.book-title { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-meta { color: var(--dim); font-size: 13px; margin: 4px 0 8px; }
.bar { height: 5px; background: var(--panel2); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.book-del { color: var(--dim); font-size: 15px; padding: 0 6px; align-self: flex-start; }
.lib-foot { font-size: 12.5px; margin-top: 22px; line-height: 1.5; }

/* ---------- reader ---------- */
#view-reader {
  max-width: 640px; margin: 0 auto; min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: calc(10px + env(safe-area-inset-top)) 18px calc(14px + env(safe-area-inset-bottom));
}
.reader-head { display: flex; align-items: center; gap: 10px; }
.icon-btn { font-size: 34px; line-height: 1; color: var(--dim); padding: 2px 10px 6px 2px; }
.reader-titles { min-width: 0; }
#reader-title { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#reader-chapter { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#stage {
  position: relative; flex: 1; min-height: 240px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
#stage::before {
  content: ""; position: absolute; left: 50%; top: 12%; bottom: 12%;
  width: 1px; background: var(--line);
}
.guide { position: absolute; left: 50%; transform: translateX(-50%); width: 0; height: 0; }
.guide-top { top: calc(50% - 52px); border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 8px solid var(--accent); }
.guide-bottom { top: calc(50% + 44px); border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 8px solid var(--accent); }
#stage[data-font="0"] #word-row { font-size: 33px; }
#stage[data-font="1"] #word-row { font-size: 44px; }
#stage[data-font="2"] #word-row { font-size: 57px; }
#word-row {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: baseline;
  width: 100%; font-weight: 600; letter-spacing: 0.2px; white-space: nowrap;
}
#word-row.long { font-size: 0.74em; }
#word-row.vlong { font-size: 0.55em; }
#w-pre { text-align: right; overflow: hidden; }
#w-orp { color: var(--accent); padding: 0 0.5px; }
#w-post { text-align: left; overflow: hidden; }
#splash {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); text-align: center; padding: 20px;
}
#splash-title { font-size: 26px; font-weight: 700; line-height: 1.3; }

#stats { text-align: center; font-size: 13.5px; margin: 4px 0 8px; }
#seek { width: 100%; accent-color: var(--accent); margin: 0 0 6px; }
.transport { display: flex; justify-content: space-between; align-items: center; margin: 6px 0 14px; }
.t-btn {
  background: var(--panel); border: 1px solid var(--line); border-radius: 50%;
  width: 52px; height: 52px; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.t-btn.play { width: 68px; height: 68px; font-size: 24px; background: var(--accent); color: #14100c; border: none; }
.speed-row { display: flex; align-items: center; gap: 10px; }
.s-btn {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  width: 42px; height: 42px; font-size: 20px; flex: none;
}
#wpm-slider { flex: 1; accent-color: var(--accent); }
#wpm-label { min-width: 76px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.reader-foot { margin-top: 14px; display: flex; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap; }
.voice-select {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 10px; font-size: 14px; max-width: 210px;
}

/* ---------- overlays ---------- */
#overlay {
  position: fixed; inset: 0; background: rgba(6, 7, 9, 0.72);
  display: flex; align-items: center; justify-content: center; z-index: 30;
}
.overlay-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px 26px; text-align: center; max-width: 84vw; }
.spinner {
  width: 30px; height: 30px; margin: 0 auto 12px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#paste-modal, #chapter-modal {
  position: fixed; inset: 0; background: rgba(6, 7, 9, 0.72); z-index: 30;
  display: flex; align-items: flex-end; justify-content: center;
}
#btn-chapters { margin-left: auto; flex: none; }
#chapter-list { max-height: 56dvh; overflow-y: auto; margin-bottom: 12px; }
.ch-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  width: 100%; text-align: left; padding: 11px 12px; margin-bottom: 6px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; color: var(--text);
}
.ch-row.cur { border-color: var(--accent); }
.ch-row .ch-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-row .ch-m { color: var(--dim); font-size: 13px; flex: none; font-variant-numeric: tabular-nums; }
.sheet {
  background: var(--panel); border-radius: 18px 18px 0 0; width: 100%; max-width: 640px;
  padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
}
.sheet h2 { margin: 0 0 12px; font-size: 19px; }
.sheet input, .sheet textarea {
  width: 100%; background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
  font: inherit; margin-bottom: 10px;
}
.sheet-actions { display: flex; justify-content: flex-end; gap: 10px; }
