:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f1f1f3;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-2: #52525b;
  --text-3: #8a8a93;
  --accent: #18181b;
  --accent-text: #ffffff;
  --danger: #c0362c;
  --danger-bg: #fdf0ef;
  --success: #1f7a4a;
  --success-bg: #ecf7f1;
  --ring: rgba(24, 24, 27, 0.16);
  --shadow: 0 1px 2px rgba(16, 16, 20, 0.04), 0 1px 3px rgba(16, 16, 20, 0.06);
  --shadow-lg: 0 12px 32px rgba(16, 16, 20, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e10;
    --surface: #17171a;
    --surface-2: #1f1f23;
    --border: #2a2a2f;
    --border-strong: #3a3a41;
    --text: #f4f4f5;
    --text-2: #b4b4bb;
    --text-3: #7c7c85;
    --accent: #f4f4f5;
    --accent-text: #111113;
    --danger: #f2766b;
    --danger-bg: #2a1614;
    --success: #5fd197;
    --success-bg: #12251b;
    --ring: rgba(244, 244, 245, 0.18);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; }

svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--text);
  font-size: 15px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
}
.brand-mark svg.i { width: 16px; height: 16px; stroke-width: 2; }

.nav {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.nav a, .nav button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: 8px;
  color: var(--text-2);
  text-decoration: none;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  background: none;
  border: 0;
  cursor: pointer;
}
.nav a:hover, .nav button:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--surface-2); color: var(--text); }
.nav form { margin: 0; }

@media (max-width: 560px) {
  .nav .lbl { display: none; }
  .nav a, .nav button { padding: 8px 10px; }
  .brand-name { display: none; }
}

/* ---------- Layout ---------- */

main {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 16px 64px;
}

main.narrow { max-width: 520px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-head > div { min-width: 0; }

h1 {
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: -0.02em;
  font-weight: 680;
  margin: 0;
  overflow-wrap: anywhere;
}

h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin: 36px 0 12px;
  font-weight: 600;
}

.sub { color: var(--text-2); margin: 4px 0 0; }
.dim { color: var(--text-3); font-size: 13px; margin: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 760px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

.footer {
  text-align: center;
  color: var(--text-3);
  font-size: 12px;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}

/* ---------- Cards & forms ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.card.center { align-items: center; text-align: center; }
.card-title { font-weight: 620; font-size: 15px; margin: 0; }

label.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 550;
  color: var(--text-2);
}

input[type=password], input[type=text], select {
  font: inherit;
  font-size: 16px; /* prevent iOS zoom */
  font-weight: 400;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px var(--ring);
  border-color: var(--text-3);
}

.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
}
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent); }

/* Drop zone */
.dropzone {
  position: relative;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 28px 16px;
  text-align: center;
  color: var(--text-2);
  transition: border-color .15s, background .15s;
  cursor: pointer;
}
.dropzone:hover, .dropzone.drag { border-color: var(--text-3); background: color-mix(in srgb, var(--surface-2) 60%, var(--border)); }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.dropzone .dz-icon {
  width: 44px; height: 44px; border-radius: 12px; margin: 0 auto 10px;
  display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border); color: var(--text);
}
.dropzone strong { display: block; color: var(--text); font-weight: 600; }
.dropzone .dz-files { margin-top: 8px; font-size: 13px; color: var(--text); font-weight: 550; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  min-height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, transform .1s, opacity .15s;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--bg)); }
.btn-block { width: 100%; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-icon { padding: 0; width: 36px; min-height: 36px; height: 36px; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }

.alert {
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); }

progress {
  width: 100%;
  height: 6px;
  border-radius: 99px;
  overflow: hidden;
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  background: var(--surface-2);
}
progress::-webkit-progress-bar { background: var(--surface-2); }
progress::-webkit-progress-value { background: var(--accent); border-radius: 99px; transition: width .2s; }
progress::-moz-progress-bar { background: var(--accent); }

