/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:     #007AFF;
  --red:      #FF3B30;
  --bg:       #FFFFFF;
  --bg2:      #F2F2F7;
  --fg:       #1C1C1E;
  --fg2:      #636366;
  --fg3:      #AEAEB2;
  --sep:      #E5E5EA;
  --nav-h:    83px;
  --top-h:    56px;
  --radius:   12px;
  --font:     -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:  #000000;
    --bg2: #1C1C1E;
    --fg:  #FFFFFF;
    --fg2: #AEAEB2;
    --fg3: #636366;
    --sep: #38383A;
  }
}

html, body { height: 100%; overscroll-behavior: none; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
button { background: none; border: none; cursor: pointer; font-family: inherit; }
.btn-text  { color: var(--blue); font-size: 17px; font-weight: 400; padding: 8px; }
.btn-text:active { opacity: .5; }
.btn-icon  { color: var(--blue); padding: 8px; display: flex; align-items: center; }
.btn-icon svg { width: 26px; height: 26px; }
.btn-icon-white { color: #FFF; padding: 10px; display: flex; align-items: center; }
.btn-icon-white svg { width: 26px; height: 26px; }
.btn-danger { color: var(--red); }

/* ── Top Bar ──────────────────────────────────────────────────────────────── */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--top-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--sep);
}
#topbar-title {
  font-size: 17px; font-weight: 600;
  position: absolute; left: 50%; transform: translateX(-50%);
}
#topbar-left, #topbar-right { display: flex; align-items: center; min-width: 80px; }
#topbar-right { justify-content: flex-end; }

/* ── Main ─────────────────────────────────────────────────────────────────── */
#main {
  position: fixed;
  top: var(--top-h); bottom: var(--nav-h); left: 0; right: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.view { display: none; }
.view.active { display: block; }

/* ── Photo Grid ───────────────────────────────────────────────────────────── */
#photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding-bottom: 20px;
}
@media (min-width: 600px) { #photo-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 900px) { #photo-grid { grid-template-columns: repeat(6, 1fr); } }

.grid-section {}
.grid-section-header {
  padding: 14px 16px 6px;
  font-size: 15px; font-weight: 600;
  color: var(--fg);
  background: var(--bg);
  position: sticky; top: 0; z-index: 10;
  grid-column: 1 / -1;
}

.thumb-wrap {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--bg2);
  cursor: pointer;
}
.thumb-wrap img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity .15s;
}
.thumb-wrap:active { opacity: .7; }
.thumb-wrap.selected::after {
  content: '';
  position: absolute; inset: 0;
  background: rgba(0,122,255,.35);
  border: 3px solid var(--blue);
}
.thumb-wrap .video-badge {
  position: absolute; bottom: 4px; left: 6px;
  color: #fff; font-size: 11px; font-weight: 600;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
  display: flex; align-items: center; gap: 3px;
}
.thumb-wrap .video-badge svg { width: 12px; height: 12px; fill: #fff; }
.thumb-wrap.processing img { opacity: .4; }
.processing-indicator {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
.processing-indicator .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--blue);
  animation: pulse 1s ease-in-out infinite;
}

/* ── Years Strip ──────────────────────────────────────────────────────────── */
#years-strip {
  display: flex; gap: 0;
  overflow-x: auto; scrollbar-width: none;
  padding: 10px 12px 6px;
  border-bottom: 0.5px solid var(--sep);
}
#years-strip::-webkit-scrollbar { display: none; }
.year-chip {
  flex-shrink: 0;
  font-size: 14px; font-weight: 500;
  color: var(--blue); background: none;
  border: none; cursor: pointer;
  padding: 4px 12px;
  border-radius: 20px;
}
.year-chip.active {
  background: var(--blue); color: #fff;
}

/* ── Upload Zone ──────────────────────────────────────────────────────────── */
#upload-zone {
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  min-height: 300px;
  color: var(--fg3);
  border: 2px dashed var(--sep);
  margin: 20px 16px;
  border-radius: var(--radius);
}
#upload-zone.visible { display: flex; }
#upload-zone.drag-over {
  border-color: var(--blue);
  background: rgba(0,122,255,.05);
}
.upload-hint { text-align: center; }
.upload-hint svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: .5; }
.upload-hint p  { font-size: 15px; line-height: 1.6; }
.upload-hint small { font-size: 13px; color: var(--fg3); }

