:root {
  --bg: #121212;
  --bg-soft: #1e1e1e;
  --card: #262626;
  --text: #f0f0f0;
  --muted: #9a9a9a;
  --accent: #3fa9f5;
  --danger: #f5545a;
  --border: #333;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

.screen { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- LOGIN ---------- */
#login { align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--bg-soft);
  border: 1px solid var(--border); border-radius: 16px; padding: 28px 24px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { margin: 0; font-size: 26px; text-align: center; }
.login-card .sub { margin: 0; text-align: center; color: var(--muted); }

input[type=text], input[type=password] {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  font-size: 16px;
}
input:focus { outline: none; border-color: var(--accent); }

.btn {
  border: none; border-radius: 10px; padding: 12px 16px; font-size: 16px;
  cursor: pointer; color: var(--text); background: var(--card);
}
.btn.primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn.full { width: 100%; }

.error { color: var(--danger); font-size: 14px; padding: 4px 2px; }

/* ---------- TOP BAR ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg-soft); border-bottom: 1px solid var(--border);
}
.breadcrumb { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; }
.crumb {
  display: flex; align-items: center;
  overflow-x: auto; overflow-y: hidden; white-space: nowrap;
  flex: 1; min-width: 0;
  scrollbar-width: none; -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}
.crumb::-webkit-scrollbar { display: none; }
.crumb .seg { flex: none; color: var(--muted); font-size: 15px; cursor: pointer; padding: 2px 2px; }
.crumb .seg.lvl { color: var(--text); font-weight: 600; }
.crumb .sep { color: var(--muted); margin: 0 2px; }

.top-actions { display: flex; gap: 8px; }
.icon-btn {
  background: var(--card); border: none; color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; font-size: 18px; cursor: pointer;
}
#back-btn { font-size: 26px; line-height: 1; }
.icon-btn.close { width: 40px; height: 40px; font-size: 20px; }

/* ---------- GRID ---------- */
#content { flex: 1; }
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 3px; padding: 3px; background: #fff;
}
.cell { position: relative; aspect-ratio: 1/1; overflow: hidden; background: #fff; cursor: pointer; }
.cell.folder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; background: var(--bg-soft); border: 1px solid var(--border);
  overflow: hidden; padding: 10px 4px 14px 4px;
}
.cell.folder .folder-icon { width: 74%; color: var(--accent); display:flex; align-items:center; justify-content:center; flex: 1; min-height: 0; }
.cell.folder .mac-folder, .list-row.folder .mac-folder { width: 100%; height: 100%; display:block; }
.cell.folder .folder-name {
  font-size: 12px; color: var(--text); max-width: 92%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cell img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.cell .video-badge {
  position: absolute; bottom: 6px; right: 6px; background: rgba(0,0,0,.55);
  padding: 2px 6px; border-radius: 6px; font-size: 10px; color: #fff;
}
.cell .vid-icon {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; background: rgba(0,0,0,.3);
}
.cell .vid-icon span { width: 52px; height: 52px; border-radius: 50%; background: rgba(0,0,0,.5); display:flex; align-items:center; justify-content:center; font-size: 24px; }
.cell .ph { position:absolute; inset:0; display:flex; align-items:center; justify-content:center; color:var(--muted); font-size: 30px; }

/* Skeleton placeholder shown while the first page of a directory loads. */
.cell.skeleton {
  background: linear-gradient(100deg, #d6d6d6 40%, #e2e2e2 50%, #d6d6d6 60%);
  background-size: 200% 100%;
  border-radius: 4px;
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer {
  to { background-position: -200% 0; }
}

/* ---------- LIST ---------- */
.list { padding: 6px; }
.list-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 6px;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.list-row .thumb { width: 60px; height: 60px; object-fit: cover; border-radius: 8px; background: var(--card); flex: none; }
.list-row .meta { flex: 1; min-width: 0; }
.list-row .name { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.list-row .type-badge { font-size: 11px; color: var(--accent); border: 1px solid var(--accent); border-radius: 6px; padding: 1px 6px; flex: none; }
.list-row.folder .flder-icon { width: 44px; height: 44px; flex: none; display:flex; align-items:center; justify-content:center; }

/* ---------- SENTINEL ---------- */
.sentinel { display: flex; flex-direction: column; align-items: center; padding: 20px; min-height: 40px; }
#end-msg { color: var(--muted); font-size: 13px; }
.spinner {
  width: 26px; height: 26px; border: 3px solid var(--card); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- THUMBNAIL SCREEN: WHITE THEME (scoped to #app only) ---------- */
#app { background: #fff; }
#app .topbar { background: #fff; border-bottom: 1px solid #e5e5e5; }
#app .crumb .seg { color: #888; }
#app .crumb .seg.lvl { color: #111; }
#app .crumb .sep { color: #bbb; }
#app .icon-btn { background: #f2f2f2; color: #222; }
#app .cell.folder { background: #f7f7f7; border-color: #e5e5e5; }
#app .cell.folder .folder-name { color: #222; }
#app .cell .ph { color: #bbb; }
#app .list-row { border-bottom-color: #eee; }
#app .list-row .thumb { background: #f2f2f2; }
#app .list-row .name { color: #222; }
#app .list-row .sub { color: #888; }
#app #end-msg { color: #999; }
#app .spinner { border-color: #eee; border-top-color: var(--accent); }

/* ---------- SHEET ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--bg-soft); border-radius: 18px 18px 0 0; padding: 18px 20px calc(18px + env(safe-area-inset-bottom));
  animation: sheetUp .25s ease;
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-title { font-size: 17px; font-weight: 600; margin-bottom: 12px; }
.row-btn {
  width: 100%; text-align: left; background: none; border: none; color: var(--text);
  padding: 14px 4px; font-size: 16px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.row-btn:last-child { border-bottom: none; color: var(--danger); }
.row-btn[data-no-danger] { color: var(--text); }

/* ---------- MENU SHEET: refined light style (scoped to #menu-sheet) ---------- */
#menu-sheet .sheet-body {
  background: #fff;
  box-shadow: 0 -6px 28px rgba(0,0,0,.18);
}
#menu-sheet .sheet-body::before {
  content: ""; display: block; width: 36px; height: 4px;
  background: #e0e0e0; border-radius: 2px; margin: 0 auto 16px;
}
#menu-sheet .sheet-title {
  color: #9a9a9a; font-size: 12px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; margin-bottom: 6px;
}
#menu-sheet .row-btn {
  color: #444; border-bottom: 1px solid #eee;
  padding: 15px 4px; font-size: 16px; transition: background .15s;
}
#menu-sheet .row-btn:active { background: #f5f5f5; }
#menu-sheet .row-btn:last-child {
  color: var(--danger); border-bottom: none;
  margin-top: 6px; padding-top: 17px; border-top: 6px solid #f4f4f4;
}

/* ---------- PASSWORD SHEET: refined light style (scoped to #pw-sheet) ---------- */
#pw-sheet .sheet-body {
  background: #fff;
  box-shadow: 0 -6px 28px rgba(0,0,0,.18);
}
#pw-sheet .sheet-body::before {
  content: ""; display: block; width: 36px; height: 4px;
  background: #e0e0e0; border-radius: 2px; margin: 0 auto 16px;
}
#pw-sheet .sheet-title {
  color: #9a9a9a; font-size: 12px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; margin-bottom: 14px;
}
#pw-form { display: flex; flex-direction: column; gap: 12px; }
#pw-sheet input[type=password] {
  background: #f5f5f5; border: 1px solid #e6e6e6; color: #333;
}
#pw-sheet input[type=password]::placeholder { color: #a8a8a8; }
#pw-sheet input:focus { border-color: var(--accent); background: #fff; }

