:root {
  --bg: #f6f7f9; --surface: #fff; --text: #16181d; --muted: #646a76; --line: #e2e5ea;
  --accent: #2f6fde; --accent-text: #fff; --danger: #c43d3d; --tile: #e7e9ee;
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318; --surface: #1a1d24; --text: #e9ebef; --muted: #9aa1ad; --line: #2a2e37;
    --accent: #5b8ff0; --tile: #22262e; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 14px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
input { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 9px 11px; width: 100%; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; }

/* login */
#login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(360px, 100%); display: grid; gap: 14px; }
.card h1 { margin: 0 0 6px; font-size: 22px; }
.card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; color: var(--text); font-size: 17px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; }
.topbar nav a.active { color: var(--text); background: var(--tile); }
.actions { display: flex; gap: 8px; margin-left: auto; }
@media (max-width: 640px) {
  .topbar { gap: 8px; }
  .topbar nav { order: 3; width: 100%; }
  #logout-btn { display: none; }
}

.album-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 16px 0; }
.album-head h2 { margin: 0; font-size: 20px; }

/* grid */
main { padding: 0 16px 96px; }
.month { margin: 22px 0 8px; font-size: 14px; font-weight: 600; }
.month span { color: var(--muted); font-weight: 400; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 3px; }
@media (max-width: 640px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 2px; } }
.tile { position: relative; aspect-ratio: 1; background: var(--tile); overflow: hidden; cursor: pointer; border: 0; padding: 0; border-radius: 0; }
.tile img { position: relative; width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .15s; }
.tile .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 26px; }
.tile .badge { position: absolute; right: 5px; bottom: 5px; color: #fff; font-size: 11px; background: rgba(0,0,0,.55); padding: 1px 5px; border-radius: 4px; }
.tile .heart { position: absolute; left: 5px; bottom: 3px; color: #fff; text-shadow: 0 0 3px rgba(0,0,0,.7); font-size: 14px; }
.selecting .tile::after { content: ""; position: absolute; top: 6px; left: 6px; width: 20px; height: 20px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 3px rgba(0,0,0,.5); }
.selecting .tile.selected img { transform: scale(.88); }
.selecting .tile.selected::after { background: var(--accent); border-color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 60px 16px; }

/* albums */
.albums { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; margin-top: 18px; }
.album-card { display: grid; gap: 6px; color: var(--text); }
.album-card .cover { aspect-ratio: 1; border-radius: 10px; background: var(--tile) center/cover no-repeat; }
.album-card small { color: var(--muted); }
.new-album { display: flex; gap: 8px; margin-top: 18px; max-width: 420px; }

.selection-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 20;
  display: flex; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 10px 8px 16px; box-shadow: 0 6px 24px rgba(0,0,0,.18); max-width: calc(100% - 32px); flex-wrap: wrap;
}

/* viewer */
.viewer { position: fixed; inset: 0; z-index: 50; background: #000; color: #fff; display: grid; grid-template-rows: auto 1fr; }
.viewer-bar { display: flex; align-items: center; gap: 6px; padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 8px; background: rgba(0,0,0,.6); z-index: 2; }
.viewer-bar .spacer { flex: 1; }
.viewer .icon { background: transparent; border: 0; color: #fff; font-size: 20px; padding: 6px 10px; line-height: 1; }
.viewer .icon.on { color: #ff5a6e; }
.viewer-stage { position: relative; display: grid; place-items: center; overflow: hidden; touch-action: pan-y; }
.viewer-stage img, .viewer-stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,.35); border: 0; color: #fff; font-size: 34px; width: 46px; height: 64px; }
.viewer .prev { left: 8px; } .viewer .next { right: 8px; }
@media (hover: none) { .viewer .nav { display: none; } }
.details { position: absolute; right: 12px; top: 60px; background: rgba(20,20,24,.92); border-radius: 10px; padding: 14px 16px; font-size: 13px; line-height: 1.7; max-width: calc(100% - 24px); }

/* dialogs */
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text); width: min(420px, calc(100% - 32px)); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h3 { margin: 0 0 12px; }
.row { display: flex; gap: 8px; margin-top: 12px; }
.row.end { justify-content: flex-end; }
.album-list { list-style: none; margin: 0; padding: 0; max-height: 45vh; overflow: auto; }
.album-list button { width: 100%; text-align: left; border: 0; border-radius: 8px; padding: 10px; background: transparent; }
.album-list button:hover { background: var(--tile); }
.upload-list { list-style: none; padding: 0; margin: 12px 0 0; max-height: 40vh; overflow: auto; font-size: 13px; }
.upload-list li { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.upload-list li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom, 0px)); z-index: 60; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; }
