/* ==========================================================================
   Proposita — design tokens
   ========================================================================== */
:root {
  --bg: #0b0b12;
  --fg: #f5f2ee;
  --fg-muted: rgba(245, 242, 238, 0.68);
  --fg-faint: rgba(245, 242, 238, 0.4);
  --surface: rgba(255, 255, 255, 0.08);
  --surface-strong: rgba(255, 255, 255, 0.14);
  --line: rgba(255, 255, 255, 0.14);
  --accent: #ff9a6c;
  --accent-2: #7c5cff;
  --like: #ff4d6d;
  --save: #ffd166;
  --radius: 18px;
  --radius-sm: 12px;
  --font-serif: "Fraunces", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --topbar-h: 56px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --frame-w: 100vw;
  color-scheme: dark;
}

/* Card themes: two gradient stops plus a glow colour used by the watermark. */
.theme-dawn   { --t1: #3b1d3d; --t2: #c0553a; --glow: #ffb08a; }
.theme-dusk   { --t1: #12102b; --t2: #4a2f8f; --glow: #9b7bff; }
.theme-forest { --t1: #0d1f1a; --t2: #1f6b57; --glow: #7fe0bf; }
.theme-ember  { --t1: #24100c; --t2: #a8351e; --glow: #ff9466; }
.theme-ocean  { --t1: #071a2b; --t2: #0f5f8c; --glow: #6ad3ff; }
.theme-sand   { --t1: #2c2116; --t2: #8b6b3f; --glow: #ffd79a; }
.theme-ink    { --t1: #0a0a0f; --t2: #2a2c3a; --glow: #b8bcd6; }
.theme-plum   { --t1: #1d0f26; --t2: #6d2a6e; --glow: #ff8ad8; }

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, h3 { margin: 0; font-family: var(--font-serif); font-weight: 500; letter-spacing: -0.01em; }
p { margin: 0; }
.muted { color: var(--fg-muted); }
.small { font-size: 0.85rem; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.72rem; color: var(--accent); font-weight: 600; }

/* The app is a phone-shaped column; on wide screens it floats centred. */
.app {
  position: relative;
  height: 100dvh;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
}
@media (min-width: 720px) {
  body { background: radial-gradient(120% 80% at 50% 0%, #1b1730 0%, #07070c 60%); }
  .app { box-shadow: 0 0 0 1px var(--line), 0 40px 120px rgba(0, 0, 0, 0.6); }
}

/* ==========================================================================
   Top bar
   ========================================================================== */
.topbar {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 20;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.topbar__brand { display: flex; align-items: center; gap: 8px; }
.brand__mark {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b0b12; font-family: var(--font-serif); font-style: italic; font-weight: 600; font-size: 1.15rem;
}
.brand__name { font-family: var(--font-serif); font-size: 1.15rem; letter-spacing: 0.01em; }
.topbar__stats { display: flex; align-items: center; gap: 8px; }
.stat {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 10px; border-radius: 999px;
  background: var(--surface); backdrop-filter: blur(12px);
  font-weight: 600; font-size: 0.9rem;
}
.stat--streak.is-hot .stat__icon { animation: flame 1.2s ease-in-out infinite alternate; }
@keyframes flame { from { transform: scale(1) rotate(-4deg); } to { transform: scale(1.18) rotate(4deg); } }

.goal { position: relative; width: 40px; height: 40px; display: grid; place-items: center; }
.goal__ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.goal__track, .goal__bar { fill: none; stroke-width: 3.5; stroke-linecap: round; }
.goal__track { stroke: rgba(255, 255, 255, 0.18); }
.goal__bar {
  stroke: var(--accent);
  stroke-dasharray: 100.53; /* 2πr, r = 16 */
  stroke-dashoffset: 100.53;
  transition: stroke-dashoffset 0.6s var(--ease-out), stroke 0.3s;
}
.goal.is-complete .goal__bar { stroke: #7fe0bf; }
.goal.is-complete { animation: pop 0.5s var(--ease-spring); }
.goal__label { font-size: 0.62rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface); backdrop-filter: blur(12px);
  display: grid; place-items: center;
}
.avatar svg { width: 20px; height: 20px; fill: var(--fg); }

/* ==========================================================================
   Feed (vertical snap scroller)
   ========================================================================== */
.feed {
  position: absolute; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.feed::-webkit-scrollbar { display: none; }
.feed__loading {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; color: var(--fg-muted);
}
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Card
   ========================================================================== */
.card {
  position: relative;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.card__bg {
  position: absolute; inset: 0; z-index: -1;
  background:
    radial-gradient(90% 70% at 20% 10%, color-mix(in srgb, var(--glow) 24%, transparent), transparent 60%),
    linear-gradient(160deg, var(--t1) 0%, var(--t2) 100%);
}
.card__bg::after {
  /* film grain */
  content: "";
  position: absolute; inset: 0; opacity: 0.12; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
.card__watermark {
  position: absolute; right: -4vw; top: 6vh;
  font-family: var(--font-serif); font-style: italic; font-weight: 300;
  font-size: clamp(220px, 60vw, 380px); line-height: 1;
  color: var(--glow); opacity: 0.08;
  transform: translateY(20px);
  transition: transform 1.2s var(--ease-out), opacity 1.2s;
}
.card.is-active .card__watermark { transform: translateY(0); opacity: 0.12; }

.card__progress {
  position: absolute; left: 16px; right: 16px; top: calc(var(--safe-top) + var(--topbar-h) + 4px);
  height: 2px; border-radius: 2px; background: rgba(255, 255, 255, 0.18); overflow: hidden;
}
.card__progress span {
  display: block; height: 100%; width: 100%;
  background: var(--fg); transform-origin: left; transform: scaleX(0);
}
.card.is-active .card__progress span { animation: read-progress 9s linear forwards; }
@keyframes read-progress { to { transform: scaleX(1); } }

.card__body {
  width: 100%;
  padding: 0 84px calc(var(--safe-bottom) + 40px) 24px;
  display: flex; flex-direction: column; gap: 14px;
}
.card__body--center { align-items: center; text-align: center; padding-right: 24px; justify-content: center; height: 100%; }

.card__kind {
  align-self: flex-start;
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase;
  padding: 5px 10px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.28); color: var(--glow);
  backdrop-filter: blur(6px);
}
.card__kind--practice { background: var(--glow); color: #0b0b12; }

.card__text {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(1.45rem, 5.6vw, 2.05rem);
  line-height: 1.28;
  letter-spacing: -0.012em;
  text-wrap: balance;
  text-shadow: 0 2px 30px rgba(0, 0, 0, 0.35);
}
.card__text.is-long { font-size: clamp(1.15rem, 4.5vw, 1.55rem); line-height: 1.34; }
.card__text::before { content: "“"; color: var(--glow); opacity: 0.8; margin-right: 2px; }
.card__text::after { content: "”"; color: var(--glow); opacity: 0.8; margin-left: 2px; }
.card__text.no-quotes::before, .card__text.no-quotes::after { content: none; }

.card__meta { display: flex; flex-direction: column; gap: 2px; }
.card__author { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.card__author-name { font-weight: 600; font-size: 1rem; }
.card__author-era { color: var(--fg-faint); font-size: 0.8rem; }
.card__source { color: var(--fg-muted); font-size: 0.82rem; }

.card__tags { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 6px 11px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 0.78rem; font-weight: 500; color: var(--fg-muted);
  transition: transform 0.2s var(--ease-spring), background 0.2s, color 0.2s;
}
.chip:active { transform: scale(0.94); }
.chip.is-on { background: var(--fg); color: #0b0b12; border-color: transparent; }
.chip.is-hot { border-color: var(--glow); color: var(--fg); }

.card__deeper {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.85rem; font-weight: 600; color: var(--glow);
}
.card__deeper-icon { transition: transform 0.25s; }
.card__deeper[aria-expanded="true"] .card__deeper-icon { transform: rotate(180deg); }
.card__commentary {
  font-size: 0.95rem; line-height: 1.5; color: rgba(245, 242, 238, 0.9);
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.42); backdrop-filter: blur(8px);
  border-left: 2px solid var(--glow);
  animation: rise 0.35s var(--ease-out);
}

/* Staggered entrance when a card becomes active. */
.card__body > * { opacity: 0; transform: translateY(18px); }
.card.is-active .card__body > * {
  animation: rise 0.6s var(--ease-out) forwards;
}
.card.is-active .card__body > :nth-child(1) { animation-delay: 0.02s; }
.card.is-active .card__body > :nth-child(2) { animation-delay: 0.08s; }
.card.is-active .card__body > :nth-child(3) { animation-delay: 0.18s; }
.card.is-active .card__body > :nth-child(4) { animation-delay: 0.26s; }
.card.is-active .card__body > :nth-child(5) { animation-delay: 0.32s; }
.card.is-active .card__body > :nth-child(6) { animation-delay: 0.36s; }
@keyframes rise { to { opacity: 1; transform: translateY(0); } }

/* Action rail */
.rail {
  position: absolute; right: 12px; bottom: calc(var(--safe-bottom) + 44px);
  display: flex; flex-direction: column; gap: 18px; align-items: center;
}
.rail__btn { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 56px; }
.rail__btn svg {
  width: 30px; height: 30px; fill: none; stroke: var(--fg); stroke-width: 1.8; stroke-linejoin: round;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.45));
  transition: transform 0.25s var(--ease-spring), fill 0.2s, stroke 0.2s;
}
.rail__btn:active svg { transform: scale(0.85); }
.rail__label { font-size: 0.68rem; font-weight: 600; color: var(--fg-muted); }
.rail__btn--like[aria-pressed="true"] svg { fill: var(--like); stroke: var(--like); animation: pop 0.45s var(--ease-spring); }
.rail__btn--save[aria-pressed="true"] svg { fill: var(--save); stroke: var(--save); animation: pop 0.45s var(--ease-spring); }
@keyframes pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* Double-tap heart burst */
.burst { position: absolute; inset: 0; pointer-events: none; }
.burst__heart {
  position: absolute; width: 96px; height: 96px; margin: -48px 0 0 -48px;
  fill: var(--like); filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.4));
  animation: burst 0.8s var(--ease-out) forwards;
}
@keyframes burst {
  0% { transform: scale(0) rotate(-12deg); opacity: 0; }
  30% { transform: scale(1.2) rotate(4deg); opacity: 1; }
  100% { transform: scale(1) translateY(-40px); opacity: 0; }
}

/* Milestone card */
.card--milestone .card__bg {
  background:
    radial-gradient(80% 60% at 50% 30%, rgba(255, 209, 102, 0.28), transparent 70%),
    linear-gradient(160deg, #1a1030, #3a1f5a);
}
.milestone__emoji { font-size: 3.5rem; animation: pop 0.8s var(--ease-spring); }
.milestone__title { font-size: 2rem; }
.milestone__text { color: var(--fg-muted); max-width: 32ch; }

/* ==========================================================================
   Hints, buttons, chips
   ========================================================================== */
.hint {
  position: absolute; left: 50%; top: calc(var(--safe-top) + var(--topbar-h) + 70px); z-index: 15;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(10px);
  font-size: 0.8rem; color: var(--fg-muted);
  opacity: 0; transition: opacity 0.4s; pointer-events: none;
}
.hint.is-visible { opacity: 1; }
.hint__arrow { animation: bob 1.4s ease-in-out infinite; font-weight: 700; }
@keyframes bob { 0%, 100% { transform: translateY(2px); } 50% { transform: translateY(-3px); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 20px; border-radius: 14px; font-weight: 600;
  transition: transform 0.2s var(--ease-spring), opacity 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn--primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #0b0b12; }
.btn--ghost { background: var(--surface); color: var(--fg-muted); }
.btn--block { width: 100%; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips .chip { font-size: 0.9rem; padding: 10px 14px; }
.chips--compact .chip { font-size: 0.8rem; padding: 7px 11px; }

/* ==========================================================================
   Overlays and sheets
   ========================================================================== */
.overlay {
  position: absolute; inset: 0; z-index: 40;
  display: flex; align-items: flex-end;
  background: linear-gradient(160deg, #1a1030, #0b0b12 70%);
  animation: fade 0.3s;
}
.overlay[hidden] { display: none; }
.overlay__panel {
  width: 100%; max-height: 100%; overflow-y: auto;
  padding: 32px 24px calc(var(--safe-bottom) + 24px);
  display: flex; flex-direction: column; gap: 16px;
}
.overlay__panel h1 { font-size: 2.1rem; line-height: 1.1; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet { position: absolute; inset: 0; z-index: 50; }
.sheet[hidden] { display: none; }
.sheet__scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); animation: fade 0.25s; }
.sheet__panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88%;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 10px 20px calc(var(--safe-bottom) + 24px);
  border-radius: 24px 24px 0 0;
  background: #14131d; border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 14px;
  animation: slide-up 0.35s var(--ease-out);
}
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet__handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 4px; }
.sheet__header { display: flex; align-items: center; justify-content: space-between; }
.sheet__header h2 { font-size: 1.6rem; }
.sheet__stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pill {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px 8px; border-radius: var(--radius-sm); background: var(--surface);
}
.pill strong { font-size: 1.4rem; font-family: var(--font-serif); }
.pill span { font-size: 0.72rem; color: var(--fg-muted); }
.sheet h3 { font-size: 1.05rem; margin-top: 6px; }

.saved { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.saved__item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--surface); text-align: left; width: 100%;
}
.saved__swatch { flex: 0 0 6px; align-self: stretch; border-radius: 3px; background: linear-gradient(var(--t1), var(--t2)); }
.saved__text { font-family: var(--font-serif); font-size: 0.98rem; line-height: 1.35; }
.saved__author { display: block; margin-top: 4px; font-size: 0.75rem; color: var(--fg-muted); }
.saved__empty { color: var(--fg-faint); font-size: 0.9rem; padding: 12px 0; }

/* ==========================================================================
   Toast
   ========================================================================== */
.toast {
  position: absolute; left: 50%; top: calc(var(--safe-top) + var(--topbar-h) + 22px); z-index: 60;
  transform: translateX(-50%);
  padding: 10px 16px; border-radius: 999px;
  background: rgba(20, 19, 29, 0.92); border: 1px solid var(--line);
  font-size: 0.85rem; font-weight: 500; white-space: nowrap;
  animation: rise 0.3s var(--ease-out);
}
.toast[hidden] { display: none; }

/* ==========================================================================
   Motion preferences
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .feed { scroll-behavior: auto; }
  .card__body > * { opacity: 1; transform: none; }
}
