/* ===== Theme tokens ===== */
:root {
  --bg: #fafafa;
  --fg: #262626;
  --muted: #8e8e8e;
  --accent: #0095f6;
  --accent-fg: #ffffff;
  --accent-hover: #1877f2;
  --card: #ffffff;
  --border: #dbdbdb;
  --danger: #ed4956;
  --row-hover: #f5f5f5;
  --unread-bg: #eaf3ff;
  --photo-bg: #efefef;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: system-ui, -apple-system, "Noto Sans KR", "Noto Sans", sans-serif;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* ===== Topbar (responsive: wraps on narrow screens) ===== */
.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand { font-weight: 700; color: var(--fg); font-size: 1.1rem; }
.topbar nav {
  display: flex;
  /* nowrap keeps all wide-screen items (primary links + secondary ☰) on one row;
     the ≤640px collapsed dropdown stacks via its panel's `flex-direction: column`,
     so wrapping here is never needed. */
  flex-wrap: nowrap;
  gap: 0.75rem 1rem;
  align-items: center;
}
.topbar nav a { color: var(--fg); }
.inline { display: inline; }
.linkish {
  background: none; border: none; color: var(--accent);
  cursor: pointer; padding: 0; font: inherit;
}

/* Topbar hamburger menu (<details class="menu">) */
.topbar nav .menu { position: relative; }
.topbar nav .menu > summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--fg);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  list-style: none;
  user-select: none;
  transition: background 0.1s;
}
.topbar nav .menu > summary::-webkit-details-marker { display: none; }
.topbar nav .menu > summary:hover,
.topbar nav .menu[open] > summary { background: var(--row-hover); }
.menu-panel {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  min-width: 200px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.15);
  padding: 0.35rem 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
}
.menu-form { margin: 0; }
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--fg);
  cursor: pointer;
  padding: 0.55rem 0.9rem;
  font: inherit;
  text-decoration: none;
}
.menu-item:hover { background: var(--row-hover); }
.menu-item[hidden] { display: none; }

/*
  Responsive top-bar nav. Markup is a single source of truth: all links live in
  #topbar-menu's panel, with the secondary group (Settings/Logout/…) in a nested
  #topbar-secondary <details>.

  Wide screens (default, below): the outer ☰ and its panel collapse to
  `display: contents`, so the primary links lay out inline in the nav and the
  nested #topbar-secondary renders as the real ☰ dropdown.

  A closed <details> hides its non-summary content via the UA stylesheet
  (`content-visibility: hidden` on the slotted/`::details-content` subtree).
  `display: contents` does NOT override that, so we must also force
  `content-visibility: visible` to reveal the primary links regardless of the
  outer <details>'s open state on wide screens.

  Narrow screens (≤640px, in the media query): the outer ☰ becomes the dropdown,
  all links stack inside it, and #topbar-secondary is flattened (its ☰ hidden).
*/
#topbar-menu,
#topbar-menu > .menu-panel {
  display: contents;
  content-visibility: visible;
}
/* Chrome 131+ wraps a <details>'s content in a `::details-content` pseudo box.
   Two things to fix on it for the wide-screen inline layout:
   1. content-visibility: visible — defeat the UA's closed-<details> hiding so the
      primary links show even when the outer <details> is closed.
   2. display: contents — without this the pseudo is a *block* box and becomes the
      sole flex child of <nav>, so `.topbar nav { flex-wrap: nowrap }` has nothing
      to act on and the block-level secondary #topbar-secondary breaks onto its own
      line (issue #164). Flattening the pseudo makes all links + the secondary ☰
      real flex children of <nav>, so nowrap keeps them on one row. */
#topbar-menu::details-content { content-visibility: visible; display: contents; }
/* Hide the outer hamburger on wide screens — the nested one is the toggle. */
#topbar-menu > summary.nav-toggle { display: none; }
/* Primary links sit inline (not as full-width dropdown rows) on wide screens. */
#topbar-menu > .menu-panel > .nav-link {
  display: inline-flex;
  align-items: center;
  width: auto;
  padding: 0;
}
#topbar-menu > .menu-panel > .nav-link:hover { background: none; text-decoration: underline; }
/* "New album" shows just the + icon inline (square, accent, no underline); the
   text label is for the collapsed menu only. */
