:root {
  --bg: #ffffff;
  --bg2: #f5f5f7;
  --bg3: #e8e8ed;
  --fill: rgba(118, 118, 128, 0.12);
  --text: #1d1d1f;
  --text2: #6e6e73;
  --text3: #aeaeb2;
  --sep: rgba(60, 60, 67, 0.14);
  --accent: #007aff;
  --star: #ff9f0a;
  --bar: rgba(255, 255, 255, 0.78);
  --side: rgba(242, 242, 247, 0.92);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.16), 0 0 0 0.5px rgba(0, 0, 0, 0.12);
  --gap: 2px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg2: #1c1c1e;
    --bg3: #2c2c2e;
    --fill: rgba(118, 118, 128, 0.24);
    --text: #f5f5f7;
    --text2: #98989d;
    --text3: #636366;
    --sep: rgba(84, 84, 88, 0.6);
    --accent: #0a84ff;
    --star: #ffb340;
    --bar: rgba(22, 22, 24, 0.78);
    --side: rgba(28, 28, 30, 0.94);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.6), 0 0 0 0.5px rgba(255, 255, 255, 0.12);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 20px; height: 20px; flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- sign in ---------- */
.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: var(--bg2); }
.gate-card { width: min(340px, 100%); text-align: center; display: grid; gap: 12px; }
.gate-icon { width: 96px; height: 96px; border-radius: 22px; margin: 0 auto 6px; box-shadow: var(--shadow); }
.gate h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.gate p { margin: 0 0 8px; color: var(--text2); }
.gate input { font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 12px; border: 0.5px solid var(--sep); background: var(--bg); color: var(--text); outline: none; }
.gate input:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.gate button { font-size: 17px; font-weight: 600; padding: 12px; border-radius: 12px; background: var(--accent); color: #fff; }
.gate button:active { transform: scale(0.98); }
.gate-err { color: #ff3b30 !important; }

/* ---------- layout ---------- */
.app { display: flex; height: 100dvh; }
.sidebar {
  width: 224px; flex: none; padding: 18px 10px; background: var(--side);
  border-right: 0.5px solid var(--sep); overflow-y: auto;
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
}
.side-head { font-size: 13px; font-weight: 700; color: var(--text2); padding: 4px 10px 14px; letter-spacing: 0.01em; }
.side-group { margin-bottom: 18px; }
.side-label { font-size: 11px; font-weight: 600; color: var(--text3); padding: 0 10px 5px; text-transform: none; letter-spacing: 0.02em; }
.side-item {
  width: 100%; display: flex; align-items: center; gap: 9px; padding: 6px 10px; border-radius: 7px;
  font-size: 13.5px; text-align: left; transition: background 0.15s;
}
.side-item svg { width: 18px; height: 18px; color: var(--accent); }
.side-item span { flex: 1; }
.side-item em { font-style: normal; font-size: 12px; color: var(--text3); font-variant-numeric: tabular-nums; }
.side-item:hover { background: var(--fill); }
.side-item.on { background: color-mix(in srgb, var(--text) 10%, transparent); font-weight: 600; }
.side-item .mini-stars { color: var(--star); letter-spacing: -1px; font-size: 12px; flex: 1; }
.side-item .mini-stars i { color: var(--text3); font-style: normal; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

.toolbar {
  display: flex; align-items: center; gap: 16px; padding: 14px 20px 12px;
  border-bottom: 0.5px solid var(--sep); background: var(--bg); z-index: 3;
}
.tb-title { flex: 1; min-width: 0; }
.tb-title h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.015em; }
.tb-title p { margin: 1px 0 0; font-size: 12.5px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-tools { display: flex; align-items: center; gap: 10px; }
.tb-btn { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; color: var(--text2); }
.tb-btn:hover { background: var(--fill); color: var(--text); }
.tb-btn.on { color: var(--accent); }
.zoom { display: flex; align-items: center; gap: 4px; color: var(--text2); }
.zoom button { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 6px; }
.zoom button:hover { background: var(--fill); }
.zoom svg { width: 14px; height: 14px; }
.zoom input { width: 92px; accent-color: var(--accent); }
.search {
  display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 8px; width: 240px;
  background: var(--fill); border-radius: 9px; color: var(--text2); transition: width 0.25s var(--ease);
}
.search svg { width: 15px; height: 15px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font: inherit; font-size: 14px; color: var(--text); }
.search input::-webkit-search-cancel-button { display: none; }
.q-clear svg { width: 16px; height: 16px; color: var(--text3); display: block; }
.phone-only { display: none; }

.chips { display: none; }

.scroller { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

/* ---------- grid ---------- */
.day { content-visibility: auto; contain-intrinsic-size: auto 600px; }
.day-head {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: baseline; gap: 8px;
  padding: 18px 20px 10px; background: linear-gradient(var(--bg) 70%, transparent);
}
.day-head b { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.day-head span { font-size: 13px; color: var(--text2); }
.grid {
  display: grid; gap: var(--gap); padding: 0 20px 4px;
  grid-template-columns: repeat(var(--cols, 5), minmax(0, 1fr));
}
.grid.aspect { display: flex; flex-wrap: wrap; }
.tile {
  position: relative; display: block; aspect-ratio: 1; overflow: hidden; background: var(--bg3);
  border-radius: 0; cursor: zoom-in; transition: opacity 0.2s;
}
.grid.aspect .tile { aspect-ratio: auto; height: var(--rowh, 200px); flex-grow: var(--ar); width: calc(var(--rowh, 200px) * var(--ar)); background: transparent; }
.grid.aspect::after { content: ""; flex-grow: 1e4; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity 0.35s, transform 0.4s var(--ease); }
.tile img.ok { opacity: 1; }
.tile:hover img { transform: scale(1.015); }
.tile:active img { transform: scale(0.985); }
.tile .badge {
  position: absolute; left: 6px; bottom: 5px; display: flex; gap: 0; color: #fff;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55));
}
.tile .badge svg { width: 12px; height: 12px; }
.tile .dur {
  position: absolute; right: 7px; bottom: 5px; color: #fff; font-size: 12px; font-weight: 600;
  font-variant-numeric: tabular-nums; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
.tile .vid { position: absolute; left: 6px; top: 6px; color: #fff; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
.tile .vid svg { width: 14px; height: 14px; }
.tile.pop .badge { animation: pop 0.45s var(--ease); }
@keyframes pop { 0% { transform: scale(0.4); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }

.empty { padding: 90px 24px; text-align: center; color: var(--text2); }
.empty b { display: block; color: var(--text); font-size: 20px; margin-bottom: 6px; }

.tabbar { display: none; }

/* ---------- viewer ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; background: var(--bg);
  transition: background 0.3s;
}
.viewer.open-anim { animation: vin 0.28s var(--ease); }
@keyframes vin { from { opacity: 0; transform: scale(0.985); } to { opacity: 1; transform: none; } }
.viewer.dark { background: #000; }
.v-top, .v-bottom { position: relative; z-index: 3; display: flex; align-items: center; transition: opacity 0.25s, transform 0.25s var(--ease); }
.v-top { gap: 12px; padding: calc(10px + var(--safe-t)) 14px 10px; }
.v-bottom { justify-content: center; padding: 10px 14px calc(14px + var(--safe-b)); gap: 16px; }
.viewer.dark .v-top, .viewer.dark .v-bottom { opacity: 0; pointer-events: none; }
.v-back { display: flex; align-items: center; gap: 2px; color: var(--accent); font-size: 16px; padding: 6px 8px 6px 2px; border-radius: 8px; }
.v-back svg { width: 22px; height: 22px; }
.v-title { flex: 1; min-width: 0; text-align: center; display: grid; }
.v-title b { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-title small { font-size: 12px; color: var(--text2); }
.v-actions { display: flex; gap: 4px; }
.v-actions button { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; color: var(--accent); }
.v-actions button:hover { background: var(--fill); }
.v-actions button.on { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.v-actions svg { width: 22px; height: 22px; }
.v-body { flex: 1; min-height: 0; display: flex; position: relative; }
.v-stage { flex: 1; position: relative; overflow: hidden; touch-action: none; }
.v-media {
  position: absolute; inset: 0; display: grid; place-items: center; will-change: transform;
}
.v-media img, .v-media video {
  max-width: 100%; max-height: 100%; object-fit: contain; display: block; user-select: none; -webkit-user-drag: none;
  transform-origin: 0 0;
}
.v-media img.zoomable { cursor: zoom-in; }
.v-media.zoomed img { cursor: grab; }
.v-media video { background: #000; }
.v-media .lowres { position: absolute; max-width: 100%; max-height: 100%; filter: blur(0); }
.v-nav {
  position: absolute; top: 50%; z-index: 2; width: 44px; height: 44px; margin-top: -22px; display: grid; place-items: center;
  border-radius: 50%; background: var(--bar); color: var(--text); box-shadow: var(--shadow); opacity: 0; transition: opacity 0.2s;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.v-prev { left: 16px; } .v-next { right: 16px; }
.v-stage:hover .v-nav:not(:disabled) { opacity: 0.92; }
.v-nav:disabled { display: none; }
.viewer.dark .v-nav { display: none; }
.v-count { position: absolute; right: 18px; font-size: 12px; color: var(--text2); font-variant-numeric: tabular-nums; }

.stars { display: flex; gap: 2px; }
.stars button { width: 26px; height: 26px; display: grid; place-items: center; color: var(--text3); border-radius: 6px; transition: transform 0.2s var(--ease), color 0.15s; }
.stars button svg { width: 20px; height: 20px; }
.stars button.on { color: var(--star); }
.stars button:hover { transform: scale(1.12); }
.stars button:active { transform: scale(0.9); }
.stars.big button { width: 44px; height: 44px; }
.stars.big button svg { width: 28px; height: 28px; }
.stars.bump button.on { animation: pop 0.4s var(--ease); }

.v-info {
  width: 340px; flex: none; overflow-y: auto; padding: 18px 20px 30px; border-left: 0.5px solid var(--sep); background: var(--bg2);
}
.sheet-grip { display: none; }
.v-info h2 { margin: 0 0 8px; font-size: 18px; letter-spacing: -0.01em; }
.v-info .stars { margin: 0 0 14px -4px; }
.i-desc { margin: 0 0 12px; line-height: 1.5; }
.i-desc.alt { color: var(--text2); font-size: 14px; }
.i-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 18px; }
.i-tags button { font-size: 12.5px; padding: 4px 10px; border-radius: 99px; background: var(--fill); }
.i-tags button:hover { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.i-meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 18px; font-size: 13px; }
.i-meta dt { color: var(--text2); }
.i-meta dd { margin: 0; word-break: break-word; }
.i-drive { color: var(--accent); text-decoration: none; font-size: 14px; }
.i-pending { color: var(--text3); font-style: italic; }

/* ---------- menus, toast ---------- */
.ctx {
  position: fixed; z-index: 40; min-width: 200px; padding: 5px; border-radius: 10px; background: var(--bar); box-shadow: var(--shadow);
  backdrop-filter: saturate(180%) blur(24px); -webkit-backdrop-filter: saturate(180%) blur(24px); font-size: 13.5px;
  animation: ctxin 0.14s ease-out;
}
@keyframes ctxin { from { opacity: 0; transform: scale(0.96); } }
.ctx .stars { padding: 4px 6px 6px; }
.ctx button.row { width: 100%; text-align: left; padding: 6px 10px; border-radius: 6px; }
.ctx button.row:hover { background: var(--accent); color: #fff; }
.ctx hr { border: 0; border-top: 0.5px solid var(--sep); margin: 4px 6px; }
.toast {
  position: fixed; left: 50%; bottom: calc(28px + var(--safe-b)); z-index: 50; transform: translateX(-50%);
  padding: 10px 16px; border-radius: 12px; background: var(--bar); box-shadow: var(--shadow); font-size: 14px;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); animation: ctxin 0.2s ease-out;
}

/* ---------- phone ---------- */
@media (max-width: 760px) {
  .sidebar { display: none; }
  .toolbar { flex-wrap: wrap; border: 0; padding: calc(8px + var(--safe-t)) 16px 4px; gap: 8px; position: relative; }
  .tb-title h1 { font-size: 32px; letter-spacing: -0.025em; }
  .tb-title p { font-size: 13px; }
  .zoom { display: none; }
  .phone-only { display: grid; }
  .tb-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--fill); color: var(--accent); }
  .tb-btn svg { width: 18px; height: 18px; }
  .search { order: 5; width: 100%; height: 36px; display: none; }
  .search svg { width: 16px; height: 16px; }
  .search input { font-size: 17px; }
  .main.searching .search { display: flex; }
  .chips {
    display: flex; gap: 8px; padding: 6px 16px 10px; overflow-x: auto; scrollbar-width: none; flex: none;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chips button {
    flex: none; display: flex; align-items: center; gap: 3px; height: 32px; padding: 0 13px; border-radius: 99px;
    background: var(--fill); font-size: 14px; font-weight: 500; white-space: nowrap; transition: background 0.2s, color 0.2s;
  }
  .chips button svg { width: 13px; height: 13px; color: var(--star); }
  .chips button.on { background: var(--text); color: var(--bg); }
  .day-head { padding: 14px 16px 8px; }
  .grid { padding: 0; --gap: 1.5px; }
  .grid.aspect { padding: 0; }
  .scroller { padding-bottom: calc(64px + var(--safe-b)); }
  .tabbar {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; justify-content: center; gap: 0;
    padding: 6px 0 calc(4px + var(--safe-b)); background: var(--bar); border-top: 0.5px solid var(--sep);
    backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  }
  .tabbar button { flex: 1; max-width: 160px; display: grid; justify-items: center; gap: 2px; font-size: 10.5px; font-weight: 500; color: var(--text3); padding: 2px 0; }
  .tabbar button svg { width: 26px; height: 26px; }
  .tabbar button.on { color: var(--accent); }
  .v-nav { display: none; }
  .v-count { display: none; }
  .v-info {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto; max-height: 62%; z-index: 4; border: 0;
    border-radius: 16px 16px 0 0; box-shadow: var(--shadow); padding: 8px 20px calc(24px + var(--safe-b));
    animation: sheet 0.35s var(--ease);
  }
  .sheet-grip { display: block; width: 36px; height: 5px; border-radius: 3px; background: var(--text3); margin: 0 auto 12px; opacity: 0.6; }
  @keyframes sheet { from { transform: translateY(100%); } }
  .v-bottom { padding-top: 6px; }
}
