:root {
  --side: clamp(48px, 7vw, 160px);      /* left/right margin = the click zones with the arrows */
  --vgap: clamp(16px, 4vh, 48px);       /* top/bottom margin around the image only */
  --fg: #e6e6e6;
  --muted: #8a8a8a;
  --faint: #555;
  --accent: #f5c518;
  --danger: #e5484d;
  --panel: rgba(18, 18, 18, 0.96);
  --border: #2a2a2a;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--fg);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: inherit; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
/* touch: no 300 ms tap delay and no double-tap zoom (pinch zoom stays); no pull-to-refresh / rubber band */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
html, body.viewer { overscroll-behavior: none; }

/* ------------------------------------------------------------------ login */
body.login { display: flex; align-items: center; justify-content: center; min-height: 100%; }
.login-box {
  display: flex; flex-direction: column; gap: 12px; width: min(320px, 86vw);
  padding: 28px 24px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
}
.login-box h1 { margin: 0 0 6px; font-size: 20px; font-weight: 600; text-align: center; }
.login-box input {
  background: #0c0c0c; border: 1px solid var(--border); border-radius: 6px; padding: 10px; outline: none;
  font-size: 16px;                  /* 16px: iOS does not zoom into the field */
}
.login-box input:focus { border-color: #555; }
.login-box .btn { padding: 10px; }
.login-msg { color: #ffb4b4; font-size: 13px; text-align: center; }

/* ------------------------------------------------------------------ viewer */
body.viewer { overflow: hidden; user-select: none; }

#stage {
  position: fixed;
  top: var(--vgap); bottom: var(--vgap);
  left: var(--side); right: var(--side);
  display: flex; align-items: center; justify-content: center;
}
#stage img, #stage video {
  display: block;
  width: 100%; height: 100%;
  object-fit: contain;              /* fit the window proportionally, centred */
  /* default: never more than 2x the original size (viewer.js sets --maxw/--maxh = 2 x natural size) */
  max-width: var(--maxw, 100%); max-height: var(--maxh, 100%);
  cursor: zoom-in;
}
/* the limits themselves are set by viewer.js: 2x (default), none = fill the window (full-fit), 1x (natural) */
body.full-fit #stage img, body.full-fit #stage video { cursor: zoom-out; }
#msg { color: var(--muted); font-size: 16px; text-align: center; padding: 24px; }

.nav {
  position: fixed; top: 0; bottom: 0;
  width: var(--side);
  display: flex; align-items: center; justify-content: center;
  padding: 0; border: 0; background: transparent;
  color: #fff; opacity: 0.16;
  font-size: clamp(30px, 3.6vw, 60px); line-height: 1;
  cursor: pointer;
  transition: opacity 0.15s, background-color 0.15s;
}
@media (hover: hover) {                 /* a tap must not leave the zone lit (touch screens) */
  .nav:hover { opacity: 0.85; background: rgba(255, 255, 255, 0.035); }
}
#spin {
  position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border: 3px solid rgba(255, 255, 255, 0.15); border-top-color: rgba(255, 255, 255, 0.7); border-radius: 50%;
  animation: spin 0.8s linear infinite; pointer-events: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
#stage { position: fixed; }
.nav:focus-visible { outline: 1px solid var(--faint); outline-offset: -4px; }
.nav:disabled { opacity: 0; cursor: default; background: transparent; }
.nav-left { left: 0; }
.nav-right { right: 0; }

#hud {
  position: fixed; left: var(--side); right: var(--side); bottom: 0;
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; justify-content: center;
  padding: 18px 12px 8px;
  font-size: 12px; color: var(--muted);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
#folderbar {
  position: fixed; left: var(--side); right: var(--side); top: 0;
  display: flex; gap: 14px; align-items: center; justify-content: center;
  padding: 8px 12px 18px;
  font-size: 13px; color: var(--fg);
  background: linear-gradient(rgba(0, 0, 0, 0.75), transparent);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
body.show-ui #hud, body.show-ui #folderbar, body.pinned-ui #hud, body.pinned-ui #folderbar {
  opacity: 1; pointer-events: auto;
}
#folderbar .fname { color: var(--accent); font-weight: 600; }
#folderbar .note { color: var(--danger); }
#hud a, #folderbar a { color: var(--fg); text-decoration: none; }
#hud a:hover, #folderbar a:hover { text-decoration: underline; }
#hud .sep { color: var(--faint); }
.hud-btn {
  border: 1px solid var(--border); background: rgba(0, 0, 0, 0.4);
  border-radius: 6px; padding: 2px 9px; cursor: pointer; color: var(--fg);
}
.hud-btn:hover { border-color: #444; }

#scale-mode {
  position: fixed; left: 10px; top: 10px; z-index: 3;
  display: flex; align-items: center; gap: 5px;
  padding: 4px 7px; border: 1px solid transparent; border-radius: 6px;
  background: rgba(0, 0, 0, 0.35); color: var(--fg);
  font-size: 11px; line-height: 1; opacity: 0.4; cursor: pointer;
  transition: opacity 0.15s, border-color 0.15s;
}
#scale-mode:hover { opacity: 1; border-color: #444; }
#scale-mode svg { width: 16px; height: 16px; display: block; }

