:root {
  --paper: #f8f0e3;
  --paper-deep: #e8dcc8;
  --ink: #2d2218;
  --muted: #6b5e4e;
  --primary: #2c3e6b;
  --primary-deep: #1a2744;
  --accent: #c8a45c;
  --accent-light: #f5ecd7;
  --cream: #fffaf1;
  --shadow: 0 28px 60px rgba(30, 24, 12, 0.14);
  --shadow-sm: 0 8px 24px rgba(30, 24, 12, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(circle at top, rgba(200, 164, 92, 0.25), transparent 32%),
    linear-gradient(180deg, #fbf6ed 0%, #f5eed8 100%);
  color: var(--ink);
  font-family: "Avenir Next", "Trebuchet MS", "Helvetica Neue", sans-serif;
}

.book {
  width: min(1120px, calc(100vw - 32px));
  margin: 24px auto 40px;
  display: grid;
  gap: 28px;
}

.page {
  background: rgba(255, 250, 241, 0.88);
  border: 1px solid rgba(44, 62, 107, 0.1);
  border-radius: 28px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

h1, h2, h3, h4 {
  margin: 0;
  font-family: "Palatino Linotype", "Book Antiqua", Georgia, serif;
}

.zh {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

.hero {
  padding: 52px 48px 40px;
  text-align: center;
  background:
    radial-gradient(ellipse 60% 50% at 50% 0%, rgba(200, 164, 92, 0.1), transparent),
    linear-gradient(180deg, rgba(44, 62, 107, 0.05), transparent),
    rgba(255, 250, 241, 0.92);
  border-radius: 28px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(44, 62, 107, 0.08);
}

.hero h1 {
  font-size: clamp(2.6rem, 4.5vw, 3.8rem);
  color: var(--primary-deep);
  line-height: 1.15;
}

.hero h2 {
  margin-top: 10px;
  font-size: clamp(1.3rem, 2.2vw, 1.7rem);
  color: var(--accent);
}

.difficulty-badge {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px 14px;
  margin: 20px 0 0;
  padding: 8px 14px;
  border: 1px solid rgba(44, 62, 107, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.difficulty-badge .zh {
  color: var(--primary-deep);
}

.hero .lead {
  margin-top: 16px;
  font-size: 1.02rem;
  line-height: 1.68;
  color: var(--muted);
  max-width: 52ch;
  margin-left: auto;
  margin-right: auto;
}

.text-only {
  clear: both;
  display: block;
  max-width: none;
  margin: 0;
}

.text-only .story-copy {
  clear: both;
  max-width: none;
  padding: 12px 6px;
}

.text-only .zh,
.text-only .en {
  display: block;
  width: 100%;
  margin-top: 14px;
}

.page-label {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
}

.story, .ending {
  padding: 36px;
}

.two-column {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 32px;
  align-items: start;
}

.two-column.reverse {
  grid-template-columns: 1.1fr 1fr;
}

.two-column.reverse .story-copy { order: 1; }
.two-column.reverse .story-art { order: 2; }

.story-copy { padding: 12px 6px; }

.story-art {
  position: sticky;
  top: 28px;
  align-self: start;
}

.story-copy h3, .ending h3 {
  margin-top: 10px;
  font-size: clamp(1.8rem, 2.6vw, 2.4rem);
  color: var(--primary-deep);
}

.story-copy h4, .ending h4 {
  margin-top: 6px;
  font-size: clamp(1.1rem, 1.8vw, 1.45rem);
  color: var(--accent);
}

.story-copy p, .ending p {
  margin: 14px 0 0;
  line-height: 1.7;
  font-size: 1rem;
}

.text-wrap-image {
  display: block;
}

.text-wrap-image .story-copy {
  max-width: none;
  padding: 12px 6px;
}

.text-wrap-image .story-copy::after {
  content: "";
  display: block;
  clear: both;
}

.floated-figure {
  float: right;
  width: 50%;
  max-width: 460px;
  margin: 0 0 22px 24px;
}

.floated-image {
  float: none;
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 22px;
  object-fit: cover;
  margin: 0 0 12px;
}

.floated-caption {
  float: none;
  clear: none;
  display: block;
  width: 100%;
  max-width: none;
  margin: 0;
  font-size: 0.82rem;
  text-align: center;
  line-height: 1.5;
  color: var(--muted);
  font-style: italic;
}

.story-art img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 22px;
  object-fit: cover;
}

.ending {
  position: relative;
  padding: 36px;
  background:
    radial-gradient(circle at top right, rgba(200, 164, 92, 0.16), transparent 30%),
    linear-gradient(180deg, rgba(44, 62, 107, 0.08), rgba(44, 62, 107, 0.01)),
    rgba(255, 250, 241, 0.95);
}

.ending-copy { max-width: none; }

.ending h3 {
  font-size: clamp(1.8rem, 2.6vw, 2.4rem);
  color: var(--primary-deep);
}

.ending h4 {
  margin-top: 6px;
  font-size: clamp(1.1rem, 1.8vw, 1.45rem);
  color: var(--accent);
}

.closing {
  font-size: 1.08rem;
  margin-top: 16px;
  line-height: 1.7;
}

.caption {
  margin-top: 10px;
  font-size: 0.88rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
  font-style: italic;
}

.glossary-entry {
  position: relative;
  display: inline-block;
}

.glossary-term {
  appearance: none;
  border: 0;
  border-bottom: 1px dotted rgba(44, 62, 107, 0.55);
  border-radius: 0.2em;
  padding: 0 0.08em;
  background: rgba(200, 164, 92, 0.16);
  color: inherit;
  font: inherit;
  line-height: inherit;
  cursor: help;
}

.glossary-term:focus-visible {
  outline: 2px solid rgba(44, 62, 107, 0.45);
  outline-offset: 2px;
}

.glossary-popover {
  position: absolute;
  z-index: 30;
  left: 50%;
  bottom: calc(100% + 10px);
  width: max-content;
  max-width: min(280px, calc(100vw - 32px));
  padding: 10px 12px;
  border: 1px solid rgba(44, 62, 107, 0.18);
  border-radius: 12px;
  background: #fffaf1;
  box-shadow: 0 14px 32px rgba(30, 24, 12, 0.16);
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.45;
  text-align: left;
  transform: translateX(-50%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.glossary-popover::after {
  content: "";
  position: absolute;
  left: var(--glossary-arrow-left, 50%);
  bottom: -6px;
  width: 10px;
  height: 10px;
  border-right: 1px solid rgba(44, 62, 107, 0.18);
  border-bottom: 1px solid rgba(44, 62, 107, 0.18);
  background: #fffaf1;
  transform: translateX(-50%) rotate(45deg);
}

@media (hover: hover) {
  .glossary-entry:hover .glossary-popover {
    opacity: 1;
    visibility: visible;
  }
}

.glossary-entry:focus-within .glossary-popover,
.glossary-entry[data-open="true"] .glossary-popover {
  opacity: 1;
  visibility: visible;
}

.glossary-entry[data-open="true"] .glossary-popover {
  position: fixed;
  left: var(--glossary-left, 50vw);
  top: var(--glossary-top, 16px);
  bottom: auto;
  transform: translateX(-50%);
}

.glossary-entry[data-side="below"] .glossary-popover {
  top: calc(100% + 10px);
  bottom: auto;
}

.glossary-entry[data-side="below"] .glossary-popover::after {
  top: -6px;
  bottom: auto;
  border: 0;
  border-left: 1px solid rgba(44, 62, 107, 0.18);
  border-top: 1px solid rgba(44, 62, 107, 0.18);
}

@media (max-width: 900px) {
  .cover-copy {
    width: 100%;
    justify-content: end;
    padding: 32px 24px;
    background: linear-gradient(180deg, rgba(26, 39, 68, 0.18), rgba(26, 39, 68, 0.8));
  }
  .cover-art img { height: 76vh; }
  .two-column, .two-column.reverse { grid-template-columns: 1fr; }
  .story-art {
    position: static;
    top: auto;
  }
  .text-wrap-image .floated-figure,
  .text-wrap-image .floated-image,
  .text-wrap-image .floated-caption {
    float: none;
    width: 100%;
    max-width: 100%;
  }
  .text-wrap-image .floated-figure {
    margin: 16px 0 14px;
  }
  .text-wrap-image .floated-image {
    margin: 0 0 10px;
  }
  .text-wrap-image .floated-caption {
    margin: 0;
  }
  .story, .ending { padding: 20px; }
  .text-only .zh,
  .text-only .en {
    margin-top: 10px;
  }

  .glossary-entry[data-open="true"] .glossary-popover,
  .glossary-entry:focus-within .glossary-popover {
    position: fixed;
    right: 16px;
    bottom: 16px;
    left: 16px;
    top: auto;
    width: auto;
    max-width: none;
    transform: none;
    font-size: 0.98rem;
  }

  .glossary-popover::after {
    display: none;
  }
}

.back-nav {
  width: min(1120px, calc(100vw - 32px));
  margin: 16px auto 0;
}
.back-nav a {
  display: inline-block;
  padding: 8px 16px;
  background: rgba(255, 250, 241, 0.85);
  border: 1px solid rgba(44, 62, 107, 0.12);
  border-radius: 14px;
  color: var(--primary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s;
}
.back-nav a:hover {
  background: rgba(200, 164, 92, 0.15);
}
