/* The desktop geometry follows the original image slices (731 / 730 px).
   13px desktop text is intentional: this experiment preserves the original design. */
:root {
  color-scheme: dark;
  --page-bg: #3a180b;
  --paper-bg: #633f29;
  --title-bg: #644026;
  --footer-bg: #643f29;
  --text: #cfb390;
  --accent: #cb8239;
  --frame-width: 731px;
  --content-width: 482px;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page-bg); color: var(--text); }
img { max-width: 100%; height: auto; }
a { color: var(--accent); }
a:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }
.skip-link {
  position: absolute;
  top: 0;
  left: 1rem;
  z-index: 10;
  padding: .75rem 1rem;
  background: var(--page-bg);
  transform: translateY(-150%);
  font: 1rem/1.5 Arial, sans-serif;
}
.skip-link:focus { transform: none; }

.site-header, .page-footer { width: min(100%, var(--frame-width)); margin-inline: auto; }
.brand-strip { display: grid; grid-template-columns: 148fr 439fr 144fr; }
.brand-strip img, .illustrated-nav img, .page-title img, .page-footer img { display: block; width: 100%; }
.illustrated-nav { display: grid; grid-template-columns: 148fr repeat(3, 31fr) 253fr repeat(3, 31fr) 144fr; }
.menu-link { display: block; background-size: 100% 100%; background-repeat: no-repeat; }
.menu-1 { background-image: url('../images/menu1_over.gif'); }
.menu-2 { background-image: url('../images/menu2_over.gif'); }
.menu-3 { background-image: url('../images/menu3_over.gif'); }
.menu-4 { background-image: url('../images/menu4_over.gif'); }
.menu-5 { background-image: url('../images/menu5_over.gif'); }
.menu-6 { background-image: url('../images/menu6_over.gif'); }
.menu-link:not([aria-current]):is(:hover, :focus-visible) img { opacity: 0; }
.menu-link:focus-visible { outline-offset: -2px; }
.page-title { display: grid; grid-template-columns: 148fr 439fr 144fr; }
.page-title::before, .page-title::after { content: ''; background-size: 100% auto; }
.page-title::before { background-image: url('../images/fon_left.jpg'); }
.page-title::after { background-image: url('../images/fon_right.jpg'); }
.page-title h1 { margin: 0; background: var(--title-bg); }
.page-title img { width: 220px; margin-inline: auto; }
.text-nav { display: none; }

