/* Cobalt — the booru panel on the phone. Noctalia's palette, like the desktop panel. */
:root {
  --surface: #131318;
  --surface-1: #1f1f25;
  --surface-2: #2a292f;
  --surface-3: #35343a;
  --text: #e4e1e9;
  --muted: #c7c5d0;
  --dim: #918f9a;
  --line: #46464f;
  --primary: #bdc2ff;
  --on-primary: #262b61;
  --second: #444559;
  --on-second: #e1e0f9;
  --tertiary: #e7b9d5;
  --error: #ffb4ab;
  --on-error: #690005;
  --radius: 16px;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--surface); color: var(--text); }
body {
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: contain;
}
img, video { display: block; max-width: 100%; }
img { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; }
input, textarea { font: inherit; color: var(--text); }
.ic { width: 18px; height: 18px; flex: none; }
.hidden { display: none !important; }

/* ---------- screens: one visible at a time, the stack follows the back button ---------- */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--surface); }
.screen.under { visibility: hidden; }
.bar {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: calc(var(--top) + 8px) 12px 8px; background: var(--surface);
}
.bar .title { flex: 1; min-width: 0; font-weight: 650; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .sub { color: var(--dim); font-size: 12px; font-weight: 400; }
.scroll { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding-bottom: calc(var(--bottom) + 16px); }

/* ---------- pills / chips / buttons ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px;
  border: 0; border-radius: 18px; background: var(--surface-2); color: var(--text);
  font-size: 14px; font-weight: 500; white-space: nowrap; cursor: pointer;
}
.pill:active { background: var(--surface-3); }
a.pill { text-decoration: none; }
.pill.on { background: var(--primary); color: var(--on-primary); font-weight: 650; }
.pill.second.on { background: var(--second); color: var(--on-second); }
.pill.danger { color: var(--error); }
.pill.danger.on { background: var(--error); color: var(--on-error); }
.pill.icon { width: 40px; min-width: 40px; height: 40px; padding: 0; justify-content: center; border-radius: 20px; }
.pill.icon .ic { width: 20px; height: 20px; }
.pill.ghost { background: transparent; }
.pill:disabled { opacity: .4; }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--primary); color: var(--on-primary);
  font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.row { display: flex; gap: 6px; align-items: center; }
.hscroll { display: flex; gap: 6px; overflow-x: auto; padding: 0 12px 8px; scrollbar-width: none; }
.hscroll::-webkit-scrollbar { display: none; }
.wrap { display: flex; flex-wrap: wrap; gap: 6px; }
.muted { color: var(--dim); font-size: 13px; }
.hint { color: var(--dim); font-size: 12px; padding: 0 12px; }
.section { padding: 8px 12px 4px; font-weight: 650; font-size: 15px; }

/* tabs */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 0 12px 8px; scrollbar-width: none; align-items: center; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; display: inline-flex; align-items: center; gap: 4px; height: 32px; max-width: 220px; padding: 0 6px 0 12px;
  border-radius: 16px; background: var(--surface-1); color: var(--muted); font-size: 13px; border: 0;
}
.tab span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab.on { background: var(--second); color: var(--on-second); font-weight: 600; }
.tab .x { width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; border-radius: 13px; }
.tab .x .ic { width: 14px; height: 14px; }

/* search field */
.searchbox { position: relative; margin: 0 12px 8px; }
.searchbox .field {
  display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 6px 0 16px; border-radius: 23px;
  background: var(--surface-2); border: 2px solid transparent;
}
.searchbox .field:focus-within { border-color: var(--primary); }
.searchbox input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; font-size: 16px; }
.suggest {
  position: absolute; left: 0; right: 0; top: 52px; z-index: 30; padding: 6px; border-radius: 16px;
  background: var(--surface-3); border: 1px solid var(--line); box-shadow: 0 12px 30px #0008; max-height: 55vh; overflow-y: auto;
}
.suggest button {
  display: flex; width: 100%; justify-content: space-between; gap: 10px; padding: 11px 10px; border: 0; border-radius: 10px;
  background: transparent; text-align: left; font-size: 15px;
}
.suggest button:active { background: var(--surface-2); }
.suggest .n { color: var(--dim); font-size: 13px; }
.cat-character { color: var(--primary); } .cat-artist { color: var(--tertiary); }
.cat-copyright { color: var(--on-second); } .cat-meta, .cat-metadata { color: var(--dim); }

