* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e2330; --panel3: #262c3d;
  --text: #e8eaf0; --muted: #8a92a6; --accent: #4f8cff; --accent2: #7aa8ff;
  --highlight: rgba(79, 140, 255, .22); --ok: #58c98b;
}
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  line-height: 1.7;
}
.hidden { display: none !important; }
.view { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---- login ---- */
#view-login { align-items: center; justify-content: center; }
.login-card {
  background: var(--panel); padding: 40px; border-radius: 16px; text-align: center;
  width: min(90vw, 380px); box-shadow: 0 8px 40px rgba(0,0,0,.4);
}
.login-card h1 { margin-bottom: 12px; }
.login-card p { color: var(--muted); margin-bottom: 20px; }
.login-card input {
  width: 100%; padding: 12px; border-radius: 8px; border: 1px solid #2a3040;
  background: var(--bg); color: var(--text); margin-bottom: 12px; font-size: 16px;
}
.login-card button {
  width: 100%; padding: 12px; border-radius: 8px; border: none;
  background: var(--accent); color: #fff; font-size: 16px; cursor: pointer;
}
.error { color: #ff7a7a; margin-top: 12px; }

/* ---- topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; background: var(--panel);
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 20px; flex: 1; }
.upload-btn {
  background: var(--accent); color: #fff; padding: 10px 16px;
  border-radius: 10px; cursor: pointer; font-size: 14px; white-space: nowrap;
}
.icon-btn {
  background: var(--panel2); border: none; color: var(--text); flex-shrink: 0;
  width: 40px; height: 40px; border-radius: 10px; font-size: 17px; cursor: pointer;
  transition: background .12s;
}
.icon-btn:hover { background: var(--panel3); }
.book-heading { flex: 1; min-width: 0; }
.reader-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-chapter { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- library ---- */
.book-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px; padding: 18px;
}
.book-card {
  background: var(--panel); border-radius: 14px; padding: 18px;
  cursor: pointer; transition: transform .12s, background .12s; position: relative;
}
.book-card:hover { background: var(--panel2); transform: translateY(-2px); }
.book-card .b-title { font-weight: 700; margin-bottom: 6px; padding-right: 22px; }
.book-card .b-author { color: var(--muted); font-size: 13px; }
.book-card .b-meta { color: var(--muted); font-size: 12px; margin-top: 10px; }
.book-card .b-del {
  position: absolute; top: 10px; right: 10px; background: none; border: none;
  color: var(--muted); cursor: pointer; font-size: 15px;
}
.book-card .b-del:hover { color: #ff7a7a; }
.b-progress { height: 4px; background: var(--panel3); border-radius: 2px; margin-top: 12px; overflow: hidden; }
.b-progress > div { height: 100%; background: var(--accent); border-radius: 2px; width: 0; }
.b-pct { color: var(--accent2); font-size: 12px; margin-top: 5px; }
.status { color: var(--muted); padding: 8px 18px; font-size: 13px; }

/* ---- reader ---- */
#text-pane {
  flex: 1; overflow-y: auto; padding: 26px 20px 45vh;
  max-width: 760px; margin: 0 auto; width: 100%;
  font-size: 17px;
}
#text-pane p { margin-bottom: 1.1em; }
#text-pane .sent { cursor: pointer; border-radius: 4px; padding: 1px 0; }
#text-pane .sent:hover { background: rgba(255,255,255,.07); }
#text-pane .sent.active { background: var(--highlight); }
#text-pane .sent.bookmarked { border-bottom: 2px solid var(--accent2); }
#chapter-select, #voice-select, #lang-select {
  background: var(--panel2); color: var(--text); border: 1px solid #2a3040;
  border-radius: 8px; padding: 8px 10px; font-size: 13px; max-width: 42vw;
}

/* ---- bookmarks panel ---- */
.panel {
  position: fixed; top: 64px; right: 12px; z-index: 30;
  width: min(92vw, 360px); max-height: 60vh; overflow-y: auto;
  background: var(--panel2); border: 1px solid #2a3040; border-radius: 14px;
  box-shadow: 0 12px 48px rgba(0,0,0,.5);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid #2a3040;
  position: sticky; top: 0; background: var(--panel2);
}
.bm-item {
  padding: 12px 14px; border-bottom: 1px solid #232938; cursor: pointer;
  display: flex; gap: 10px; align-items: flex-start;
}
.bm-item:hover { background: var(--panel3); }
.bm-body { flex: 1; min-width: 0; }
.bm-excerpt { font-size: 14px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.bm-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.bm-del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; }
.bm-del:hover { color: #ff7a7a; }

/* ---- player ---- */
.player {
  position: sticky; bottom: 0; background: var(--panel);
  padding: 8px 16px calc(10px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 24px rgba(0,0,0,.35);
}
.seek-row {
  display: flex; align-items: center; gap: 10px;
  max-width: 760px; margin: 0 auto 6px;
}
#seekbar { flex: 1; accent-color: var(--accent); height: 4px; cursor: pointer; }
.time-label {
  color: var(--muted); font-size: 12px; min-width: 60px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
#remain-label { text-align: right; min-width: 96px; }
.player-row { display: flex; align-items: center; gap: 10px; max-width: 760px; margin: 0 auto; }
.player-row.selects { margin-top: 8px; }
.player-row.selects select { flex: 1; max-width: none; }
.play-btn {
  background: var(--accent); border: none; color: #fff; flex-shrink: 0;
  width: 52px; height: 52px; border-radius: 50%; font-size: 20px; cursor: pointer;
}
.speed-chip {
  background: var(--panel3); border: 1px solid #313a52; color: var(--accent2);
  border-radius: 18px; padding: 8px 14px; font-size: 14px; font-weight: 700;
  cursor: pointer; flex-shrink: 0; font-variant-numeric: tabular-nums;
}
.speed-chip:hover { background: #2d3550; }
#speed { flex: 1; accent-color: var(--accent); min-width: 60px; }

.font-btn { font-size: 12px; width: 44px; }
.trans-book-btn {
  background: var(--panel3); border: 1px solid #313a52; color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; cursor: pointer;
  white-space: nowrap; flex-shrink: 0;
}
.trans-book-btn:hover { background: #2d3550; }
.trans-progress {
  max-width: 760px; margin: 6px auto 0; color: var(--accent2);
  font-size: 12px; text-align: center;
}

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 170px; transform: translateX(-50%);
  background: #2a3040; color: var(--text); padding: 10px 18px;
  border-radius: 20px; font-size: 13px; z-index: 50;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
  opacity: 0; transition: opacity .25s; pointer-events: none;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }

@media (max-width: 560px) {
  .book-grid { grid-template-columns: 1fr 1fr; }
  #text-pane { font-size: 16px; }
  .topbar h1 { font-size: 17px; }
  #chapter-select { max-width: 30vw; }
}