#topbar-menu > .menu-panel > .nav-new-album {
  justify-content: center;
  width: 28px;
  height: 28px;
  color: var(--accent);
  font-size: 1.35rem;
  line-height: 1;
  border-radius: 50%;
  transition: background 0.1s, color 0.1s;
}
#topbar-menu > .menu-panel > .nav-new-album:hover { background: var(--row-hover); text-decoration: none; }
.nav-new-album .nav-new-album-label { display: none; }

main { padding: 1rem; max-width: 960px; margin: 0 auto; }

/* ===== Buttons (unified) ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  min-width: 6rem;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--card); color: var(--fg); border-color: var(--border); }
.btn-secondary:hover { background: var(--row-hover); }

/* ===== Form card (used by login + new album) ===== */
.form-card {
  max-width: 480px;
  margin: 2rem auto;
  background: var(--card);
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.form-card h1 { margin: 0 0 1rem; font-size: 1.3rem; }
.stack-form { display: flex; flex-direction: column; gap: 1rem; }
.stack-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.stack-form input,
.stack-form textarea {
  padding: 0.55rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 4px;
  font: inherit;
  width: 100%;
}
.stack-form textarea { resize: vertical; }
.stack-form .actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}

/* Legacy login wrapper styled as form-card */
.login { max-width: 320px; margin: 4rem auto; background: var(--card); padding: 1.5rem; border: 1px solid var(--border); border-radius: 8px; }
.login form { display: flex; flex-direction: column; gap: 0.75rem; }
.login label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--muted); }
.login input { padding: 0.5rem; background: var(--bg); border: 1px solid var(--border); color: var(--fg); border-radius: 4px; }
.login button { padding: 0.6rem; background: var(--accent); color: var(--accent-fg); border: none; border-radius: 4px; font-weight: 600; cursor: pointer; }
.error { color: var(--danger); }

/* ===== Album grid ===== */
.album-grid {
  list-style: none; padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}
