:root {
  --bg: #111214;
  --surface: #1b1d21;
  --surface-2: #26292f;
  --text: #eceef1;
  --muted: #9aa1ab;
  --accent: #7cb0ff;
  --danger: #ff8a80;
  --like: #e5484d;
  --radius: 10px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

body.no-scroll {
  overflow: hidden;
}

a {
  color: inherit;
}

.btn {
  display: inline-block;
  background: var(--surface-2);
  color: var(--text);
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(1.2);
}

.btn.primary {
  background: var(--accent);
  color: #0b1a33;
  font-weight: 600;
}

/* ---- Header & navigation ---- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: rgb(17 18 20 / 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgb(255 255 255 / 0.07);
}

.brand {
  font-size: 17px;
  font-weight: 600;
  text-decoration: none;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  min-width: 0;
}

.topnav-link {
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.topnav-link:hover {
  background: var(--surface-2);
}

#nav-liked.active {
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px rgb(229 72 77 / 0.6);
}

#nav-liked.active .heart-icon {
  color: var(--like);
}

#me {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.me-label {
  color: var(--muted);
}

.me-name {
  font-weight: 600;
}

.muted {
  color: var(--muted);
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 14px;
}

.breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}

.breadcrumb .here {
  color: var(--text);
}

.status {
  color: var(--muted);
}

.status:empty {
  display: none;
}

/* ---- Albums ---- */

.folders {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.folders:empty {
  display: none;
}

.folder {
  display: block;
  min-width: 0;
  text-decoration: none;
}

.folder-cover {
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface-2) center / 36% no-repeat
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%239aa1ab' d='M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z'/%3E%3C/svg%3E");
}

.folder-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}

.folder:hover .folder-cover img {
  transform: scale(1.03);
}

.folder-name {
  margin-top: 8px;
  overflow: hidden;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-count {
  color: var(--muted);
  font-size: 13px;
}

/* ---- Photo grid ---- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 4px;
}

.tile {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
}

.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.25s;
}

.tile img.loaded {
  opacity: 1;
}

/* Gentle pulse while a thumbnail is on its way. */
.tile:not(.no-thumb):has(img:not(.loaded)) {
  animation: tile-pulse 1.4s ease-in-out infinite;
}

@keyframes tile-pulse {
  50% {
    background: var(--surface-2);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile:not(.no-thumb):has(img:not(.loaded)) {
    animation: none;
  }
}

.tile.no-thumb img {
  visibility: hidden;
}

.badges {
  position: absolute;
  left: 6px;
  bottom: 6px;
  display: flex;
  gap: 4px;
}

.badge {
  padding: 2px 7px;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.6);
  color: #fff;
  font-size: 12px;
  line-height: 1.5;
}

.badge.liked {
  background: var(--like);
}

.tile.video::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 44px;
  height: 44px;
  margin: auto;
  border-radius: 50%;
  background: rgb(0 0 0 / 0.55) center / 22px no-repeat
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M8 5v14l11-7z'/%3E%3C/svg%3E");
}

/* ---- Full-screen viewer ---- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: #000;
}

.viewer[hidden] {
  display: none;
}

.viewer-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 14px;
}

.viewer-caption {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-bar .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.like-btn[aria-pressed='true'] .heart {
  color: var(--like);
}

#viewer-panel-toggle[aria-pressed='true'] {
  background: #3a3f48;
}

.viewer-body {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 0;
}

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

.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  min-height: 0;
  align-items: center;
  justify-content: center;
}

/* Nearby photos under the current one. */
.filmstrip {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px 12px;
}

.film-slot {
  position: relative;
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  padding: 0;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 6px;
  background: var(--surface);
  opacity: 0.55;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
}

.film-slot:hover {
  opacity: 0.9;
}

.film-slot.current {
  border-color: var(--accent);
  opacity: 1;
  transform: scale(1.1);
  cursor: default;
}

.film-slot.empty {
  visibility: hidden;
}

.film-slot img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.film-slot.video::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 22px;
  height: 22px;
  margin: auto;
  border-radius: 50%;
  background: rgb(0 0 0 / 0.55) center / 12px no-repeat
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M8 5v14l11-7z'/%3E%3C/svg%3E");
}

