:root {
  --bg: #14161c;
  --panel: #1e212a;
  --panel-2: #272b36;
  --text: #f2f3f5;
  --muted: #a3a8b5;
  --accent: #ffcc33;
  --accent-text: #1a1a1a;
  --danger: #ff6b6b;
  --warn-bg: #3a3017;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

a { color: var(--accent); }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 14px 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--panel-2);
}
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: .3px; }
.count { color: var(--muted); font-size: 14px; }

main { padding: 16px; max-width: 640px; margin: 0 auto; }
h2 { font-size: 17px; margin: 24px 0 8px; }
.view > h2:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 10px 16px;
  border: 1px solid var(--panel-2); border-radius: var(--radius);
  background: var(--panel); color: var(--text);
  font: inherit; cursor: pointer; text-align: center;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.big { min-height: 56px; padding: 14px 28px; font-size: 18px; }
.btn.wide { display: flex; width: 100%; margin-bottom: 10px; }
.btn[disabled] { opacity: .5; }

.row { display: flex; gap: 10px; align-items: flex-end; }
.row > * { flex: 1; }
.row > .narrow, .row > .btn { flex: 0 0 auto; }
.row .narrow { width: 64px; }

.field { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px;
  min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--panel-2); border-radius: 10px;
  background: var(--panel); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row input { margin-top: 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.check input { width: 20px; min-height: 20px; margin: 0; }

/* Scanner */
.camera {
  position: relative; overflow: hidden;
  aspect-ratio: 4 / 3; border-radius: var(--radius);
  background: #000;
}
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.guide {
  position: absolute; inset: 20% 8%;
  border: 2px solid rgba(255, 204, 51, .9); border-radius: 10px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, .35);
  pointer-events: none;
}
.guide span {
  position: absolute; left: 4%; right: 4%; top: 50%; height: 2px;
  background: rgba(255, 80, 80, .8);
  animation: sweep 1.6s ease-in-out infinite alternate;
}
@keyframes sweep { from { transform: translateY(-30px); } to { transform: translateY(30px); } }
.camera-idle {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel);
}
.scan-status { min-height: 44px; color: var(--muted); text-align: center; margin: 12px 0; }
.scan-status.good { color: var(--accent); }
.alt-actions { display: grid; gap: 10px; margin-top: 16px; }

