:root {
  --bg: #0b0d12;
  --bg-2: #12151c;
  --surface: #171a22;
  --surface-2: #1f2330;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f3f4f7;
  --text-2: #b4b9c6;
  --text-3: #7d8394;
  --accent: #8b9cff;
  --danger: #ff6b6b;
  --radius: 18px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --topbar-h: calc(var(--sat) + 104px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

#app { position: absolute; inset: 0; }

/* ---------- Top bar ---------- */
.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 20;
  padding: calc(var(--sat) + 6px) 0 10px;
  background: linear-gradient(to bottom, rgba(11, 13, 18, 0.92) 0%, rgba(11, 13, 18, 0.7) 70%, rgba(11, 13, 18, 0) 100%);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 calc(14px + var(--sar)) 0 calc(18px + var(--sal));
  height: 44px;
}

.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: conic-gradient(from 210deg, #38bdf8, #a78bfa, #f472b6, #fbbf24, #34d399, #38bdf8);
  box-shadow: 0 0 18px rgba(167, 139, 250, 0.45);
}
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 19px; letter-spacing: -0.02em; }

.topbar-actions { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 12px;
  transition: background 0.15s, transform 0.1s;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.08); transform: scale(0.94); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--text); stroke-width: 1.9; stroke-linejoin: round; }

.goal-pill {
  display: flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px 0 6px;
  margin-right: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--text-2);
}
.goal-pill.done { color: #34d399; background: rgba(52, 211, 153, 0.12); }
.goal-ring { width: 22px; height: 22px; transform: rotate(-90deg); }
.goal-ring circle { fill: none; stroke-width: 4; }
.goal-ring-bg { stroke: rgba(255, 255, 255, 0.12); }
.goal-ring-fg { stroke: #34d399; stroke-linecap: round; stroke-dasharray: 94.25; stroke-dashoffset: 94.25; transition: stroke-dashoffset 0.4s ease; }

/* ---------- Category chips ---------- */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px calc(16px + var(--sar)) 4px calc(16px + var(--sal));
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-padding: 0 16px;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex; align-items: center; gap: 7px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, #fff); opacity: 0.85; }
.chip[aria-pressed="true"] {
  color: #0b0d12;
  background: var(--c, #fff);
  border-color: transparent;
}
.chip[aria-pressed="true"] .dot { background: rgba(0, 0, 0, 0.35); }
.chip:active { transform: scale(0.96); }

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

.card {
  position: relative;
  height: 100%;
  min-height: 100%;
  width: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: calc(var(--topbar-h) + 8px) calc(76px + var(--sar)) calc(var(--sab) + 40px) calc(24px + var(--sal));
  overflow: hidden;
  background:
    radial-gradient(120% 70% at 0% 0%, color-mix(in srgb, var(--c) 26%, transparent) 0%, transparent 60%),
    radial-gradient(90% 60% at 100% 100%, color-mix(in srgb, var(--c) 14%, transparent) 0%, transparent 60%),
    var(--bg);
  contain: layout paint;
}
/* Fallback for browsers without color-mix */
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .card { background: radial-gradient(120% 70% at 0% 0%, var(--c-soft) 0%, transparent 60%), var(--bg); }
}

.card-inner {
  max-width: 620px;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.45s ease, transform 0.45s ease;
}
.card.in-view .card-inner { opacity: 1; transform: none; }

.tag {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c);
  padding: 6px 11px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--c) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
}
.tag .src { color: var(--text-3); font-weight: 600; letter-spacing: 0.04em; }

.card-title {
  font-family: var(--font-display);
  font-size: clamp(28px, 8.2vw, 40px);
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.025em;
  margin: 18px 0 16px;
  text-wrap: balance;
}

.card-summary {
  font-size: clamp(18px, 5vw, 21px);
  line-height: 1.5;
  color: var(--text-2);
  margin: 0;
  text-wrap: pretty;
}

