/* The margins of the herbology plate also hold the pupil's letter and reply. */
#book { grid-template-columns: minmax(0, 1fr); }
#book #stage { container: flower-room / size; }
body:not(.clean):is([data-mode=letter], [data-mode=ending]) #book #stage {
  display: grid;
  grid-template: minmax(0, 1fr) auto / minmax(0, 1fr);
}

#book :is(#letter, #ending) {
  right: auto;
  bottom: auto;
  max-height: calc(100% - 24px);
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
#book #letter {
  left: 3.5%;
  top: 50%;
  width: min(43%, 32rem);
  max-width: none;
  padding: clamp(12px, 1.65vw, 28px);
  transform: translateY(-50%);
}
#book #letter .letterhead { flex-wrap: wrap; gap: .5em; }
#book #letter .letterhead .en { line-height: 1.22; }
#book #letter .lesson { letter-spacing: .08em; }
#book #letter .lesson span { color: var(--faint); margin: 0; }
html:lang(en) #book #letter h1 {
  display: flex;
  flex-wrap: wrap;
  gap: 0 .22em;
  font-size: clamp(27px, 3.45vw, 62px);
  line-height: 1.08;
  letter-spacing: -.025em;
}
html:lang(en) #book #letter h1 br { display: none; }
#book .inkbutton span { margin: 0; }
#book #enter, #book #gate { white-space: normal; }
#book :is(#enter, #gate) span[aria-hidden] { margin-inline-start: .55em; }

#book #ending {
  top: 50%;
  left: auto;
  right: 3%;
  width: min(43%, 32rem);
  padding: clamp(12px, 1.6vw, 26px);
  transform: translateY(-50%);
  background: var(--grain), var(--paper);
}
#book #ending h2 { line-height: 1.22; }
#book #ending p { line-height: 1.58; }
#book .ending-actions { gap: 2px 1em; margin-top: .55em; }
#book .ending-actions .inkbutton {
  min-width: 0;
  max-width: 100%;
  min-height: 42px;
  gap: .5em;
  padding: .52em .75em;
  line-height: 1.18;
  white-space: normal;
}
#book .ending-actions .inkbutton > [aria-hidden] { flex: none; }
#book .ending-actions :not(.inkbutton) > [data-i18n] { display: inline; }
#book .ending-actions :not(.inkbutton) > [aria-hidden] { display: none; }
#book :is(.instructions, .device-control, .flower-language) { min-width: 0; }
#book #actions { max-width: 100%; flex-wrap: wrap; justify-content: flex-end; }
body[data-mode=letter] #book #actions { display: none; }
#book #accession { text-align: center; line-height: 1.38; }
body:is([data-mode=letter], [data-mode=ending]) #book .plate {
  padding: 2px 5px;
  background: var(--grain), var(--paper);
}

#guide {
  width: min(36rem, calc(100% - 24px));
  max-width: none;
  max-height: calc(100dvh - 24px);
  padding: clamp(14px, 3.5vw, 36px);
  overflow: auto;
  overscroll-behavior: contain;
}
#guide .guideHead {
  position: sticky;
  z-index: 1;
  top: 0;
  min-height: 33px;
  gap: 1em;
  background: var(--grain), var(--paper);
}
#closeGuide { min-width: 34px; min-height: 33px; }
#guide p, #guide dd { overflow-wrap: break-word; }

/* The classroom renderer changes to its portrait composition at this same
   aspect ratio. Give the illustration and the text separate rows there. */
@container flower-room (aspect-ratio < 9/10) {
  body:not(.clean)[data-mode=letter] #scene,
  body:not(.clean)[data-mode=ending] #glasshouse {
    position: relative;
    inset: auto;
    grid-area: 1 / 1;
    min-height: 0;
    overflow: hidden;
  }
  body[data-mode=letter] #scene canvas {
    object-fit: contain;
    scale: 1.25;
    transform-origin: 50% 40%;
  }
  body:not(.clean)[data-mode=ending] #glasshouse {
    object-fit: cover;
    object-position: 50% 24%;
  }
  #book :is(#letter, #ending) {
    position: relative;
    inset: auto;
    grid-area: 2 / 1;
    justify-self: center;
    width: min(calc(100% - 20px), 31rem);
    max-height: 74cqh;
    margin: 0 0 9px;
    padding: 9px 12px;
    transform: none;
  }
  #book #letter .letterhead .seal { width: 25px; }
  #book #letter h1 { margin-bottom: 5px; }
  #book #letter .invitation, #book #letter blockquote { line-height: 1.48; }
  #book #ending h2 { font-size: clamp(20px, 5.5vw, 29px); }
  #book #ending .ending-actions { margin-top: 5px; }
}
@container flower-room (min-aspect-ratio: 9/10) and (max-height: 360px) {
  #book #letter, #book #ending { padding: 7px 12px; }
  #book #letter .letterhead { display: none; }
  #book #letter :is(h1, .lesson, .invitation) { margin-block: 0 3px; }
  #book #letter blockquote { margin: 3px 0 5px; padding-top: 4px; }
  #book #letter :is(.invitation, blockquote) { font-size: 12px; line-height: 1.35; }
  #book #ending .ending-actions .inkbutton { min-height: 34px; font-size: 14px; }
  #book #ending .ending-actions :is(a, button):not(.inkbutton) { min-height: 28px; }
}
@container flower-room (min-aspect-ratio: 9/10) {
  body:not(.clean)[data-mode=ending] #glasshouse {
    padding-right: min(14cqw, 9rem);
    object-fit: contain;
    object-position: left center;
  }
}
@container flower-room (min-aspect-ratio: 9/10) and (max-height: 260px) {
  #book :is(#letter, #ending) { max-height: calc(100% - 8px); padding: 4px 9px; }
  #book #letter { width: 53%; left: 2%; }
  #book #ending { width: 49%; right: 2%; }
  #book #letter h1, html:lang(en) #book #letter h1 { font-size: 23px; line-height: 1.05; }
  #book #letter .lesson { font-size: 10px; line-height: 1.2; }
  #book #letter :is(.invitation, blockquote), #book #ending p { font-size: 12px; line-height: 1.32; }
  #book #ending h2 { font-size: 18px; line-height: 1.15; }
  #book #ending .ending-actions { margin-top: 4px; }
  #book #enter { padding: 5px 11px; }
}
@container flower-room (min-aspect-ratio: 9/10) and (max-aspect-ratio: 5/4) {
  body[data-mode=letter] #book #scene { translate: 7% 0; }
}
@container flower-room (max-width: 480px) {
  #book .plant-label {
    left: auto !important;
    right: 5px;
    gap: 4px;
    transform: none;
  }
  #book .plant-label::before { width: 10px; }
  #book #stage:has(.camera-view:not([hidden])) .plate {
    max-width: calc(100% - clamp(116px, 35.5vw, 166px) - 25px);
    flex-wrap: wrap;
    gap: 2px 7px;
  }
  #book #stage:has(.camera-view:not([hidden])) .plant-label {
    top: auto !important;
    right: auto;
    bottom: 8px;
    left: 8px !important;
  }
}
@media (max-width: 900px) {
  #book .folio, #book .folioNo { display: none; }
}
@media (max-width: 680px) and (orientation: portrait) {
  #book .mast .brand { white-space: normal; line-height: 1.15; }
  #book footer { display: grid; gap: 4px; }
  #book #actions { margin-left: 0; }
}
