/* ==========================================================
   app.css — base resets + shared components
   Tokens from theme.css.
   ========================================================== */

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

html, body { min-height: 100%; }

body {
  font-family: var(--font-body);
  font-size: var(--fs-md);
  color: var(--ink);
  background:
    linear-gradient(180deg,
      var(--sky-top) 0%,
      var(--sky-mid) 35%,
      var(--sky-bottom) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-user-select: none;
  user-select: none;
  overflow-x: hidden;
  position: relative;
  line-height: 1.4;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ============================================================
   WORLD — decorative background (fixed, non-interactive)
   ============================================================ */
.world {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.cloud {
  position: absolute;
  background: var(--cloud);
  border-radius: 100px;
  opacity: 0.85;
}
.cloud::before, .cloud::after {
  content: ''; position: absolute; background: var(--cloud); border-radius: 50%;
}
.c1 { top: 8%;  left: 6%;   width: 90px; height: 28px;
      animation: drift 22s ease-in-out infinite; }
.c1::before { width: 44px; height: 44px; top: -22px; left: 14px; }
.c1::after  { width: 32px; height: 32px; top: -16px; right: 10px; }
.c2 { top: 18%; right: 8%;  width: 72px; height: 24px;
      animation: drift 28s ease-in-out infinite reverse; }
.c2::before { width: 36px; height: 36px; top: -18px; left: 10px; }
.c2::after  { width: 28px; height: 28px; top: -14px; right: 8px; }
.c3 { top: 5%; right: 28%;  width: 56px; height: 20px; opacity: 0.6;
      animation: drift 26s ease-in-out infinite; }
.c3::before { width: 28px; height: 28px; top: -14px; left: 8px; }
.c3::after  { width: 22px; height: 22px; top: -10px; right: 6px; }

@keyframes drift {
  0%, 100% { transform: translateX(0); }
  50%      { transform: translateX(20px); }
}

.paws {
  position: absolute;
  opacity: 0.08;
  font-size: 32px;
  transform: rotate(var(--r, 0deg));
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-3) var(--s-5);
  background: linear-gradient(180deg,
    rgba(184, 229, 255, 0.92) 0%,
    rgba(217, 240, 255, 0.85) 70%,
    rgba(217, 240, 255, 0) 100%);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
/* Brand mark = SVG circle with star (rendered by brand.js) */
.brand .li-mark { box-shadow: var(--shadow-soft); border-radius: 50%; }
/* Wordmark sits next to the mark; size set inline by brand.js */
.brand .li-wordmark { /* .li-wordmark styles come from brand.js */ }

@media (max-width: 720px) {
  .brand { gap: 6px; }
}

.topbar-right {
  margin-left: auto;
  display: flex;
  gap: var(--s-2);
  align-items: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--paper);
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-size: var(--fs-sm);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
  transition: transform 0.15s var(--ease-pop);
  border: 0;
}
.pill:hover { transform: translateY(-1px); }
.pill .num { font-family: var(--font-display); font-size: var(--fs-md); }
.pill.cta {
  background: var(--ink);
  color: var(--paper-warm);
}
.pill.ghost {
  background: transparent;
  box-shadow: none;
  color: var(--ink-soft);
}

/* ============================================================
   PAGE LAYOUT
   ============================================================ */
.container {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--s-5);
}

/* ============================================================
   HERO
   ============================================================ */
.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--s-5);
  align-items: center;
  padding: var(--s-7) 0 var(--s-6);
}
.hero-text h1 {
  font-family: var(--font-display);
  font-size: clamp(36px, 6vw, 64px);
  line-height: 0.95;
  letter-spacing: 0.5px;
  margin-bottom: var(--s-3);
}
.hero-text h1 .accent { color: var(--brand-coral); }
.hero-text p {
  font-size: var(--fs-lg);
  color: var(--ink-soft);
  max-width: 520px;
  line-height: 1.5;
}
.hero-bobo {
  width: 200px;
  height: 200px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hero-bobo::before {
  content: '';
  position: absolute;
  inset: 10px;
  background: radial-gradient(circle, rgba(255,205,58,0.4) 0%, transparent 70%);
  border-radius: 50%;
  z-index: -1;
}
.bobo-hello {
  position: absolute;
  top: 30px;
  right: -10px;
  background: white;
  padding: 8px 14px;
  border-radius: 14px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink);
  box-shadow: var(--shadow-soft);
  white-space: nowrap;
  z-index: 2;
}
.bobo-hello::after {
  content: '';
  position: absolute;
  left: -8px;
  bottom: 14px;
  border: 7px solid transparent;
  border-right-color: white;
}

/* ============================================================
   SEARCH SHELL
   ============================================================ */
.search-shell {
  background: var(--paper);
  border-radius: var(--radius-xl);
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-5);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  box-shadow: var(--shadow-card);
  margin-bottom: var(--s-5);
  transition: transform 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}
