:root {
  --bg: #faf9f6;
  --surface: #ffffff;
  --surface-subtle: #f3f1ec;
  --ink: #171717;
  --ink-muted: #6b6b66;
  --ink-faint: #9a9a94;
  --border: rgba(23, 23, 23, 0.08);
  --border-strong: rgba(23, 23, 23, 0.16);
  --accent: #c86442;
  --accent-soft: rgba(200, 100, 66, 0.1);
  --story-gradient: linear-gradient(135deg, #e07a5f 0%, #d97706 55%, #b45309 100%);
  --heart: #e11d48;
  --success: #15803d;

  --font-display: "Instrument Serif", Georgia, serif;
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow-card: 0 1px 2px rgba(23, 23, 23, 0.04), 0 8px 24px rgba(23, 23, 23, 0.03);
  --max-feed: 540px;
  --max-page: 920px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 84px;
}

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

img,
video {
  display: block;
  max-width: 100%;
}

button {
  font-family: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Scroll Progress */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
  z-index: 60;
  pointer-events: none;
}

.scroll-progress__bar {
  height: 100%;
  width: 0%;
  background: var(--story-gradient);
  transition: width 80ms linear;
}

/* Sticky Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(250, 249, 246, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar__inner {
  max-width: var(--max-page);
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar__brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
}

.topbar__dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--story-gradient);
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar__chapter-pill {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-muted);
  background: var(--surface-subtle);
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

@media (max-width: 560px) {
  .topbar__chapter-pill {
    display: none;
  }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  transition: transform 140ms ease, background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn--sm {
  padding: 7px 13px;
  font-size: 12.5px;
}

.btn--primary {
  background: var(--ink);
  color: #ffffff;
}

.btn--primary:hover {
  background: #2b2b29;
}

.btn--outline {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border-strong);
}

.btn--outline:hover {
  background: var(--surface-subtle);
}

.btn--outline.is-downloaded {
  color: var(--success);
  border-color: rgba(21, 128, 61, 0.3);
  background: rgba(21, 128, 61, 0.06);
}

.btn--ghost {
  background: transparent;
  color: var(--ink-muted);
}

.btn--ghost:hover {
  color: var(--ink);
  background: var(--surface-subtle);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--ink);
  transition: background-color 140ms ease, transform 140ms ease, color 140ms ease;
}

.icon-btn:hover {
  background: var(--surface-subtle);
}

.icon-btn:active {
  transform: scale(0.92);
}

.icon-btn.is-liked {
  color: var(--heart);
}

.icon-btn.is-saved {
  color: var(--accent);
}

.icon-btn--light {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.12);
}

.icon-btn--light:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* Page Container */
.page {
  max-width: var(--max-page);
  margin: 0 auto;
  padding: 28px 16px 48px;
}

/* Profile Hero */
.profile-hero {
  max-width: 720px;
  margin: 0 auto 24px;
}

.profile-hero__card {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 8px 4px 24px;
}

.story-ring {
  padding: 3px;
  border-radius: 999px;
  background: var(--story-gradient);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.story-ring--lg {
  padding: 3.5px;
}

.profile-hero__avatar {
  width: 108px;
  height: 108px;
  border-radius: 999px;
  object-fit: cover;
  border: 3px solid var(--bg);
}

.profile-hero__eyebrow {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 4px;
}

.profile-hero__title {
  font-family: var(--font-display);
  font-size: clamp(34px, 5vw, 46px);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
}

.profile-hero__bio {
  margin: 0 0 14px;
  color: var(--ink-muted);
  font-size: 14.5px;
  max-width: 48ch;
}

.profile-hero__stats {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  font-size: 13.5px;
  color: var(--ink-muted);
}

.profile-hero__stats strong {
  color: var(--ink);
  font-weight: 700;
}

@media (max-width: 600px) {
  .profile-hero__card {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
    padding-bottom: 18px;
  }

  .profile-hero__avatar {
    width: 84px;
    height: 84px;
  }
}

/* Stories / Chapters Rail */
.stories-rail {
  margin: 6px 0 20px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.stories-rail__track {
  display: flex;
  gap: 18px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px 2px;
}

.stories-rail__track::-webkit-scrollbar {
  display: none;
}

.story-item {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: none;
  padding: 0;
  color: var(--ink-muted);
  transition: color 150ms ease, transform 150ms ease;
}

.story-item:hover {
  color: var(--ink);
  transform: translateY(-2px);
}

.story-item.is-active {
  color: var(--ink);
}

.story-item__ring {
  padding: 2.5px;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background 200ms ease;
}

.story-item.is-active .story-item__ring,
.story-item:hover .story-item__ring {
  background: var(--story-gradient);
}

.story-item__thumb {
  width: 62px;
  height: 62px;
  border-radius: 999px;
  object-fit: cover;
  border: 2.5px solid var(--bg);
}

.story-item__label {
  font-size: 12px;
  font-weight: 500;
  max-width: 82px;
  text-align: center;
  line-height: 1.2;
}

/* Tabs */
.feed-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-muted);
  font-size: 13px;
  font-weight: 600;
  transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}

.tab-btn:hover {
  color: var(--ink);
  background: var(--surface-subtle);
}

.tab-btn.is-active {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border-strong);
  box-shadow: 0 1px 3px rgba(23, 23, 23, 0.05);
}

/* Scrollytelling Chapter Divider */
.chapter-banner {
  max-width: var(--max-feed);
  margin: 44px auto 22px;
  padding: 24px 20px;
  text-align: center;
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 520ms ease, transform 520ms ease;
}

