:root {
  --bg: #000000;
  --gap: 4px;
  --heart: #ff5a72;
  --accent: #78c39b;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body.viewing { overflow: hidden; }

button, input { font: inherit; color: inherit; }

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

#feed {
  display: flex;
  align-items: flex-start;
  gap: var(--gap);
}

.col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.tile {
  display: block;
  position: relative;
  width: 100%;
  padding: 0;
  border: 0;
  background: color-mix(in srgb, currentColor 8%, transparent);
  cursor: zoom-in;
  scroll-margin-top: 40vh;
}

.tile img {
  display: block;
  width: 100%;
  height: auto;
}

.tile:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.tile.is-video { cursor: pointer; }

.play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.play svg {
  width: 52px;
  height: 52px;
  filter: drop-shadow(0 2px 8px rgb(0 0 0 / 0.35));
}

.duration {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.55);
  color: #fff;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.status {
  padding: 40vh 16px 0;
  color: #888;
  text-align: center;
}

/* --- full screen viewer (always dark) -------------------------------------------- */

#viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: #000;
  color: #f2f2f2;
  cursor: zoom-out;
}

#viewer[hidden] { display: none; }

.stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  container-type: size;
}

.stage img,
.stage video {
  display: block;
  /* Fill the stage on the limiting side. Black bars beside a video stay clickable to close. */
  width: min(100cqw, calc(100cqh * var(--ratio)));
  height: auto;
  aspect-ratio: var(--ratio);
}

.stage video { cursor: auto; }

.bar {
  position: absolute;
  inset: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 28px max(16px, env(safe-area-inset-left));
  background: linear-gradient(rgb(0 0 0 / 0.5), transparent);
  pointer-events: none;
  cursor: auto;
  z-index: 2; /* stays clickable above the comments panel */
}

.bar > * { pointer-events: auto; }

.bar time {
  font-size: 14px;
  color: rgb(255 255 255 / 0.85);
  text-shadow: 0 1px 3px rgb(0 0 0 / 0.5);
}

.actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.actions button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 44px;
  height: 44px;
  justify-content: center;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.12);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.actions button:hover { background: rgb(255 255 255 / 0.22); }

.actions svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.like[aria-pressed="true"] { color: var(--heart); }
.like[aria-pressed="true"] svg { fill: currentColor; }
.like.pop svg { animation: pop 0.3s ease-out; }

@keyframes pop {
  40% { transform: scale(1.3); }
}

/* --- comments panel ---------------------------------------------------------------- */

.panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  padding: calc(max(10px, env(safe-area-inset-top)) + 56px) 16px max(16px, env(safe-area-inset-bottom));
  background: rgb(18 18 18 / 0.94);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  cursor: auto;
}

.panel[hidden] { display: none; }

@media (max-width: 600px) {
  .panel { width: 100%; }
}

/* With room to spare, slide the photo over instead of covering it. */
@media (min-width: 900px) {
  #viewer.with-panel .stage { right: 380px; }
}

.comments {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
}

.comments li {
  padding: 6px 0;
  overflow-wrap: anywhere;
}

.comments b { font-weight: 600; margin-right: 6px; }

.empty {
  flex: 1;
  margin: 0;
  color: rgb(255 255 255 / 0.5);
}

.comments:not(:empty) + .empty { display: none; }
.comments:empty { display: none; }

.comment-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 12px;
}

.comment-form input {
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid rgb(255 255 255 / 0.16);
  border-radius: 10px;
  background: rgb(255 255 255 / 0.06);
}

.comment-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.comment-form [name="name"] { flex: 1 1 100%; }
.comment-form [name="body"] { flex: 1 1 0; }

.comment-form button {
  padding: 9px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #0b0f0c;
  font-weight: 600;
  cursor: pointer;
}

.comment-form button:disabled { opacity: 0.6; cursor: default; }

.form-error {
  flex-basis: 100%;
  margin: 0;
  color: var(--heart);
  font-size: 14px;
}

.form-error:empty { display: none; }

/* Honeypot: off screen for people, still in the form for bots. */
.hp {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .like.pop svg { animation: none; }
}
