:root {
  --bg0: #0d0f12;              /* deepest surface — thumb wells, viewer/reader bg */
  --bg: #14161a;
  --bg2: #1c1f26;
  --fg: #e6e8ec;
  --muted: #9aa3b2;
  --accent: #4c8dff;
  --flash: 232, 240, 255;      /* back/forward flash — crisp cool-white ring */
  --flash-glow: 92, 150, 255;  /* …with a vivid blue halo for depth (RGB; alpha per use) */
  --tile: #20242c;
  --tile-hover: #2a2f39;
  --thumb: 180px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg2);
  border-bottom: 1px solid #000;
}
.crumbs {
  flex: 1 1 240px;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  overflow: hidden;
}
.crumbs a, .crumbs span {
  color: var(--muted);
  text-decoration: none;
  padding: 2px 4px;
  border-radius: 4px;
  white-space: nowrap;
}
.crumbs a:hover { background: var(--tile-hover); color: var(--fg); }
.crumbs .sep { color: #555; padding: 0; }
.crumbs .cur { color: var(--fg); font-weight: 600; }

.controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.btn, select {
  background: var(--tile);
  color: var(--fg);
  border: 1px solid #333;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font: inherit;
}
.btn:hover, select:hover { background: var(--tile-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.active { outline: 2px solid var(--accent); }
.chk { color: var(--muted); display: flex; align-items: center; gap: 4px; cursor: pointer; user-select: none; }

/* ---------- Grid ---------- */
.view.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--thumb), 1fr));
  gap: 10px;
  padding: 12px;
}
.tile {
  display: flex;
  flex-direction: column;
  background: var(--tile);
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  color: var(--fg);
  cursor: pointer;
}
.tile:hover { background: var(--tile-hover); }
.tile .thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg0);
  font-size: 48px;
  overflow: hidden;
}
.tile .thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.tile .thumb.failed img { display: none; }
.tile .thumb.failed::after { content: "🖼"; font-size: 40px; opacity: .4; }
/* Folder cover: show 📁 by default; the loaded cover (an absolutely-positioned img,
   so it paints over the static ::after glyph) fades in on top. On error the img
   removes itself, leaving the 📁. */
.tile .thumb.dir::after { content: "📁"; }
.tile .thumb.dir img {
  position: absolute;
  inset: 0;
  object-fit: cover;
  opacity: 0;
  transition: opacity .15s;
}
.tile .thumb.dir.covered img { opacity: 1; }
.tile .badge {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  color: #fff;
  text-shadow: 0 1px 6px #000;
  pointer-events: none;
}
.tile .name {
  padding: 6px 8px;
  font-size: 12px;
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
/* When a scraper-DB label is present, stack label (clamped) over the raw ID.
   Unlabeled tiles keep the plain -webkit-box clamp above, untouched. */
.tile .name:has(.label) {
  display: block;
  -webkit-line-clamp: initial;
}
.tile .name .label {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-weight: 600;
}
.subname {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Meta line under the name (size · date). margin-top:auto pins it to the bottom of
   the tile so the value lines up across a row regardless of name length. */
.tile .meta2 {
  margin-top: auto;
  padding: 2px 8px 6px;
  font-size: 11px;
  color: var(--muted);
}

/* ---------- List view ---------- */
.view.list { padding: 8px 12px; display: flex; flex-direction: column; }
.view.list .row {
  display: grid;
  grid-template-columns: 40px 1fr 110px 160px;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-bottom: 1px solid #23262d;
  text-decoration: none;
  color: var(--fg);
}
.view.list .row:hover { background: var(--tile-hover); }
.view.list .row .ic { font-size: 22px; text-align: center; }
.view.list .row .nm { word-break: break-all; min-width: 0; }
.view.list .row .nm .label { font-weight: 600; }
.view.list .row .meta { color: var(--muted); font-size: 12px; text-align: right; }

/* Briefly flashed on back/forward to mark the entry you'd gone into from here.
   A white-cored ring with a blue halo (two hues give it depth — plain white read
   flat). Only the alpha fades, so both layers ease away cleanly with no abrupt
   drop; the class is removed after, reverting each view to its resting style. */
@keyframes fb-justleft {
  0%, 30% {
    box-shadow: 0 0 0 2px rgba(var(--flash), .85), 0 0 22px 4px rgba(var(--flash-glow), .45);
  }
  100% {
    box-shadow: 0 0 0 2px rgba(var(--flash), 0), 0 0 22px 4px rgba(var(--flash-glow), 0);
  }
}
.tile.justleft, .view.list .row.justleft {
  /* Duration is paired with app.js's class-removal timer (2300ms in highlightReturn);
     that timer must stay >= this so the fade isn't cut off. Update both together. */
  animation: fb-justleft 2.2s ease-out;
  border-radius: 8px;
  position: relative;
  z-index: 1;
}

/* ---------- Status ---------- */
.status { padding: 40px; text-align: center; color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Lightbox ---------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 9, 11, .97);
  display: flex;
  align-items: center;
  justify-content: center;
}
.viewer .stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.viewer .stage img,
.viewer .stage video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}
/* Prevent the browser's native image-drag ghost (cursor is set in JS by zoom). */
.viewer .stage img {
  user-select: none;
  -webkit-user-drag: none;
}
.viewer .stage audio { width: min(90vw, 480px); }
.vbtn {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.4);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
  padding: 10px 14px;
  text-decoration: none;
  user-select: none;
}
.vbtn:hover { background: rgba(0,0,0,.7); }
/* Prev/next: bigger hit area + a faint light fill so they read against the
   near-black backdrop without being loud (no border, slightly dimmed). */
.vbtn.prev, .vbtn.next {
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 88px;
  font-size: 40px;
  background: rgba(255, 255, 255, .07);
}
.vbtn.prev { left: 12px; }
.vbtn.next { right: 12px; }
.vbtn.prev:hover, .vbtn.next:hover { background: rgba(255, 255, 255, .16); }
/* at the first/last item the matching arrow dims (click clamps to a no-op) */
.vbtn.disabled { opacity: .2; cursor: default; }
.vbtn.disabled:hover { background: rgba(255, 255, 255, .07); }
.vbtn.close { right: 12px; top: 12px; }
.vbtn.dl { right: 64px; top: 12px; }
.vinfo {
  position: absolute;
  left: 12px; top: 12px;
  background: rgba(0,0,0,.4);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  max-width: 60vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Text viewer ---------- */
.textviewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: var(--bg0);
}
.tvbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg2);
  border-bottom: 1px solid #000;
}
.tvname { font-weight: 600; word-break: break-all; }
.tvspacer { flex: 1; }
.tvbody {
  flex: 1;
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font: 13px/1.5 ui-monospace, "Cascadia Code", Consolas, "D2Coding", monospace;
  color: #d7dbe2;
  tab-size: 4;
}

/* ---------- Reader (전부 펼치기) ---------- */
.view.reader {
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg0);
}
.view.reader .reader-bar {
  position: sticky;
  top: 0;
  width: 100%;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: rgba(20,22,26,.9);
  color: var(--muted);
  z-index: 5;
}
.view.reader img {
  display: block;
  width: 67.5vw;
  height: auto;
  margin: 0 auto;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  :root { --thumb: 130px; }
  .vbtn.prev, .vbtn.next { width: 46px; height: 76px; font-size: 32px; }
}
