:root {
  color-scheme: light dark;
  --gap: 1rem;
  --muted: color-mix(in srgb, currentColor 60%, transparent);
  --line: color-mix(in srgb, currentColor 15%, transparent);
  font-family: system-ui, sans-serif;
  line-height: 1.4;
}

body {
  margin: 0;
}

.flash {
  margin: 0;
  padding: 0.5rem var(--gap);
  border-bottom: 1px solid var(--line);
}

.sign-in {
  display: grid;
  place-items: center;
  gap: var(--gap);
  min-height: 80vh;
}

.layout {
  display: grid;
  grid-template-columns: 14rem minmax(0, 1fr);
  gap: calc(var(--gap) * 2);
  padding: var(--gap);
}

.sidebar {
  position: sticky;
  top: var(--gap);
  align-self: start;
  max-height: calc(100vh - var(--gap) * 2);
  overflow-y: auto;
}

.sidebar-toggle {
  margin-bottom: var(--gap);
  font-size: 1.2rem;
}

/* The sidebar stays at the left edge and the feed takes the rest of the
   window. Collapsed, the sidebar column narrows to the toggle. */
.layout.sidebar-collapsed {
  grid-template-columns: auto minmax(0, 1fr);
}

.sidebar-collapsed #sidebar-content {
  display: none;
}

.sidebar-nav,
.communities {
  display: grid;
  gap: 0.5rem;
  margin-bottom: var(--gap);
}

.sidebar-nav .current {
  font-weight: bold;
}

.communities label {
  display: flex;
  gap: 0.4rem;
  font-size: 0.9rem;
}

.communities label[hidden] {
  display: none;
}

@media (max-width: 48rem) {
  .layout,
  .layout.sidebar-collapsed {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: static;
    max-height: 12rem;
  }
}

/* Grid: up to three columns of at least 20rem each. masonry_controller.js
   reads --columns and keeps that many .media-column elements. */
.feed {
  container-type: inline-size;
}

.media-grid {
  --columns: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--gap);
}

@container (min-width: 41rem) {
  .media-grid {
    --columns: 2;
  }
}

@container (min-width: 62rem) {
  .media-grid {
    --columns: 3;
  }
}

/* Before masonry_controller.js places them, tiles stack in one column. */
.media-grid > .media-item {
  flex: 1 0 100%;
}

.media-column {
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  gap: calc(var(--gap) * 2);
}

/* One at a time: one column, and each image or video fills the height of the
   window, less its title row. */
.display-stack .media-grid {
  --columns: 1;
}

.display-stack .media img,
.display-stack .media video {
  height: calc(100dvh - 4rem);
  max-height: none;
}

/* Each scroll stops at the top of the next tile. The next-page frame is a
   stop too: without it, scrolling never reaches the frame, so the next page
   never loads. */
html:has(.display-stack) {
  scroll-snap-type: y mandatory;
}

.display-stack .media-item,
.display-stack .next-page {
  scroll-snap-align: start;
  scroll-margin-top: var(--gap);
}

.display-options {
  display: flex;
  gap: 0.5rem;
  margin-bottom: var(--gap);
}

.display-options [aria-pressed="true"] {
  font-weight: bold;
}

.keys-hint {
  margin: 0 0 var(--gap);
  font-size: 0.8rem;
  color: var(--muted);
}

/* keyboard_controller.js moves between posts in one-at-a-time mode only. */
.stack-keys {
  display: none;
}

.display-stack .stack-keys {
  display: inline;
}

.media-title {
  display: flex;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: 0.4rem;
}

.media-title a {
  color: inherit;
  text-decoration: none;
}

.subreddit {
  color: var(--muted);
  white-space: nowrap;
}

.media {
  position: relative;
  display: grid;
  gap: 0.5rem;
  overflow: hidden;
  border-radius: 0.5rem;
}

.media img,
.media video {
  display: block;
  width: 100%;
  height: auto;
  max-height: 85vh;
  object-fit: contain;
  background: var(--line);
}

.gallery {
  position: relative;
}

.gallery-track {
  display: flex;
  align-items: center;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.gallery-track img {
  flex: 0 0 100%;
  scroll-snap-align: start;
}

.gallery-nav,
.gallery-count {
  position: absolute;
  border: none;
  border-radius: 0.3rem;
  color: white;
  background: rgb(0 0 0 / 55%);
}

.gallery-nav {
  top: 50%;
  translate: 0 -50%;
  padding: 0.2rem 0.6rem;
  font-size: 1.5rem;
  cursor: pointer;
}

.gallery-previous {
  left: 0.5rem;
}

.gallery-next {
  right: 0.5rem;
}

.gallery-count {
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.1rem 0.4rem;
  font-size: 0.8rem;
}

/* While blurred, a tap only reveals; it does not also move the gallery. */
.media.blurred .gallery-nav,
.media.blurred .gallery-count {
  display: none;
}

.media.blurred {
  cursor: pointer;
}

.media.blurred img,
.media.blurred video {
  filter: blur(2.5rem);
}

.media.blurred::after {
  content: "NSFW: tap to show";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: bold;
  color: white;
  text-shadow: 0 0 0.5rem black;
}

.feed-note {
  color: var(--muted);
  text-align: center;
}