.card-more {
  margin-top: 26px;
  display: inline-flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 18px;
  border-radius: 999px;
  font-weight: 700; font-size: 15px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.card-more:active { transform: scale(0.97); background: rgba(255, 255, 255, 0.14); }
.card-more::after { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); margin-left: 2px; }

/* Cards whose text would not fit get progressively tighter type */
.card.compact .card-title { font-size: clamp(24px, 6.6vw, 32px); margin: 14px 0 12px; }
.card.compact .card-summary { font-size: 17px; line-height: 1.45; }
.card.compact .card-more { margin-top: 18px; }
.card.compact-2 .card-title { font-size: 22px; }
.card.compact-2 .card-summary { font-size: 15.5px; }

/* Side actions */
.card-actions {
  position: absolute;
  right: calc(12px + var(--sar));
  bottom: calc(var(--sab) + 44px);
  display: flex; flex-direction: column; gap: 14px;
  align-items: center;
}
.act {
  width: 52px; height: 52px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: transform 0.12s, background 0.15s;
}
.act:active { transform: scale(0.9); }
.act svg { width: 24px; height: 24px; fill: none; stroke: var(--text); stroke-width: 1.9; stroke-linejoin: round; stroke-linecap: round; }
.act.saved { background: color-mix(in srgb, var(--c) 22%, transparent); border-color: color-mix(in srgb, var(--c) 45%, transparent); }
.act.saved svg { fill: var(--c); stroke: var(--c); }
.act.pop { animation: pop 0.35s ease; }
@keyframes pop { 40% { transform: scale(1.22); } 100% { transform: scale(1); } }

.card-index {
  position: absolute;
  left: calc(24px + var(--sal));
  bottom: calc(var(--sab) + 16px);
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: 0.04em;
}

/* Special cards */
.card.special { padding-right: calc(24px + var(--sar)); text-align: center; align-items: center; }
.card.special .card-inner { display: flex; flex-direction: column; align-items: center; }
.card.special .emoji { font-size: 64px; line-height: 1; margin-bottom: 8px; }
.card.special .card-summary { max-width: 460px; }
.card.special .btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 28px; }

.card.loading .card-inner { opacity: 1; transform: none; }
.skeleton { background: linear-gradient(90deg, rgba(255,255,255,0.05), rgba(255,255,255,0.11), rgba(255,255,255,0.05)); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 22px;
  border-radius: 14px;
  font-weight: 700; font-size: 16px;
  background: var(--c, var(--accent));
  color: #0b0d12;
  text-decoration: none;
  transition: transform 0.1s, opacity 0.15s;
}
.btn:active { transform: scale(0.97); opacity: 0.9; }
.btn-ghost { background: rgba(255, 255, 255, 0.08); color: var(--text); border: 1px solid rgba(255, 255, 255, 0.1); }

/* ---------- Detail sheet ---------- */
.sheet-backdrop {
  position: absolute; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0; transition: opacity 0.25s ease;
}
.sheet-backdrop.open { opacity: 1; }

.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 41;
  max-height: calc(100% - var(--sat) - 40px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  border-top: 1px solid var(--line);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.2, 0.9, 0.25, 1);
  will-change: transform;
}
.sheet.open { transform: translateY(0); }
.sheet-grabber { width: 40px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.22); margin: 10px auto 4px; flex: 0 0 auto; }
.sheet-scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px calc(24px + var(--sar)) calc(var(--sab) + 28px) calc(24px + var(--sal));
}
.sheet-title { font-family: var(--font-display); font-size: 28px; line-height: 1.15; font-weight: 800; letter-spacing: -0.02em; margin: 14px 0 14px; }
.sheet-body { font-size: 18px; line-height: 1.62; color: #d7dae2; }
.sheet-body p { margin: 0 0 14px; }
.sheet-body .lead { color: var(--text); font-weight: 500; }
.sheet-body .loading-more { color: var(--text-3); font-size: 15px; }
.sheet-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.sheet-actions .btn { flex: 1 1 140px; }

/* ---------- Full screens ---------- */
.screen {
  position: absolute; inset: 0; z-index: 30;
  background: var(--bg);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.25, 1);
}
.screen.open { transform: none; }
.screen-head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--sat) + 6px) calc(10px + var(--sar)) 8px calc(10px + var(--sal));
  border-bottom: 1px solid var(--line);
  background: rgba(11, 13, 18, 0.95);
}
.screen-head h2 { font-size: 17px; font-weight: 700; margin: 0; }
.screen-head-spacer { width: 40px; }
.screen-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 18px calc(16px + var(--sar)) calc(var(--sab) + 32px) calc(16px + var(--sal));
}

