:root {
  /* dark is the default — no prefers-color-scheme, a data-theme="light" opt-in */
  --bg: #0f0f16;
  --bg-2: #16161f;
  --surface: #1e1e29;
  --surface-2: #262633;
  --border: #34343f;
  --text: #f0f0f5;
  --text-dim: #9c9cad;
  --brand: #8b7dff;
  --brand-ink: #14101f;
  --ok: #34d399;
  --radius: 14px;
  --frame-radius: 18px;
  --tile: #ffffff; /* backdrop behind favicons — always light so dark icons read */
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="light"] {
  --bg: #f2f2f7;
  --bg-2: #e9e9f0;
  --surface: #ffffff;
  --surface-2: #f4f4f8;
  --border: #dcdce4;
  --text: #1a1a22;
  --text-dim: #6b6b78;
  --brand: #6d5efc;
  --brand-ink: #ffffff;
  --tile: #f4f4f6;
}

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

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg-2), var(--bg));
  color: var(--text);
}
body { min-height: 100vh; display: flex; flex-direction: column; }

.sprite { position: absolute; width: 0; height: 0; }
.vi { width: 18px; height: 18px; display: block; }
.vi.lg { width: 26px; height: 26px; }

/* ---------- top bar ---------- */
.v-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 30; flex-wrap: wrap;
}
.v-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.v-logo {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(150deg, #8b7dff, #d76ad4 55%, #ff9d6c);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18); position: relative;
}
.v-logo::before, .v-logo::after { content: ""; position: absolute; border-radius: 3px; background: rgba(255, 255, 255, 0.92); }
.v-logo::before { inset: 8px 11px 12px 7px; }
.v-logo::after { inset: 6px 7px 14px 11px; background: rgba(255, 255, 255, 0.6); }
.v-logo.big { width: 56px; height: 56px; border-radius: 16px; }
.v-logo.big::before { inset: 15px 20px 22px 13px; }
.v-logo.big::after { inset: 11px 13px 26px 20px; }

.v-titles { min-width: 0; }
.v-titles h1 { font-size: 15px; margin: 0; font-weight: 680; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.v-titles p { margin: 0; font-size: 12px; color: var(--text-dim); }

.v-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.v-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink);
  border-radius: 10px; padding: 8px 12px; font: inherit; font-size: 12.5px; font-weight: 620;
  cursor: pointer; text-decoration: none;
}
.v-btn:hover { filter: brightness(1.07); }
.v-btn.ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.v-btn.ghost:hover { background: var(--surface-2); filter: none; }
.v-btn.icon-only { padding: 8px; }
.v-btn.icon-only[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.v-menu-wrap { position: relative; }
.v-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.5); padding: 6px; min-width: 240px;
  display: flex; flex-direction: column; gap: 2px;
}
.v-menu-check {
  display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px;
  font-size: 12.5px; color: var(--text-dim); cursor: pointer;
}
.v-menu-check input { margin-top: 2px; accent-color: var(--brand); }
.v-menu-item {
  width: 100%; text-align: left; background: transparent; border: 0; color: var(--text);
  font: inherit; font-size: 13px; padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
.v-menu-item:hover { background: var(--surface-2); }

/* selection bar */
.v-selbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 20px; border-bottom: 1px solid var(--border);
  background: var(--brand-soft, color-mix(in srgb, var(--brand) 14%, var(--surface)));
  position: sticky; top: 61px; z-index: 26;
}
.v-sel-count { font-weight: 700; font-size: 13px; margin-right: auto; }
.v-selbar .v-btn { font-size: 12.5px; padding: 7px 11px; }

/* card checkboxes in select mode */
.g-check, .bg-check {
  width: 18px; height: 18px; accent-color: var(--brand); flex: none; cursor: pointer;
}
.bg-check { position: absolute; top: 10px; left: 10px; z-index: 2; }
.bg-card { position: relative; }

