:root {
  --bg: #101216;
  --panel: #171a20;
  --panel-2: #1e222a;
  --border: #2a2f38;
  --text: #e8e9ec;
  --muted: #9aa1ad;
  --accent: #4f8cff;
  --ok: #3ecf8e;
  --topbar-h: 52px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans JP", sans-serif;
  overscroll-behavior-y: none;
}

.view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: calc(env(safe-area-inset-top) + 6px) 10px 6px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar .title {
  flex: 1;
  min-width: 0;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.iconbtn, .textbtn, .navbtn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
}

.iconbtn { padding: 6px 11px; font-size: 18px; }
.textbtn.small { padding: 5px 9px; font-size: 12px; }
.textbtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.textbtn.active, .iconbtn.active { border-color: var(--accent); color: var(--accent); }
.textbtn.danger { color: #ff7b72; }

.search {
  flex: 1.2;
  min-width: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 14px;
}

.section { padding: 10px 10px 0; }
.section-title {
  font-size: 13px;
  color: var(--muted);
  margin: 4px 2px 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.section-title.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.linkbtn {
  appearance: none;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.02em;
  padding: 2px 0;
  cursor: pointer;
  text-transform: none;
}

.view .scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
  padding-bottom: 20px;
}

.card { cursor: pointer; }
.card .cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: contain;
  background: var(--panel-2);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.card .name {
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .sub {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rail {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
}
.chip {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  max-width: 240px;
  cursor: pointer;
}
.chip img {
  width: 40px;
  height: 58px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--panel-2);
}
.chip .info { min-width: 0; }
.chip .t { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip .s { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.title-head {
  display: flex;
  gap: 12px;
  padding: 12px 12px 6px;
}
.title-cover {
  width: 96px;
  height: 140px;
  object-fit: contain;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.title-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.title-fullname {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.muted { color: var(--muted); font-size: 12.5px; }
.progressbar {
  height: 6px;
  border-radius: 3px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  overflow: hidden;
}
.progressbar > div { height: 100%; background: var(--accent); width: 0; }

.spacer { flex: 1; }

.title-actions { display: flex; gap: 6px; }

.library-sort { display: flex; align-items: center; gap: 6px; }
.library-sort select {
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px 6px;
}

.title-notes {
  font-size: 12.5px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  max-height: 96px;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.note-add { align-self: flex-start; }
.note-editor { display: flex; flex-direction: column; gap: 6px; }
.note-editor textarea {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  min-height: 72px;
  max-height: 40vh;
  font: inherit;
  font-size: 12.5px;
  line-height: 1.4;
  color: inherit;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
}
.note-buttons { display: flex; gap: 6px; }

.translate-panel {
  margin: 2px 12px 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}
.tr-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.tr-head .muted { flex: 1; min-width: 0; }
.tr-list { max-height: 38vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.tr-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--border);
}
.tr-row:last-child { border-bottom: none; }
.tr-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  accent-color: var(--accent);
}
.tr-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin: 0 5px;
  border-radius: 50%;
  background: var(--accent);
}
.tr-main { flex: 1; min-width: 0; }
.tr-label {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tr-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.tr-actions .muted {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.select-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 2px 12px 10px;
}
.select-bar #select-count { font-size: 13px; color: var(--muted); margin-right: auto; }

.chapter-list { padding: 0 10px; }
.chapter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 6px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.chapter-row .check { display: none; width: 18px; height: 18px; accent-color: var(--accent); }
.title.select-mode .chapter-row .check { display: inline-block; }
.chapter-main { flex: 1; min-width: 0; }
.chapter-label {
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}
.badge {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge.tr { color: var(--ok); border-color: rgba(62, 207, 142, 0.5); }
.badge.raw { color: #d9a441; border-color: rgba(217, 164, 65, 0.5); }
.chapter-sub { margin-top: 2px; font-size: 11.5px; color: var(--muted); }
.chapter-status {
  flex: 0 0 auto;
  font-size: 12.5px;
  color: var(--muted);
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
}
.chapter-status.finished { color: var(--ok); }
.chapter-status:active { background: var(--panel-2); }

/* ---- reader ---- */
.reader { background: #000; }
.reader .topbar, .reader .reader-bottom {
  background: rgba(16, 18, 22, 0.92);
}
.reader.hide-bars .topbar, .reader.hide-bars .reader-bottom { display: none; }
.page-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: stretch;
  justify-content: center;
  position: relative;
}
.page-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.page-end, .page-start {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #000;
  text-align: center;
  padding: 24px;
}
.page-end .end-title, .page-start .end-title { font-size: 18px; font-weight: 600; }

.reader-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px);
  border-top: 1px solid var(--border);
}
.reader-bottom .slider { flex: 1; accent-color: var(--accent); min-width: 60px; }
.reader-bottom .navbtn { white-space: nowrap; }
.reader-bottom #page-counter { flex: 0 0 auto; font-size: 12px; min-width: 54px; text-align: center; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 70px);
  transform: translateX(-50%) translateY(10px);
  background: rgba(40, 44, 52, 0.96);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 100;
  max-width: 85vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Background translate task: info strip under a view's topbar. */
.task-chip {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 12px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}
.task-chip #task-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.task-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  animation: task-pulse 1.4s ease-in-out infinite;
}
.task-chip.failed { border-bottom-color: #ff7b72; }
.task-chip.failed .task-dot { background: #ff7b72; animation: none; }
.task-chip.failed #task-text { color: #ff7b72; }
@keyframes task-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.reader.hide-bars .task-chip { display: none; }

/* ---- login overlay ---- */
.login {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.login-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, 100%);
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.login-title { font-size: 20px; font-weight: 700; }
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.login-card .textbtn.primary { padding: 10px 12px; border-radius: 8px; }
.login-error { color: #ff7b72; font-size: 12.5px; min-height: 16px; }