/* ── Upload Toast ─────────────────────────────────────────────────────────── */
#upload-toast {
  position: fixed; bottom: calc(var(--nav-h) + 12px); left: 50%; transform: translateX(-50%);
  z-index: 500;
  background: var(--fg); color: var(--bg);
  border-radius: 20px;
  padding: 10px 18px;
}
#upload-toast-inner { display: flex; align-items: center; gap: 10px; }
.upload-spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ── Albums ───────────────────────────────────────────────────────────────── */
#albums-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 16px 12px;
}
#albums-header h2 { font-size: 22px; font-weight: 700; }
#btn-new-album { font-size: 28px; line-height: 1; color: var(--blue); }

#albums-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px 16px;
  padding: 0 16px 20px;
}
@media (min-width: 600px) { #albums-grid { grid-template-columns: repeat(3, 1fr); } }

.album-card { cursor: pointer; }
.album-cover {
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg2);
  margin-bottom: 6px;
}
.album-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.album-cover-empty {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--fg3);
}
.album-cover-empty svg { width: 40px; height: 40px; }
.album-name  { font-size: 14px; font-weight: 500; }
.album-count { font-size: 13px; color: var(--fg2); }

#album-detail { padding-bottom: 20px; }
#album-detail-header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 8px;
}
#album-detail-header h3 { font-size: 18px; font-weight: 600; }
#album-detail-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px;
}
@media (min-width: 600px) { #album-detail-grid { grid-template-columns: repeat(4, 1fr); } }

/* ── Viewer ───────────────────────────────────────────────────────────────── */
#viewer {
  position: fixed; inset: 0; z-index: 200;
  display: flex; flex-direction: column;
}
#viewer-bg { position: absolute; inset: 0; background: #000; }

#viewer-topbar {
  position: relative; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px;
  background: linear-gradient(to bottom, rgba(0,0,0,.5), transparent);
}
#viewer-date {
  position: absolute; left: 50%; transform: translateX(-50%);
  color: #fff; font-size: 15px; font-weight: 500;
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
}

#viewer-stage {
  position: relative; z-index: 5;
  flex: 1; overflow: hidden;
}
#viewer-strip {
  display: flex;
  height: 100%;
  will-change: transform;
  transition: transform .3s cubic-bezier(.25,.46,.45,.94);
}
.viewer-slide {
  flex-shrink: 0;
  width: 100vw; height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}
.viewer-slide img, .viewer-slide video {
  max-width: 100%; max-height: 100%;
  object-fit: contain;
  user-select: none; -webkit-user-drag: none;
  border-radius: 4px;
}
.viewer-slide video { background: #000; }

#viewer-footer {
  position: relative; z-index: 10;
  display: flex; align-items: center; justify-content: space-around;
  padding: 12px 20px calc(env(safe-area-inset-bottom, 0px) + 24px);
  background: linear-gradient(to top, rgba(0,0,0,.5), transparent);
}

/* ── Info Panel ───────────────────────────────────────────────────────────── */
#info-panel {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 20px 20px calc(env(safe-area-inset-bottom, 0px) + 20px);
}
#info-panel h3 { font-size: 18px; font-weight: 600; margin-bottom: 16px; }
.info-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--sep);
}
.info-row:last-child { border-bottom: none; }
.info-row svg { width: 20px; height: 20px; flex-shrink: 0; color: var(--fg2); margin-top: 1px; }
.info-row-text { display: flex; flex-direction: column; }
.info-row-label { font-size: 13px; color: var(--fg2); }
.info-row-value { font-size: 15px; color: var(--fg); margin-top: 2px; }
#info-close { display: block; margin: 16px auto 0; color: var(--blue); font-size: 17px; }

/* ── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 60px 32px;
  color: var(--fg3); text-align: center;
}
.empty-state svg { width: 60px; height: 60px; margin-bottom: 16px; opacity: .4; }
.empty-state h3  { font-size: 18px; font-weight: 600; color: var(--fg2); margin-bottom: 8px; }
.empty-state p   { font-size: 14px; line-height: 1.5; }

/* ── Bottom Nav ───────────────────────────────────────────────────────────── */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  display: flex;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  color: var(--fg3); font-size: 10px; font-weight: 500;
  transition: color .15s;
}
.nav-btn svg { width: 26px; height: 26px; }
.nav-btn.active { color: var(--blue); }
.nav-btn:active { opacity: .5; }

/* ── Animations ───────────────────────────────────────────────────────────── */
@keyframes spin  { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { opacity: .3; } 50% { opacity: 1; } }
@keyframes slide-up {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
