* { box-sizing: border-box; }

:root {
  color-scheme: light;
  --sea: #143b3d;
  --ink: #193b3a;
  --muted: #4d6660;
  --paper: #fff8ec;
  --line: #ded5c4;
  --gold: #edb17e;
  --serif: "Songti SC", STSong, "Noto Serif CJK SC", "Noto Serif SC", SimSun, serif;
  background: #143b3d;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  background: radial-gradient(ellipse at 46% 8%, #376963, var(--sea) 53%, #0e2e34);
}

button { font: inherit; touch-action: manipulation; transition: background-color 140ms ease-out, border-color 140ms ease-out, transform 120ms ease-out; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible { outline: 2px solid #b26940; outline-offset: 3px; }
button { cursor: pointer; }
button:active { transform: scale(.985); }
h1, h2 { margin: 0; font-family: var(--serif); text-wrap: balance; }
@media (pointer: coarse) {
  button { min-block-size: 44px; min-inline-size: 44px; }
}

.book {
  width: min(100%, 31rem);
  min-height: 100svh;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: calc(.64rem + env(safe-area-inset-top)) clamp(1rem, 4.9vw, 1.6rem) .62rem;
  color: #fff3df;
  background: var(--sea);
}

.identity { display: flex; align-items: center; gap: .64rem; }
.masthead h1 { font-size: clamp(1.04rem, 4.6vw, 1.36rem); letter-spacing: .06em; }
.sun-mark { position: relative; width: 1.36rem; height: 1.3rem; flex: none; }
.sun-mark::before, .sun-mark::after { content: ""; position: absolute; }
.sun-mark::before {
  width: .95rem;
  height: .49rem;
  left: .2rem;
  top: .15rem;
  border-radius: 1rem 1rem 0 0;
  background: var(--gold);
}
.sun-mark::after {
  width: 1.36rem;
  height: 1px;
  left: 0;
  top: .79rem;
  background: var(--gold);
  box-shadow: 0 .2rem 0 var(--gold);
}

.masthead-actions { display: flex; align-items: center; gap: .45rem; }
.sound-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .34rem;
  min-height: 2.75rem;
  padding: .42rem .58rem;
  border: 1px solid #73908a;
  border-radius: .44rem;
  background: #254c4b;
  color: #e6ebe6;
  font-size: .875rem;
  white-space: nowrap;
}
.sound-toggle[aria-pressed="true"] {
  border-color: var(--gold);
  background: #2f5e5a;
  color: #fff3df;
}
.sound-toggle .sound-icon {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.sound-toggle .sound-on { display: none; color: var(--gold); }
.sound-toggle[aria-pressed="true"] .sound-off { display: none; }
.sound-toggle[aria-pressed="true"] .sound-on { display: block; }
@media (max-width: 360px) {
  .sound-toggle .sound-text { display: none; }
}

.map-toggle {
  display: flex;
  align-items: center;
  gap: .45rem;
  min-height: 2.75rem;
  padding: .42rem .61rem;
  border: 1px solid #73908a;
  border-radius: .44rem;
  background: #254c4b;
  color: #fff3df;
  font-size: .875rem;
  white-space: nowrap;
}
.map-icon {
  width: .69rem;
  height: .69rem;
  border: 1px solid var(--gold);
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
}
.map-count { color: #f0bd90; font-variant-numeric: tabular-nums; }

.art {
  position: relative;
  margin: 0;
  height: min(115vw, 51svh, 30rem);
  min-height: 15rem;
  overflow: hidden;
  background: #375c5a;
  isolation: isolate;
}
.art img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center var(--art-focus, 50%);
}
.art::after {
  content: "";
  position: absolute;
  inset: 61% 0 0;
  background: linear-gradient(transparent, rgb(9 28 29 / .62));
  pointer-events: none;
}
.art figcaption {
  z-index: 1;
  position: absolute;
  bottom: 1.05rem;
  left: clamp(1.12rem, 5.4vw, 1.85rem);
  padding: .28rem .58rem;
  border: 1px solid #fff6e49c;
  border-radius: 2rem;
  color: #fff8ec;
  background: #122c2ca8;
  font-size: .875rem;
  letter-spacing: .07em;
}

.page {
  position: relative;
  padding: 1.12rem clamp(1.12rem, 5.4vw, 1.85rem) 1.25rem;
  border-top: 3px solid var(--gold);
}
.chapter {
  display: flex;
  align-items: center;
  gap: .65rem;
  color: var(--muted);
  font-size: .875rem;
  line-height: 1.4;
  letter-spacing: .045em;
}
.chapter-rule { flex: 1; height: 1px; background: var(--line); }
#scene-title {
  margin-block: .48rem .46rem;
  font-size: clamp(1.84rem, 7.7vw, 2.68rem);
  line-height: 1.2;
  letter-spacing: .03em;
  font-weight: 800;
}
#scene-title:focus { outline: none; }
.passage { margin: 0; font-size: 1.04rem; line-height: 1.8; letter-spacing: .025em; text-wrap: pretty; }

.choices { display: grid; gap: .52rem; margin-top: 1.06rem; }
.choices button {
  display: flex;
  align-items: center;
  gap: .72rem;
  width: 100%;
  min-height: 3.15rem;
  padding: .64rem .85rem;
  border: 1px solid #a6b8ab;
  border-radius: .46rem;
  background: #eef0e6;
  color: var(--ink);
  text-align: start;
  font-size: .98rem;
  font-weight: 650;
}
.choices button::before {
  content: "";
  width: .54rem;
  height: .54rem;
  flex: none;
  border: 1px solid #487165;
  border-radius: 50%;
}
.choices button.solo { background: var(--sea); border-color: var(--sea); color: #fff6e6; }
.choices button.solo::before { border-color: var(--gold); background: var(--gold); }
.choices button.solo .choice-detail { color: #e9d9be; }
.choices button.secondary { background: transparent; border-color: var(--line); color: var(--muted); font-weight: 550; }
.choices button.secondary::before { border-color: #8fa399; }
.choice-label { display: grid; gap: .12rem; }
.choice-detail { color: var(--muted); font-size: .875rem; font-weight: 450; }

@media (hover: hover) {
  .sound-toggle:hover, .map-toggle:hover { background: #315957; }
  .choices button:hover { background: #dce6d9; border-color: #527469; }
  .choices button.solo:hover { background: #28534f; border-color: #28534f; }
  .choices button.secondary:hover { background: #f3ecdd; border-color: #9bb0a2; color: var(--ink); }
}

.ending-message {
  margin: .88rem 0 0;
  padding: .7rem .85rem;
  border-inline-start: 3px solid #a96035;
  background: #f5e5cf;
  color: #604125;
  font-weight: 650;
  font-size: .9375rem;
}

.collection {
  display: flex;
  gap: .63rem;
  align-items: center;
  margin: auto clamp(1.12rem, 5.4vw, 1.85rem) 0;
  padding: .78rem 0 calc(.86rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
}
.collection-marks { display: flex; gap: .32rem; margin-left: auto; }
.collection-marks span { width: .45rem; height: .45rem; border-radius: 50%; background: #ded7c9; }
.collection-marks .found { background: #315f57; }

.atlas {
  width: min(calc(100% - 1.35rem), 28.5rem);
  max-height: min(88svh, 50rem);
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid #8d9c89;
  border-radius: .75rem;
  background: var(--paper);
  color: var(--ink);
}
.atlas::backdrop { background: #0a2629b8; }
.atlas-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--sea);
  color: #fff3df;
  padding: .75rem 1rem;
}
.atlas-head h2 { font-size: 1.44rem; }
.close-atlas {
  min-height: 2.75rem;
  padding: .38rem .76rem;
  border: 1px solid #82a39b;
  border-radius: .38rem;
  background: #234948;
  color: #fff3df;
}
.atlas-body { padding: .98rem 1rem 1.2rem; }
.atlas h3 { margin: 0; font-family: var(--serif); font-size: 1.12rem; }
.route {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: .36rem;
  margin: .65rem 0 1.1rem;
  padding: 0;
}
.route li {
  padding: .28rem .55rem;
  background: #e8ede1;
  border: 1px solid #d2dccf;
  border-radius: 1rem;
  font-size: .875rem;
}
.route li[aria-current] { background: #315a50; color: #fff8ec; border-color: #315a50; }
.atlas-subheading { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
#atlas-count { color: var(--muted); font-size: .875rem; }
.atlas-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .53rem; margin-top: .62rem; }
.atlas-card { display: grid; overflow: hidden; border: 1px solid var(--line); border-radius: .4rem; background: #f9f1e1; }
.atlas-card img, .unvisited-art {
  display: block;
  width: 100%;
  aspect-ratio: 1.8;
  object-fit: cover;
  background: #e5e9dd;
}
.unvisited-art {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: .875rem;
  background: repeating-linear-gradient(154deg, #e7ebdf, #e7ebdf 8px, #e0e6da 8px, #e0e6da 9px);
}
.atlas-card span:last-child { padding: .4rem .45rem; font-size: .875rem; }
.atlas-note { margin: .75rem 0 0; font-size: .875rem; line-height: 1.6; color: var(--muted); }
.atlas-note a { color: #28594e; text-underline-offset: .16em; }

@media (min-width: 34rem) {
  body { padding-block: clamp(1rem, 3vh, 2rem); }
  .book {
    min-height: 0;
    border-radius: .75rem;
    overflow: hidden;
    border: 1px solid #759087;
    box-shadow: 0 1.25rem 4rem #061d248c;
  }
}
