@import url('https://fonts.googleapis.com/css2?family=Onest:wght@400;500;600&family=Unbounded:wght@500;700&display=swap');

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
h1, h2, h3, .display { font-family: var(--font-display); font-weight: 500; letter-spacing: -0.01em; margin: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
input, textarea { font: inherit; font-size: max(16px, var(--text-md)); color: inherit; }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
svg { display: block; }
[hidden] { display: none !important; }

.app {
  max-width: var(--app-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
  padding-top: calc(env(safe-area-inset-top, 0px) + var(--space-5));
  /* room for the fixed composer */
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 9rem);
}

/* ---------- header: big counter as the anchor ---------- */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); }
.head__count { font-family: var(--font-display); font-size: var(--text-xl); line-height: 1; font-weight: 700; }
.head__count small { display: block; font-family: var(--font-body); font-size: var(--text-sm); font-weight: 500; color: var(--color-muted); margin-top: var(--space-2); }
.head__live { font-size: var(--text-sm); color: var(--color-accent); display: flex; align-items: center; gap: var(--space-2); }
.head__live::before { content: ''; width: 0.5rem; height: 0.5rem; border-radius: var(--radius-full); background: currentColor; animation: pulse 1.4s ease-in-out infinite; }

/* ---------- feed ---------- */
.feed { display: grid; gap: var(--space-3); list-style: none; margin: 0; padding: 0; }
.item {
  display: grid; grid-template-columns: var(--thumb) minmax(0, 1fr); gap: var(--space-3);
  padding: var(--space-3); background: var(--color-surface); border: 1px solid var(--color-line);
  border-radius: var(--radius-md); text-align: left; width: 100%;
  animation: fade-in 0.3s var(--ease-out);
  transition: transform 0.15s var(--ease-out), border-color 0.2s;
}
.item:active { transform: scale(0.985); }
.item--failed { border-color: color-mix(in oklab, var(--color-danger) 45%, var(--color-line)); }
.item__thumb {
  width: var(--thumb); aspect-ratio: 9 / 13; border-radius: var(--radius-sm); overflow: hidden;
  background: var(--color-surface-2); display: grid; place-items: center; color: var(--color-muted);
}
.item__thumb img { width: 100%; height: 100%; object-fit: cover; }
.item__body { min-width: 0; display: grid; gap: var(--space-2); align-content: start; }
.item__title {
  font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.item__title--pending { color: var(--color-muted); font-weight: 500; }
.item__meta { font-size: var(--text-xs); color: var(--color-muted); display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); }
.item__err { font-size: var(--text-sm); color: var(--color-danger); overflow-wrap: anywhere; }

.tags { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.tag {
  font-size: var(--text-xs); font-weight: 600; padding: 0.125rem var(--space-2); border-radius: var(--radius-full);
  color: var(--tag); background: color-mix(in oklab, var(--tag) 16%, var(--color-surface));
}

/* stage track: 4 segments, the signature of the feed */
.track { display: grid; gap: var(--space-1); }
.track__bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; }
.track__bar i { height: 3px; border-radius: var(--radius-full); background: var(--color-line); }
.track__bar i.on { background: var(--color-accent); }
.track__bar i.now { background: var(--color-accent); animation: pulse 1.2s ease-in-out infinite; }
.track__label { font-size: var(--text-xs); color: var(--color-accent); }

.retry { justify-self: start; font-size: var(--text-sm); font-weight: 600; color: var(--color-accent); min-height: var(--tap); }

.empty { padding: var(--space-7) var(--space-4); text-align: center; color: var(--color-muted); }
.empty h2 { font-size: var(--text-lg); color: var(--color-text); margin-bottom: var(--space-2); }

