:root {
  color-scheme: light;
  --ink: #20170e;
  --text: #2c241a;
  --muted: #766a5c;
  --paper: #fbf5e8;
  --gold: #c9903d;
  --red: #b84537;
  --teal: #247b78;
  --science-blue: #1f6f9f;
  --science-teal: #16806f;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  background:
    radial-gradient(circle at 16% 10%, rgba(201, 144, 61, 0.18), transparent 30%),
    linear-gradient(180deg, #fff8ec 0%, #f6ead6 52%, #efe1c7 100%);
}

img {
  max-width: 100%;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 30px));
  margin: 0 auto;
  padding: 28px 0 60px;
}

.comic-library-shell {
  width: min(1320px, calc(100% - 30px));
}

.site-header {
  min-height: 54px;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  border: 1px solid rgba(31, 111, 159, 0.22);
  border-radius: 10px;
  padding: 10px 14px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(239, 250, 246, 0.78)),
    rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(14px);
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
  text-decoration: none;
}

.site-brand::before {
  content: "";
  width: 28px;
  aspect-ratio: 1;
  border: 2px solid #17324a;
  border-radius: 8px;
  background:
    radial-gradient(circle at 64% 34%, #fff 0 8%, transparent 9%),
    linear-gradient(135deg, #ffd35c 0 48%, #21a8a0 49% 100%);
}

.site-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.site-meta span,
.site-meta a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid rgba(36, 123, 120, 0.22);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
  background: rgba(238, 247, 246, 0.82);
}

.site-meta a {
  color: var(--ink);
  background: #fffaf0;
}

.hero,
.library-hero {
  min-height: 78vh;
  display: grid;
  grid-template-columns: minmax(0, 0.98fr) minmax(320px, 0.9fr);
  gap: 32px;
  align-items: center;
}

.library-hero {
  min-height: 360px;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
}

.hero-copy {
  min-width: 0;
}

.series-label,
.eyebrow {
  margin: 0 0 12px;
  color: var(--teal);
  font-weight: 900;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(42px, 6vw, 76px);
  line-height: 1.04;
}

.hook {
  max-width: 720px;
  color: var(--muted);
  font-size: clamp(17px, 1.5vw, 21px);
  line-height: 1.78;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 28px;
}

.primary-action,
.secondary-action {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #21170d;
  border-radius: 8px;
  padding: 0 18px;
  color: var(--ink);
  font-weight: 900;
  text-decoration: none;
  background: #fffaf0;
}

.primary-action {
  color: #fff;
  background: linear-gradient(135deg, #21170d, #533019);
  box-shadow: 5px 5px 0 var(--gold);
}

.anime-poster,
.generated-poster,
.library-summary {
  position: relative;
  overflow: hidden;
  border: 2px solid #21170d;
  border-radius: 10px;
  background: #fffdf7;
  box-shadow: 0 18px 46px rgba(64, 43, 20, 0.18);
}

.anime-poster {
  min-height: 620px;
}

.poster-main,
.generated-poster-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.poster-overlay,
.poster-badge,
.generated-poster > *:not(.generated-poster-bg) {
  position: relative;
  z-index: 1;
}

.generated-lesson-poster .poster-overlay {
  display: none;
}

.generated-lesson-poster .poster-main {
  position: static;
  display: block;
  width: 100%;
  height: auto;
}

.generated-lesson-poster .generated-dedicated-poster {
  aspect-ratio: 16 / 9;
  object-fit: cover;
  object-position: 50% 50%;
}

.science-lesson3-shell .generated-science-hero .science-poster,
.science-lesson7-shell .generated-science-hero .science-poster {
  min-height: 0;
}

.science-lesson3-shell .generated-science-hero .poster-main,
.science-lesson3-shell .generated-lesson-poster .generated-dedicated-poster,
.science-lesson7-shell .generated-science-hero .poster-main,
.science-lesson7-shell .generated-lesson-poster .generated-dedicated-poster {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  min-height: 0;
  max-height: none;
  object-fit: cover;
  object-position: 50% 50%;
}

.poster-badge {
  position: absolute;
  top: 22px;
  left: 22px;
  border-radius: 999px;
  padding: 10px 14px;
  color: #fff;
  font-weight: 900;
  background: rgba(184, 69, 55, 0.88);
}

.generated-poster {
  min-height: 520px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  padding: 22px;
  border-width: 1px;
}

.generated-poster::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(18, 11, 5, 0.04), rgba(18, 11, 5, 0.42)),
    linear-gradient(90deg, rgba(255, 250, 240, 0.54), rgba(255, 250, 240, 0.08));
  pointer-events: none;
}

