/* もしもえほん 共通の見た目。話ごとの色は story.js の BOOK.theme で CSS 変数を上書きする */
:root {
  color-scheme: dark;
  --indigo: #263744;
  --paper: #f5ebd5;
  --ink: #38382f;
  --persimmon: #ab4931;
  --bamboo: #526b52;
  --peach: #efac91;
  /* 紙を切ったボタンや札の色（少し透ける） */
  --tint-main: #ab4931ed;   /* はじめる・もういちど・選択肢の左 */
  --tint-alt: #526b52f2;    /* 選択肢の右 */
  --tint-dark: #263744ee;   /* つぎへ・おしまい図鑑 */
  --tint-secret: #8a6a2cf0; /* ひみつの おしまい */
  --tint-paper: #f5ebd5f2;  /* 題字の札・図鑑のカード・とじる */
  --sheet-top: #f5ebd5ef;   /* 下の和紙（上と下で少し濃さが違う） */
  --sheet-bottom: #f5ebd5eb;
  --cover-pos: 50% 12%;     /* 表紙の絵の位置 */
  --grain: none;            /* 紙の繊維。ehon.js が話の BOOK.grain から入れる */
  --cut: polygon(.6% 2%, 11% .8%, 26% 1.6%, 43% 0, 61% 1%, 81% .3%, 99.6% 1.8%, 100% 42%, 99.5% 69%, 99.8% 97.8%, 79% 99%, 58% 98.5%, 40% 100%, 20% 98.6%, .3% 99%, .6% 72%, 0 44%);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  color: var(--ink);
  font-weight: 700;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--indigo);
  display: grid;
  place-items: center;
  overflow: hidden;
  isolation: isolate;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
body::before {
  content: ""; position: fixed; inset: 0;
  background: var(--grain); filter: grayscale(1);
  mix-blend-mode: soft-light; opacity: .22; pointer-events: none; z-index: -1;
}
main {
  width: min(100%, 127vh, 1520px);
  height: min(97vh, 75vw);
  height: min(97svh, 75vw);
  container-type: inline-size;
  display: flex; flex-direction: column;
  padding-bottom: 1.6cqw;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: .32cqw solid var(--peach); outline-offset: .4cqw; }

