:root {
  --bg: #0a0b0d;
  --bg-soft: #0f1115;
  --panel: #14171c;
  --panel-2: #1b1f26;
  --line: #272c35;
  --text: #f1f4f8;
  --muted: #98a1ac;
  --accent: #6f9bff;
  --accent-strong: #4f83ff;
  --danger: #ff6b6b;
  --ok: #4cd6a0;
  --radius: 14px;
  --shadow: 0 20px 60px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.viewer-open { overflow: hidden; }

::selection { background: rgba(111, 155, 255, .35); }

a { color: var(--accent); text-decoration: none; }
a:hover { color: #9bbaff; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

button, input, select { font: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
  padding: 0 22px;
  background: rgba(10, 11, 13, .78);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(39, 44, 53, .8);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-weight: 650;
  font-size: 17px;
  letter-spacing: -.02em;
}
.brand:hover { color: var(--text); }
.brand.large { font-size: 22px; }

.brand-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8fc0ff, var(--accent-strong));
  box-shadow: 0 0 18px rgba(111, 155, 255, .55);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.quota-chip {
  color: var(--muted);
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}

.inline { display: inline; margin: 0; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .08s ease;
  white-space: nowrap;
}
.btn:hover { background: #232833; color: var(--text); }
.btn:active { transform: translateY(1px); }

.btn.primary {
  background: linear-gradient(180deg, #7fa8ff, var(--accent-strong));
  color: #06101f;
  font-weight: 650;
  box-shadow: 0 6px 20px rgba(79, 131, 255, .25);
}
.btn.primary:hover { background: linear-gradient(180deg, #93b6ff, #5f8fff); color: #06101f; }

.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.ghost:hover { background: var(--panel-2); }

.btn.danger { color: var(--danger); }
.btn.danger:hover { background: rgba(255, 107, 107, .1); border-color: rgba(255, 107, 107, .35); }

.btn.wide { width: 100%; }

.icon {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 8px;
}
.icon:hover { background: var(--panel-2); color: var(--text); }

/* ---------- forms ---------- */

.field { display: grid; gap: 6px; }
.field > span { color: var(--muted); font-size: 13px; }

input, select {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  transition: border-color .15s ease, background .15s ease;
}
input:focus, select:focus { border-color: var(--accent); outline: none; background: #0c0e12; }
input::placeholder { color: #5f6874; }

.text-input { font-size: 13px; padding: 10px 12px; }

.stack { display: grid; gap: 14px; }
.form-grid { display: grid; gap: 14px; margin-top: 14px; }

.alert {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  border: 1px solid transparent;
}
.alert.error { background: rgba(255, 107, 107, .08); border-color: rgba(255, 107, 107, .3); color: #ffb3b3; }
.alert.ok { background: rgba(76, 214, 160, .08); border-color: rgba(76, 214, 160, .3); color: #9df0ce; }

/* ---------- auth ---------- */

.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(79, 131, 255, .16), transparent 65%),
    radial-gradient(700px 400px at 100% 100%, rgba(111, 155, 255, .06), transparent 60%),
    var(--bg);
}

.auth-card {
  width: min(390px, 100%);
  background: rgba(20, 23, 28, .88);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}
.auth-card .brand { justify-self: start; }
.auth-card .stack { margin-top: 4px; }

/* ---------- gallery ---------- */

.gallery {
  max-width: 1680px;
  margin: 0 auto;
  padding: 0 14px 40px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
}

.month {
  grid-column: 1 / -1;
  position: sticky;
  top: 64px;
  z-index: 5;
  padding: 26px 4px 10px;
  background: linear-gradient(180deg, var(--bg) 55%, rgba(10, 11, 13, 0));
  color: var(--text);
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.01em;
  text-transform: capitalize;
}

.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-2);
  cursor: pointer;
  isolation: isolate;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .35s cubic-bezier(.2, .7, .2, 1), opacity .3s ease;
  opacity: 0;
}
.tile img.loaded { opacity: 1; }
.tile:hover img { transform: scale(1.035); }

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .04);
  border-radius: 8px;
  pointer-events: none;
}

.tile.skeleton {
  background: linear-gradient(100deg, #15181d 30%, #1e232b 50%, #15181d 70%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite linear;
}

.tile .badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 11px;
  backdrop-filter: blur(6px);
  padding-left: 2px;
}

.tile.no-thumb::before {
  content: "◒";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #4a5260;
  font-size: 30px;
}

/* ---------- kind tabs ---------- */

.kind-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 18px 4px 6px;
}

.kind-tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 7px 15px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.kind-tab:hover { color: var(--text); background: var(--panel-2); }
.kind-tab[aria-selected="true"] {
  color: var(--text);
  background: var(--panel-2);
  border-color: rgba(111, 155, 255, .4);
}

/* ---------- file list ---------- */

.file-list { padding: 14px 0 20px; }

.file-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px minmax(120px, 220px) 170px;
  gap: 16px;
  align-items: center;
}

.file-sort {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 0 14px 12px;
}

.file-sort-label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-right: 2px;
}