.poster-cast,
.poster-cast-card,
.generated-poster-map {
  display: none;
}

.library-summary {
  padding: 24px;
}

.library-summary strong {
  display: block;
  color: #c4542d;
  font-size: 72px;
  line-height: 0.95;
}

.science-lesson-cover {
  position: relative;
  isolation: isolate;
  min-height: min(760px, calc(100dvh - 116px));
  display: grid;
  grid-template-columns: minmax(0, 0.78fr) minmax(220px, 0.22fr);
  align-items: end;
  gap: clamp(18px, 4vw, 46px);
  overflow: hidden;
  border: 2px solid #17324a;
  border-radius: 12px;
  padding: clamp(22px, 5vw, 58px);
  color: #fff;
  background:
    linear-gradient(90deg, rgba(9, 31, 49, 0.84) 0%, rgba(9, 31, 49, 0.64) 42%, rgba(9, 31, 49, 0.2) 72%),
    linear-gradient(180deg, rgba(9, 31, 49, 0.02), rgba(9, 31, 49, 0.68)),
    url("assets/science/grade3b/lesson1/hero-digestive-mission-ai-v3.webp") center / cover no-repeat;
}

.science-lesson-cover h1,
.science-lesson-cover .hook,
.science-lesson-cover .series-label {
  color: #fff;
}

.science-lesson-cover .anime-poster {
  display: none;
}

.science-lesson-cover .hero-copy::before {
  content: "SCIENCE QUEST";
  display: inline-flex;
  margin-bottom: 8px;
  border-radius: 999px;
  padding: 5px 9px;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  background: var(--science-blue);
}

.science-party {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.science-party span,
.riceball-sos {
  border: 1px solid rgba(23, 50, 74, 0.18);
  border-radius: 8px;
  padding: 8px 12px;
  color: #17324a;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.86);
}

.riceball-sos {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 18px;
  padding: 14px;
}

.riceball-sos p {
  margin: 4px 0 0;
}

.riceball-face {
  display: inline-flex;
  width: 52px;
  aspect-ratio: 1;
  align-items: center;
  justify-content: center;
  border: 2px solid #17324a;
  border-radius: 999px;
  font-size: 13px;
  background: #fffdf7;
}

.panel {
  margin-top: 24px;
  border: 1px solid rgba(23, 50, 74, 0.14);
  border-radius: 12px;
  padding: clamp(18px, 3vw, 28px);
  background: rgba(255, 253, 246, 0.92);
}

.route-preview-game {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  gap: 14px;
  align-items: stretch;
}

.route-preview-map {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  border: 1px solid rgba(23, 50, 74, 0.14);
  border-radius: 14px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.68);
}