/* view-mode tile menu */
.v-viewmenu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.5); padding: 8px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 280px;
}
.v-tile {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; min-height: 92px; padding: 12px 8px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 12.5px; font-weight: 620;
}
.v-tile:hover { border-color: color-mix(in srgb, var(--brand) 50%, var(--border)); }
.v-tile .ti { width: 26px; height: 26px; }
.v-tile .tl { display: inline-flex; align-items: baseline; gap: 4px; line-height: 1.2; }
.v-tile .tl em { font-style: italic; font-weight: 500; font-size: 10.5px; color: var(--text-dim); }
.v-tile .tc { position: absolute; top: 6px; right: 6px; width: 15px; height: 15px; color: var(--brand); opacity: 0; }
.v-tile[aria-checked="true"] { border-color: var(--brand); }
.v-tile[aria-checked="true"] .tc { opacity: 1; }

/* search bar */
.v-searchbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 61px; z-index: 25;
}
.v-searchbar .vi { color: var(--text-dim); flex: none; }
.v-searchbar input {
  flex: 1; min-width: 0; font: inherit; border: 0; background: transparent; color: var(--text);
  outline: none;
}
.v-searchbar button {
  border: 0; background: transparent; color: var(--text-dim); cursor: pointer; font-size: 15px; padding: 4px 6px;
}