.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0;
  padding: 4px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  line-height: 1.3;
  cursor: pointer;
}
.sort-btn:hover { color: var(--text); border-color: rgba(111, 155, 255, .45); }
.sort-btn[data-active="true"] {
  color: var(--text);
  background: var(--panel-2);
  border-color: rgba(111, 155, 255, .55);
}
.sort-btn[data-active="true"]::after { content: "↓"; font-size: 11px; }
.sort-btn[data-active="true"][data-dir="asc"]::after { content: "↑"; }

.file-row {
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.file-row:hover { background: var(--bg-soft); }

.file-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.file-row .file-ext { flex: none; }
.file-row .file-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.file-size,
.file-mime,
.file-date {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- file badge ---------- */

.file-ext {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 38px;
  padding: 0 9px;
  border-radius: 10px;
  border: 1px solid rgba(111, 155, 255, .3);
  background: rgba(111, 155, 255, .12);
  color: #a9c5ff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
}
.file-ext.big {
  min-width: 64px;
  height: 64px;
  border-radius: 16px;
  font-size: 15px;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ---------- empty / loader ---------- */

.empty {
  padding: 90px 20px 110px;
  text-align: center;
  display: grid;
  gap: 10px;
  justify-items: center;
}
.empty h1 { font-size: 26px; }
.empty p { max-width: 420px; margin: 0; }
.empty-art { font-size: 54px; color: #2f3742; line-height: 1; }
.empty .btn { margin-top: 10px; }

.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px;
  color: var(--muted);
  font-size: 14px;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.sentinel { height: 1px; }

/* ---------- drop zone ---------- */

.dropzone {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: rgba(6, 8, 12, .82);
  border: 2px dashed rgba(111, 155, 255, .8);
  color: #cfe0ff;
  font-size: 20px;
  font-weight: 600;
  backdrop-filter: blur(3px);
  pointer-events: none;
}

/* ---------- uploads panel ---------- */

.uploads {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 60;
  width: 360px;
  max-width: calc(100vw - 36px);
  background: rgba(20, 23, 28, .95);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  backdrop-filter: blur(12px);
}
.uploads header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.uploads header strong { font-weight: 600; }
#uploads-list { max-height: 240px; overflow: auto; }

.upload-row {
  display: grid;
  gap: 6px;
  padding: 9px 12px;
  border-bottom: 1px solid rgba(39, 44, 53, .6);
  font-size: 13px;
}
.upload-row:last-child { border-bottom: 0; }
.upload-row .upload-name {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}
.upload-row .upload-name span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-row .upload-name span:last-child { color: var(--muted); flex: none; }
.upload-row .track { height: 3px; border-radius: 99px; background: var(--line); overflow: hidden; }
.upload-row .track i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s ease; }
.upload-row.done .track i { background: var(--ok); }
.upload-row.failed .track i { background: var(--danger); }

/* ---------- viewer ---------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(4, 5, 7, .96);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(6px);
}

.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  flex: none;
}

.viewer-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.viewer-meta strong { font-size: 14px; font-weight: 600; }
.viewer-meta span {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 46vw;
}

.viewer-actions { display: flex; gap: 8px; flex: none; }
.viewer-actions .btn { padding: 7px 11px; font-size: 13px; background: rgba(20, 23, 28, .7); }

.viewer-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 0 72px 24px;
}
.viewer-stage img, .viewer-stage video {
  max-width: 100%;
  max-height: calc(100dvh - 120px);
  border-radius: 6px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
  background: #000;
}
.viewer-stage .note {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 23, 28, .9);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  color: var(--muted);
  font-size: 12px;
}
.viewer-stage .loading-note { color: var(--muted); display: flex; gap: 10px; align-items: center; }
.viewer-stage .note a { margin-left: 6px; }

.viewer-stage .file-stage {
  display: grid;
  justify-items: center;
  gap: 10px;
  max-width: 520px;
  padding: 28px;
  text-align: center;
}
.file-stage .file-name { font-size: 16px; font-weight: 600; word-break: break-word; }
.file-stage .file-meta { color: var(--muted); font-size: 13px; }
.file-stage .file-note { color: var(--muted); font-size: 12px; max-width: 420px; }

.nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 48px;
  height: 64px;
  border: 0;
  border-radius: 12px;
  background: rgba(20, 23, 28, .6);
  color: var(--text);
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s ease;
}
.nav:hover { background: rgba(40, 46, 56, .9); }
.nav.prev { left: 12px; }
.nav.next { right: 12px; }
.nav[disabled] { opacity: .18; cursor: default; }

/* ---------- dialog ---------- */

.dialog {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(4px);
}

.dialog-card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}
.dialog-card h2 { font-size: 18px; }
.dialog-card p { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: rgba(24, 28, 34, .96);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  animation: toast-in .18s ease-out;
  max-width: 90vw;
}
.toast.error { border-color: rgba(255, 107, 107, .45); color: #ffb3b3; }
.toast.ok { border-color: rgba(76, 214, 160, .4); color: #9df0ce; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- settings ---------- */

.settings {
  max-width: 760px;
  margin: 0 auto;
  padding: 34px 20px 60px;
  display: grid;
  gap: 18px;
}
.page-title { font-size: 28px; margin-bottom: 2px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
}
.card h2 { font-size: 17px; margin-bottom: 14px; }
.card p { margin: 0 0 8px; }

.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: 14px; }
.kv dd { margin: 0; font-size: 14px; font-weight: 550; }

.usage { margin-top: 18px; display: grid; gap: 8px; }
.usage-head { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 13px; }

progress.bar {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 8px;
  border: 0;
  border-radius: 99px;
  overflow: hidden;
  background: var(--line);
}
progress.bar::-webkit-progress-bar { background: var(--line); border-radius: 99px; }
progress.bar::-webkit-progress-value {
  background: linear-gradient(90deg, #5f8fff, #8fc0ff);
  border-radius: 99px;
}
progress.bar::-moz-progress-bar { background: linear-gradient(90deg, #5f8fff, #8fc0ff); border-radius: 99px; }

.sessions { list-style: none; margin: 12px 0 0; padding: 0; }
.session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-top: 1px solid rgba(39, 44, 53, .7);
}
.session-info { display: grid; gap: 2px; min-width: 0; }
.session-info strong { font-size: 14px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.site-footer { text-align: center; padding: 8px 20px 34px; font-size: 12px; }

/* ---------- share page ---------- */

.simple {
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(79, 131, 255, .1), transparent 65%),
    var(--bg);
}

.share-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.share-card {
  width: min(920px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.share-media {
  background: #000;
  display: grid;
  place-items: center;
  max-height: 72vh;
  min-height: 180px;
}
.share-media img, .share-media video {
  display: block;
  max-width: 100%;
  max-height: 72vh;
  object-fit: contain;
}
.share-meta { padding: 20px 22px 8px; display: grid; gap: 8px; justify-items: start; }
.share-meta h1 { font-size: 18px; word-break: break-word; }
.share-meta p { margin: 0; }
.share-card footer { padding: 12px 22px 20px; }
.share-card > h1, .share-card > p { padding: 26px; margin: 0; }

.share-media.is-file { background: var(--panel-2); }
.share-file {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 34px 24px;
  max-width: 100%;
}
.share-file-info { display: grid; gap: 4px; min-width: 0; }
.share-file-info h2 { font-size: 18px; word-break: break-word; }
.share-file-info p { margin: 0; }

/* ---------- responsive ---------- */

@media (max-width: 760px) {
  .topbar { height: 56px; padding: 0 12px; gap: 8px; }
  .brand { font-size: 15px; gap: 7px; }
  .brand-dot { width: 9px; height: 9px; }
  .quota-chip { display: none; }
  .topbar-actions { gap: 5px; }
  .topbar-actions .btn { padding: 7px 10px; font-size: 13px; }
  .gallery { padding: 0 6px 30px; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(106px, 1fr)); gap: 3px; }
  .month { top: 56px; font-size: 15px; padding: 20px 4px 8px; }
  .kind-tabs { padding: 12px 2px 2px; }
  .file-sort { padding: 0 8px 10px; gap: 6px; }
  .file-sort-label { font-size: 11px; }
  .sort-btn { padding: 4px 9px; font-size: 12px; }
  .file-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "main size" "main date";
    gap: 2px 12px;
    padding: 11px 8px;
  }
  .file-main { grid-area: main; }
  .file-size { grid-area: size; text-align: right; align-self: end; }
  .file-date { grid-area: date; text-align: right; align-self: start; }
  .file-mime { display: none; }
  .file-row .file-ext { min-width: 34px; height: 34px; padding: 0 7px; font-size: 11px; }
  .viewer-bar { padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
  .viewer-meta span { max-width: 70vw; }
  .viewer-actions { gap: 5px; flex-wrap: wrap; }
  .viewer-actions .btn { padding: 6px 9px; font-size: 12px; }
  .viewer-stage { padding: 0 8px 16px; }
  .viewer-stage img, .viewer-stage video { max-height: calc(100dvh - 150px); }
  .nav { display: none; }
  .uploads { left: 8px; right: 8px; bottom: 8px; width: auto; max-width: none; }
  .settings { padding: 22px 12px 50px; }
  .card { padding: 18px; }
  .kv { grid-template-columns: 100px 1fr; }
  .auth-card { padding: 24px; }
  .share-page { padding: 10px; }
  .share-card { border-radius: 14px; }
  .dialog-card { padding: 18px; }
}

@media (min-width: 1300px) {
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
  .tile, .tile::after { border-radius: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---------- AI filters ---------- */

.ai-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 2px;
}
.ai-chips { display: contents; }
.ai-chip[aria-pressed="true"] {
  color: var(--text);
  background: var(--panel-2);
  border-color: rgba(111, 155, 255, .55);
}
.ai-chip .ai-count { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.ai-status { color: var(--muted); font-size: 12px; margin-left: 4px; }
@media (max-width: 760px) {
  .ai-bar { padding: 2px 2px 0; gap: 5px; }
  .ai-chip { padding: 4px 9px; font-size: 12px; }
}

/* ---------- search ---------- */

.search-row { padding: 6px 4px 2px; }
.search-input {
  width: min(420px, 100%);
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
.search-input:focus { outline: none; border-color: rgba(111, 155, 255, .55); }

/* ---------- books ---------- */

.gallery-grid.books { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 18px 12px; padding-top: 14px; }
.book-tile {
  display: grid;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.book-cover {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 6px;
  overflow: hidden;
  background: linear-gradient(160deg, #26303f, #161a21);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .3s ease; }
.book-cover img.loaded { opacity: 1; }
.book-cover .book-plain {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #c9d3e3;
}
.book-format {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(10, 11, 13, .78);
  color: #dfe6f2;
  font: 700 10px/1.4 -apple-system, "Segoe UI", Roboto, sans-serif;
  letter-spacing: .06em;
}
.book-tile:hover .book-cover { outline: 1px solid rgba(111, 155, 255, .5); }
.book-title { font-size: 13px; font-weight: 600; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.book-author, .book-series { font-size: 12px; color: var(--muted); line-height: 1.3; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ---------- reader ---------- */

body.reader-page { display: flex; flex-direction: column; height: 100vh; height: 100dvh; margin: 0; background: #0f1115; }
.reader-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 8px 12px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
}
.reader-meta { display: grid; min-width: 0; flex: 1 1 200px; }
.reader-meta strong, .reader-meta span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.reader-meta span { font-size: 13px; }
.reader-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.reader-actions select {
  max-width: 220px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.reader-actions .btn { padding: 7px 11px; }
.reader-text {
  --reader-font: 19px;
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px 30vh;
  font: var(--reader-font)/1.65 Georgia, "PT Serif", "Times New Roman", serif;
  color: #e3e6ea;
  outline: none;
}
.reader-text > * { max-width: 40em; margin-left: auto; margin-right: auto; }
.reader-text p { margin-top: 0; margin-bottom: 0; text-indent: 1.5em; }
.reader-text p.v { text-indent: 0; padding-left: 2em; }
.reader-text p.q { text-indent: 0; padding-left: 2em; font-style: italic; color: #c9ced6; }
.reader-text h2, .reader-text h3, .reader-text h4, .reader-text h5 {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.3;
  margin-top: 1.6em;
  margin-bottom: .7em;
}
.reader-text h2 { font-size: 1.5em; }
.reader-text h3 { font-size: 1.25em; }
.reader-text h4, .reader-text h5 { font-size: 1.05em; }
.reader-text .sep { height: 1.2em; }
.reader-text figure { margin: 1em auto; text-align: center; }
.reader-text figure img { max-width: 100%; max-height: 80vh; height: auto; }
.reader-text .speaking { background: rgba(111, 155, 255, .16); border-radius: 4px; box-shadow: 0 0 0 4px rgba(111, 155, 255, .16); }
.reader-text .loader { font-family: inherit; }
@media (max-width: 760px) {
  .reader-actions select { max-width: 150px; }
  .reader-text { padding: 12px 14px 30vh; }
  .reader-bar .btn { padding: 6px 9px; font-size: 13px; }
}

/* ---------- selection ---------- */

.search-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.tile.selected img, .book-tile.selected .book-cover img { opacity: .72; }
.tile.selected::before, .book-tile.selected .book-cover::before {
  content: "✓";
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #0a0b0d;
  font-size: 13px;
  font-weight: 800;
}
.book-tile.selected { outline: none; }
.book-tile.selected .book-cover { outline: 3px solid var(--accent); }
.file-row.selected { background: rgba(111, 155, 255, .12); outline: none; }
body.selecting .tile, body.selecting .book-tile, body.selecting .file-row { cursor: copy; }
.select-bar {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 40;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  max-width: calc(100vw - 24px);
}
#select-btn[aria-pressed="true"] { border-color: rgba(111, 155, 255, .55); background: var(--panel-2); }

/* ---------- folders ---------- */

.folder-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 0 14px 10px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-width: 0; font-size: 15px; }
.crumb { border: 0; background: none; color: var(--accent); font: inherit; padding: 2px 4px; cursor: pointer; border-radius: 6px; }
span.crumb { color: var(--text); font-weight: 650; cursor: default; }
button.crumb:hover { background: var(--panel-2); }
.crumb-sep { color: var(--muted); }
.folder-row { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--line); }
.folder-open {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 11px 14px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.folder-open:hover { background: var(--panel); }
.folder-icon { width: 44px; text-align: center; font-size: 22px; }
.folder-row .icon { border: 0; background: none; color: var(--muted); font-size: 16px; padding: 8px 10px; cursor: pointer; border-radius: 8px; }
.folder-row .icon:hover { color: var(--text); background: var(--panel-2); }
.move-select {
  width: 100%;
  min-width: min(360px, 80vw);
  margin: 10px 0 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
.move-select option { padding: 6px 8px; }
