:root {
  color-scheme: light;
  font-family: system-ui, "Hiragino Sans", "Yu Gothic", sans-serif;
  color: #50312e;
  background: #fff6eb;
  --rose: #a64048;
  --paper: #fff6eb;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
body, html { overscroll-behavior: none; }
button {
  font: inherit;
  font-weight: 700;
  color: inherit;
  cursor: pointer;
  border: 1px solid #edc8bb;
  background: #fffaf4;
  min-height: 44px;
  padding: .45rem 1rem;
  border-radius: 999px;
}
button:focus-visible, #stage:focus-visible { outline: 3px solid #a64048; outline-offset: 3px; }
.primary {
  position: relative;
  min-width: 11rem;
  padding: .8rem 1.7rem;
  border-color: var(--rose);
  background: var(--rose);
  color: #fff8f3;
  box-shadow: 0 7px 18px #a6404829;
}
.primary:hover { background: #86303a; }
.primary span { position: absolute; right: 1rem; font-size: 1.35em; line-height: 1; }

.home, .ending {
  min-height: 100svh;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  padding: max(1.25rem, env(safe-area-inset-top)) 1.25rem max(1.25rem, env(safe-area-inset-bottom));
  background: radial-gradient(ellipse at 16% 18%, #fffdf6, transparent 53%),
              radial-gradient(ellipse at 85% 80%, #f6d4cb, transparent 64%), var(--paper);
}
.home { gap: clamp(.65rem, 2vh, 1.35rem); }
.cover {
  display: block;
  width: min(76vw, 360px, 35svh);
  height: auto;
  border-radius: 7px 13px 13px 7px;
  border: 1px solid #fff9f3;
  box-shadow: 0 14px 32px #73423738, 0 3px 7px #73423725;
}
.home-copy { position: relative; min-width: min(275px, 84vw); }
.mascot { object-fit: cover; border-radius: 50%; mix-blend-mode: multiply; }
.home-copy .mascot {
  position: absolute;
  top: -2.7rem;
  right: -1.2rem;
  width: clamp(56px, 16vw, 88px);
  height: auto;
}
h1 { margin: .22em 0 0; font-size: clamp(1.85rem, 6vw, 3.6rem); line-height: 1.26; letter-spacing: .055em; }
.details { margin: .7rem 0 1.15rem; font-size: .875rem; color: #754640; }
.ending { gap: 1.4rem; }
.ending img { width: min(82vw, 440px); max-height: 52svh; object-fit: contain; border-radius: 1.1rem; }
.ending h2 { margin: 0; font-size: clamp(2rem, 7vw, 3.2rem); letter-spacing: .14em; }

#reader {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
  background: #282022;
}
#stage {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#stage:focus-visible { outline-offset: -3px; z-index: 1; }
.sheet {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
#page { will-change: transform; }
.progress {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .8rem;
  padding: .55rem 1.05rem max(.55rem, env(safe-area-inset-bottom));
  background: var(--paper);
  font-size: .775rem;
  font-variant-numeric: tabular-nums;
}
#count { min-width: 3.5rem; }
progress {
  direction: rtl;
  appearance: none;
  width: min(100%, 40rem);
  height: 5px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: #eed6cc;
  accent-color: var(--rose);
}
progress::-webkit-progress-bar { background: #eed6cc; }
progress::-webkit-progress-value { background: var(--rose); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--rose); border-radius: 999px; }
.reader-menu {
  position: absolute;
  z-index: 2;
  top: calc(env(safe-area-inset-top) + .75rem);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: .4rem;
  white-space: nowrap;
  background: var(--paper);
  padding: .4rem;
  border-radius: 999px;
  box-shadow: 0 4px 18px #24121466;
}
dialog {
  width: min(94vw, 620px);
  max-height: 87dvh;
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  color: inherit;
  background: var(--paper);
  border: 1px solid #edc8bb;
  border-radius: 1.2rem;
}
dialog::backdrop { background: #211719b8; }
dialog header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .65rem .85rem;
  background: var(--paper);
  border-bottom: 1px solid #edc8bb;
}
dialog h2 { margin: 0; font-size: 1.1rem; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(64px, 24%), 1fr));
  gap: .65rem;
  padding: .85rem;
}
.grid button {
  direction: ltr;
  min-width: 0;
  border-radius: .5rem;
  padding: .22rem;
  font-size: .75rem;
}
.grid button[aria-current="page"] { background: var(--rose); color: white; }
.grid img { display: block; width: 100%; height: auto; border-radius: .3rem; margin-bottom: .12rem; }

@media (min-width: 720px) and (min-height: 440px) {
  .home { grid-auto-flow: column; align-items: center; gap: clamp(3rem, 8vw, 8rem); }
  .cover { width: min(35vw, 400px, 48svh); }
  .home-copy .mascot { position: static; width: 88px; }
}
