:root {
  --bg: #0c0c0d;
  --bg-soft: #131314;
  --elev: #1a1a1c;
  --elev-2: #222225;
  --line: rgba(243, 239, 232, 0.08);
  --line-strong: rgba(243, 239, 232, 0.16);
  --text: #f3efe8;
  --muted: #9a948a;
  --faint: #6d6860;
  --accent: #e0b57a;
  --accent-2: #c4894a;
  --accent-soft: rgba(224, 181, 122, 0.14);
  --danger: #e07a7a;
  --danger-soft: rgba(224, 122, 122, 0.12);
  --ok: #86c49a;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --serif: "Fraunces", "Times New Roman", serif;
  --sans: "Plus Jakarta Sans", system-ui, sans-serif;
  --header: 64px;
  --nav: 68px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { color-scheme: dark; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }

#grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 80;
  opacity: 0.045;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

#app { min-height: 100%; }

.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 32px 20px calc(32px + var(--safe-bottom));
  background:
    radial-gradient(1000px 500px at 50% -10%, rgba(224, 181, 122, 0.16), transparent 55%),
    radial-gradient(700px 400px at 100% 100%, rgba(80, 50, 20, 0.25), transparent 50%),
    var(--bg);
}
.auth-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.015));
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 36px 28px 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.brand {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 28px;
  text-align: center;
}
.brand-mark {
  width: 44px;
  height: 44px;
  margin: 0 auto 8px;
}
.brand h1 {
  font-family: var(--serif);
  font-weight: 650;
  font-size: 42px;
  margin: 0;
  letter-spacing: -0.03em;
}
.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.field label { font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 13px 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 600;
  transition: transform 0.12s, background 0.12s, opacity 0.12s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(180deg, #edd0a0, var(--accent));
  color: #2a1c0c;
  width: 100%;
  padding: 14px;
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line-strong);
}
.btn-soft { background: var(--elev-2); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-accent { background: var(--accent-soft); color: var(--accent); }
.btn-sm { padding: 8px 12px; border-radius: 12px; font-size: 13px; }
.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 12px;
}

.shell { min-height: 100dvh; padding-bottom: calc(var(--nav) + var(--safe-bottom)); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--header);
  padding: calc(10px + var(--safe-top)) 18px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  overflow: visible;
}
.topbar h1, .topbar .title {
  font-family: var(--serif);
  font-size: 24px;
  margin: 0;
  letter-spacing: -0.03em;
}
.topbar .meta { color: var(--muted); font-size: 13px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.who {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  border-radius: 999px;
  background: var(--elev);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 12px;
}

.page { padding: 18px 16px 28px; max-width: 1280px; margin: 0 auto; }

.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 12px;
}
.folder-card {
  position: relative;
  display: block;
  border: 1px solid var(--line);
  background: var(--elev);
  border-radius: 20px;
  overflow: hidden;
  min-height: 180px;
  text-align: left;
  padding: 0;
  cursor: pointer;
  transition: transform 0.18s, border-color 0.18s;
}
.folder-card:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.folder-cover {
  height: 118px;
  background:
    linear-gradient(180deg, rgba(224,181,122,0.18), rgba(12,12,13,0.2)),
    var(--elev-2);
  overflow: hidden;
}
.folder-cover img { width: 100%; height: 100%; object-fit: cover; }
.folder-body { padding: 12px 14px 14px; }
.folder-body h3 { margin: 0 0 4px; font-size: 15px; font-weight: 650; }
.folder-body p { margin: 0; color: var(--muted); font-size: 12px; }
.folder-menu {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  background: rgba(12,12,13,0.55);
  color: #fff;
  display: grid;
  place-items: center;
  backdrop-filter: blur(8px);
}
.folder-menu svg { width: 18px; height: 18px; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 12px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--elev);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
}
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}
.photo {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--elev);
  border: 0;
  padding: 0;
}
.photo-grid.enter .photo {
  animation: rise 0.35s ease both;
}
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo.selected::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 3px var(--accent);
  background: rgba(224, 181, 122, 0.18);
}
.photo .tick {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.7);
  background: rgba(0,0,0,0.25);
  display: none;
}
.shell.root-mode .photo .tick { display: block; }
.photo.selected .tick {
  background: var(--accent);
  border-color: var(--accent);
}
.select-bar {
  position: sticky;
  top: calc(var(--header) + var(--safe-top) - 10px);
  z-index: 25;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 16px;
  margin: 0 -16px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.select-bar select {
  background: var(--elev);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 8px 10px;
}

.empty {
  text-align: center;
  padding: 64px 20px;
  color: var(--muted);
}
.empty h2 { font-family: var(--serif); color: var(--text); margin: 0 0 8px; font-weight: 500; }
.empty p { margin: 0 auto 18px; max-width: 360px; }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-auto-flow: column;
  gap: 4px;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(18px);
}
.tab {
  border: 0;
  background: transparent;
  color: var(--faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 600;
}
.tab.active { color: var(--accent); }
.tab svg { width: 22px; height: 22px; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(6,6,7,0.92);
  display: flex;
  flex-direction: column;
}
.lightbox-title {
  min-width: 0;
  padding-right: 12px;
}
.lightbox-title strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lightbox-actions { display: flex; gap: 8px; flex-shrink: 0; }
.lightbox-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: pan-y;
}
.lightbox-stage img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  padding: 8px;
  user-select: none;
  -webkit-user-drag: none;
}
.lightbox-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(10px + var(--safe-top)) 14px 14px;
  gap: 12px;
}
.lightbox-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 14px calc(16px + var(--safe-bottom));
}
.lightbox-nav .btn-accent { width: auto; padding: 12px 18px; }