/* 上の帯 */
.masthead { height: 6.6cqw; flex: none; display: flex; align-items: center; justify-content: space-between; padding: 0 .8cqw; color: var(--paper); }
.home { display: flex; align-items: center; gap: 1.1cqw; font-size: 2.45cqw; letter-spacing: .12em; }
.peach { position: relative; width: 3.9cqw; height: 3.6cqw; filter: drop-shadow(.1cqw .2cqw .08cqw #12232a); }
.peach::before, .peach::after { content: ""; position: absolute; }
.peach::before { background: var(--peach); inset: 5% 7% 20% 4%; border-radius: 15% 60% 46% 65%; transform: rotate(20deg); clip-path: polygon(0 0, 52% 10%, 70% 4%, 86% 15%, 100% 47%, 96% 83%, 69% 100%, 33% 95%, 12% 74%, 4% 41%); }
.peach::after { background: #96ab80; width: 50%; height: 27%; bottom: 5%; right: 2%; border-radius: 100% 0 100% 0; transform: rotate(-9deg); }
/* 帯の印：かめ（うらしまたろう）。切り紙の甲らと ひれ */
.kame { position: relative; width: 3.9cqw; height: 3.6cqw; filter: drop-shadow(.1cqw .2cqw .08cqw #12232a); }
.kame::before, .kame::after { content: ""; position: absolute; }
.kame::before { background: #8fb383 radial-gradient(ellipse at 50% 42%, #b8cf9f 0 24%, transparent 27%); inset: 22% 22% 22% 0; border-radius: 50% 50% 14% 14%; clip-path: polygon(0 88%, 2% 58%, 12% 30%, 34% 8%, 62% 6%, 86% 28%, 98% 60%, 100% 88%, 88% 100%, 72% 88%, 28% 88%, 12% 100%); }
.kame::after { background: #e6d9a8; width: 36%; height: 44%; right: 0; top: 26%; border-radius: 50%; clip-path: polygon(0 60%, 10% 20%, 50% 0, 90% 16%, 100% 56%, 84% 94%, 44% 100%, 12% 88%); }
.catalog { display: flex; align-items: center; gap: .8cqw; font-size: 1.6cqw; letter-spacing: .08em; padding: 1cqw; }
.book-icon { width: 2.2cqw; height: 1.5cqw; position: relative; display: inline-block; }
.book-icon::before, .book-icon::after { content: ""; position: absolute; width: 43%; height: 90%; background: #e4d8bd; top: 0; border-radius: 12% 25% 0 0; transform: skewY(10deg); }
.book-icon::after { right: 0; transform: skewY(-10deg); }
.count { font-family: Georgia, serif; font-size: 1.85cqw; border-left: 1px solid #8b9694; padding-left: 1cqw; }

/* 紙の重なり */
.page { display: flex; flex-direction: column; position: relative; isolation: isolate; flex: 1; min-height: 0; filter: drop-shadow(0 .5cqw .4cqw #101c2666); }
.page::before, .page::after { content: ""; position: absolute; inset: .8% .2% -.5%; background: #b4ac93; transform: rotate(.28deg); z-index: -1; clip-path: var(--cut); }
.page::after { inset: .5% .1% -.4%; background: #d9d0b6; transform: rotate(-.24deg); }
.scene { flex: 1; min-height: 0; position: relative; margin: 0; background: #dcccac; padding: .54cqw .55cqw 0; clip-path: polygon(.22% .4%, 16% 0, 40% .28%, 70% 0, 99.85% .35%, 100% 100%, 0 100%); }
.scene img { position: absolute; inset: .54cqw .55cqw 0; width: calc(100% - 1.1cqw); height: calc(100% - .54cqw); display: block; object-fit: cover; object-position: 50% 45%; transition: opacity .5s; }
.scene img.hide { opacity: 0; }

/* 下の和紙 */
.sheet { position: relative; isolation: isolate; margin-top: -1.2cqw; height: 21.5cqw; flex: none; padding: 2.6cqw 2.9cqw 1.6cqw; }
.sheet::before { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(var(--sheet-top), var(--sheet-bottom)), var(--grain); clip-path: polygon(0 4%, 3% 3.2%, 7% 3.9%, 11% 2.5%, 15% 3%, 21% 1.8%, 25% 3%, 32% 1.7%, 39% 2.7%, 44% 1.5%, 49% 2.3%, 56% .8%, 60% 2%, 65% .5%, 71% 1.4%, 77% .6%, 83% 1.7%, 89% .8%, 94% 2%, 100% 1%, 99.9% 99.5%, 75% 99.8%, 50% 99.2%, 22% 100%, .2% 99%); }
.mode { position: absolute; inset: 2.6cqw 2.9cqw 1.6cqw; display: none; }
.sheet[data-mode="text"] .m-text,
.sheet[data-mode="choice"] .m-choice,
.sheet[data-mode="end"] .m-end { display: flex; animation: rise .35s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(.8cqw); } }

/* 文のとき */
.m-text { align-items: center; gap: 2cqw; cursor: pointer; }
.story { flex: 1; margin: 0; white-space: pre; font-size: 2.85cqw; line-height: 1.8; letter-spacing: .01em; }
.paper-btn { position: relative; isolation: isolate; color: #fff8e8; filter: drop-shadow(.17cqw .4cqw .12cqw #675a4159); transition: transform .12s, filter .12s; }
.paper-btn::before { content: ""; position: absolute; inset: 0; z-index: -1; clip-path: var(--cut); background: linear-gradient(var(--tint), var(--tint)), var(--grain); }
.paper-btn:active { transform: translateY(.35cqw) rotate(0deg); filter: drop-shadow(0 .08cqw .05cqw #675a4177) brightness(.86); }
.next { --tint: var(--tint-dark); flex: none; width: 15cqw; height: max(64px, 9cqw); font-size: 2.3cqw; letter-spacing: .08em; transform: rotate(-.8deg); }
.next::after { content: ""; display: inline-block; width: .9cqw; height: .9cqw; margin-left: .7cqw; border: solid currentColor; border-width: .3cqw .3cqw 0 0; transform: rotate(45deg) translateY(-.1cqw); }

/* えらぶとき：下一面 */
.m-choice { flex-direction: column; align-items: stretch; gap: 1.3cqw; }
.question { margin: 0; text-align: center; font-size: 2.6cqw; letter-spacing: .06em; }
.buttons { flex: 1; display: flex; gap: 2.4cqw; min-height: 0; }
.opt { flex: 1; min-height: 72px; font-size: 3.7cqw; letter-spacing: .1em; }
.opt.a { --tint: var(--tint-main); transform: rotate(-.7deg); }
.opt.b { --tint: var(--tint-alt); transform: rotate(.6deg); }

/* おしまい */
.m-end { align-items: center; gap: 2.4cqw; }
.end-title { flex: 1; text-align: center; }
.end-title small { display: block; font-size: 1.7cqw; letter-spacing: .3em; color: #8a6d4b; }
.end-title b { display: block; font-size: 3.5cqw; letter-spacing: .08em; margin: .3cqw 0; }
.end-title span { font-size: 1.6cqw; color: #7a705c; letter-spacing: .06em; }
.end-btns { flex: none; display: flex; flex-direction: column; gap: 1.1cqw; width: 26cqw; }
.end-btns .paper-btn { height: max(52px, 7.2cqw); font-size: 2.1cqw; letter-spacing: .06em; }
.again { --tint: var(--tint-main); }
.tozukan { --tint: var(--tint-dark); }
.secret { --tint: var(--tint-secret); }

/* 表紙 */
.cover-title { position: absolute; right: 3%; top: 6%; pointer-events: none; }
.cover-title .plate { text-align: center; }
.scene.is-cover img { object-position: var(--cover-pos); }
.cover-title .plate { display: inline-block; position: relative; isolation: isolate; padding: 1.4cqw 3.4cqw 1.7cqw; transform: rotate(1.2deg); filter: drop-shadow(.2cqw .5cqw .2cqw #0006); }
.cover-title .plate::before { content: ""; position: absolute; inset: 0; z-index: -1; clip-path: var(--cut); background: linear-gradient(var(--tint-paper), var(--tint-paper)), var(--grain); }
.cover-title small { display: block; font-size: 1.7cqw; letter-spacing: .35em; color: var(--persimmon); }
.cover-title b { display: block; font-size: 5.4cqw; letter-spacing: .14em; line-height: 1.25; }
.cover-title em { display: block; font-style: normal; font-size: 1.75cqw; letter-spacing: .08em; color: var(--indigo); margin-top: .3cqw; }
.m-cover { align-items: center; justify-content: center; gap: 3cqw; }
.sheet[data-mode="cover"] .m-cover { display: flex; }
.m-cover .paper-btn { height: max(72px, 11cqw); font-size: 3.2cqw; letter-spacing: .1em; }
.start { --tint: var(--tint-main); width: 40cqw; transform: rotate(-.7deg); }
.m-cover .tozukan { width: 30cqw; transform: rotate(.6deg); }

/* 表紙の「ほんだなへ」（玄関ページへ戻る小さな札） */
.shelf { position: absolute; left: 1.6%; top: 3.2%; display: none; align-items: center; min-height: 44px; padding: .5cqw 1.5cqw .6cqw 1.1cqw; isolation: isolate; color: var(--ink); text-decoration: none; font-size: 1.45cqw; letter-spacing: .1em; transform: rotate(-1.4deg); filter: drop-shadow(.12cqw .3cqw .12cqw #0005); }
.shelf::before { content: ""; position: absolute; inset: 0; z-index: -1; clip-path: var(--cut); background: linear-gradient(var(--tint-paper), var(--tint-paper)), var(--grain); }
.shelf::after { content: ""; order: -1; width: .7cqw; height: .7cqw; margin-right: .8cqw; border: solid var(--persimmon); border-width: 0 0 .25cqw .25cqw; transform: rotate(45deg); }
.scene.is-cover .shelf { display: flex; }
.shelf:active { transform: rotate(-1.4deg) translateY(.2cqw); }
.shelf:focus-visible { outline: .32cqw solid var(--peach); outline-offset: .4cqw; }

/* 図鑑 */
.zukan { position: absolute; inset: 0; z-index: 5; background: var(--indigo); display: none; flex-direction: column; padding: 2.4cqw 3cqw 2cqw; color: var(--paper); }
.zukan.open { display: flex; }
.zukan::before { content: ""; position: absolute; inset: 0; background: var(--grain); filter: grayscale(1); mix-blend-mode: soft-light; opacity: .22; pointer-events: none; }
.zukan header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2cqw; position: relative; }
.zukan h2 { margin: 0; font-size: 3cqw; letter-spacing: .14em; }
.zukan .close { --tint: var(--tint-paper); color: var(--ink); width: 16cqw; height: max(52px, 6.4cqw); font-size: 2.1cqw; }
.cards { position: relative; flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(var(--rows, 2), 1fr); gap: 2cqw; min-height: 0; }
.card { position: relative; isolation: isolate; display: flex; flex-direction: column; padding: .7cqw .7cqw 0; color: var(--ink); filter: drop-shadow(.2cqw .5cqw .25cqw #0007); min-height: 0; }
.card::before { content: ""; position: absolute; inset: 0; z-index: -1; clip-path: var(--cut); background: linear-gradient(var(--tint-paper), var(--tint-paper)), var(--grain); }
.card:nth-child(odd) { transform: rotate(-.8deg); }
.card:nth-child(even) { transform: rotate(.7deg); }
.card .thumb { flex: 1; min-height: 0; background: #3a4a55 center / cover; display: grid; place-items: center; color: #f5ebd555; font: 700 6cqw Georgia, serif; }
.card p { margin: 0; padding: .9cqw 0 1.1cqw; text-align: center; font-size: 1.75cqw; letter-spacing: .04em; white-space: nowrap; }
.card small { display: block; font-size: 1.2cqw; color: #8a6d4b; letter-spacing: .12em; }
.card.locked p { color: #9a917c; }
.card.sec.locked .thumb { background-color: #4d4330; }

@media (orientation: portrait) {
  main { width: 100%; height: 96svh; }
  .masthead { height: 11cqw; }
  .home { font-size: 4.4cqw; } .peach, .kame { width: 6cqw; height: 5.6cqw; }
  .catalog { font-size: 3.2cqw; } .count { font-size: 3.4cqw; }
  .sheet { height: 62cqw; padding: 6cqw 5cqw 4cqw; }
  .mode { inset: 6cqw 5cqw 4cqw; }
  .m-text { flex-direction: column; align-items: stretch; }
  .story { font-size: 4.5cqw; white-space: pre-wrap; }
  .next { width: auto; height: 13cqw; font-size: 4.4cqw; }
  .question { font-size: 4.8cqw; }
  .buttons { gap: 4cqw; } .opt { font-size: 6cqw; }
  .m-end { flex-direction: column; }
  .end-title small { font-size: 3.2cqw; } .end-title b { font-size: 6.4cqw; } .end-title span { font-size: 3cqw; }
  .end-btns { width: 100%; flex-direction: row; } .end-btns .paper-btn { flex: 1; height: 12cqw; font-size: 3.6cqw; }
  .cover-title small { font-size: 3.2cqw; } .cover-title b { font-size: 11cqw; } .cover-title em { font-size: 3.5cqw; }
  .m-cover { flex-direction: column; gap: 4cqw; }
  .m-cover .paper-btn { width: 80cqw; height: 16cqw; font-size: 5.4cqw; }
  .cards { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(var(--rows-portrait, 4), 1fr); gap: 3cqw; }
  .zukan h2 { font-size: 5.4cqw; } .zukan .close { width: 28cqw; height: 11cqw; font-size: 3.8cqw; }
  .card p { font-size: 3.2cqw; } .card small { font-size: 2.3cqw; }
  .shelf { top: auto; bottom: 2.4%; font-size: 3cqw; padding: .8cqw 2.6cqw 1cqw 2cqw; } /* 縦では題字の札とぶつかるので下へ */ .shelf::after { width: 1.4cqw; height: 1.4cqw; margin-right: 1.4cqw; border-width: 0 0 .5cqw .5cqw; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