.search-shell:focus-within {
  transform: translateY(-2px);
  box-shadow: var(--shadow-pop);
}
.search-shell .icon {
  font-size: 24px;
  color: var(--ink-muted);
}
.search-shell input {
  flex: 1;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: var(--fs-lg);
  padding: 14px 0;
  color: var(--ink);
  outline: none;
}
.search-shell input::placeholder { color: var(--ink-muted); }
.search-shell .clear-btn {
  background: var(--paper-cool);
  border: 0;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: var(--fs-lg);
  color: var(--ink-muted);
  display: none;
}
.search-shell.has-text .clear-btn { display: inline-flex; align-items: center; justify-content: center; }

/* ============================================================
   FILTERS — pill chips
   ============================================================ */
.filters {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: var(--s-6);
}
.filter-label {
  font-size: var(--fs-xs);
  color: var(--ink-muted);
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-right: var(--s-2);
}
.chip {
  background: var(--paper);
  border: 0;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink);
  box-shadow: var(--shadow-soft);
  transition: all 0.15s var(--ease-out);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip:hover { transform: translateY(-1px); }
.chip.active {
  background: var(--ink);
  color: var(--paper-warm);
}
.filter-spacer { width: 16px; display: inline-block; }

/* ============================================================
   SECTION HEADER
   ============================================================ */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: var(--s-6) 0 var(--s-4);
  flex-wrap: wrap;
  gap: var(--s-2);
}
.section-head h2 {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  letter-spacing: 0.3px;
}
.section-head .sub {
  color: var(--ink-muted);
  font-size: var(--fs-sm);
}

/* ============================================================
   FEATURED ROW (hero gradient cards)
   ============================================================ */
.featured-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s-5);
  margin-bottom: var(--s-7);
}
@media (max-width: 720px) {
  .featured-row { grid-template-columns: 1fr; }
}
.featured {
  border-radius: var(--radius-xl);
  padding: var(--s-5);
  color: var(--paper);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.25s var(--ease-out), box-shadow 0.25s var(--ease-out);
  box-shadow: var(--shadow-card);
  min-height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--card-grad, linear-gradient(135deg, #FF6B6B 0%, #FF8FB1 100%));
}
.featured:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-pop);
}
/* Subtle bottom scrim so description text reads cleanly over bright gradients */
.featured::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 0%, transparent 55%, rgba(0,0,0,0.18) 100%);
  pointer-events: none;
  z-index: 0;
}
.featured > * { position: relative; z-index: 1; }
.featured::after {
  content: '';
  position: absolute;
  right: -40px; bottom: -40px;
  width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(255,255,255,0.2), transparent 70%);
  border-radius: 50%;
  z-index: 0;
}
.featured .badge {
  display: inline-block;
  background: rgba(255,255,255,0.25);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  margin-bottom: var(--s-2);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  width: fit-content;
}
.featured .emoji {
  font-size: 64px;
  line-height: 1;
  position: absolute;
  right: var(--s-5);
  top: 50%;
  transform: translateY(-50%);
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15));
}
.featured h3 {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  line-height: 1.1;
  margin-bottom: var(--s-2);
  max-width: 70%;
  letter-spacing: 0.2px;
}
.featured p {
  font-size: var(--fs-sm);
  opacity: 0.9;
  max-width: 70%;
  margin-bottom: var(--s-3);
}
.featured .meta {
  display: flex;
  gap: var(--s-3);
  font-size: var(--fs-xs);
  opacity: 0.85;
}

/* ============================================================
   ACTIVITY GRID — small cards
   ============================================================ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--s-4);
  margin-bottom: var(--s-7);
}

.card {
  position: relative;             /* anchors absolutely-positioned badges */
  background: var(--paper);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  border: 0;
  text-align: left;
  width: 100%;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-card);
}
.card:focus-visible {
  outline: 3px solid var(--brand-teal);
  outline-offset: 3px;
}

.card-cover {
  height: 120px;
  background: var(--card-accent, var(--subj-default));
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.card-cover .emoji {
  font-size: 64px;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.12));
  transition: transform 0.3s var(--ease-pop);
}
.card:hover .card-cover .emoji { transform: scale(1.1) rotate(-5deg); }

.card-cover::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,0.25) 0%, transparent 8%),
    radial-gradient(circle at 70% 60%, rgba(255,255,255,0.2) 0%, transparent 6%),
    radial-gradient(circle at 40% 80%, rgba(255,255,255,0.15) 0%, transparent 5%);
}