/* ---------- error / locked ---------- */
.v-error:not([hidden]) {
  margin: auto; text-align: center; max-width: 440px; padding: 40px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.v-error h2 { margin: 4px 0 0; font-size: 18px; }
.v-error p { margin: 0; color: var(--text-dim); }
.v-unlock { display: flex; gap: 8px; margin-top: 8px; width: 100%; max-width: 340px; }
.v-unlock input {
  flex: 1; min-width: 0; font: inherit; border-radius: 10px; padding: 10px 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.v-unlock-err { color: #f0788f; }

/* ---------- slideshow ---------- */
.v-stage:not([hidden]) {
  flex: 1; display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  grid-template-rows: 1fr auto auto auto;
  align-items: center; gap: 10px 12px;
  padding: 22px clamp(10px, 3vw, 34px) 18px; max-width: 1120px; width: 100%; margin: 0 auto;
}
.v-nav {
  grid-row: 1; align-self: center; height: 56px; width: 44px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 12px; cursor: pointer; display: grid; place-items: center;
}
.v-nav:hover { background: var(--surface-2); }
.v-nav:disabled { opacity: 0.3; cursor: default; }
.v-nav.prev { grid-column: 1; }
.v-nav.next { grid-column: 3; }

.v-frame {
  grid-column: 2; grid-row: 1; margin: 0; width: 100%; height: min(68vh, 700px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--frame-radius);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.5);
  display: flex; flex-direction: column; overflow: hidden;
}
.v-frame-bar {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-bottom: 1px solid var(--border); background: var(--surface-2); flex: none;
}
.v-dots { display: inline-flex; gap: 5px; }
.v-dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--border); display: block; }
.v-frame-title {
  flex: 1; min-width: 0; font-size: 12.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-dim); text-align: center;
}
.v-open {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 620;
  color: var(--brand); text-decoration: none; padding: 4px 8px; border-radius: 7px;
}
.v-open:hover { background: var(--surface); }
.v-viewport {
  flex: 1; position: relative;
  background: repeating-linear-gradient(45deg, transparent 0 12px, color-mix(in srgb, var(--border) 30%, transparent) 12px 13px);
  overflow: auto;
}
.v-card {
  position: absolute; inset: 0; margin: auto; height: max-content; max-width: 460px; padding: 28px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
}
.v-card-mono {
  width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 24px; margin-bottom: 6px; position: relative; overflow: hidden;
}
.v-card-title { margin: 0; font-size: 17px; font-weight: 700; }
.v-card-host { margin: 0; color: var(--brand); font-size: 13px; font-weight: 600; }
.v-card-url {
  margin: 2px 0 0; color: var(--text-dim); font-size: 11.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; max-width: 100%;
}
.v-card-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; justify-content: center; }
.v-card-note { margin: 12px 0 0; font-size: 11px; color: var(--text-dim); line-height: 1.5; }
.v-embed { position: absolute; inset: 0; }
.v-embed iframe { width: 100%; height: 100%; border: 0; background: #fff; }

/* favicon tile — sits over the monogram, always on a light backdrop */
.v-fav {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: var(--tile); padding: 12%;
}

/* bottom nav row */
.v-counter {
  grid-column: 1 / -1; grid-row: 2;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.v-mini {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 9px; min-width: 34px; height: 34px; padding: 0 6px;
  display: inline-grid; place-items: center; cursor: pointer; font-size: 13px;
}
.v-mini:hover { background: var(--surface-2); }
.v-mini:disabled { opacity: 0.3; cursor: default; }
.v-count {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 14px; min-width: 72px; text-align: center;
  background: transparent; border: 0; color: var(--text); cursor: pointer; padding: 6px 8px; border-radius: 8px;
}
.v-count:hover { background: var(--surface); }
.v-jump {
  width: 84px; font: inherit; font-weight: 700; text-align: center;
  border: 1px solid var(--brand); border-radius: 8px; padding: 6px; background: var(--surface); color: var(--text);
}

/* segmented pager — centered, current only */
.v-segwrap { grid-column: 1 / -1; grid-row: 3; display: flex; justify-content: center; }
.v-seg { display: flex; gap: 4px; align-items: stretch; padding: 2px; width: 100%; max-width: 640px; }
.v-seg.dense { gap: 2px; }
.v-seg.packed { gap: 1px; }
.seg-i {
  flex: 1 1 0; min-width: 3px; height: 8px; border: 0; border-radius: 999px;
  background: var(--border); cursor: pointer; padding: 0;
}
.v-seg.packed .seg-i { border-radius: 2px; }
.seg-i.active { background: var(--brand); }
.seg-i:hover { filter: brightness(1.25); }

.v-footnote { grid-column: 1 / -1; grid-row: 4; margin: 0; font-size: 12px; color: var(--text-dim); text-align: center; }

/* ---------- generic pager ---------- */
.v-pager { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 0 32px; }

/* ---------- grid ---------- */
.v-grid {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 12px;
  padding: 22px clamp(12px, 4vw, 40px) 0; max-width: 1180px; width: 100%; margin: 0 auto;
}
.g-card {
  position: relative;
  width: 300px; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px;
  padding: 14px 40px 14px 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  text-decoration: none; color: var(--text);
}
.g-card:has(.g-check:not([hidden])) { grid-template-columns: auto auto 1fr; }
.g-card:hover { background: var(--surface-2); border-color: var(--brand); }
.g-mono {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 14px; flex: none; position: relative; overflow: hidden;
}
.g-meta { min-width: 0; display: flex; flex-direction: column; }
.g-title { font-weight: 620; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-host { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-corner {
  position: absolute; top: 10px; right: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.g-index { font-size: 11px; font-weight: 700; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.g-ext { width: 14px; height: 14px; display: block; color: var(--text-dim); }
.g-card:hover .g-ext { color: var(--brand); }
#state-grid:not([hidden]), #state-biggrid:not([hidden]) { flex: 1; display: flex; flex-direction: column; }

/* ---------- list ---------- */
.v-list:not([hidden]) {
  flex: 1; max-width: 900px; width: 100%; margin: 0 auto;
  padding: 22px clamp(12px, 4vw, 40px) 44px; display: flex; flex-direction: column; gap: 12px;
}
.v-list-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.v-list-hint { color: var(--text-dim); font-size: 12px; }
.v-list-ol {
  margin: 0; list-style: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 14px; font-size: 13px; color: var(--text);
}
.v-list-ol li {
  display: flex; align-items: baseline; gap: 12px;
  padding: 10px 2px; border-bottom: 1px solid var(--border);
}
.v-list-ol li:last-child { border-bottom: 0; }
.v-list-ol.selectable li { cursor: pointer; }
.v-list-ol.selectable li:hover { background: var(--surface-2); }
.li-check { flex: none; width: 16px; height: 16px; accent-color: var(--brand); align-self: center; cursor: pointer; }
.li-index {
  flex: none; color: var(--text-dim); font-weight: 700; font-size: 11px;
  font-variant-numeric: tabular-nums; padding-top: 1px;
  user-select: none; -webkit-user-select: none; /* keep it out of a Ctrl+C selection */
}
.li-meta { min-width: 0; flex: 1; }
.li-t { display: block; font-weight: 600; }
.li-u {
  display: block; color: var(--text-dim); font-size: 12px; text-decoration: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all;
}
.li-u:hover { color: var(--brand); text-decoration: underline; }

/* ---------- preview grid ---------- */
.v-biggrid {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 14px;
  padding: 22px clamp(12px, 4vw, 40px) 0; max-width: 1200px; width: 100%; margin: 0 auto;
}
.bg-card {
  width: 340px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  overflow: hidden; display: flex; flex-direction: column;
}
.bg-shot {
  height: 200px; position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 16px; text-align: center;
}
.bg-card.no-preview .bg-shot {
  background: repeating-linear-gradient(45deg, transparent 0 12px, color-mix(in srgb, var(--border) 35%, transparent) 12px 13px);
}
.bg-card.no-preview .bg-shot p { margin: 0; font-size: 11.5px; color: var(--text-dim); }
.bg-bigmono {
  width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 18px; position: relative; overflow: hidden;
}
.bg-frame { width: 100%; height: 100%; border: 0; background: #fff; }
.bg-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 12px; border-top: 1px solid var(--border); }
.bg-mono {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 12px; flex: none; position: relative; overflow: hidden;
}
.bg-meta { min-width: 0; display: flex; flex-direction: column; }
.bg-title {
  display: block; font-weight: 620; font-size: 13px; color: var(--text); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bg-title:hover { color: var(--brand); text-decoration: underline; }
.bg-host { font-size: 11.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bg-corner { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bg-index { font-size: 11px; font-weight: 700; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.bg-open { color: var(--text-dim); display: grid; place-items: center; padding: 2px; }
.bg-open:hover { color: var(--brand); }
.bg-view {
  border: 0; border-top: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 12px; font-weight: 600; padding: 9px; cursor: pointer;
}
.bg-view:hover { background: var(--surface); }

/* ---------- toast / footer ---------- */
.v-toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-weight: 600; font-size: 13px; z-index: 40; max-width: 90vw; text-align: center;
}
.v-source { text-align: center; padding: 20px 12px 28px; color: var(--text-dim); font-size: 11.5px; }
.v-source a { color: var(--text-dim); text-decoration: underline; }
/* leave a clear strip at the bottom on narrow screens so the fixed Ko-fi button
   never sits on top of the (centred) footer text */
@media (max-width: 640px) { .v-source { margin-bottom: 40px; } }

/* Ko-fi button — pinned to the bottom-right of the viewport, out of the way of
   the centred slideshow nav / pagers / toast (which sits centre-bottom at z 40). */
.v-kofi {
  position: fixed; right: 12px; bottom: 12px; z-index: 20;
  line-height: 0; border-radius: 12px;
  box-shadow: 0 6px 20px -6px rgba(0, 0, 0, 0.45);
  opacity: 0.8; transition: opacity .15s, transform .15s;
}
.v-kofi:hover, .v-kofi:focus-visible { opacity: 1; transform: translateY(-1px); }
.v-kofi img { display: block; width: 116px; height: auto; }
@media (max-width: 640px) {
  .v-kofi { right: 8px; bottom: 8px; opacity: 0.72; }
  .v-kofi img { width: 96px; }
}

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  .v-stage { grid-template-columns: 1fr; }
  .v-nav { display: none; }
  .v-frame { grid-column: 1; height: min(60vh, 540px); }
  .v-titles h1 { max-width: 56vw; }
  .v-tools .v-btn:not(.icon-only) span { display: none; }
  .v-tools .v-btn:not(.icon-only) { padding: 8px; }
  .v-searchbar { top: 105px; }
}