.chip {
  display: inline-flex; align-items: center; gap: 2px; height: 32px; padding: 0 4px 0 12px; border-radius: 16px;
  background: var(--second); color: var(--on-second); font-size: 14px; border: 0;
}
.chip.excluded { background: var(--surface-3); color: var(--error); text-decoration: line-through; }
.chip .x { width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; }
.chip .x .ic { width: 14px; height: 14px; }

/* ---------- the results grid ---------- */
.grid { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: 6px; padding: 4px 8px; }
.card {
  position: relative; aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; background: var(--surface-1);
  touch-action: manipulation;
}
.card img { width: 100%; height: 100%; object-fit: cover; }
.card .tag {
  position: absolute; left: 6px; top: 6px; padding: 2px 8px; border-radius: 10px; background: #131318d9;
  font-size: 11px; display: inline-flex; gap: 4px; align-items: center;
}
.card .tag .ic { width: 12px; height: 12px; }
.card .have {
  position: absolute; right: 6px; top: 6px; padding: 2px 8px; border-radius: 10px; background: var(--primary); color: var(--on-primary);
  font-size: 11px; font-weight: 600; display: inline-flex; gap: 3px; align-items: center;
}
.card .have .ic { width: 12px; height: 12px; }
.card .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 8px 7px; font-size: 12px; line-height: 1.25;
  background: linear-gradient(transparent, #131318f0 40%); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card .prog {
  position: absolute; right: 6px; bottom: 6px; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 650;
  background: var(--second); color: var(--on-second);
}
.card .prog.done { background: var(--tertiary); color: var(--surface); }
.loadmore { padding: 18px; text-align: center; color: var(--dim); font-size: 13px; }
.empty { padding: 48px 24px; text-align: center; color: var(--dim); }
.status { flex: none; padding: 4px 12px calc(var(--bottom) + 6px); color: var(--dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- a post ---------- */
.media { background: var(--surface-1); }
.media img, .media video { width: 100%; max-height: 78vh; object-fit: contain; margin: 0 auto; background: #000; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; }
.taggroup { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 12px 8px; align-items: center; }
.taggroup .label { color: var(--dim); font-size: 12px; width: 100%; }
.taggroup .pill { min-height: 32px; font-size: 13px; padding: 0 12px; }
.taggroup .pill.artist { background: var(--tertiary); color: var(--surface); font-weight: 600; }
.info { padding: 0 12px; color: var(--dim); font-size: 12px; }

/* ---------- reader ---------- */
.pages { display: flex; flex-direction: column; gap: 4px; }
.page { position: relative; background: var(--surface-1); min-height: 40vh; }
.page img { width: 100%; height: auto; }
.page .num { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--dim); font-size: 22px; }
.counter {
  position: fixed; right: 12px; bottom: calc(var(--bottom) + 12px); z-index: 5; padding: 6px 12px; border-radius: 14px;
  background: #131318e0; color: var(--muted); font-size: 13px; pointer-events: none;
}

/* ---------- library ---------- */
.files { display: grid; grid-template-columns: repeat(var(--fcols, 3), minmax(0, 1fr)); gap: 6px; padding: 4px 8px; }
.file { min-width: 0; }
.file .thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-1); display: flex; align-items: center; justify-content: center; color: var(--dim); }
.file .thumb img { width: 100%; height: 100%; object-fit: cover; }
.file .thumb .ic { width: 32px; height: 32px; }
.file .thumb .tag {
  position: absolute; left: 4px; top: 4px; padding: 1px 6px; border-radius: 8px; font-size: 10px; font-weight: 650;
  background: #131318d9; display: inline-flex; gap: 3px; align-items: center;
}
.file .thumb .tag.dir { background: var(--second); color: var(--on-second); }
.file .thumb .tag .ic { width: 11px; height: 11px; }
.file .name { font-size: 11px; color: var(--muted); padding: 3px 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file.dir .name { color: var(--text); font-weight: 500; }
.manga { display: grid; grid-template-columns: repeat(var(--mcols, 3), minmax(0, 1fr)); gap: 8px; padding: 4px 8px; }
.manga .cover { position: relative; aspect-ratio: 1 / 1.42; border-radius: 12px; overflow: hidden; background: var(--surface-1); }
.manga .cover img { width: 100%; height: 100%; object-fit: cover; }
.manga .t { font-size: 12px; font-weight: 500; padding: 4px 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.manga .s { font-size: 11px; color: var(--dim); padding: 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs { display: flex; gap: 4px; align-items: center; overflow-x: auto; padding: 0 12px 8px; scrollbar-width: none; }
.crumbs::-webkit-scrollbar { display: none; }
.crumbs .ic { width: 14px; height: 14px; color: var(--dim); }

/* ---------- forms ---------- */
.input {
  width: 100%; height: 44px; padding: 0 16px; border-radius: 22px; border: 2px solid transparent; outline: 0;
  background: var(--surface-2); font-size: 16px;
}
.input:focus { border-color: var(--primary); }
label.f { display: block; padding: 6px 12px; }
label.f > span { display: block; color: var(--dim); font-size: 12px; padding: 0 4px 4px; }
.card-box { margin: 8px 12px; padding: 12px; border-radius: var(--radius); background: var(--surface-1); }

/* ---------- sheets, dialogs, peek, toast ---------- */
.backdrop { position: fixed; inset: 0; z-index: 50; background: #0009; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 640px; max-height: 88vh; display: flex; flex-direction: column; border-radius: 22px 22px 0 0;
  background: var(--surface-2); padding: 6px 0 calc(var(--bottom) + 10px); animation: up .16s ease-out;
}
.sheet .grab { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 8px; flex: none; }
.sheet .head { padding: 2px 16px 8px; font-weight: 650; font-size: 16px; flex: none; }
.sheet .body { overflow-y: auto; padding: 0 0 4px; }
.sheet .item {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 50px; padding: 0 18px; border: 0; background: transparent;
  text-align: left; font-size: 15px;
}
.sheet .item:active { background: var(--surface-3); }
.sheet .item.danger { color: var(--error); }
.sheet .item.confirm { background: var(--error); color: var(--on-error); }
.sheet .item .ic { width: 20px; height: 20px; color: var(--muted); }
.sheet .item.danger .ic, .sheet .item.confirm .ic { color: inherit; }
.sheet .preview { margin: 0 16px 10px; border-radius: 12px; overflow: hidden; background: var(--surface-1); height: 150px; display: flex; justify-content: center; }
.sheet .preview img { height: 100%; width: auto; object-fit: contain; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
.peek { position: fixed; inset: 0; z-index: 70; background: #000e; display: flex; align-items: center; justify-content: center; }
.peek img, .peek video { max-width: 100%; max-height: 100%; object-fit: contain; }
.peek.manga { flex-direction: column; justify-content: flex-start; padding: calc(var(--top) + 12px) 0 var(--bottom); overflow: hidden; }
.peek.manga .cover { flex: 0 1 auto; min-height: 0; max-height: 58vh; display: flex; justify-content: center; padding: 0 12px; }
.peek.manga .cover img { border-radius: 10px; }
.peek.manga .info { flex: 1 1 0; min-height: 0; overflow: hidden; width: 100%; padding-top: 10px; color: var(--text); }
.peek.manga .title { padding: 0 12px 2px; font-size: 16px; font-weight: 600; }
.peek.manga .sub { padding: 0 12px 6px; color: var(--muted); font-size: 13px; }
.peek.manga .hint { padding: 4px 12px; }
.sheet .taggroup .pill { pointer-events: none; }
.peek .lbl { position: absolute; bottom: calc(var(--bottom) + 24px); left: 50%; transform: translateX(-50%); padding: 6px 14px; border-radius: 14px; background: var(--surface); color: var(--muted); font-size: 13px; }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom) + 18px); transform: translateX(-50%) translateY(20px); z-index: 90;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 14px; background: var(--surface-3); color: var(--text);
  font-size: 14px; box-shadow: 0 8px 24px #0008; opacity: 0; pointer-events: none; transition: .2s;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
.dl { margin: 6px 12px; padding: 10px 12px; border-radius: 12px; background: var(--surface-1); }
.dl .l { display: flex; gap: 8px; align-items: center; }
.dl .l span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.dl .s { font-size: 12px; color: var(--dim); padding-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl .s.err { color: var(--error); }
.bar-p { height: 4px; border-radius: 2px; background: var(--surface-3); margin-top: 8px; overflow: hidden; }
.bar-p i { display: block; height: 100%; background: var(--primary); }
.bar-p i.done { background: var(--tertiary); }

/* login */
.login { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 14px; padding: 24px; max-width: 420px; margin: 0 auto; width: 100%; }
.login h1 { margin: 0 0 6px; font-size: 26px; }
.login .err { color: var(--error); min-height: 20px; font-size: 14px; }

@media (min-width: 700px) {
  .grid { --cols: 3; } .files { --fcols: 5; } .manga { --mcols: 5; }
}
.sheet-tags { max-height: 34vh; overflow-y: auto; padding-bottom: 6px; }
