:root {
  --bg: #14182b;
  --panel: #1e2440;
  --panel-2: #283056;
  --line: #3a4372;
  --text: #e8eaf4;
  --muted: #9aa1c4;
  --accent: #5b8cff;
  --reader-bg: #111214;
  --bar: rgba(20, 24, 43, 0.94);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  touch-action: manipulation;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; }

/* ---------- 最初の画面 ---------- */
#home {
  max-width: 760px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px 40px;
}
.home-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.home-head h1 { font-size: 1.4rem; margin: 8px 0; }
.home-head .primary { padding: 12px 22px; font-size: 1.05rem; }
h2 { font-size: 1rem; color: var(--muted); font-weight: 600; margin: 28px 0 8px; }
.hint { color: var(--muted); font-size: 0.9rem; line-height: 1.6; }
.note {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 14px; font-size: 0.9rem; line-height: 1.6;
}

#book-list { list-style: none; margin: 0; padding: 0; }
#book-list li {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
}
#book-list li:active { background: var(--panel-2); }
.book-main { flex: 1; min-width: 0; }
.book-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-sub { color: var(--muted); font-size: 0.85rem; margin-top: 3px; }
.progress { height: 4px; background: var(--panel-2); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }
.book-del { border: none; background: transparent; color: var(--muted); font-size: 1.2rem; padding: 4px 8px; }

#drop-cover {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 24, 43, 0.85); border: 3px dashed var(--accent);
  font-size: 1.4rem; pointer-events: none;
}

/* ---------- ビューア ---------- */
#reader { position: fixed; inset: 0; background: var(--reader-bg); }
#stage {
  position: absolute; inset: 0; overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#pages {
  position: absolute; left: 0; top: 0;
  display: flex; flex-direction: row;
  transform-origin: 0 0; will-change: transform;
}
#pages.rtl { flex-direction: row-reverse; }
#pages canvas { display: block; background: #fff; }

#loading {
  position: absolute; inset: 0; display: flex; gap: 12px;
  align-items: center; justify-content: center; color: var(--muted);
  pointer-events: none;
}
.spinner {
  width: 22px; height: 22px; 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); } }

#menu .bar {
  position: absolute; left: 0; right: 0; background: var(--bar);
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  backdrop-filter: blur(6px);
}
#menu .top {
  top: 0; display: flex; align-items: center; gap: 12px;
  padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: 8px;
}
#menu .top .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.page-label { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
#menu .bottom {
  bottom: 0; padding-top: 10px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.slider-row { display: flex; align-items: center; gap: 10px; }
#slider { flex: 1; accent-color: var(--accent); height: 28px; }
#slider.rtl { direction: rtl; }
#page-input {
  width: 5.5em; background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; text-align: right;
}
.settings { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-top: 10px; }
.setting { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.setting > span { color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; background: transparent; padding: 7px 12px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }
.seg.disabled { opacity: 0.45; }
#offset-btn.on { border-color: var(--accent); color: var(--accent); }

.usage { font-weight: 400; font-size: 0.85rem; margin-left: 8px; }
.hint.small { font-size: 0.8rem; margin: 0 0 10px; }
.badge {
  display: inline-block; font-size: 0.72rem; font-weight: 600; color: #fff;
  background: #2f8f5b; border-radius: 4px; padding: 1px 6px; margin-right: 6px; vertical-align: 1px;
}

#save-ask {
  position: absolute; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%); width: min(520px, calc(100% - 32px));
  background: var(--bar); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  font-size: 0.92rem; line-height: 1.6; z-index: 5;
}
.save-ask-btns { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }
#save-progress { margin-top: 10px; }

#toast {
  position: absolute; left: 50%; bottom: 40px; transform: translateX(-50%);
  background: var(--bar); border: 1px solid var(--line); border-radius: 20px;
  padding: 8px 18px; font-size: 0.9rem; pointer-events: none;
}
