:root {
  --bg: #fff6ee;
  --bg-tint: #ffeede;
  --surface: #ffffff;
  --ink: #2b2734;
  --muted: #6f6a7d;
  --accent: #ff7a59;
  --accent-2: #7c5cff;
  --line: rgba(43, 39, 52, 0.10);
  --radius: 22px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(124, 92, 255, 0.12), 0 2px 8px rgba(43, 39, 52, 0.06);
  --tap: 44px;
  --maxw: 600px;
  --space: 16px;
  font-family: "Outfit", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 100% -10%, var(--bg-tint), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #efe9ff, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.6;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
}

/* First screen: fills the device viewport (dynamic vh + safe-area insets so
   the Dynamic Island / home indicator never clip). Saved sits below it. */
.screen {
  box-sizing: border-box;
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100vh;
  height: 100dvh;
  padding:
    calc(env(safe-area-inset-top) + 14px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 12px)
    calc(env(safe-area-inset-left) + 16px);
}

/* Top bar */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-name {
  margin: 0;
  font-size: clamp(1.2rem, 5vw, 1.6rem);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.cat-header { animation: bob 3.2s ease-in-out infinite; }

/* Reader */
.reader {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(20px, 5.5vw, 30px);
  overflow: hidden;
}

.card-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.eyebrow {
  flex: 0 0 auto;
  margin: 0 0 6px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-2);
}

.title {
  flex: 0 0 auto;
  margin: 0 0 14px;
  font-size: clamp(1.5rem, 7vw, 2.1rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.card-body { font-size: clamp(1.1rem, 4.6vw, 1.25rem); line-height: 1.65; }
.card-body p { margin: 0 0 0.9em; }
.card-body p:last-child { margin-bottom: 0; }
.card-body strong { color: var(--accent-2); }
.card-body code {
  background: var(--bg-tint);
  padding: 0.1em 0.4em;
  border-radius: 6px;
  font-size: 0.92em;
}
.card-body a { color: var(--accent); }

.card-image { margin: 16px 0 0; }
.card-image img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
  background: var(--bg-tint);
}

.card-footer {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding-top: 14px;
}

.chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
}

.search-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  min-height: var(--tap);
  padding: 0 14px;
  border-radius: 999px;
  background: var(--bg-tint);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}
.search-chip:hover { background: #ffe2d4; }

.progress {
  display: flex;
  gap: 8px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
  transition: width 0.25s ease, background 0.25s ease;
}
.dot-active { width: 26px; border-radius: 999px; background: var(--accent); }

/* Controls */
.controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }

.btn-primary {
  margin-left: auto;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #ff9264);
  box-shadow: 0 6px 16px rgba(255, 122, 89, 0.35);
}
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-pin { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-pin.is-pinned { background: #fff0d6; border-color: #ffd58a; color: #8a5a00; }
.btn-new {
  color: var(--accent-2);
  background: #efe9ff;
  border-color: rgba(124, 92, 255, 0.25);
}

/* Saved shelf (scroll down past the reader to reach it) */
.scroll-hint {
  flex: 0 0 auto;
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
  opacity: 0.65;
}

.saved {
  box-sizing: border-box;
  width: calc(100% - 32px);
  max-width: calc(var(--maxw) - 32px);
  margin: 14px auto 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px clamp(16px, 5vw, 24px);
}
.saved-title { margin: 0 0 10px; font-size: 1rem; color: var(--muted); }
.saved-empty { margin: 0; color: var(--muted); font-size: 0.95rem; }
.saved-list { display: flex; flex-wrap: wrap; gap: 10px; }
.saved-item {
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}
.saved-item:hover { border-color: var(--accent); }
.saved-item:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }

/* Footer */
.footer {
  box-sizing: border-box;
  width: calc(100% - 32px);
  max-width: calc(var(--maxw) - 32px);
  margin: 22px auto calc(env(safe-area-inset-bottom) + 18px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  text-align: center;
}
.footer-note { margin: 0; font-size: 0.9rem; }

/* Motion */
.card-enter { animation: cardIn 0.32s cubic-bezier(0.22, 1, 0.36, 1); }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to { opacity: 1; transform: none; }
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
