/* Mobile first: base styles target phones, min-width queries widen things. */

/* Bricolage Grotesque (SIL Open Font License), latin subset, variable weight. */
@font-face {
  font-family: "Bricolage Grotesque";
  src: url("bricolage.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}

:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --text: #1d1b19;
  --muted: #7a746d;
  --line: #e7e2db;
  --accent: #e8433f;
  --media-bg: #efebe5;
  --radius: 12px;
  --gutter: 16px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --display: "Bricolage Grotesque", var(--sans);
  --brand: linear-gradient(100deg, #ff5a3c 0%, #e8336b 55%, #b23ac9 100%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141312;
    --surface: #1d1c1a;
    --text: #f0ece6;
    --muted: #9b948b;
    --line: #2e2c29;
    --media-bg: #0c0b0b;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--sans);
  -webkit-tap-highlight-color: transparent;
}

main { flex: 1; width: 100%; max-width: 935px; margin: 0 auto; }

a { color: inherit; }
img, video { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea {
  font: inherit;
  color: inherit;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  /* 16px keeps iOS from zooming in on focus */
  font-size: 16px;
}
input:focus, textarea:focus { outline: 2px solid var(--text); outline-offset: -1px; }
textarea { resize: vertical; }

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

/* ---- Header ---- */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(52px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--gutter) 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.8) blur(14px);
  -webkit-backdrop-filter: saturate(1.8) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand, .profile h1 {
  font-family: var(--display);
  font-weight: 800;
  letter-spacing: -0.045em;
  background: var(--brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand {
  font-size: 25px;
  line-height: 1.1;
  padding-bottom: 2px;
  text-decoration: none;
}
.owner { display: flex; align-items: center; margin-right: -10px; }
.owner form { margin: 0; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  border-radius: 50%;
}
.icon-btn:active { transform: scale(0.9); }

.link {
  border: 0;
  background: none;
  padding: 8px;
  color: var(--muted);
  font-size: 14px;
}

.primary, .danger {
  display: block;
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: var(--radius);
  font-weight: 600;
}
.primary { background: var(--text); color: var(--bg); }
.primary:disabled { opacity: 0.5; }
.danger { background: none; color: var(--accent); border: 1px solid currentColor; }

/* ---- Feed ---- */

.profile { padding: 28px var(--gutter) 20px; text-align: center; }
.profile h1 { display: inline-block; margin: 0; font-size: 40px; line-height: 1.1; padding: 0 2px 4px; }
.bio { margin: 8px auto 0; max-width: 36ch; }
.stats { margin: 8px 0 0; color: var(--muted); font-size: 14px; }

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
}
.tile {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--media-bg);
}
.tile img { width: 100%; height: 100%; object-fit: cover; }
.tile-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}
.badge {
  position: absolute;
  top: 6px;
  right: 6px;
  color: #fff;
  filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.5));
}
.tile-stats { display: none; }
.more {
  grid-column: 1 / -1;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}
.empty { padding: 48px var(--gutter); text-align: center; color: var(--muted); }

@media (hover: hover) {
  .tile-stats {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgb(0 0 0 / 0.35);
    color: #fff;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.15s;
  }
  .tile:hover .tile-stats { opacity: 1; }
}

@media (min-width: 736px) {
  .grid { gap: 4px; padding: 0 var(--gutter); }
  .tile { border-radius: 4px; }
}

/* ---- Post ---- */

.post { max-width: 640px; margin: 0 auto; }

.frame {
  position: relative;
  aspect-ratio: var(--ratio, 1);
  background: var(--media-bg);
  touch-action: manipulation;
}
.carousel {
  display: flex;
  height: 100%;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.carousel::-webkit-scrollbar { display: none; }
.slide {
  flex: 0 0 100%;
  height: 100%;
  scroll-snap-align: center;
  scroll-snap-stop: always;
}
.slide img, .slide video { width: 100%; height: 100%; object-fit: contain; }
.slide-status { height: 100%; display: grid; place-items: center; color: var(--muted); }

.dots {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  display: flex;
  justify-content: center;
  gap: 5px;
  pointer-events: none;
}
.dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.5;
  box-shadow: 0 0 2px rgb(0 0 0 / 0.4);
  transition: opacity 0.2s;
}
.dots span.on { opacity: 1; }