.album-card {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: var(--photo-bg);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.album-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,0.15); }
.album-card a { display: block; color: #fff; }
.album-card a:hover { text-decoration: none; }
.album-card img, .album-card video.album-cover-video, .album-cover.placeholder {
  width: 100%; aspect-ratio: 4 / 5; object-fit: cover; display: block; background: var(--photo-bg);
}
.album-meta {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 1.75rem 0.85rem 0.7rem;
  background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, rgba(0,0,0,0.45) 55%, rgba(0,0,0,0) 100%);
  color: #fff;
}
.album-meta h3 {
  margin: 0 0 0.15rem;
  font-size: 1.05rem;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.album-meta time,
.album-meta small {
  display: block;
  color: rgba(255,255,255,0.85);
  font-size: 0.78rem;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* ===== Album detail + photo grid ===== */
.album-header { margin-bottom: 1rem; }
.album-header h1 { margin: 0 0 0.25rem; }
.album-header time { color: var(--muted); font-size: 0.85rem; }
.album-detail .collage { margin: 1rem 0; }

/* ===== Upload form ===== */
.upload-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin: 1rem 0;
}
.file-drop {
  display: inline-block;
  padding: 0.5rem 0.75rem;
  border: 1px dashed var(--border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--muted);
  background: var(--card);
}
.upload-form button {
  padding: 0.55rem 1rem;
  background: var(--accent); color: var(--accent-fg);
  border: none; border-radius: 6px; cursor: pointer; font-weight: 600;
}
.upload-progress {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.5rem 0 0.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.upload-progress[hidden] { display: none; }
.upload-progress-bar { width: 100%; max-width: 24rem; height: 0.6rem; }

/* ===== Photo detail ===== */
.photo-detail figure { margin: 0; }
.photo-detail figure img {
  max-width: 100%; height: auto; display: block;
  border-radius: 4px; background: var(--photo-bg);
}
.photo-detail .back { display: inline-block; margin-bottom: 0.5rem; }
.photo-meta {
  display: flex; flex-wrap: wrap;
  align-items: center; gap: 0.5rem;
  margin: 0.5rem 0;
}

/* ===== Comments ===== */
.comments-block { border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 1rem; }
.comment-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.comment { padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.comment .ts { color: var(--muted); font-size: 0.75rem; margin-left: 0.5rem; }
.comment .body { margin: 0.25rem 0 0; word-break: break-word; }
/* Auto-translate "show original" toggle (refs #236). Styled as an inline link. */
.translate-toggle {
  background: transparent; border: none; padding: 0; margin-left: 0.4rem;
  color: var(--accent); cursor: pointer; font-size: 0.85em; text-decoration: underline;
}
.translate-toggle:hover { opacity: 0.8; }
.comment-form { display: flex; flex-direction: column; gap: 0.4rem; }
.comment-form textarea {
  padding: 0.4rem; background: var(--card); color: var(--fg);
  border: 1px solid var(--border); border-radius: 4px; resize: vertical; font: inherit;
}
.comment-form button {
  align-self: flex-end; padding: 0.4rem 0.8rem;
  background: var(--accent); color: var(--accent-fg);
  border: none; border-radius: 6px; cursor: pointer; font-weight: 600;
}

/* ===== Reactions ===== */
.reactions-block { margin: 0.5rem 0; }
.reaction-list {
  list-style: none; padding: 0;
  display: flex; gap: 0.4rem; flex-wrap: wrap;
}
.reaction-list button,
.add-reaction summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  min-height: 32px;
  line-height: 1;
  font-size: 0.95rem;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0.3rem 0.7rem;
  border-radius: 16px;
  cursor: pointer;
  list-style: none;
}
.reaction-list button:hover,
.add-reaction summary:hover { background: var(--row-hover); }
.reaction-list .count { color: var(--muted); font-size: 0.8rem; }

/* Reactions the current viewer already selected: accent border + tint so
   re-clicking reads as a toggle-off, not a new reaction (issue #181). */
.reaction-list button.is-mine {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, var(--card));
  font-weight: 600;
}
.reaction-list button.is-mine:hover {
  background: color-mix(in srgb, var(--accent) 28%, var(--card));
}

/* Custom reactor-names tooltip (replaces native title: no hover delay, works on tap via :focus-within) */
.reaction-pill, .collage-reaction { position: relative; }
.reactor-tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  max-width: min(16rem, 80vw);
  width: max-content;
  white-space: normal;
  text-align: center;
  background: var(--fg);
  color: var(--bg);
  font-weight: normal; /* don't inherit is-mine bold from pill button (#187) */
  font-size: 0.78rem;
  line-height: 1.3;
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.1s ease;
}
.reactor-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--fg);
}
.reaction-pill:hover .reactor-tooltip,
.reaction-pill:focus-visible .reactor-tooltip,
.reaction-pill:focus-within .reactor-tooltip,
.collage-reaction:hover .reactor-tooltip {
  opacity: 1;
  visibility: visible;
}
/* Collage chips sit at the top-right of an overflow:hidden tile, so the default
   upward, centered tooltip gets clipped top & right. Drop it below the chip and
   right-align it to the chip so it stays inside the tile; point arrow upward. */
.collage-reaction .reactor-tooltip {
  bottom: auto;
  top: calc(100% + 6px);
  left: auto;
  right: 0;
  transform: none;
  max-width: min(12rem, 60vw);
}
.collage-reaction .reactor-tooltip::after {
  top: auto;
  bottom: 100%;
  left: auto;
  right: 0.5rem;
  transform: none;
  border-top-color: transparent;
  border-bottom-color: var(--fg);
}
/* Detail page: reactions sit inside .photo-viewport, whose overflow-y:auto (for
   the comment-form scroll, #167) makes overflow-x compute to auto too — so the
   default centered tooltip on the LEFTMOST pill is clipped on its left edge
   (#178). z-index can't help: the clip is from an ancestor's overflow, not
   stacking. Left-anchor only the first pill's tooltip (and its arrow) to the
   pill so it stays inside the panel; other pills keep the centered default. */