/* ---------- Lists ---------- */

.list {
  list-style: none;
  padding: 0;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 10px; }
.list li + li { border-top: 1px solid var(--border); }
.list li.inactive .list-main { opacity: .5; }
.list form { margin: 0; }

.list-main {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: inherit;
  border-radius: 8px;
}
.list-text { min-width: 0; display: flex; flex-direction: column; }
.list-title { font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.thumb {
  width: 44px;
  height: 44px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  flex: none;
  overflow: hidden;
  display: grid;
  place-items: center;
  color: var(--text-3);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 560;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.badge-ok { background: var(--success-bg); color: var(--success); }

.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-3);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  font-size: 14px;
}
.empty .i { width: 28px; height: 28px; margin-bottom: 6px; }
.empty p { margin: 0; }

/* Folder cards */
.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.folder-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}
.folder-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.folder-cover {
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  color: var(--text-3);
}
.folder-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.folder-cover .i { width: 32px; height: 32px; stroke-width: 1.4; }
.folder-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.folder-body .list-title { display: flex; align-items: center; gap: 6px; }
.folder-body .list-title .i { width: 14px; height: 14px; color: var(--text-3); }

/* ---------- Share / QR ---------- */

.qr-wrap {
  background: #fff;
  border-radius: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  line-height: 0;
}
.qr { width: 200px; height: 200px; image-rendering: pixelated; }

.url-row { display: flex; gap: 8px; width: 100%; }
.url-row input { flex: 1; font-size: 14px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text-2); background: var(--surface-2); }

.stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }

/* ---------- Gallery ---------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

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

.tile {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  margin: 0;
  background: var(--surface-2);
  border-radius: 8px;
  overflow: hidden;
  cursor: zoom-in;
  display: block;
  width: 100%;
}
@media (max-width: 480px) { .tile { border-radius: 4px; } }
.tile img, .tile video { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s; }
.tile:hover img, .tile:hover video { transform: scale(1.03); }
.tile .tile-badge {
  position: absolute; left: 6px; bottom: 6px;
  background: rgba(0,0,0,.55); color: #fff; border-radius: 6px; padding: 3px 5px; line-height: 0;
}
.tile .tile-badge .i { width: 14px; height: 14px; }
.tile .generic {
  width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  color: var(--text-3); font-size: 12px; padding: 8px; overflow-wrap: anywhere; text-align: center;
}
.tile-actions { position: absolute; top: 6px; right: 6px; opacity: 0; transition: opacity .15s; }
.tile-wrap { position: relative; }
.tile-wrap:hover .tile-actions, .tile-wrap:focus-within .tile-actions { opacity: 1; }
@media (hover: none) { .tile-actions { opacity: 1; } }
.tile-actions button {
  width: 30px; height: 30px; border-radius: 8px; border: 0; cursor: pointer;
  background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center;
}
.tile-actions .i { width: 15px; height: 15px; }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8, 8, 10, 0.94);
  display: none; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  overscroll-behavior: contain;
}
.lightbox.open { display: flex; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.lb-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; color: #fff; }
.lb-bar .lb-name { flex: 1; min-width: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85; }
.lb-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 0; background: rgba(255,255,255,.1); color: #fff;
  display: grid; place-items: center; cursor: pointer; text-decoration: none; flex: none;
}
.lb-btn:hover { background: rgba(255,255,255,.18); }
.lb-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; padding: 0 8px 12px; }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); }
.lb-prev { left: 12px; }
.lb-next { right: 12px; }
@media (max-width: 560px) { .lb-nav { display: none; } }

/* ---------- Auth / centered pages ---------- */

.center-page {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px 64px;
}
.auth-card { width: 100%; max-width: 380px; }
.auth-icon {
  width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 4px;
  display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--border);
}
.auth-icon .i { width: 24px; height: 24px; }
.auth-card h1 { font-size: 21px; text-align: center; }
.auth-card .sub { text-align: center; margin-top: -8px; }