.card-tag {
  position: absolute;
  top: var(--s-3);
  left: var(--s-3);
  background: rgba(255,255,255,0.95);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.card-time {
  position: absolute;
  bottom: var(--s-3);
  right: var(--s-3);
  background: rgba(31,26,61,0.7);
  color: white;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* Pro Learner badge — sits over the cover image, top-right.
   Visible on every premium card (subscribers + non-subscribers alike)
   so the value of the subscription is always advertised.

   Specificity intentionally bumped (.card .card-pro-badge etc) so it
   wins against .featured > * { position: relative; z-index: 1; } which
   would otherwise kill the absolute positioning. */
.card .card-pro-badge,
.featured .card-pro-badge {
  position: absolute;
  top: var(--s-3);
  right: var(--s-3);
  background: linear-gradient(135deg, #FFD23F, #FF9F1C);
  color: #2B2356;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
  z-index: 3;
  pointer-events: none;          /* don't block clicks on the card */
}
/* Locked cards (premium + viewer not subscribed) get a subtle dim
   so it's visually clear something's gated. The Pro badge is
   the affordance that explains why. */
.card.is-locked .card-cover,
.featured.is-locked {
  filter: saturate(0.7);
}
.card.is-locked:hover .card-cover,
.featured.is-locked:hover {
  filter: saturate(1);
}

.card-body {
  padding: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  flex: 1;
}
.card-meta {
  display: flex;
  gap: var(--s-2);
  font-size: var(--fs-xs);
  color: var(--ink-muted);
  font-weight: 600;
}
.card-title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  line-height: 1.2;
  color: var(--ink);
  letter-spacing: 0.2px;
}
.card-desc {
  font-size: var(--fs-sm);
  color: var(--ink-soft);
  line-height: 1.4;
}

/* Subject color variants */
/* Card gradient is set inline via app.js using topic_gradient_from / _to from the API.
   Subject-class fallbacks remain for completeness when no topic gradient is provided. */
.card.subj-maths   { --card-accent: var(--subj-maths); }
.card.subj-english { --card-accent: var(--subj-english); }
.card.subj-science { --card-accent: var(--subj-science); }

.featured.subj-maths   { --card-grad: var(--subj-maths); }
.featured.subj-english { --card-grad: var(--subj-english); }
.featured.subj-science { --card-grad: var(--subj-science); }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: var(--s-7) var(--s-5);
  color: var(--ink-muted);
}
.empty-state .big { font-size: 80px; margin-bottom: var(--s-3); display: block; }
.empty-state h3 {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  color: var(--ink);
  margin-bottom: var(--s-2);
}

/* ============================================================
   ACTIVITY POPUP (full-screen overlay with iframe)
   ============================================================ */
.popup {
  position: fixed;
  inset: 0;
  background: rgba(31, 26, 61, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: stretch;
  justify-content: center;
  animation: fade-in 0.2s ease;
}
.popup.show { display: flex; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.popup-inner {
  width: 100%;
  background: var(--paper);
  position: relative;
  display: flex;
  flex-direction: column;
}
.popup-bar {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  /* Slim bar — saves vertical space for the activity below.
     Total height ~44px (close button = 36, plus 4px top/bottom padding). */
  padding: 4px 6px 4px 16px;
  background: var(--paper-warm);
  border-bottom: 1px solid rgba(31,26,61,0.08);
}
.popup-bar h3 {
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.2px;
  margin: 0;
}
.popup-close {
  background: var(--brand-coral);
  color: white;
  border: 0;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: var(--fs-md);
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
  box-shadow: var(--shadow-soft);
  transition: transform 0.15s var(--ease-pop);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.popup-close:hover { transform: scale(1.1); }
.popup-frame {
  flex: 1;
  border: 0;
  width: 100%;
  background: white;
}
.popup-locked {
  flex: 1;
  background: white;
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.popup-locked[hidden] { display: none; }
.popup-frame[hidden] { display: none; }

/* ============================================================
   SAVE-PROGRESS NUDGE (after activity completion)
   ============================================================ */
.nudge {
  position: fixed;
  bottom: var(--s-5);
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--paper);
  border-radius: var(--radius-lg);
  padding: var(--s-3) var(--s-4);
  box-shadow: var(--shadow-pop);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  z-index: 90;
  max-width: 480px;
  width: calc(100% - var(--s-5) * 2);
  transition: transform 0.4s var(--ease-pop);
}
.nudge.show { transform: translateX(-50%) translateY(0); }
.nudge .text { flex: 1; font-size: var(--fs-sm); }
.nudge .text strong {
  display: block;
  font-family: var(--font-display);
  font-size: var(--fs-md);
  margin-bottom: 2px;
  letter-spacing: 0.2px;
}
.nudge .text span { color: var(--ink-muted); }
.nudge button {
  background: var(--brand-teal);
  color: white;
  border: 0;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-stamp-sm);
}
.nudge button.dismiss {
  background: transparent;
  color: var(--ink-muted);
  box-shadow: none;
  font-weight: 600;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 720px) {
  .container { padding: 0 var(--s-3); }
  .topbar { padding: var(--s-3); }
  .pill { padding: 6px 10px; font-size: var(--fs-xs); }
  .pill.cta { padding: 8px 12px; }

  .hero {
    grid-template-columns: 1fr;
    text-align: center;
    padding: var(--s-5) 0;
  }
  .hero-bobo {
    width: 140px;
    height: 140px;
    margin: 0 auto;
  }
  .bobo-hello { top: 0; right: 50%; transform: translateX(50%); }
  .bobo-hello::after { display: none; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--s-3); }
  .card-cover { height: 90px; }
  .card-cover .emoji { font-size: 44px; }
  .card-body { padding: var(--s-3); }
  .card-title { font-size: var(--fs-md); }
  .card-desc { font-size: var(--fs-xs); }
}