.photo-viewport .reaction-list li:first-child .reactor-tooltip {
  left: 0;
  transform: none;
}
.photo-viewport .reaction-list li:first-child .reactor-tooltip::after {
  left: 1rem;
  transform: none;
}
/* When closed, the picker is hidden; when open, it sits inline to the right of the + */
.add-reaction .emoji-picker { display: none; }
.add-reaction[open] {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.add-reaction[open] .emoji-picker {
  display: inline-flex;
  gap: 0.25rem;
  margin: 0;
  flex-wrap: wrap;
}
.emoji-picker button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  line-height: 1;
  font-size: 1rem;
  padding: 0 0.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
}
.emoji-picker button:hover { background: var(--row-hover); }

.empty { color: var(--muted); text-align: center; margin: 4rem 0; }

/* ===== Danger / delete buttons ===== */
button.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  margin-left: 0.5rem;
}
button.danger:hover { background: var(--danger); color: #fff; }
.comment button.del {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; float: right; font-size: 1rem; padding: 0 0.3rem;
}
.comment button.del:hover { color: var(--danger); }

/* ===== Notifications ===== */
.notif-link { position: relative; color: var(--fg); }
.notif-link .badge {
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  padding: 0 0.4em;
  font-size: 0.7rem;
  font-weight: 600;
  margin-left: 0.25rem;
  vertical-align: top;
}
.notifs-header {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
  justify-content: space-between; align-items: center;
  margin-bottom: 1rem;
}
.notif-list { list-style: none; padding: 0; }
.notif { border-bottom: 1px solid var(--border); padding: 0.6rem 0.5rem; }
.notif a { color: var(--fg); display: block; word-break: break-word; }
.notif a:hover { text-decoration: none; }
.notif.unread { background: var(--unread-bg); border-radius: 4px; }
.notif .kind { color: var(--muted); margin-left: 0.3rem; }
.notif .summary { margin-left: 0.3rem; }
.notif time { color: var(--muted); font-size: 0.75rem; margin-left: 0.5rem; }

/* ===== Mobile tweaks ===== */
@media (max-width: 640px) {
  main { padding: 0.75rem; }
  .topbar { padding: 0.5rem 0.75rem; }
  .topbar .brand { font-size: 1rem; }
  .topbar nav { gap: 0.5rem 0.8rem; font-size: 0.9rem; }

  /* Collapse all primary nav links into the ☰ hamburger. */
  /* Outer details is the real dropdown again (undo the wide-screen contents flatten).
     The wide-screen rule force-shows the panel via `display: contents`, which defeats
     the UA closed-<details> hiding; so here we must explicitly hide it when closed and
     show it only when open. */
  #topbar-menu { display: block; position: relative; }
  #topbar-menu > .menu-panel { display: none; }
  #topbar-menu[open] > .menu-panel { display: flex; flex-direction: column; }
  #topbar-menu > summary.nav-toggle { display: inline-flex; }
  /* Primary links render as full-width dropdown rows (revert wide-screen inline styling). */
  #topbar-menu > .menu-panel > .nav-link {
    display: block;
    width: 100%;
    padding: 0.55rem 0.9rem;
  }
  #topbar-menu > .menu-panel > .nav-link:hover {
    background: var(--row-hover);
    text-decoration: none;
  }
  /* "New album" shows its text label (not just the + icon) inside the menu.
     Must out-specify the wide-screen ID rule
     (`#topbar-menu > .menu-panel > .nav-new-album`, specificity 1,2,1) that sets
     the big inline icon size, so match its ID-anchored selector here. */
  #topbar-menu > .menu-panel > .nav-new-album {
    justify-content: flex-start;
    width: 100%;
    height: auto;
    color: var(--fg);
    font-size: inherit;
    line-height: inherit;
    border-radius: 0;
  }
  .nav-new-album .nav-new-album-icon { color: var(--accent); margin-right: 0.4rem; }
  .nav-new-album .nav-new-album-label { display: inline; }
  /* Flatten the secondary group into the single dropdown (hide its own ☰). The
     base `.topbar nav .menu > summary` rule (specificity 0,2,2) would otherwise
     win over a class-only hide, so anchor the hide selector on the ID. */
  .nav-secondary,
  .nav-secondary > .menu-panel { display: contents; }
  #topbar-secondary > summary.nav-toggle { display: none; }
  .form-card { margin: 1rem auto; padding: 1rem; }
  .form-card h1 { font-size: 1.15rem; }
  .album-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.6rem; }
  .album-meta { padding: 1.25rem 0.6rem 0.55rem; }
  .album-meta h3 { font-size: 0.95rem; }
  .stack-form .actions { flex-direction: row; }
  .stack-form .actions .btn { flex: 1; }
  .upload-form button, .file-drop { width: 100%; }
  .upload-form { flex-direction: column; align-items: stretch; }
}


