/* English Defense only: decorative paint, with no changes to document geometry.
   Illustrations are static and non-interactive; opaque parchment shields content.
   The original title artwork, canvas, characters and game controls stay intact. */
body {
  --storybook-world-width: max(100vw, 5760px);
  isolation: isolate;
  background-color: var(--paper);
  background-image: none;
}
/* One original world, centered at a large page scale. Native browser zoom
   reveals more of the same illustration; no repeated or mirrored artwork. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: url('./assets/storybook/english-defense-panorama.webp') center top / var(--storybook-world-width) auto no-repeat;
}
body::after { display: none; }
/* Tall windows can reveal the complete lower edge of the 2:1 painting.
   Feather only that edge into parchment; never tile or stretch the artwork. */
@media (max-aspect-ratio: 19/10) {
  body::before {
    mask-image: linear-gradient(to bottom, #000 calc(var(--storybook-world-width) / 2 - 160px), transparent calc(var(--storybook-world-width) / 2));
  }
}
/* Paint only: keep the existing column dimensions and every control in place. */
#app > .wrap, #app > .battle-wrap, #app > .loading, #guide-main {
  background-color: var(--paper);
  box-shadow: 0 0 70px 55px var(--paper);
}
/* Parchment feathering must stay behind navigation and footer text. */
.topbar, .guide-page-header, footer { position: relative; z-index: 1; }
.topbar .wallet small { color: #625c50; }

/* Approved shield-and-quill wordmark. Reserve its space before it loads and
   keep the existing home action, header height and navigation layout. */
.topbar .brand {
  flex: 0 0 auto;
  width: 228px;
  height: 76px;
  padding: 0;
  gap: 0;
  border-radius: 4px;
  line-height: 0;
}
.topbar .brand-logo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
@media (max-width: 800px) {
  .topbar .brand {
    width: min(220px, calc(100vw - 156px));
    height: auto;
    aspect-ratio: 3 / 1;
  }
}

/* A pale reading surface keeps the new scenery away from lesson text. */
.practice-hub { background: var(--paper); }
.topbar, .guide-page-header {
  background: linear-gradient(100deg, #fff9eb, #f9f3e3 45%, #f2e6c8);
  box-shadow: 0 2px 0 #b68c3820;
}
/* Keep footer text on opaque parchment. */
footer { background: #f9f3e3; }
#app > .wrap:not(.practice-hub) > .section-head .eyebrow,
#app > .wrap:not(.practice-hub) > .section-head p { color: #625c50; }
#app > .wrap:not(.practice-hub) > .section-head > .rating { color: #876018; }
.study-guide, .guide-card, .browser-question {
  border-color: #c3a66d;
  box-shadow: 0 3px 0 #8c642116, inset 0 0 30px #edd8a01c;
}
.progress-card { background-color: #fff8e7; }
.study-guide { background: #fff9eb; }
.guide-contents { background: #fff9eb; }
.study-guide > section[id] { border-color: #c6ab73; }
.study-feedback-link { box-shadow: 0 2px 0 #8c642116; }
.question-panel { box-shadow: 0 4px 0 #252c2820, 0 0 0 4px #d7b26714; }
.level-card, .stage-card, .character, .swatch {
  box-shadow: 0 3px 0 #9e783329;
}
.level-card { background-image: linear-gradient(135deg, #fffdf43d, transparent 55%); }
.level-card.complete { background-image: linear-gradient(135deg, #fff8d954, transparent 55%); }
.level-card.boss-level { box-shadow: 0 3px 0 #9e783329, inset 0 0 0 2px #e4bd5a38; }
.shop-banner { box-shadow: inset 0 0 0 1px #cda747, inset 0 0 0 5px #252c28, inset 0 0 0 6px #cda74755; }
.loadout-strip { box-shadow: inset 0 0 0 1px #bba36b44; }
.title-scene { box-shadow: 0 6px 0 #49302225, 0 0 0 5px #c49b4d2b; }

/* Curled gold corners paint inside the existing borders, without extra padding. */
.guide-card, .study-guide, .question-panel, .stage-card, .level-card {
  border-image-source: url('./assets/storybook/concept-gold-frame.svg');
  border-image-slice: 24;
  border-image-width: 18px;
}
.study-guide > section[id]::after {
  content: "";
  position: absolute;
  top: -4px;
  left: calc(50% - 3px);
  width: 6px;
  height: 6px;
  border: 2px solid #ba8e37;
  transform: rotate(45deg);
  pointer-events: none;
}

/* Background landscapes sit in unused header space; controls paint above them.
   No new positioning is applied to the field frame or its pause overlay. */
@media (min-width: 1100px) {
  #app > .wrap:not(.home-wrap), .shop-banner { position: relative; }
  #app > .wrap:not(.home-wrap) { isolation: isolate; }
  /* Actual copy supplies an opaque shield, regardless of platform font width. */
  #app > .wrap:not(.home-wrap) > .section-head > div,
  #app > .wrap:not(.home-wrap) > .section-head > .rating { background: var(--paper); }
  #app > .wrap:not(.home-wrap)::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 570px;
    height: 285px;
    pointer-events: none;
    z-index: -1;
    background: url('./assets/storybook/concept-library-scenery.webp') right top / 570px auto no-repeat;
  }
  #app > .wrap:has(> .shop-banner)::before { display: none; }
  #app > .wrap:has(> .stage-grid)::before {
    height: 210px;
    mask-image: linear-gradient(to bottom, #000 65%, transparent);
  }
  .quiz-tools > label { background: var(--paper); }
  #app > .wrap:not(.home-wrap) > .section-head > .rating {
    border-radius: 0;
    box-shadow: 0 0 0 6px var(--paper);
  }
  .standalone-guide { position: relative; isolation: isolate; }
  .standalone-guide > .study-return-note,
  .standalone-guide > .guide-search { background: var(--paper); }
  .standalone-guide::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 800px;
    height: 400px;
    z-index: -1;
    pointer-events: none;
    background: url('./assets/storybook/concept-library-scenery.webp') right top / contain no-repeat;
  }
  .shop-banner::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 140px;
    width: clamp(180px, 22vw, 320px);
    height: 190px;
    transform: translateY(-50%);
    pointer-events: none;
    background: url('./assets/storybook/max-reading-cat.webp') center / contain no-repeat;
  }
}
@media (min-width: 1280px) {
  #app > .wrap:not(.home-wrap) > .section-head { position: relative; }
  /* The Practice concepts contain scenery here, never a mascot over the title. */
  #app > .wrap:not(.home-wrap) > .section-head::before,
  #app > .wrap:not(.home-wrap) > .section-head::after { content: none; }
  #app > .wrap:has(> .stage-grid)::after,
  #app > .wrap:has(> .loadout-strip)::after {
    content: "";
    position: absolute;
    top: 24px;
    right: 282px;
    width: 340px;
    height: 190px;
    z-index: -1;
    pointer-events: none;
    background: url('./assets/storybook/max-reading-cat.webp') center / contain no-repeat;
  }
  #practice-panel-guides:has(#guide-list), #practice-panel-questions { position: relative; }
  #practice-panel-guides:has(#guide-list)::before {
    content: "";
    position: absolute;
    right: 0;
    pointer-events: none;
    background:
      url('./assets/storybook/concept-max-reading.webp') left bottom / 200px 240px no-repeat,
      url('./assets/storybook/cat-book-stack.webp') right bottom / 110px 150px no-repeat;
  }
  #practice-panel-guides:has(#guide-list)::before { top: -20px; width: 310px; height: 240px; }
  .home-wrap > .max-guide { position: relative; }
  .home-wrap > .max-guide::after {
    content: "";
    position: absolute;
    top: 0;
    right: -250px;
    width: 230px;
    height: 150px;
    pointer-events: none;
    background: url('./assets/storybook/library-vista.webp') center / contain no-repeat;
  }
  .home-wrap > .max-guide::before {
    content: "";
    position: absolute;
    top: 0;
    left: -200px;
    width: 150px;
    height: 170px;
    pointer-events: none;
    background: url('./assets/storybook/cat-book-stack.webp') center / contain no-repeat;
  }
  .practice, .loadout-strip { position: relative; }
  .practice::before, .practice::after {
    content: "";
    position: absolute;
    pointer-events: none;
    background-position: center;
    background-size: contain;
    background-repeat: no-repeat;
  }
  .practice::before {
    left: -184px;
    top: 52px;
    width: 170px;
    height: 360px;
    background-image: url('./assets/storybook/concept-quill-books.webp');
  }
  .practice::after {
    right: -168px;
    top: 102px;
    width: 145px;
    height: 285px;
    background-image: url('./assets/storybook/cat-book-stack.webp');
  }
}
/* Every guide retains its small original Max/cat illustrations at each section.
   Larger reading companions use the existing empty side margins on wide screens. */
@media (min-width: 1380px) {
  body .story-guide-side-max {
    width: 240px;
    height: 310px;
    left: -256px;
    top: 58px;
    background: url('./assets/storybook/concept-max-reading.webp') center / contain no-repeat;
  }
  body .story-guide-side-books {
    width: 240px;
    height: 320px;
    right: -256px;
    top: 236px;
    background: url('./assets/storybook/cat-book-stack.webp') center / contain no-repeat;
  }
}
@media (min-width: 1440px) {
  .shop-banner::after { width: 400px; height: 210px; }
  /* Only the introductory fight panel has an empty area below it. Questions
     and feedback never receive this decoration; the canvas is untouched. */
  #question:has(> span.live-dot) { position: relative; }
  #question:has(> span.live-dot)::after {
    content: "";
    position: absolute;
    top: calc(100% + 20px);
    left: 50%;
    width: 150px;
    height: 180px;
    transform: translateX(-50%);
    pointer-events: none;
    background: url('./assets/storybook/cat-book-stack.webp') center / contain no-repeat;
  }
}
@media (min-width: 1600px) {
  #app:has(.battle-wrap) {
    background: url('./assets/storybook/library-vista.webp') right 28px bottom 20px / 180px auto no-repeat;
  }
}
/* The title scene remains the original image and exact button hit regions.
   Leaves and books decorate its page margins and the greeting's empty side space. */
@media (max-width: 1099px) {
  body::before { opacity: .18; }
}
@media (forced-colors: active) {
  body::before, body::after,
  #app > .wrap:not(.home-wrap)::before, #app > .wrap:not(.home-wrap)::after,
  #app > .wrap:not(.home-wrap) > .section-head::after,
  .standalone-guide::before,
  #app > .wrap:not(.home-wrap) > .section-head::before,
  .shop-banner::after, #practice-panel-guides:has(#guide-list)::before, #practice-panel-questions::before,
  .home-wrap > .max-guide::after, .home-wrap > .max-guide::before,
  .practice::before, .practice::after, .loadout-strip::after,
  #question:has(> span.live-dot)::after,
  .study-guide > section[id]::after,
  body .story-guide-art, body .story-guide-side-max, body .story-guide-side-books { display: none; }
  .home-wrap, #app:has(.battle-wrap) { background-image: none; }
  .guide-card, .study-guide, .question-panel, .stage-card, .level-card { border-image: none; }
}
@media print {
  body::before, body::after,
  #app > .wrap:not(.home-wrap)::before, #app > .wrap:not(.home-wrap)::after,
  #app > .wrap:not(.home-wrap) > .section-head::after,
  .standalone-guide::before,
  #app > .wrap:not(.home-wrap) > .section-head::before,
  .shop-banner::after, #practice-panel-guides:has(#guide-list)::before, #practice-panel-questions::before,
  .home-wrap > .max-guide::after, .home-wrap > .max-guide::before,
  .practice::before, .practice::after, .loadout-strip::after,
  #question:has(> span.live-dot)::after,
  .study-guide > section[id]::after { display: none; }
  body, .practice-hub, .study-guide { background: white; }
  .guide-card, .study-guide, .question-panel, .stage-card, .level-card { border-image: none; }
  .study-guide { box-shadow: none; }
}

/* Concept series 01: the title's original illustration and hit regions stay intact. */
.title-scene::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 28%;
  height: 50%;
  pointer-events: none;
  background: url('./assets/storybook/concept-ivy-corner.webp') left top / contain no-repeat;
}
@media print, (forced-colors: active) {
  .title-scene::before { display: none; }
}

/* Concept series 02: one reading group beside the Study Hub search. */
@media (min-width: 1280px) {
  #practice-panel-guides:has(#guide-list)::before {
    top: 0;
    width: 360px;
    height: 220px;
    background: url('./assets/storybook/max-reading-cat.webp') right bottom / contain no-repeat;
  }
}
body .guide-card > .story-guide-bookplate {
  top: 0;
  right: 6px;
  width: 46px;
  height: 34px;
  background: url('./assets/storybook/concept-quill-books.webp') right top / contain no-repeat;
}

/* Concept series 03: matching book-page frames for the approved question library. */
.browser-question {
  position: relative;
  border-image: url('./assets/storybook/concept-gold-frame.svg') 24 / 18px;
}
.topic-tab[aria-selected=true] {
  box-shadow: inset 0 0 0 2px #f9e6b1, 0 2px 0 #9c78322b;
}
@media (min-width: 1100px) {
  .browser-question::after {
    content: "";
    position: absolute;
    right: 7px;
    bottom: 7px;
    width: 46px;
    height: 46px;
    pointer-events: none;
    background: url('./assets/storybook/concept-quill-books.webp') right bottom / contain no-repeat;
  }
}
@media print, (forced-colors: active) {
  .browser-question::after { display: none; }
  .browser-question { border-image: none; }
}

/* Concept series 04: a quiet reading pose for wrong-answer review. */
.practice #feedback:has(.feedback.bad) .max-sprite {
  animation: none;
  background: url('./assets/storybook/concept-max-reading.webp') center / contain no-repeat;
}
@media (min-width: 1280px) {
  /* Short questions still leave the field-notes heading completely clear. */
  .practice::before { left: -195px; width: 180px; height: 300px; max-height: calc(100% - 68px); }
  .practice::after { right: -190px; width: 170px; height: 300px; max-height: calc(100% - 118px); }
}

/* Concept series 05: consistent transparent cat/book art in every lesson. */
body .story-guide-rule-cat {
  border-radius: 0;
  box-shadow: none;
  background: url('./assets/storybook/cat-book-stack.webp') center / contain no-repeat;
}
@media (min-width: 1380px) {
  .study-guide::before, .study-guide::after {
    content: "";
    position: absolute;
    width: 54px;
    height: 54px;
    pointer-events: none;
    background: url('./assets/storybook/concept-ivy-corner.webp') center / contain no-repeat;
  }
  .study-guide::before { left: -14px; top: -14px; }
  .study-guide::after { right: -14px; bottom: -14px; transform: rotate(180deg); }
}
@media print, (forced-colors: active) {
  .study-guide::before, .study-guide::after { display: none; }
}

/* Concept series 06: gold corners surround the original map illustrations too. */
.stage-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid transparent;
  border-image: url('./assets/storybook/concept-gold-frame.svg') 24 / 18px;
  pointer-events: none;
}
@media print, (forced-colors: active) {
  .stage-card::after { display: none; }
}

/* Concept series 07: the team strip is a quiet forest-green shelf. */
.loadout-strip { background-color: #263b30; }
#app > .wrap:has(> .loadout-strip) .character {
  border-color: #bfa36a;
  box-shadow: inset 0 0 0 3px #fff7e2, 0 3px 0 #9e783329;
}

/* Concept series 08: the Book Nook gets its own concept-derived reading vignette. */
.shop-banner { position: relative; }
.shop-banner::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid transparent;
  border-image: url('./assets/storybook/concept-gold-frame.svg') 24 / 18px;
  pointer-events: none;
}
@media (min-width: 1100px) {
  .shop-banner::after { background-image: url('./assets/storybook/concept-book-nook.webp'); }
}
@media (min-width: 1440px) {
  .shop-banner::after {
    width: 500px;
    right: 110px;
    background-size: 500px auto;
    background-position: center bottom -20px;
  }
}
@media print, (forced-colors: active) {
  .shop-banner::before { display: none; }
}

/* Concept series 09: frame the original level-selector map panorama. */
.map-banner {
  position: relative;
  box-shadow: 0 3px 0 #8c642126, inset 0 0 0 2px #d7b66a;
}
.level-card.complete {
  box-shadow: 0 3px 0 #9e783329, inset 0 0 0 2px #faedc5;
}
@media (min-width: 1100px) {
  .map-banner::before {
    content: "";
    position: absolute;
    right: 0;
    top: 0;
    width: 120px;
    height: 100px;
    transform: scaleX(-1);
    pointer-events: none;
    background: url('./assets/storybook/concept-ivy-corner.webp') left top / contain no-repeat;
  }
}
@media print, (forced-colors: active) {
  .map-banner::before { display: none; }
}

/* Concept series 10: decorative framing stays outside the live combat canvas. */
.field-frame {
  box-shadow: 0 4px 0 #8c642126, 0 0 0 3px #d5b26740;
}
.field-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid transparent;
  border-image: url('./assets/storybook/concept-gold-frame.svg') 24 / 18px;
  pointer-events: none;
}
.field-hud { background-color: #263b30; }
@media (min-width: 1740px) {
  .battle-wrap { position: relative; isolation: isolate; }
  .battle-wrap::before, .battle-wrap::after {
    content: "";
    position: absolute;
    width: 140px;
    height: 220px;
    z-index: -1;
    pointer-events: none;
    background-position: center;
    background-size: contain;
    background-repeat: no-repeat;
  }
  .battle-wrap::before {
    left: -154px;
    top: 130px;
    background-image: url('./assets/storybook/concept-quill-books.webp');
  }
  .battle-wrap::after {
    right: -154px;
    top: 260px;
    background-image: url('./assets/storybook/cat-book-stack.webp');
  }
}
@media print, (forced-colors: active) {
  .field-frame::after, .battle-wrap::before, .battle-wrap::after { display: none; }
}

/* The panorama and its soft reading surface add no ink in reading modes. */
@media print, (forced-colors: active) {
  body::before { display: none; }
  #app > .wrap, #app > .battle-wrap, #app > .loading, #guide-main { box-shadow: none; }
}

/* The fight's outer scenery matches the post-battle library painting.
   Paint only: retain the battlefield, question panel and control geometry. */
#app:has(> .battle-wrap) {
  background: #9b9866 url('./assets/storybook/results-library.webp') center / cover no-repeat;
}
/* Remove the floating margin books/cat and the introductory question's cat.
   The existing parchment reading surface continues to shield the controls. */
#app > .battle-wrap::before,
#app > .battle-wrap::after,
#app > .battle-wrap #question::after {
  content: none;
}
@media (max-width: 640px) {
  #app:has(> .battle-wrap) { background-position: 55% center; }
}
@media print, (forced-colors: active) {
  #app:has(> .battle-wrap) { background: Canvas; }
}