.route-preview-map button {
  border: 2px solid rgba(23, 50, 74, 0.18);
  border-radius: 16px;
  padding: 12px 8px;
  color: #17324a;
  font-weight: 1000;
  background: linear-gradient(180deg, #fff7cf, #dff5ef);
}

.route-preview-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  border: 1px solid rgba(23, 50, 74, 0.15);
  border-radius: 14px;
  padding: 16px;
  background: linear-gradient(180deg, #fffdf6, #f0faf6);
}

.avatar-portrait {
  display: block;
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  border: 3px solid rgba(255, 253, 246, 0.94);
  border-radius: 50%;
  background: #f5d36d;
}

.lesson1-comic-reader {
  display: grid;
  grid-template-columns: minmax(300px, 520px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.lesson1-comic-stage {
  margin: 0;
}

.lesson1-comic-stage img {
  display: block;
  width: 100%;
  height: auto;
  max-height: none;
  aspect-ratio: auto;
  border: 2px solid rgba(23, 50, 74, 0.2);
  border-radius: 14px;
  object-fit: contain;
  object-position: top center;
  background: #fff;
}

.lesson1-comic-stage figcaption {
  margin-top: 10px;
  border: 1px solid rgba(23, 50, 74, 0.14);
  border-radius: 12px;
  padding: 12px 14px;
  color: #17324a;
  font-weight: 900;
  background: #fffdf6;
}

.lesson1-comic-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.lesson1-comic-controls button {
  min-height: 70px;
  border: 2px solid rgba(23, 50, 74, 0.18);
  border-radius: 14px;
  color: #17324a;
  font-size: 1.25rem;
  font-weight: 1000;
  background: linear-gradient(180deg, #fff7cf, #edf8f4);
}

.science-germ-cover {
  border-color: rgba(16, 47, 61, 0.72);
  background:
    linear-gradient(90deg, rgba(8, 32, 46, 0.88) 0%, rgba(8, 32, 46, 0.68) 44%, rgba(8, 32, 46, 0.16) 78%),
    linear-gradient(180deg, rgba(8, 32, 46, 0.04), rgba(8, 32, 46, 0.66)),
    url("assets/science/grade3b/lesson2/hero-germ-defense-ai-v3.webp") center / cover no-repeat;
}

.mission-tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 8px;
  margin: 2px 0 24px;
  border: 1px solid rgba(23, 50, 74, 0.16);
  border-radius: 8px;
  padding: 8px;
  overflow-x: auto;
  background: rgba(255, 253, 247, 0.92);
}

.mission-tabs a {
  flex: 0 0 auto;
  border: 1px solid rgba(143, 94, 36, 0.24);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--ink);
  font-weight: 900;
  text-decoration: none;
  background: #fffaf0;
}

.panel,
.quest-dashboard,
.science-flow-strip,
.comic-page-grid,
.lesson-comic-grid,
.compact-comic-grid,
.track-grid {
  content-visibility: auto;
  contain-intrinsic-size: 1px 720px;
}

img[data-src] {
  background:
    linear-gradient(135deg, rgba(36, 123, 120, 0.12), rgba(201, 144, 61, 0.12)),
    rgba(255, 250, 240, 0.78);
}

@media (max-width: 1040px) {
  .hero,
  .library-hero,
  .science-lesson-cover {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .app-shell,
  .comic-library-shell {
    width: min(100% - 20px, 420px);
    padding-top: 14px;
  }

  .site-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    border-radius: 8px;
  }

  .site-meta {
    justify-content: flex-start;
  }

  .hero {
    min-height: auto;
    gap: 18px;
    padding: 26px 0;
  }

  h1 {
    font-size: clamp(38px, 11vw, 52px);
  }

  .hook {
    font-size: 16px;
    line-height: 1.68;
  }

  .anime-poster,
  .generated-poster {
    min-height: 420px;
  }

  .science-lesson-cover {
    min-height: 690px;
    padding: 22px 16px;
    background:
      linear-gradient(180deg, rgba(9, 31, 49, 0.42) 0%, rgba(9, 31, 49, 0.62) 34%, rgba(9, 31, 49, 0.88) 100%),
      url("assets/science/grade3b/lesson1/hero-digestive-mission-ai-v3-mobile.webp") 58% 50% / cover no-repeat;
  }

  .route-preview-game {
    grid-template-columns: 1fr;
  }

  .route-preview-map {
    display: flex;
    min-height: 0;
    overflow-x: auto;
    padding-bottom: 16px;
    scroll-snap-type: x mandatory;
  }

  .route-preview-map button {
    min-width: 108px;
    scroll-snap-align: start;
  }

  .lesson1-comic-reader {
    grid-template-columns: 1fr;
  }

  .lesson1-comic-controls {
    display: flex;
    overflow-x: auto;
    padding-bottom: 10px;
    scroll-snap-type: x mandatory;
  }

  .lesson1-comic-controls button {
    min-width: 82px;
    min-height: 62px;
    scroll-snap-align: start;
  }

  .science-germ-cover {
    min-height: 720px;
    background:
      linear-gradient(180deg, rgba(8, 32, 46, 0.58) 0%, rgba(8, 32, 46, 0.68) 44%, rgba(8, 32, 46, 0.9) 100%),
      url("assets/science/grade3b/lesson2/hero-germ-defense-ai-v3-mobile.webp") 54% 50% / cover no-repeat;
  }

  .science-lesson-cover h1 {
    font-size: clamp(42px, 12vw, 54px);
    line-height: 1.08;
  }

  .science-party {
    gap: 7px;
    margin-top: 16px;
  }

  .science-party span {
    padding: 7px 9px;
    font-size: 13px;
  }
}

/* Taste v1: stabilize generated lesson posters before the full stylesheet loads. */
.generated-science-shell .generated-lesson-poster,
.generated-science-shell .science-poster {
  min-height: 0;
}

.generated-science-shell .generated-lesson-poster .generated-dedicated-poster {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  min-height: 0;
  max-height: none;
  object-fit: cover;
  object-position: 50% 50%;
}

@media (max-width: 900px) {
  .generated-science-shell .generated-science-hero {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .generated-science-shell .generated-lesson-poster,
  .generated-science-shell .science-poster {
    width: 100%;
    max-width: none;
    min-height: 0;
    margin: 0;
    padding: 6px;
  }

  .generated-science-shell .generated-science-hero .poster-main,
  .generated-science-shell .generated-lesson-poster .generated-dedicated-poster {
    position: static;
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    min-height: 0;
    max-height: none;
    border-radius: 8px;
    object-fit: cover;
    object-position: 50% 50%;
  }
}