/* Notification rows with thumbnail */
.notif-row { display: flex; gap: 0.6rem; align-items: center; padding: 0.25rem; }
.notif-thumb {
  flex: 0 0 auto;
  width: 48px; height: 48px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--photo-bg);
  border: 1px solid var(--border);
}
.notif-thumb.placeholder { display: inline-block; }
.notif-text { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.3rem; }
.notif-text time { color: var(--muted); font-size: 0.75rem; }

.badge.hidden { display: none; }


/* Album settings page */
.album-settings h1 { margin: 0 0 1rem; }
.album-settings h2 { margin-top: 1.5rem; font-size: 1.05rem; color: var(--muted); font-weight: 600; }
.settings-link { font-size: 0.9rem; padding: 0.35rem 0.8rem; min-width: auto; }
.photo-settings-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.photo-settings-row {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--card); border: 1px solid var(--border); border-radius: 6px;
  padding: 0.5rem;
}
.ps-thumb { width: 96px; height: 96px; object-fit: cover; border-radius: 4px; background: var(--photo-bg); flex: 0 0 auto; }
.ps-fields { flex: 1; min-width: 0; }
.ps-fields label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.8rem; color: var(--muted); }
.ps-fields input { padding: 0.4rem 0.55rem; background: var(--bg); border: 1px solid var(--border); color: var(--fg); border-radius: 4px; font: inherit; font-size: 0.8rem; width: 100%; }
.ps-fields .photo-location-form { display: flex; flex-direction: column; gap: 0.2rem; margin-top: 0.5rem; }
.ps-actions { display: flex; flex-direction: column; gap: 0.4rem; align-items: stretch; flex: 0 0 auto; }
/* Cover + delete buttons share one container; pin height + font-size so the two
   stay consistent regardless of label length. */
.ps-actions .btn, .ps-cover-badge {
  font-size: 0.85rem; line-height: 1.2;
  min-height: 2.25rem; padding-top: 0.4rem; padding-bottom: 0.4rem;
  min-width: 7rem; box-sizing: border-box;
}
.photo-settings-row.is-cover { border-color: var(--accent); }
.ps-cover-badge { display: inline-flex; align-items: center; justify-content: center; color: var(--accent); text-align: center; border: 1px solid var(--accent); border-radius: 6px; }
.danger-zone { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); }
@media (max-width: 640px) {
  .photo-settings-row { flex-wrap: wrap; }
  .ps-thumb { width: 72px; height: 72px; }
}


/* Pencil edit icon next to album name */
.album-header h1 { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.edit-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  color: var(--muted);
  border-radius: 50%;
  transition: background 0.1s, color 0.1s;
}
.edit-icon:hover {
  background: var(--row-hover);
  color: var(--fg);
  text-decoration: none;
}


/* Unified card-style sections on /albums/{id}/settings */
.settings-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.settings-card h2 {
  margin-top: 0;
}
.album-settings .danger-zone {
  border-color: var(--danger);
  /* override the top-border-only rule from earlier */
  border-top: 1px solid var(--danger);
  padding-top: 1rem;
  margin-top: 1rem;
}


/* Photo feed (home) — per-album sections with masonry-ish collage */
.feed-album { margin-bottom: 2rem; }
.feed-album-header { margin-bottom: 0.6rem; }
.feed-album-header h2 { margin: 0; font-size: 1.1rem; }
.feed-album-header h2 a { color: var(--fg); }
.feed-album-header h2 a:hover { color: var(--accent); text-decoration: none; }
.feed-album-desc { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.9rem; }
.feed-album-header time { color: var(--muted); font-size: 0.8rem; }

/* Row-wise masonry (Pinterest-style stagger): collage-masonry.js adds the
   `masonry` class to switch the container to CSS grid and sets each tile's
   grid-row span from its aspect ratio, so tiles keep the column width but vary
   in height. The flex rules below are the no-JS fallback — even rows of a fixed
   height, cropped to fill. */