#star-mark {
  position: fixed; right: 12px; top: 8px; z-index: 3;     /* very corner, like the scaling icon on the left */
  color: var(--accent); font-size: 18px; opacity: 0.7; pointer-events: none;
}

.pop {
  position: fixed; right: calc(var(--side) + 8px); bottom: 48px;
  min-width: 260px; max-width: min(360px, 80vw); max-height: 70vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; z-index: 10; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  user-select: text;
}
.pop-title { font-weight: 600; margin-bottom: 8px; }
.pop-hint { color: var(--muted); font-size: 12px; margin-top: 8px; }
#fav-list { list-style: none; margin: 0 0 10px; padding: 0; }
#fav-list li label {
  display: flex; align-items: center; gap: 8px; padding: 5px 4px; border-radius: 5px; cursor: pointer;
}
#fav-list li label:hover { background: rgba(255, 255, 255, 0.05); }
#fav-list .count { margin-left: auto; color: var(--muted); font-size: 12px; }
#fav-list .def { color: var(--accent); font-size: 11px; }
.row-form { display: flex; gap: 6px; }
.row-form input {
  flex: 1; min-width: 0; background: #0c0c0c; border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 8px; outline: none;
}
.row-form input:focus { border-color: #555; }
.row-form button, .btn {
  background: #1d1d1d; border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; cursor: pointer;
}
.row-form button:hover, .btn:hover { border-color: #555; }
#help-pop { bottom: auto; top: 50%; right: 50%; transform: translate(50%, -50%); }
#help-pop table { border-collapse: collapse; }
#help-pop td { padding: 3px 10px 3px 0; vertical-align: top; }
#help-pop kbd {
  display: inline-block; min-width: 22px; text-align: center; padding: 1px 6px;
  border: 1px solid #444; border-bottom-width: 2px; border-radius: 4px; font: 12px ui-monospace, monospace;
}
#goto-pop { bottom: auto; top: 50%; right: 50%; transform: translate(50%, -50%); }

#toast {
  position: fixed; left: 50%; top: 18px; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--border); border-radius: 20px;
  padding: 6px 16px; z-index: 20; font-size: 13px;
}
#toast.err { border-color: var(--danger); color: #ffb4b4; }

/* ------------------------------------------------------------------ favourites pages */
body.fav { min-height: 100%; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
  padding: 14px 24px; background: rgba(0, 0, 0, 0.92); border-bottom: 1px solid #151515;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.topbar .sub { color: var(--muted); }
.topbar a { color: var(--muted); text-decoration: none; }
.topbar a:hover { color: var(--fg); }
.topbar .logout { margin-left: auto; font-size: 12px; padding: 4px 10px; }
#content { padding: 20px 24px 48px; }

.folders {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
.card {
  background: #0b0b0b; border: 1px solid #1b1b1b; border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column;
}
.card .cover {
  display: block; aspect-ratio: 1 / 1; background: #111 center / cover no-repeat;
  text-decoration: none;
}
.card .cover.empty { display: flex; align-items: center; justify-content: center; color: var(--faint); font-size: 40px; }
.card .body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.card .name { font-weight: 600; word-break: break-word; }
.card .meta { color: var(--muted); font-size: 12px; display: flex; gap: 8px; align-items: center; }
.card .badge { color: var(--accent); }
.card .actions { display: flex; gap: 6px; }
.card .actions button {
  background: #161616; border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; cursor: pointer; font-size: 12px;
}
.card .actions button:hover:not(:disabled) { border-color: #555; }
.card .actions button:disabled { opacity: 0.35; cursor: not-allowed; }
.card .actions .del:hover:not(:disabled) { border-color: var(--danger); color: #ffb4b4; }
.card.new .body { justify-content: center; height: 100%; min-height: 120px; }
.card .rename input { width: 100%; }

.gallery {
  display: grid; gap: 6px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.tile {
  position: relative; display: block; aspect-ratio: 1 / 1; background: #0d0d0d; overflow: hidden;
  border-radius: 4px; outline: 2px solid transparent; outline-offset: -2px;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.2s; }
.tile:hover img { transform: scale(1.04); }
.tile .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 6px; font-size: 11px; color: #ccc;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.8)); opacity: 0; transition: opacity 0.15s;
}
.tile:hover .cap { opacity: 1; }
.tile.last { outline-color: var(--accent); }
.tile.missing { display: flex; align-items: center; justify-content: center; color: var(--faint); font-size: 12px; }
.empty-note { color: var(--muted); padding: 40px 0; text-align: center; }
#sentinel { height: 1px; }