.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 0; margin-bottom: 18px; }
.group-title { font-size: 12.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); padding: 10px 16px 6px; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 50px; padding: 0 16px;
  font-size: 16px; width: 100%; text-align: left;
}
.row + .row { border-top: 1px solid var(--line); }
.row-btn:active { background: rgba(255, 255, 255, 0.05); }
.row .chev { color: var(--text-3); font-size: 22px; }
.row.danger { color: var(--danger); }
.muted { color: var(--text-3); font-variant-numeric: tabular-nums; }
.hint { font-size: 13.5px; line-height: 1.45; color: var(--text-3); padding: 4px 16px 10px; margin: 0; }
.about { font-size: 13px; line-height: 1.5; color: var(--text-3); text-align: center; padding: 0 10px; }
.about a { color: var(--text-2); }

.segmented { display: flex; margin: 6px 16px 12px; background: var(--bg-2); border-radius: 12px; padding: 3px; }
.segmented button { flex: 1; height: 38px; border-radius: 9px; font-weight: 600; font-size: 15px; color: var(--text-2); }
.segmented button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); }

.switch {
  appearance: none; -webkit-appearance: none;
  width: 51px; height: 31px; border-radius: 999px;
  background: #3a3f4d; position: relative; flex: 0 0 auto; margin: 0;
  transition: background 0.2s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}
.switch:checked { background: #34c759; }
.switch:checked::after { transform: translateX(20px); }

.stepper { display: flex; align-items: center; gap: 4px; background: var(--bg-2); border-radius: 10px; padding: 3px; }
.stepper button { width: 36px; height: 32px; border-radius: 8px; font-size: 20px; font-weight: 600; }
.stepper button:active { background: var(--surface-2); }
.stepper output { min-width: 34px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Favorites list */
.fav-item {
  display: block; width: 100%; text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--c);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
  position: relative;
}
.fav-item:active { background: var(--surface-2); }
.fav-item .tag { font-size: 11px; padding: 4px 9px; }
.fav-item h3 { font-size: 18px; line-height: 1.25; margin: 10px 44px 6px 0; font-weight: 700; }
.fav-item p { font-size: 14.5px; line-height: 1.45; color: var(--text-2); margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.fav-remove {
  position: absolute; top: 10px; right: 10px;
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; color: var(--text-3);
}
.fav-remove:active { background: rgba(255, 255, 255, 0.06); }
.fav-remove svg { width: 20px; height: 20px; fill: var(--c); stroke: var(--c); stroke-width: 1.9; }
.empty { text-align: center; color: var(--text-3); padding: 60px 20px; font-size: 16px; line-height: 1.5; }
.empty .emoji { font-size: 48px; display: block; margin-bottom: 12px; }

/* Toast */
.toast {
  position: absolute; z-index: 60;
  left: 50%; bottom: calc(var(--sab) + 28px);
  transform: translate(-50%, 20px);
  background: rgba(30, 34, 45, 0.96);
  border: 1px solid var(--line);
  padding: 12px 18px; border-radius: 14px;
  font-size: 15px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  opacity: 0; transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100% - 40px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  .card { padding-left: max(48px, calc(50% - 320px)); padding-right: max(96px, calc(50% - 300px)); }
  .card-actions { right: max(20px, calc(50% - 380px)); }
  .sheet { left: 50%; right: auto; width: 640px; margin-left: -320px; }
  .screen-body { max-width: 680px; margin: 0 auto; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  .card-inner { opacity: 1; transform: none; }
}