.collage { display: flex; flex-wrap: wrap; gap: 0.5rem; align-content: flex-start; }
.collage-item {
  display: block;
  flex: 1 1 12rem;   /* no-JS fallback; masonry grid overrides the width */
  height: 220px;     /* no-JS fallback row height; masonry grid overrides */
  margin: 0;
  border-radius: 4px;
  overflow: hidden;
}
/* JS-upgraded masonry grid. Fine grid-auto-rows quantum (8px) keeps the
   aspect-ratio rounding (and thus object-fit crop) negligible. Column min-width
   sets the tile count per breakpoint. */
.collage.masonry {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  grid-auto-rows: 8px;
  align-content: stretch;
}
.collage.masonry .collage-item { width: auto; height: auto; flex: none; }
@media (max-width: 960px) {
  .collage.masonry { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
@media (max-width: 640px) {
  .collage.masonry { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
.collage-item img,
.collage-item video {
  width: 100%; height: 100%; object-fit: cover; display: block;
  background: var(--photo-bg);
}
/* Play-glyph overlay so video tiles are recognizable even when the browser
   can't decode the codec (e.g. iPhone HEVC .mov on Chrome/Firefox renders
   a blank first frame). Centered, non-interactive, legible on any bg. */
.collage-item.is-video::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 3rem; height: 3rem;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.55);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'><path d='M8 5v14l11-7z'/></svg>");
  background-repeat: no-repeat;
  background-position: 55% 50%;
  background-size: 55% 55%;
  pointer-events: none;
}
@media (max-width: 640px) { .collage { gap: 0.35rem; } }


/* Caption overlay on collage items */
.collage-item { position: relative; display: block; }
.collage-caption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 1.5rem 0.6rem 0.55rem;
  background: linear-gradient(to bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,0.7) 100%);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1.3;
  pointer-events: none;
  word-wrap: break-word;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}


/* Reaction chips on collage items */
.collage-reactions {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  max-width: 70%;
  justify-content: flex-end;
}
.collage-reaction {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border-radius: 12px;
  padding: 0.1rem 0.45rem;
  font-size: 0.78rem;
  line-height: 1.2;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.collage-reaction .n { font-size: 0.72rem; opacity: 0.9; }


/* Photo detail: the viewport column fills the screen minus the topbar and the
   page padding; the image area flexes to whatever space the surrounding chrome
   (back link, caption, location, location form, toolbar, comment form) leaves,
   so everything fits without a magic pixel reserve. Only actual comments
   (.below-viewport) scroll past the fold. */
.photo-detail { display: block; }
.photo-viewport {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  /* Explicit height (not just max-height) so the basis-0 .image-area has
     definite free space to flex-grow into; with only max-height the column
     height is content-based and the basis-0 image-area collapses to 0,
     zeroing the media (#170).

     --topbar-h is measured at runtime by app.js (ResizeObserver on .topbar)
     so the reserve tracks the real topbar height — it wraps to two rows on
     narrow-but-not-mobile widths and shrinks under the ≤640px media query, so
     a hardcoded constant either pushed content down or left harmless slack.
     Fallback 52px keeps a sane no-JS column. 2rem = main top+bottom padding. */
  height: calc(100dvh - var(--topbar-h, 52px) - 2rem);
  /* When the chrome (back link + caption + location + toolbar + comment form)
     alone is taller than the column on a short viewport, the image-area
     collapses to its min and the surplus would otherwise overflow the column
     bottom and re-clip the comment Post button (#167). Degrade to a scroll. */
  overflow-y: auto;
}
.photo-viewport .image-area {
  display: flex;
  justify-content: center;
  align-items: center;
  /* Flex to fill leftover space; min-height:0 lets it shrink below content. */
  flex: 1 1 0;
  min-height: 0;
}
.photo-viewport .photo-img {
  max-width: 100%;
  /* Shrink to whatever height the flexed image-area leaves. */
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  background: var(--photo-bg);
  border-radius: 4px;
}
.photo-viewport .photo-caption { margin: 0; font-size: 0.95rem; text-align: left; }
.photo-viewport .photo-location-label { margin: 0; font-size: 0.95rem; text-align: left; }
.photo-viewport .photo-meta { margin: 0; font-size: 0.85rem; color: var(--muted); }
.photo-viewport .reactions, .photo-viewport .reactions-block { margin: 0; }
/* margin:0 collapses default gaps into the column's own gap; flex-shrink:0
   keeps the Post button from being crushed when the column scrolls (#167). */
.photo-viewport .comment-form { margin: 0; flex-shrink: 0; }

/* Location search (geocode autocomplete) on the per-photo location form in album settings */
.location-search { position: relative; }
.location-search-input { width: 100%; box-sizing: border-box; }
.location-search-results {
  list-style: none;
  margin: 2px 0 0;
  padding: 0;
  position: absolute;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  max-height: 240px;
  overflow-y: auto;
}
.location-search-result {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.6rem;
  background: none;
  border: none;
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}
.location-search-result:hover { background: var(--row-hover); }
.location-search-empty {
  padding: 0.5rem 0.6rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Below-fold comments: empty list takes no visual space and no border, so the
   "horizontal line" only appears when there are actual comments to delimit. */
.below-viewport { margin-top: 0; }
.below-viewport:has(.comment-list) { margin-top: 1.5rem; }
.comments-block.is-empty {
  border: none;
  padding: 0;
  margin: 0;
}


/* Download (diskette) icon on photo detail */
.download-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--muted);
  border-radius: 50%;
  transition: background 0.1s, color 0.1s;
}
.download-icon:hover {
  background: var(--row-hover);
  color: var(--fg);
  text-decoration: none;
}