/* ---------- composer (fixed bottom) ---------- */
.composer {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 10;
  background: color-mix(in oklab, var(--color-bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--color-line);
  padding: var(--space-3) var(--gutter) calc(env(safe-area-inset-bottom, 0px) + var(--space-3));
}
.composer__inner { max-width: var(--app-max); margin-inline: auto; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-2); align-items: end; }
.composer textarea {
  width: 100%; min-height: calc(var(--tap) + var(--space-1)); max-height: 9rem; resize: none;
  padding: var(--space-3) var(--space-4); line-height: 1.35;
  background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-md);
}
.composer textarea:focus { outline: none; border-color: var(--color-accent); }
.composer__actions { display: flex; gap: var(--space-2); }
.round {
  width: calc(var(--tap) + var(--space-1)); height: calc(var(--tap) + var(--space-1)); border-radius: var(--radius-full);
  display: grid; place-items: center; background: var(--color-surface-2); border: 1px solid var(--color-line);
  transition: transform 0.15s var(--ease-out), background 0.2s;
}
.round:active { transform: scale(0.94); }
.round--accent { background: var(--color-accent); color: var(--color-on-accent); border-color: transparent; }
.round--rec { background: var(--color-rec); color: var(--color-on-accent); border-color: transparent; animation: pulse 1.2s ease-in-out infinite; }
.round:disabled { opacity: 0.4; pointer-events: none; }
.rec-label { grid-column: 1 / -1; font-size: var(--text-sm); color: var(--color-rec); display: flex; align-items: center; gap: var(--space-2); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + var(--space-3)); z-index: 30;
  transform: translateX(-50%); max-width: calc(100% - 2 * var(--gutter));
  background: var(--color-surface-2); border: 1px solid var(--color-line); border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-4); font-size: var(--text-sm); font-weight: 600;
  box-shadow: var(--shadow-raise); animation: drop-in 0.3s var(--ease-out);
}

/* ---------- card viewer (full-screen sheet) ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 20; background: var(--color-bg); overflow-y: auto;
  -webkit-overflow-scrolling: touch; animation: rise 0.28s var(--ease-out);
}
.sheet__bar {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: var(--space-2);
  padding: calc(env(safe-area-inset-top, 0px) + var(--space-2)) var(--gutter) var(--space-2);
  background: color-mix(in oklab, var(--color-bg) 90%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--color-line);
}
.sheet__bar a { margin-left: auto; font-size: var(--text-sm); color: var(--color-accent); text-decoration: none; min-height: var(--tap); display: flex; align-items: center; }
.icon-btn { width: var(--tap); height: var(--tap); display: grid; place-items: center; border-radius: var(--radius-full); color: var(--color-muted); }
.icon-btn:active { background: var(--color-surface-2); }
.doc {
  max-width: var(--app-max); margin-inline: auto;
  padding: var(--space-5) var(--gutter) calc(env(safe-area-inset-bottom, 0px) + var(--space-7));
  overflow-wrap: anywhere;
}
.doc h1 { font-size: var(--text-lg); line-height: 1.25; margin-bottom: var(--space-4); }
.doc h2 { font-size: var(--text-md); margin: var(--space-6) 0 var(--space-3); color: var(--color-accent); }
.doc h3 { font-family: var(--font-body); font-size: var(--text-sm); color: var(--color-muted); margin: var(--space-4) 0 var(--space-2); }
.doc p { margin: 0 0 var(--space-3); }
.doc .ts { font-variant-numeric: tabular-nums; color: var(--color-accent); font-weight: 600; font-size: var(--text-sm); margin-right: var(--space-1); }
.doc img { max-width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--color-line); display: block; }
.doc blockquote { margin: var(--space-2) 0 var(--space-3); padding: var(--space-2) var(--space-3); border-left: 2px solid var(--color-line); color: var(--color-muted); font-size: var(--text-sm); white-space: pre-line; }
.doc a { color: var(--color-accent); }
.doc .meta { font-size: var(--text-sm); color: var(--color-muted); }
.frames { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.frames figure { margin: 0; }
.frames figcaption { font-size: var(--text-xs); color: var(--color-muted); margin-top: var(--space-1); }
.frames blockquote { grid-column: 1 / -1; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; align-content: center; gap: var(--space-5); max-width: 22rem; margin-inline: auto; padding: var(--space-5) var(--gutter); }
.login h1 { font-size: var(--text-xl); font-weight: 700; line-height: 1.05; }
.login p { color: var(--color-muted); margin: 0; }
.login input {
  width: 100%; min-height: calc(var(--tap) + var(--space-2)); padding: var(--space-3) var(--space-4);
  background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-sm);
}
.login input:focus { outline: none; border-color: var(--color-accent); }
.btn {
  min-height: calc(var(--tap) + var(--space-2)); border-radius: var(--radius-sm); font-weight: 600;
  background: var(--color-accent); color: var(--color-on-accent); width: 100%;
}
.login .err { color: var(--color-danger); font-size: var(--text-sm); }

@keyframes pulse { 50% { opacity: 0.45; } }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes rise { from { opacity: 0; transform: translateY(2rem); } }
@keyframes drop-in { from { opacity: 0; transform: translate(-50%, -0.75rem); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 768px) {
  .frames { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.frames__note { grid-column: 1 / -1; margin: 0; }