/* Collection */
.search { margin: 0 0 10px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-bottom: 12px; }
.filters select { width: auto; margin: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; gap: 12px; align-items: center;
  padding: 10px; margin-bottom: 8px;
  background: var(--panel); border-radius: var(--radius); cursor: pointer;
}
.thumb {
  flex: 0 0 44px; height: 66px; border-radius: 4px;
  background: var(--panel-2) center / cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 11px; text-align: center;
}
.item-main { flex: 1; min-width: 0; }
/* Up to two lines each, so a long series name doesn't hide the issue number. */
.item-title, .item-sub { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
.item-title { font-weight: 600; }
.item-sub { color: var(--muted); font-size: 13px; }
.list li .chev { color: var(--muted); font-size: 24px; line-height: 1; padding: 0 2px; }
#list-note { margin: 0 0 10px; }
.segmented { display: flex; gap: 4px; padding: 4px; margin-bottom: 10px; background: var(--panel); border-radius: var(--radius); }
.segmented button {
  flex: 1; min-height: 36px; border: 0; border-radius: 9px;
  background: none; color: var(--muted); font: inherit; font-size: 15px; cursor: pointer;
}
.segmented button.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge.todo { background: var(--warn-bg); color: var(--accent); }
.empty { text-align: center; color: var(--muted); margin-top: 40px; }
#bulk-lookup { width: 100%; margin-bottom: 12px; }
.small-btn { min-height: 36px; padding: 6px 12px; margin-left: auto; }
.select-bar {
  position: sticky; top: 50px; z-index: 4;
  display: flex; gap: 12px; align-items: center;
  padding: 8px 10px; margin-bottom: 10px;
  background: var(--panel-2); border-radius: var(--radius);
}
.list li .pick { width: 22px; min-height: 22px; margin: 0; flex: 0 0 auto; }
.list li.picked { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Scan-many list */
.batch-toggle { margin: 4px 0 12px; justify-content: center; }
.tray { margin: 8px 0 16px; }
.tray-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.tray-head h2 { margin: 0; }
.tray .list li { cursor: default; }
.tray .list li input[type=checkbox] { width: 22px; min-height: 22px; margin: 0; flex: 0 0 auto; }
.tray .remove { background: none; border: 0; color: var(--muted); font-size: 18px; min-width: 40px; min-height: 40px; }
.tray .row { margin-top: 4px; }

.notice { padding: 10px 12px; border-radius: 10px; background: var(--panel-2); margin-bottom: 12px; font-size: 14px; }
.notice.warn { background: var(--warn-bg); }
.notice .btn { margin-top: 8px; min-height: 36px; padding: 6px 12px; }
.notice.good { background: #17351f; }
.btn.mic { flex: 0 0 auto; min-width: 48px; padding: 0 10px; }
.btn.mic.listening { background: var(--accent); color: var(--accent-text); }
.badge.wish { background: #17351f; color: #8fe3a5; }
.wish-arc { margin: 18px 0 6px; font-size: 15px; color: var(--accent); }
.wish-arc:first-child { margin-top: 4px; }
.wish-item { padding: 10px 12px; background: var(--panel); border-radius: 10px; margin-bottom: 6px; }

/* Bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--panel);
  border-top: 1px solid var(--panel-2);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; min-width: 0; min-height: 60px; border: 0; background: none;
  color: var(--muted); font: inherit; font-size: 13px; padding: 0 1px;
}
.tabs button.active { color: var(--accent); font-weight: 600; }

/* Sheets */
dialog {
  width: 100%; max-width: 640px; max-height: 92vh;
  margin: auto auto 0; padding: 16px;
  border: 0; border-radius: 18px 18px 0 0;
  background: var(--bg); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
#type-dialog { margin: auto; border-radius: 18px; max-width: 420px; }
#type-dialog h2 { margin-top: 0; }
#dupe-dialog, #box-dialog { margin: auto; border-radius: 18px; max-width: 420px; }
#box-dialog h2 { margin-top: 0; }
#dupe-dialog h2 { margin-top: 0; }
#dupe-dialog p { font-size: 16px; line-height: 1.4; }
.dupe-box-row { display: flex; gap: 8px; margin: 0 0 14px; }
.dupe-box-row[hidden] { display: none; }
.dupe-box-row input { flex: 1; min-width: 0; }
.dupe-box-row .btn { width: auto; margin: 0; flex: none; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; }
.close { background: none; border: 0; color: var(--muted); font-size: 22px; min-width: 44px; min-height: 44px; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; position: sticky; bottom: -16px; background: var(--bg); padding: 10px 0; }
.sheet-actions .btn { flex: 1; }
.barcode-box { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.barcode-box b { color: var(--text); font-variant-numeric: tabular-nums; }
.addon-box { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 8px; }
.addon-box .field { flex: 1; margin-bottom: 0; }
.lookup-box { margin-bottom: 12px; }
.matches { list-style: none; margin: 8px 0; padding: 0; }
.matches li {
  display: flex; gap: 12px; align-items: center;
  padding: 8px; margin-bottom: 6px; border-radius: 10px;
  background: var(--panel); border: 2px solid transparent; cursor: pointer;
}
.matches li.chosen { border-color: var(--accent); }
details summary { color: var(--accent); cursor: pointer; padding: 6px 0; }
details .row { margin-top: 6px; }
.cover-preview { text-align: center; }
.cover-preview img { max-height: 180px; border-radius: 6px; margin-bottom: 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 99px;
  background: var(--text); color: var(--bg); font-size: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
}
.toast-undo {
  margin-left: 10px; padding: 4px 12px; border: 0; border-radius: 99px;
  background: var(--accent); color: var(--bg); font: inherit; font-weight: 600; cursor: pointer;
}
.bin-list li { cursor: default; }
.nudge-actions { display: flex; gap: 8px; margin-top: 8px; }
.read-check { margin: 4px 0 10px; }
.badge.read { background: transparent; color: var(--muted); }
.badge.key { background: var(--warn-bg); color: var(--accent); }
.badge.signed { background: transparent; color: var(--accent); }
.similar { margin: 6px 0 0; padding-left: 20px; }

.sync-code { font: 600 1.4rem/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.06em; text-align: center; margin: 0.4rem 0 0.6rem; user-select: all; }

/* Read: digital comics on the phone */
.read-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 14px 12px; margin: 8px 0 16px; }
.read-tile { position: relative; cursor: pointer; min-width: 0; }
.read-cover {
  position: relative; aspect-ratio: 2 / 3; border-radius: 8px; overflow: hidden;
  background: var(--panel-2); display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.read-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.read-new {
  position: absolute; top: 6px; left: 6px; padding: 1px 6px; border-radius: 4px;
  background: var(--accent); color: var(--accent-text); font-size: 11px;
}
.read-progress { position: absolute; left: 6px; right: 6px; bottom: 6px; height: 4px; border-radius: 2px; background: rgba(0, 0, 0, .6); }
.read-progress i { display: block; height: 100%; border-radius: 2px; background: var(--accent); }
.read-name { margin-top: 6px; font-size: 14px; font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.read-sub { color: var(--muted); font-size: 12px; }
.read-more {
  position: absolute; top: 4px; right: 4px; width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 18px; line-height: 1;
}
.read-empty p { margin: 8px 0 12px; }
.read-folder-bar { display: flex; align-items: center; justify-content: flex-start; gap: 12px; margin: 4px 0 8px; }
.read-folder-bar .btn { width: auto; margin: 0; flex: none; }
.read-folder-bar h2 { margin: 0; font-size: 18px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* A series folder: two more covers peeking out behind, like a pile. */
.read-tile.folder .read-cover { margin: 8px 8px 0 0; overflow: visible; }
.read-tile.folder .read-cover img { border-radius: 8px; }
.read-tile.folder .read-cover::before, .read-tile.folder .read-cover::after {
  content: ''; position: absolute; inset: 0; border-radius: 8px; border: 1px solid var(--bg);
}
.read-tile.folder .read-cover::before { transform: translate(8px, -8px); background: var(--panel); z-index: -2; }
.read-tile.folder .read-cover::after { transform: translate(4px, -4px); background: var(--panel-2); z-index: -1; }
.read-tile.folder .read-cover { isolation: isolate; }
#read-menu { margin: auto auto 0; }
#read-menu h2 { margin-top: 0; }

/* The reader, over everything */
body.reading { overflow: hidden; }
.reader {
  position: fixed; inset: 0; z-index: 100; background: #0e0e11; color: #fff;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.reader-pages { position: absolute; inset: 0; overflow: hidden; }
.reader-track { position: absolute; inset: 0; will-change: transform; }
.reader-slot { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.reader-slot img { max-width: 100%; max-height: 100%; object-fit: contain; transform-origin: center; will-change: transform; }
.reader-pages.webtoon { touch-action: pan-y; }
.reader-strip {
  position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  overscroll-behavior: contain;
}
.reader-strip img { display: block; width: 100%; max-width: 820px; margin: 0 auto; background: #1b1c21; }
.reader-strip img.pending { aspect-ratio: 2 / 3; }
.reader-top, .reader-bottom {
  position: absolute; left: 0; right: 0; z-index: 2; background: rgba(20, 22, 28, .94);
  transition: transform .2s ease, opacity .2s ease;
}
.reader-top {
  top: 0; display: flex; align-items: center; gap: 10px;
  padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
}
.reader-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.reader-count { color: var(--muted); font-size: 14px; }
.reader-bottom { bottom: 0; padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
.reader-slider { margin: 0 0 8px; min-height: 30px; padding: 0; background: none; border: 0; accent-color: var(--accent); }
.reader-modes { display: flex; gap: 8px; }
.reader-btn {
  min-height: 40px; padding: 6px 12px; border: 1px solid var(--panel-2); border-radius: 10px;
  background: var(--panel); color: var(--text); font: inherit; font-size: 14px;
}
.reader-modes .reader-btn { flex: 1; }
.reader-btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.reader-hint {
  position: absolute; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 2; max-width: 90%; padding: 8px 14px; border-radius: 10px; background: rgba(20, 22, 28, .9);
  color: var(--text); font-size: 14px; text-align: center; transition: opacity .3s;
}
.reader.ui-hidden .reader-top { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.reader.ui-hidden .reader-bottom { transform: translateY(100%); opacity: 0; pointer-events: none; }
.reader.ui-hidden .reader-hint { opacity: 0; pointer-events: none; }
/* On the last page: carry straight on with the next issue in the folder. Stays put when the bars hide. */
.reader-next {
  position: absolute; right: 12px; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 3; max-width: calc(100% - 24px);
  padding: 12px 16px; border: 0; border-radius: 999px; background: var(--accent); color: var(--accent-text);
  font-weight: 700; font-size: 15px; box-shadow: 0 4px 16px rgba(0, 0, 0, .5);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Boxes */
#boxes-note { margin: 0; flex: 1; }
.box-open-title { margin: 0; font-size: 20px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.box-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.box-actions .btn { flex: 1 1 auto; }
.box-icon {
  flex: 0 0 44px; height: 44px; border-radius: 8px; background: var(--panel-2);
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}
#box-pc h3 { margin: 18px 0 6px; font-size: 15px; color: var(--accent); }