/* Photo detail toolbar: reactions left, actions (view/download) right */
.photo-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.photo-toolbar .reactions, .photo-toolbar .reactions-block { margin: 0; flex: 1; }
.photo-actions { display: flex; gap: 0.25rem; flex-shrink: 0; align-items: center; }

/* ===== Favorites / star ===== */
.favorite-button {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}
.favorite-button.is-on { color: #f5b400; }
.favorite-button:hover { background: var(--row-hover); }
.collage-favorite {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  color: #f5b400;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  font-size: 1.1rem;
  line-height: 1;
  pointer-events: none;
}


/* ===== Settings page ===== */
.settings-page h1 { margin: 0 0 1rem; }
.settings-page .stack-form select {
  padding: 0.55rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 4px;
  font: inherit;
  width: 100%;
}
.settings-hint { color: var(--muted); font-size: 0.8rem; margin: 0; }
.settings-flash {
  padding: 0.55rem 0.8rem;
  border-radius: 6px;
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
}
.settings-flash.success { background: #e6f4ea; color: #1e7e34; border: 1px solid #b7dfc1; }
.settings-flash.error { background: #fdeaea; color: #b3261e; border: 1px solid #f1b8b8; }
.settings-card .settings-flash { margin-bottom: 0.75rem; }
/* ===== Album projector (fullscreen slideshow) ===== */
.projector-body {
  margin: 0;
  padding: 0;
  background: #000;
  color: #fff;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}
.projector {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.projector-img,
.projector-video {
  max-width: 100vw;
  max-height: 100vh;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}
/* `display: block` above wins over the UA's `[hidden]{display:none}`, so
   without this rule both the <img> and <video> stay visible on mixed albums:
   when switching from a photo to a video, the previous still lingers behind
   the playing clip. */
.projector-img[hidden],
.projector-video[hidden] {
  display: none;
}
.projector-empty {
  color: #fff;
  font-size: 1.2rem;
  opacity: 0.8;
  text-align: center;
  margin: 0;
}
.projector-exit {
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 50%;
  transition: background 0.15s, opacity 0.25s;
  z-index: 2;
}
.projector-exit:hover {
  background: rgba(0, 0, 0, 0.7);
  text-decoration: none;
}
.projector-controls {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 999px;
  z-index: 2;
  transition: opacity 0.25s;
}
.projector-controls.projector-hidden {
  opacity: 0;
  pointer-events: none;
}
.projector-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}
.projector-btn:hover,
.projector-btn:focus-visible {
  background: rgba(255, 255, 255, 0.15);
  outline: none;
}
.projector-btn:focus-visible {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);
}