.chapter-banner:first-child {
  margin-top: 12px;
}

.chapter-banner.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.chapter-banner__num {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.chapter-banner__title {
  font-family: var(--font-display);
  font-size: clamp(28px, 4.5vw, 36px);
  font-weight: 400;
  margin: 0 0 6px;
  line-height: 1.1;
}

.chapter-banner__desc {
  margin: 0 auto;
  max-width: 42ch;
  font-size: 14px;
  color: var(--ink-muted);
}

/* Instagram-like Post Card */
.post-card {
  max-width: var(--max-feed);
  margin: 0 auto 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 480ms ease, transform 480ms ease;
}

.post-card.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.post-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}

.post-card__author {
  display: flex;
  align-items: center;
  gap: 10px;
}

.post-card__mini-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.post-card__meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.post-card__handle {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}

.post-card__sub {
  font-size: 11.5px;
  color: var(--ink-muted);
}

.post-card__index {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.post-card__media {
  position: relative;
  background: #f0eee9;
  overflow: hidden;
  user-select: none;
}

.post-card__img,
.post-card__video {
  width: 100%;
  height: auto;
  max-height: 76vh;
  object-fit: contain;
  background: #141413;
}

.post-card__img {
  background: #f0eee9;
  object-fit: cover;
  cursor: zoom-in;
}

.post-card__video-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(23, 23, 23, 0.72);
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
  pointer-events: none;
}

/* Double-tap heart burst */
.heart-burst {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
}

.heart-burst.is-animating {
  animation: heartPop 720ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes heartPop {
  0% {
    opacity: 0;
    transform: scale(0.4);
  }
  25% {
    opacity: 0.95;
    transform: scale(1.15);
  }
  55% {
    opacity: 0.95;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.2);
  }
}

.post-card__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 6px;
}

.post-card__actions-left {
  display: flex;
  align-items: center;
  gap: 2px;
}

.post-card__body {
  padding: 2px 16px 14px;
}

.post-card__caption {
  margin: 0;
  font-size: 13.5px;
  color: var(--ink);
}

.post-card__caption strong {
  font-weight: 600;
  margin-right: 6px;
}

.post-card__filename {
  display: inline-block;
  margin-top: 5px;
  font-size: 11.5px;
  color: var(--ink-faint);
}

/* Grid Mode (IG Profile 3-col Grid) */
.grid-view {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  max-width: 820px;
  margin: 16px auto 0;
}

@media (max-width: 560px) {
  .grid-view {
    gap: 3px;
  }
}

.grid-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--surface-subtle);
  overflow: hidden;
  border-radius: 6px;
  cursor: pointer;
}

.grid-tile img,
.grid-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 240ms ease;
}

.grid-tile:hover img,
.grid-tile:hover video {
  transform: scale(1.03);
}

.grid-tile__overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55) 0%, transparent 50%);
  opacity: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 10px;
  transition: opacity 160ms ease;
}

.grid-tile:hover .grid-tile__overlay,
.grid-tile:focus-within .grid-tile__overlay {
  opacity: 1;
}

.grid-tile__type {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(23, 23, 23, 0.72);
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 999px;
}

.grid-tile__dl {
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  border: none;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.grid-tile__dl:hover {
  background: #ffffff;
}

/* Empty State */
.empty-state {
  max-width: var(--max-feed);
  margin: 40px auto;
  text-align: center;
  padding: 48px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.empty-state h3 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 400;
  margin: 0 0 8px;
}

.empty-state p {
  margin: 0;
  color: var(--ink-muted);
  font-size: 14px;
}

/* Footer */
.footer {
  max-width: var(--max-page);
  margin: 0 auto;
  padding: 24px 20px 44px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--ink-muted);
  font-size: 13px;
}

/* Lightbox Modal */
.lightbox[hidden] {
  display: none;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 16, 15, 0.92);
  backdrop-filter: blur(8px);
}

.lightbox__panel {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px 20px;
}

.lightbox__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #ffffff;
}

.lightbox__counter {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.8);
  font-variant-numeric: tabular-nums;
}

.lightbox__header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lightbox__stage {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 12px 48px;
}

@media (max-width: 600px) {
  .lightbox__stage {
    padding: 12px 4px;
  }
}

.lightbox__media-wrap {
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox__media-wrap img,
.lightbox__media-wrap video {
  max-width: 100%;
  max-height: 78vh;
  border-radius: 10px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.lightbox__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(23, 23, 23, 0.65);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 140ms ease;
}

.lightbox__nav:hover {
  background: rgba(255, 255, 255, 0.2);
}

.lightbox__nav--prev {
  left: 8px;
}

.lightbox__nav--next {
  right: 8px;
}

.lightbox__caption {
  text-align: center;
  color: rgba(255, 255, 255, 0.78);
  font-size: 13px;
  padding-top: 8px;
}

/* Toast */
.toast[hidden] {
  display: none;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  background: var(--ink);
  color: #ffffff;
  padding: 12px 18px;
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  min-width: 240px;
  max-width: 90vw;
  font-size: 13px;
  font-weight: 500;
}

.toast__progress {
  margin-top: 8px;
  height: 4px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  overflow: hidden;
}

.toast__progress-bar {
  height: 100%;
  width: 0%;
  background: var(--story-gradient);
  transition: width 120ms linear;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .chapter-banner,
  .post-card {
    opacity: 1;
    transform: none;
    transition: none;
  }

  .heart-burst.is-animating {
    animation: none;
  }
}