.stage img,
.stage video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Dark translucent circles stay readable over both bright and dark photos. */
.nav {
  position: absolute;
  top: 50%;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 1px solid rgb(255 255 255 / 0.3);
  border-radius: 50%;
  background: rgb(0 0 0 / 0.55);
  color: #fff;
  cursor: pointer;
  transform: translateY(-50%);
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.4);
  transition: background 0.15s, transform 0.15s;
}

.nav:hover {
  background: rgb(0 0 0 / 0.8);
  transform: translateY(-50%) scale(1.06);
}

.nav svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav.prev {
  left: 16px;
}

.nav.next {
  right: 16px;
}

.nav:disabled {
  visibility: hidden;
}

/* Big Previous / Next buttons for phones; hidden on wider screens. */
.viewer-footer {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}

.viewer-footer .btn {
  flex: 1;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
}

.viewer-footer .btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.viewer-position {
  min-width: 72px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

/* Likes & comments panel: a sidebar on wide screens, a bottom sheet on phones. */
.panel {
  display: none;
  flex-direction: column;
  width: 340px;
  flex-shrink: 0;
  border-left: 1px solid rgb(255 255 255 / 0.08);
  background: var(--surface);
}

.viewer.panel-open .panel {
  display: flex;
}

.liked-by {
  margin: 0;
  padding: 14px 16px;
  border-bottom: 1px solid rgb(255 255 255 / 0.06);
  color: var(--muted);
  font-size: 14px;
}

.liked-by:empty {
  display: none;
}

.comments {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 8px 16px;
  overflow-y: auto;
  list-style: none;
}

.comment {
  padding: 10px 0;
  border-bottom: 1px solid rgb(255 255 255 / 0.05);
}

.comment.empty {
  color: var(--muted);
  border: 0;
}

.comment-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.comment-meta strong {
  color: var(--text);
  font-size: 14px;
}

.comment-meta .link-btn {
  margin-left: auto;
  font-size: 12px;
}

.comment p {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.comment-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid rgb(255 255 255 / 0.06);
}

.comment-form textarea {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  resize: none;
}

.comment-form .btn {
  align-self: flex-end;
}

/* ---- Name dialog ---- */

.name-dialog {
  width: min(360px, calc(100% - 32px));
  padding: 24px;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}

.name-dialog::backdrop {
  background: rgb(0 0 0 / 0.6);
}

.name-dialog h2 {
  margin: 0 0 4px;
  font-size: 19px;
}

.name-dialog input {
  width: 100%;
  margin: 12px 0 16px;
  padding: 11px 12px;
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---- Login ---- */

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 16px;
}

.login-card {
  display: grid;
  gap: 12px;
  width: min(360px, 100%);
  padding: 28px;
  border-radius: 14px;
  background: var(--surface);
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
}

.login-hint {
  margin: 0;
  color: var(--muted);
}

.login-error {
  margin: 0;
  color: var(--danger);
}

.password-field {
  position: relative;
}

.login-card .password-field input {
  width: 100%;
  padding-right: 76px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transform: translateY(-50%);
}

.login-note {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.login-card input {
  padding: 11px 12px;
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

/* ---- Phones ---- */

@media (max-width: 600px) {
  main {
    padding: 12px;
  }

  .folders {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
  }

  .tile {
    border-radius: 0;
  }

  .nav {
    display: none;
  }

  .viewer-footer {
    display: flex;
  }

  .filmstrip {
    gap: 6px;
    padding: 8px 8px 4px;
  }

  .film-slot {
    width: 52px;
    height: 52px;
  }

  .topbar {
    gap: 8px;
    padding: 10px 12px;
  }

  .brand {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topnav-link {
    padding: 6px 7px;
    font-size: 13px;
  }

  #me {
    max-width: 150px;
  }

  .topnav-text {
    display: none;
  }

  /* Not enough room for "Signed in as" on phones; show an icon instead. */
  .me-label {
    display: none;
  }

  .me-name::before {
    content: '👤 ';
  }

  .viewer-bar {
    gap: 6px;
    padding: 8px;
  }

  .viewer-bar .btn {
    padding: 7px 10px;
  }
}

@media (max-width: 899px) {
  .panel {
    position: absolute;
    inset: auto 0 0 0;
    z-index: 2;
    width: auto;
    max-height: 65%;
    border-left: 0;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -8px 24px rgb(0 0 0 / 0.5);
  }
}
