/* Marginalia — [marginalia-feed-v1]
 * Full-screen note feed. Every selector is mg- prefixed so nothing here can
 * reach into the grid, editor, or settings pages.
 */

:root {
  --mg-ink: #0F1115;
  --mg-paper: #F0EDE4;
  --mg-ochre: #D9A574;
  --mg-line: rgba(240, 237, 228, 0.08);
}

html.mg-feed-open, html.mg-feed-open body { overflow: hidden; height: 100%; }

.mg-feed {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--mg-ink);
  overflow: hidden;
  font-family: 'Manrope', ui-sans-serif, system-ui, sans-serif;
}

/* ---------- scroller ---------- */

.mg-scroll {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
.mg-scroll::-webkit-scrollbar { display: none; }

.mg-slide {
  position: relative;
  height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.mg-slide.is-leaving { opacity: 0; transition: opacity 200ms ease; }

.mg-bg {
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    0deg, transparent, transparent 31px,
    rgba(240, 237, 228, 0.016) 31px, rgba(240, 237, 228, 0.016) 32px);
}
.mg-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg,
    rgba(0, 0, 0, 0.55) 0%, transparent 18%,
    transparent 62%, rgba(0, 0, 0, 0.72) 100%);
}

/* whole-screen tints — the card colors, scaled up */
.mg-c-default { background: #141317; }
.mg-c-coral   { background: #241A18; }
.mg-c-mustard { background: #221E15; }
.mg-c-sage    { background: #16201B; }
.mg-c-slate   { background: #161B22; }
.mg-c-plum    { background: #20161E; }
.mg-c-sand    { background: #1F1A14; }

.mg-inner {
  position: relative;
  z-index: 2;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: calc(64px + env(safe-area-inset-top)) 74px calc(96px + env(safe-area-inset-bottom)) 22px;
  touch-action: pan-y;
  will-change: transform;
}
.mg-inner.is-settling { transition: transform 360ms cubic-bezier(0.34, 1.56, 0.64, 1); }

/* ---------- meta row ---------- */

.mg-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.mg-stamp {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem; letter-spacing: 0.06em;
  color: rgba(240, 237, 228, 0.42);
}
.mg-dot { width: 3px; height: 3px; border-radius: 50%; background: rgba(240, 237, 228, 0.22); }
.mg-group {
  font-size: 0.68rem; padding: 2px 9px; border-radius: 999px;
  background: rgba(240, 237, 228, 0.06); color: rgba(240, 237, 228, 0.6);
  border: 1px solid var(--mg-line);
}
.mg-remind {
  font-size: 0.68rem; padding: 2px 9px; border-radius: 999px;
  background: rgba(217, 165, 116, 0.13); color: var(--mg-ochre);
  border: 1px solid rgba(217, 165, 116, 0.28);
}

/* ---------- the note ---------- */

.mg-body {
  flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: none;
  overscroll-behavior: contain;
  -webkit-mask-image: linear-gradient(180deg, #000 0, #000 88%, transparent 100%);
          mask-image: linear-gradient(180deg, #000 0, #000 88%, transparent 100%);
}
.mg-body::-webkit-scrollbar { display: none; }

.mg-lede {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.86rem;
  line-height: 1.14;
  letter-spacing: -0.028em;
  font-variation-settings: "SOFT" 60, "WONK" 1;
  margin-bottom: 12px;
  text-wrap: balance;
  word-break: break-word;
}
.mg-slide.is-long .mg-lede { font-size: 1.36rem; line-height: 1.2; }
.mg-slide.is-done .mg-lede,
.mg-slide.is-done .mg-prose {
  text-decoration: line-through;
  text-decoration-color: rgba(240, 237, 228, 0.35);
  opacity: 0.6;
}

/* .note-content carries the shared markdown styling; only the scale differs */
.mg-prose { font-size: 1.01rem; line-height: 1.62; }

.mg-media { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.mg-tile {
  border-radius: 14px; overflow: hidden; border: 1px solid var(--mg-line);
  background: #000; max-height: 42vh;
}
.mg-tile img, .mg-tile video { display: block; width: 100%; height: 100%; object-fit: cover; max-height: 42vh; }
.mg-tile img { cursor: zoom-in; }
.mg-media-more { font-size: 0.72rem; color: rgba(240, 237, 228, 0.45); }
.mg-audio audio { width: 100%; }

.mg-link {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px; margin-top: 10px;
  border-radius: 10px; text-decoration: none;
  background: rgba(240, 237, 228, 0.05);
  border: 1px solid var(--mg-line);
  font-size: 0.8rem; color: rgba(240, 237, 228, 0.85);
}
.mg-link-icon { color: var(--mg-ochre); flex-shrink: 0; display: inline-flex; }
.mg-link-text { min-width: 0; }
.mg-link-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-link-host {
  display: block; font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem; color: rgba(240, 237, 228, 0.45);
}

.mg-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.mg-tag {
  font-family: 'JetBrains Mono', monospace; font-size: 0.68rem;
  padding: 3px 9px; border-radius: 999px;
  background: rgba(240, 237, 228, 0.05); color: rgba(240, 237, 228, 0.5);
}

/* ---------- action rail ---------- */

.mg-rail {
  position: absolute; right: 6px; z-index: 5;
  bottom: calc(96px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 15px;
}
.mg-rail-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  width: 52px; padding: 0; border: 0; background: none; cursor: pointer;
  color: rgba(240, 237, 228, 0.82); font-family: inherit;
}
.mg-glyph {
  width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 19, 23, 0.55);
  border: 1px solid rgba(240, 237, 228, 0.10);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1),
              background 160ms ease, color 160ms ease, border-color 160ms ease;
}
.mg-rail-btn:active .mg-glyph { transform: scale(0.88); }
.mg-cap { font-size: 0.58rem; letter-spacing: 0.05em; color: rgba(240, 237, 228, 0.5); }
.mg-rail-btn.is-on .mg-glyph {
  color: var(--mg-ochre);
  background: rgba(217, 165, 116, 0.14);
  border-color: rgba(217, 165, 116, 0.5);
}
.mg-rail-btn.is-on .mg-cap { color: var(--mg-ochre); }
.mg-rail-btn[data-act="pin"].is-on .mg-glyph { transform: rotate(-24deg); }
.mg-rail-btn[data-act="delete"] .mg-glyph { color: rgba(230, 130, 130, 0.9); }
.mg-rail-btn.is-armed .mg-glyph {
  border-color: rgba(220, 80, 80, 0.7);
  background: rgba(220, 80, 80, 0.18);
}

/* ---------- swipe affordances ---------- */

.mg-edge {
  position: absolute; top: 0; bottom: 0; width: 44%; z-index: 1;
  display: flex; align-items: center; opacity: 0; pointer-events: none;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
}
.mg-edge.left {
  left: 0; justify-content: flex-start; padding-left: 26px; color: #8FBFA3;
  background: linear-gradient(90deg, rgba(88, 150, 116, 0.28), transparent);
}
.mg-edge.right {
  right: 0; justify-content: flex-end; padding-right: 26px; color: #C9A9D6;
  background: linear-gradient(270deg, rgba(140, 105, 160, 0.28), transparent);
}

.mg-burst {
  position: absolute; z-index: 9; pointer-events: none; color: var(--mg-ochre);
  animation: mg-burst 720ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.mg-burst svg { width: 76px; height: 76px; }
@keyframes mg-burst {
  0%   { transform: translate(-50%, -50%) scale(0.2) rotate(-40deg); opacity: 0; }
  35%  { transform: translate(-50%, -50%) scale(1.15) rotate(-14deg); opacity: 1; }
  100% { transform: translate(-50%, -90%) scale(0.9) rotate(-14deg); opacity: 0; }
}

/* ---------- chrome ---------- */

.mg-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 8;
  padding: max(12px, env(safe-area-inset-top)) 14px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  pointer-events: none;
}
.mg-top > * { pointer-events: auto; }

.mg-pill {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 13px; border-radius: 999px;
  background: rgba(20, 19, 23, 0.6);
  border: 1px solid rgba(240, 237, 228, 0.12);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  font-family: inherit; font-size: 0.78rem; font-weight: 600;
  color: var(--mg-paper); cursor: pointer;
  transition: transform 140ms cubic-bezier(0.34, 1.56, 0.64, 1), background 160ms ease;
}
.mg-pill:active { transform: scale(0.94); }
.mg-pill-accent { color: var(--mg-ochre); border-color: rgba(217, 165, 116, 0.35); }
.mg-pill span { display: inline-flex; }
.mg-pill svg { width: 15px; height: 15px; }

.mg-counter {
  font-family: 'JetBrains Mono', monospace; font-size: 0.74rem;
  letter-spacing: 0.04em; color: rgba(240, 237, 228, 0.55);
}
.mg-counter b { color: var(--mg-paper); font-weight: 500; }

.mg-spine {
  position: absolute; right: 2px; z-index: 6; width: 2px;
  top: calc(84px + env(safe-area-inset-top));
  bottom: calc(104px + env(safe-area-inset-bottom));
  background: rgba(240, 237, 228, 0.07); border-radius: 2px;
}
.mg-spine-fill {
  position: absolute; left: 0; top: 0; width: 2px; height: 100%;
  background: var(--mg-ochre); opacity: 0.75; border-radius: 2px;
  transform-origin: top; transform: scaleY(0);
  transition: transform 260ms cubic-bezier(0.16, 1, 0.3, 1);
}

.mg-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 8;
  display: flex; align-items: center; justify-content: space-around;
  padding: 8px 8px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(15, 17, 21, 0) 0%, rgba(15, 17, 21, 0.88) 45%);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid rgba(240, 237, 228, 0.05);
}
.mg-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 0; border: 0; background: none; cursor: pointer;
  font-family: inherit; font-size: 0.6rem; letter-spacing: 0.02em;
  color: rgba(240, 237, 228, 0.45); transition: color 160ms ease;
}
.mg-tab.is-active { color: var(--mg-paper); }
.mg-tab.is-active .mg-tab-icon { color: var(--mg-ochre); }
.mg-tab-icon { display: inline-flex; }
.mg-slot { flex: 1; display: flex; justify-content: center; }
.mg-compose {
  width: 46px; height: 34px; border-radius: 12px;
  background: var(--mg-ochre); color: #0F1115; border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(217, 165, 116, 0.28);
  transition: transform 150ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.mg-compose:active { transform: scale(0.9); }

/* ---------- status (loading / empty / error) ---------- */

.mg-status {
  position: absolute; inset: 0; z-index: 3;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 40px; text-align: center;
}
.mg-status.is-shown { display: flex; }
.mg-status h2 { font-family: 'Fraunces', serif; font-size: 1.4rem; font-weight: 600; }
.mg-status p { font-size: 0.88rem; color: #918B7E; max-width: 30ch; }

.mg-end-inner { align-items: flex-start; justify-content: center; }
.mg-end-sub { font-size: 0.9rem; color: #918B7E; margin-top: -4px; }
.mg-end-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

.mg-feed :focus-visible { outline: 2px solid rgba(217, 165, 116, 0.65); outline-offset: 2px; border-radius: 8px; }

@media (prefers-reduced-motion: reduce) {
  .mg-inner, .mg-glyph, .mg-pill, .mg-compose, .mg-spine-fill, .mg-slide {
    transition: none !important;
  }
  .mg-burst { display: none !important; }
  .mg-scroll { scroll-behavior: auto; }
}

/* Desktop gets a centered column — the feed is a phone shape by nature. */
@media (min-width: 1024px) {
  .mg-slide { max-width: 520px; margin: 0 auto; }
  .mg-top, .mg-bottom { max-width: 560px; left: 50%; transform: translateX(-50%); }
  .mg-spine { right: max(8px, calc(50vw - 290px)); }
}