.burst {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  color: #fff;
  opacity: 0;
}
.burst svg { width: 96px; height: 96px; fill: #fff; stroke: none; filter: drop-shadow(0 2px 10px rgb(0 0 0 / 0.3)); }
.burst.go { animation: burst 0.8s ease-out; }
@keyframes burst {
  0% { opacity: 0; transform: scale(0.4); }
  15% { opacity: 1; transform: scale(1.1); }
  30% { transform: scale(0.95); }
  70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}

.body { padding: 4px 12px 0; }
.actions { display: flex; margin-left: -6px; }
.actions form { margin: 0; }
.like.liked { color: var(--accent); }
.like.liked svg { fill: currentColor; }
.like.pop { animation: pop 0.3s ease-out; }
@keyframes pop { 50% { transform: scale(1.25); } }

.likes { margin: 0; font-weight: 600; font-size: 15px; }
.caption { margin: 6px 0 0; white-space: pre-line; overflow-wrap: anywhere; }
.when { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; letter-spacing: 0.02em; text-transform: uppercase; }

.comments ul { list-style: none; margin: 16px 0 0; padding: 0; }
.comments li { padding: 6px 0; }
.comments p { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }
.comments .meta { color: var(--muted); font-size: 13px; }
.comments .meta form { display: inline; }
.comments .meta .link { padding: 0; font-size: 13px; }

.pager {
  display: flex;
  justify-content: space-between;
  padding: 20px 0 8px;
  font-size: 14px;
}
.pager a { color: var(--muted); text-decoration: none; padding: 8px 0; }

.owner-tools { margin-top: 14px; padding: 12px; border: 1px dashed var(--line); border-radius: var(--radius); }
.owner-tools summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.owner-tools form { display: grid; gap: 8px; margin-top: 10px; }

/* Sticks to the bottom of the screen while reading the post. */
.comment-form {
  position: sticky;
  bottom: 0;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.comment-form .row { display: flex; gap: 8px; align-items: flex-end; }
.comment-form textarea { resize: none; max-height: 30vh; border-radius: 22px; padding: 10px 16px; }
.comment-form .row button {
  flex: none;
  min-height: 44px;
  padding: 0 6px;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
}
.who { margin-bottom: 8px; }
.who .as { font-size: 13px; color: var(--muted); }
.who .as button { padding: 0 0 0 4px; font-size: 13px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; }

@media (min-width: 700px) {
  .post { padding-top: 24px; }
  .frame { border-radius: var(--radius); overflow: hidden; }
  .body { padding: 4px 0 0; }
  .comment-form { padding-left: 0; padding-right: 0; }
}

/* ---- Subscribe ---- */

.subscribe {
  max-width: 480px;
  margin: 32px auto 0;
  padding: 0 var(--gutter);
  text-align: center;
}
.post .subscribe { padding: 0; margin-top: 16px; }
.subscribe label { display: block; margin-bottom: 8px; font-size: 14px; color: var(--muted); }
.subscribe .row { display: flex; gap: 8px; }
.subscribe .row input { min-width: 0; }
.subscribe .row button {
  flex: none;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
}
.subscribe .note { margin: 10px 0 0; font-size: 14px; }

.message, .subscribers {
  display: grid;
  gap: 12px;
  max-width: 480px;
  margin: 0 auto;
  padding: 48px var(--gutter);
  text-align: center;
}
.message h1, .subscribers h1 { margin: 0; font: 700 28px/1.2 var(--display); letter-spacing: -0.03em; }
.message p { margin: 0; }
.message a { color: var(--muted); }
.subscribers { text-align: left; padding-top: 24px; }
.subscribers ul { list-style: none; margin: 0; padding: 0; }
.subscribers li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.subscribers li form { margin: 0; }
.subscribers small { color: var(--muted); }
.muted { color: var(--muted); }

/* ---- Forms: upload & login ---- */

.upload, .login {
  display: grid;
  gap: 14px;
  max-width: 480px;
  margin: 0 auto;
  padding: 24px var(--gutter) calc(24px + env(safe-area-inset-bottom));
}
.upload h1, .login h1 { margin: 0; font: 700 28px/1.2 var(--display); letter-spacing: -0.03em; }

.drop {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 160px;
  padding: 20px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  font-weight: 600;
}
.drop.over { border-color: var(--text); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop small { display: block; margin-top: 4px; color: var(--muted); font-weight: 400; }

.previews {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.previews:empty { display: none; }
.previews li {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 8px;
  background: var(--media-bg);
}
.previews img, .previews video { width: 100%; height: 100%; object-fit: cover; }
.previews .name {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 6px;
  font-size: 11px;
  color: var(--muted);
  overflow-wrap: anywhere;
  text-align: center;
}
.previews .remove {
  position: absolute;
  z-index: 1;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0 0 2px;
  border: 0;
  border-radius: 50%;
  background: rgb(0 0 0 / 0.6);
  color: #fff;
  font-size: 20px;
  line-height: 1;
}
/* Bigger invisible hit area for fingers. */
.previews .remove::before { content: ""; position: absolute; inset: -8px; }
.previews .bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 4px;
  width: 0;
  background: var(--accent);
  transition: width 0.2s;
}
.previews li.sending img, .previews li.sending video { opacity: 0.6; }
.previews li.done::after,
.previews li.failed::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 28px;
  color: #fff;
  background: rgb(0 0 0 / 0.35);
  pointer-events: none;
}
.previews li.done::after { content: "✓"; }
.previews li.failed::after { content: "!"; background: rgb(232 67 63 / 0.55); }
.upload.busy .remove, .previews li.done .remove { display: none; }

@media (min-width: 480px) {
  .previews { grid-template-columns: repeat(4, 1fr); }
}

.check { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.check input { width: 20px; height: 20px; }

.progress { position: relative; height: 28px; border-radius: 14px; background: var(--media-bg); overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--text); transition: width 0.2s; }
.progress span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  mix-blend-mode: difference;
}
.error { margin: 0; color: var(--accent); white-space: pre-line; }

.foot { padding: 24px var(--gutter) calc(16px + env(safe-area-inset-bottom)); text-align: center; font-size: 12px; }
.foot a { color: var(--muted); text-decoration: none; opacity: 0.6; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