/* ---------- VIEWER ---------- */
.viewer { position: fixed; inset: 0; background: #000; z-index: 40; overflow: hidden; touch-action: none; }
.viewer-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px; padding: 12px; justify-content: space-between;
  background: linear-gradient(rgba(0,0,0,.5), transparent);
}
.viewer-top .icon-btn { background: rgba(255,255,255,.18); color: #fff; }
.counter { color: #fff; font-size: 14px; background: rgba(0,0,0,.4); border-radius: 12px; padding: 4px 10px; }
.viewer-stage { width: 100%; height: 100%; position: relative; overflow: hidden; }
.viewer-stage img, .viewer-stage video {
  width: 100%; height: 100%; object-fit: contain; display: block;
}
.viewer-nav {
  position: absolute; bottom: 14px; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-between; padding: 0 10px;
}
.nav-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.18); color: #fff; font-size: 24px; cursor: pointer;
}
.nav-btn:disabled { opacity: .35; }

.exif-float {
  position: absolute; right: 18px; bottom: 70px; z-index: 6;
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(255,255,255,.18); color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}

#download-btn {
  background: rgba(255,255,255,.18); color: #fff;
}

/* ---------- EXIF ---------- */
.exif-content {
  max-height: 60vh; overflow: auto; font-size: 14px;
  scrollbar-width: none; -ms-overflow-style: none;
}
.exif-content::-webkit-scrollbar { display: none; }
.exif-content table { width: 100%; border-collapse: collapse; }
.exif-content td { padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.exif-content td:first-child { color: var(--muted); white-space: nowrap; width: 40%; }

/* Fixed: was ".exif-sheet" (a class selector) but the element only has id="exif-sheet",
   so this rule never matched and the panel stayed opaque. Now targets the id. */
#exif-sheet .sheet-backdrop { background: rgba(0,0,0,.25); }
#exif-sheet .sheet-body {
  max-height: 70vh; overflow: hidden; display: flex; flex-direction: column;
  background: rgba(30,30,30,.25);
  -webkit-backdrop-filter: blur(20px) saturate(1.4); backdrop-filter: blur(20px) saturate(1.4);
}

@media (min-width: 760px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

@media (max-width: 759px) {
  .viewer-top .icon-btn.close { display: none; }
  .viewer-nav { display: none; }
}