.content-frame {
  display: grid;
  grid-template-columns: minmax(0, 124px) minmax(0, var(--content-width)) minmax(0, 124px);
  width: min(100%, 730px);
  margin-inline: auto;
}
.content-frame::before, .content-frame::after {
  content: '';
  align-self: end;
  aspect-ratio: 124 / 68;
  background: center bottom / 100% auto no-repeat;
}
.content-frame::before { background-image: url('../images/left_footer.gif'); }
.content-frame::after { background-image: url('../images/right_footer.gif'); }
main { min-width: 0; display: flow-root; background: var(--paper-bg); }
.contents { margin-block: 1.33em; text-align: center; font: .8125rem/normal Arial, sans-serif; }
.story { display: flow-root; }
.story-illustration { display: block; width: 455px; margin-inline: auto; }
.story h2 {
  margin: 1em 0;
  color: var(--accent);
  font: normal .9375rem/normal Arial, sans-serif;
  text-align: center;
}
.story p { margin: 10px 20px; font: .8125rem/1rem Arial, sans-serif; text-align: justify; }
.story h3 { margin: 1.33em 0; color: var(--accent); font: normal .8125rem/normal Arial, sans-serif; text-align: center; }
.text-section h2:first-child { margin-top: 5px; }
.content-image { display: block; width: 455px; margin-inline: auto; }
.inline-icon { float: inline-start; margin-inline: 5px; }
.icon-text { display: flow-root; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.creature-list { display: grid; gap: 4px; padding: 3px; }
.creature { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 4px; align-items: center; }
.creature-image img { display: block; }
.table-wrap { min-width: 0; }
.spell-table { width: 440px; max-width: calc(100% - 24px); margin-inline: auto; border-spacing: 2px; }
.spell-table td { padding: 1px; }
.spell-table img { max-width: none; vertical-align: bottom; }
.auxiliary { max-width: 44rem; margin: 2rem auto; padding: 1rem; background: var(--title-bg); }
.auxiliary h1 { margin: 0; }
.strength-table { width: 100%; margin-block: 1rem; border-spacing: 4px; }
.strength-table th { font-weight: normal; overflow-wrap: anywhere; }
.page-footer { display: grid; grid-template-columns: 148fr 432fr 151fr; grid-template-rows: auto auto; }
.footer-left { grid-column: 1; grid-row: 1 / 3; }
.footer-right { grid-column: 3; grid-row: 1 / 3; }
.footer-center { grid-column: 2; grid-row: 2; }
.footer-actions {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-columns: 177fr 77fr 178fr;
  align-items: end;
  background: var(--footer-bg);
}
.back-to-top { grid-column: 2; }
.previous-page { grid-column: 1; }
.next-page { grid-column: 3; }
.previous-page span, .next-page span { display: none; }

/* Reflow only when the original composition no longer fits (or uses touch).
   The artwork remains the same; text navigation repeats existing labels. */
@media (max-width: 730px), (pointer: coarse) {
  /* Fit the 439px central artwork to the same panel as the content.
     Crop only the 148px/144px decorative sides of the full 731px image. */
  .header-artwork {
    width: min(100%, var(--content-width));
    margin-inline: auto;
    overflow: hidden;
    overflow: clip;
  }
  .header-artwork > :is(.brand-strip, .illustrated-nav, .page-title) {
    width: calc(100% * 731 / 439);
    margin-inline-start: calc(-100% * 148 / 439);
  }
  .header-artwork .brand-strip a:focus-visible { outline-offset: -3px; }
  .text-nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 .75rem;
    padding: .5rem 1rem;
    max-width: var(--content-width);
    margin-inline: auto;
    background: var(--paper-bg);
    font: 1rem/1.35 Arial, sans-serif;
  }
  .text-nav a { display: flex; align-items: center; min-height: 44px; padding-block: .5rem; }
  .text-nav [aria-current] { color: var(--text); }
  .content-frame { grid-template-columns: minmax(0, 1fr) minmax(0, var(--content-width)) minmax(0, 1fr); }
  .contents { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 .75rem; margin: .25rem 1rem .75rem; font: 1rem/1.4 Arial, sans-serif; }
  .contents a { display: flex; align-items: center; min-height: 44px; }
  .contents span { display: none; }
  .contents br { display: none; }
  .story-illustration, .content-image { width: calc(100% - 24px); max-width: 455px; }
  .story h2 { margin: 1rem .75rem; font-size: 1.125rem; line-height: 1.4; }
  .story h3 { margin: 1rem .75rem; font-size: 1rem; line-height: 1.4; }
  .text-section h2:first-child { margin-top: 1rem; }
  .story p { margin: .75rem 1rem; font-size: 1rem; line-height: 1.5; text-align: start; }
  .creature { grid-template-columns: 1fr; gap: 0; }
  .creature-image { justify-self: center; }
  .creature-description { min-width: 0; }
  .spell-table { width: calc(100% - 16px); max-width: none; table-layout: fixed; }
  .spell-table .rune-column { width: 68px; }
  .spell-table .spell-icon-column { width: 52px; }
  .spell-table p { margin: .5rem; overflow-wrap: anywhere; }
  .auxiliary { margin: 0; }
  .page-footer { position: relative; padding-top: 44px; }
  .page-footer::before { content: ''; grid-column: 2; grid-row: 1; background: var(--footer-bg); }
  .footer-actions { position: absolute; grid-area: auto; top: 0; left: 0; width: 100%; min-height: 44px; grid-template-columns: 1fr 77px 1fr; }
  .footer-actions a { display: flex; align-items: center; justify-content: center; min-height: 44px; }
  .previous-page img, .next-page img { display: none; }
  .previous-page span, .next-page span { display: block; padding: .25rem; font: .875rem/1.4 Arial, sans-serif; }
  .footer-center { align-self: stretch; height: 100%; object-fit: contain; object-position: bottom; background: var(--footer-bg); }
}