.modal-back {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0,0,0,0.55);
  display: grid;
  place-items: end center;
}
.sheet {
  width: min(560px, 100%);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  padding: 18px 18px calc(20px + var(--safe-bottom));
  box-shadow: var(--shadow);
  max-height: min(92dvh, 820px);
  overflow: auto;
}
.sheet h2 { font-family: var(--serif); margin: 4px 0 16px; font-size: 28px; font-weight: 550; }
.drop {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 200px;
  margin-top: 8px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 18px;
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  background: rgba(255,255,255,0.015);
}
.drop input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.drop.hot { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.upload-status {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--elev);
}
.upload-status-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 15px;
}
.upload-status .meta { margin: 10px 0 0; word-break: break-all; }

.user-list { display: flex; flex-direction: column; gap: 10px; }
.user-card {
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
}
.user-card h3 { margin: 0 0 4px; font-size: 16px; }
.user-card p { margin: 0; color: var(--muted); font-size: 13px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--elev-2);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
}
.row-actions { display: flex; gap: 8px; margin-top: 12px; }

#toasts {
  position: fixed;
  top: calc(16px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(420px, calc(100% - 24px));
  pointer-events: none;
}
.toast {
  background: var(--elev-2);
  border: 1px solid var(--line-strong);
  padding: 12px 14px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  font-size: 14px;
}
.toast.err { border-color: rgba(224,122,122,0.4); color: #ffd4d4; }

.progress {
  height: 6px;
  background: var(--elev);
  border-radius: 99px;
  overflow: hidden;
  margin: 12px 0;
}
.progress > span { display: block; height: 100%; background: var(--accent); width: 0%; transition: width 0.15s; }

.menu {
  position: relative;
}
.menu-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 180px;
  background: var(--elev-2);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 6px;
  box-shadow: var(--shadow);
  z-index: 50;
}
.menu-pop button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text);
}
.menu-pop button:hover { background: rgba(255,255,255,0.05); }

.hidden { display: none !important; }
.err-text { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 10px; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@media (min-width: 720px) {
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
  .photo { border-radius: 12px; }
  .folder-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
  .folder-card { min-height: 220px; }
  .folder-cover { height: 148px; }
  .modal-back { place-items: center; }
  .sheet { border-radius: 24px; border-bottom: 1px solid var(--line); }
  .tabbar { display: none; }
  .shell { padding-bottom: 24px; }
  .desktop-nav { display: flex !important; }
}

.desktop-nav { display: none; gap: 6px; }
.desktop-nav .tab {
  flex-direction: row;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 12px;
  color: var(--muted);
}
.desktop-nav .tab.active { background: var(--accent-soft); color: var(--accent); }

#drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 65;
  background: rgba(12,12,13,0.72);
  display: none;
  place-items: center;
  color: var(--accent);
  font-family: var(--serif);
  font-size: clamp(22px, 4vw, 36px);
  pointer-events: none;
  letter-spacing: -0.03em;
}
body.dragging #drop-overlay { display: grid; }
body.dragging .drop {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
