body[data-world^="terem-"] {
  --base:#2e1e19; --accent:#efc391; --dark:#42271e; --panel:#4c3228; --line:#a5815f;
}
body[data-world^="terem-"] #toolbar {
  min-height:58px; gap:8px; background:linear-gradient(#4c3527,#33251d);
  border-bottom:1px solid #d0a86f59; box-shadow:0 4px 12px #23160f4d;
}
body[data-world^="terem-"] .toolbar .tool { background:#4b3429; border-color:#a7875c8c; color:#f5dcad; }
body[data-world^="terem-"] .toolbar :is(.tool,.story-progress):hover { background:#634737; }
.terem-editions { display:grid; gap:8px; }
.terem-edition {
  display:grid; gap:4px; padding:12px 14px; text-align:left;
  color:#fff0d8; background:#39271e; border:1px solid #b4956a7a; border-radius:5px;
}
.terem-edition[aria-pressed="true"] { border-color:#f1c784; background:#694b36; }
.terem-edition strong { color:#ffdda8; font-size:.93rem; }
.terem-edition small { font-size:.76rem; color:#fff0cf; }
.terem-edition span { font-size:.75rem; line-height:1.45; color:#eddbbf; }

.physical-book[data-binding] {
  --stage-box:5% 4% auto 40%; --stage-height:min(67%,35cqw);
  --copy-left:7%; --copy-top:13%; --copy-width:28%;
  --fold-warmth:#78472c38; --fold-highlight:#ffe6b74f; --fold-width:8%;
  --edge-paper:#d4a574; --edge-line:#f6d7a3;
}
.physical-book[data-binding="2"] {
  --fold-warmth:#68402e69; --fold-highlight:#ffe8ba7d; --fold-width:12%;
  --edge-paper:#c79163; --edge-line:#f4d5a7;
}
.physical-book[data-binding="3"] {
  --fold-warmth:#67423255; --fold-highlight:#fff3d384; --fold-width:17%;
  --edge-paper:#e0b783; --edge-line:#a6754d;
}
.physical-book[data-binding] .book-sheets {
  inset:0 -2px -8px; background:linear-gradient(#e8bd90,#bf8d64);
}
.physical-book[data-binding] .book-casing { inset:-3px -6px -17px; }
.physical-book[data-binding] .book-gutter { display:none; }
.physical-book[data-binding] :is([data-leaf="left"],[data-leaf="right"]) .book-paper::after { background:none; }
.physical-book[data-binding] .story-sheet-content::after {
  content:""; position:absolute; z-index:1; inset:0; pointer-events:none;
  background:linear-gradient(90deg,transparent calc(50% - var(--fold-width)),
    var(--fold-highlight) 46%,var(--fold-warmth) 49.96%,var(--fold-warmth) 50.04%,
    #c590602c 52.5%,transparent calc(50% + var(--fold-width)));
  mask-image:linear-gradient(180deg,#000a,#000 18% 85%,#000e);
}
.physical-book[data-binding] .paper-landscape { background-position:center bottom; }
.physical-book[data-binding] .story-picture::before {
  content:""; position:absolute; z-index:0; pointer-events:none; inset:57% -3% -5% -5%;
  background:radial-gradient(ellipse at 51% 72%,#88603c59 0%,#9f775f36 34%,transparent 71%);
}
.physical-book[data-binding] .story-picture .story-plane { filter:none; }
.physical-book[data-binding] .story-plane:not([data-plane="action"]) img {
  mask-image:linear-gradient(90deg,transparent 0%,#000 8% 92%,transparent 100%),
    linear-gradient(180deg,#000 0 75%,#000b 90%,transparent 100%);
  mask-composite:intersect;
}
.physical-book[data-binding] .story-sheet-content:not([data-story-day="4"],[data-story-day="5"]) [data-plane="action"] img {
  mask-image:linear-gradient(90deg,transparent,#000 5% 95%,transparent),
    linear-gradient(180deg,#000 0 79%,#000c 90%,transparent 100%);
  mask-composite:intersect;
}
.physical-book[data-binding] .story-sheet-content:is([data-story-day="4"],[data-story-day="5"]) .story-plane[data-plane="action"] {
  filter:drop-shadow(0 4px 3px #45271943);
}
.physical-book[data-binding] .story-picture .story-plinth {
  filter:brightness(.88) saturate(.94) drop-shadow(0 5px 2px #4f321e58);
}
.story-layer-set { display:contents; }
.physical-book[data-binding] [data-relief] .story-picture [data-plane="action"] img {
  object-position:center bottom; clip-path:none; mask-image:none; filter:none;
}
.physical-book[data-binding] [data-relief] .story-picture .story-plane[data-plane="action"] {
  inset:1% 5% 5%; filter:drop-shadow(0 3px 2px #45271948);
}
.physical-book[data-binding] [data-relief][data-story-day="5"] .story-picture .story-plane[data-plane="action"] { inset:0 5% 2%; }
.physical-book[data-binding] [data-relief]:not([data-story-day="4"]) .story-picture [data-plane="ground"] img { filter:saturate(.62) sepia(.24); }
.physical-book[data-binding] [data-relief][data-story-day="7"] .story-picture .story-plane[data-plane="horizon"] { inset:1% 4% 4%; }
.terem-head-edge,.terem-fore-edge { position:absolute; z-index:7; pointer-events:none; width:100%; overflow:visible; }
.terem-head-edge { inset:0 0 auto; height:15px; }
.terem-head-shadow { fill:#b4865f; }
.terem-head-line { fill:none; stroke:#ffe8ba; stroke-width:.9; opacity:.83; }
.terem-fore-edge { inset:auto 0 -11px; height:24px; }
.terem-edge-block { fill:var(--edge-paper); }
.terem-edge-line { fill:none; stroke:var(--edge-line); stroke-width:1; opacity:.56; }
.physical-book[data-binding="3"] .terem-edge-line { opacity:.28; }
.physical-book[data-binding] .terem-blizzard { isolation:isolate; overflow:hidden; border-radius:13px; }
.terem-snow-print { position:absolute; inset:0; width:100%; height:100%; object-fit:cover; object-position:center; }
.terem-snow-drift {
  position:absolute; inset:-17%; opacity:.3;
  background:radial-gradient(ellipse at 22% 74%,#fff8e7b8,transparent 32%),
    radial-gradient(ellipse at 75% 32%,#f3faffb9,transparent 34%);
  animation:terem-wind 8s ease-in-out infinite alternate;
}
.region[data-active="false"] .terem-snow-drift { animation-play-state:paused; }
.terem-snow-caption {
  position:absolute; z-index:2; inset:35% 8% auto; text-align:center; color:#372f2a;
  padding:18px 8px; background:radial-gradient(ellipse,#fff3dbd6,transparent 68%);
}
.terem-snow-caption h2 { font:400 clamp(2rem,6cqw,4.6rem)/1.02 Oranienbaum,Georgia,serif; }
.terem-snow-caption p { margin-top:10px; font-size:clamp(.9rem,1.5cqw,1.13rem); }
@keyframes terem-wind {
  from { transform:translate(-8%,5%) skewX(-6deg); }
  to { transform:translate(8%,-5%) skewX(5deg); }
}
@media (prefers-reduced-motion: reduce) { .terem-snow-drift { animation:none; } }


.stage[data-paper-index][data-binding]:where(:not([data-binding=""])) {
  --bookmark-row:62px;
  --book-foot:calc(var(--dock-safe,84px) + var(--bookmark-row) - 10px);
}
.stage[data-paper-index][data-binding]:where(:not([data-binding=""])) #paper-contents {
  min-height:var(--bookmark-row); align-items:start; overflow:visible; background:none;
  inset-inline:max(calc(var(--edge) + 21px),calc((100cqw - 720px)/2)); gap:12px;
}
.stage[data-paper-index][data-binding]:where(:not([data-binding=""])) .region-tab:focus-visible {
  outline-offset:2px; outline-color:#ffe6b9;
}
.stage[data-paper-index][data-binding="1"] .region-tab {
  min-height:calc(48px + var(--bookmark-order,0) * 4px); align-content:center;
  isolation:isolate; background:none; box-shadow:none; border:0; padding:6px 4px 9px;
}
.stage[data-binding="1"] .region-tab::before {
  content:""; position:absolute; z-index:-1; inset:0; pointer-events:none;
  clip-path:polygon(0 0,100% 0,97% 100%,50% 85%,3% 100%);
  background:linear-gradient(#3020179c,transparent 14px),
    repeating-linear-gradient(105deg,#eedbaf24 0 1px,transparent 1px 3px),
    repeating-linear-gradient(0deg,#24191548 0 1px,transparent 1px 3px),var(--cloth);
  border-inline:1px dashed #f8d4a85e;
}
.stage[data-binding="1"] .region-tab[aria-current="true"]::before {
  background:linear-gradient(#7b4c345d,transparent 12px),repeating-linear-gradient(105deg,#fff2ce73 0 1px,transparent 1px 3px),#e2af75;
}
.stage[data-binding="1"] .region-tab[data-go="0"] { --cloth:#80453d; }
.stage[data-binding="1"] .region-tab[data-go="1"] { --cloth:#665139; }
.stage[data-binding="1"] .region-tab[data-go="2"] { --cloth:#425e57; }
.stage[data-binding="1"] .region-tab[data-go="3"] { --cloth:#593e45; }
.stage[data-binding="1"] .region-tab:hover::before { filter:brightness(1.14); }
.stage[data-binding="1"] .region-tab[aria-current="true"] { background:none; }

.stage[data-paper-index][data-binding="2"] #paper-contents {
  gap:3px; inset-inline:max(calc(var(--edge) + 19px),calc((100cqw - 560px)/2));
}
.stage[data-paper-index][data-binding="2"] .region-tab {
  --thumb-rim:#b28154; background:none; border:0; box-shadow:none; padding:3px 2px 6px;
  min-height:51px; align-content:center; isolation:isolate; color:#49311f;
}
.stage[data-binding="2"] .region-tab::before {
  content:""; position:absolute; inset:0 1px 1px; z-index:-1; pointer-events:none;
  border-radius:50% 50% 14% 14% / 64% 64% 18% 18%;
  background:linear-gradient(180deg,#e8c496 0,#f5d9ad 24%,#d0a071);
  border:1px solid var(--thumb-rim); box-shadow:inset 0 4px 5px #794c343d,0 4px 6px #20120d6b;
}
.stage[data-paper-index][data-binding="2"] .region-tab[aria-current="true"] { --thumb-rim:#dc9b55; background:none; }
.stage[data-binding="2"] .region-tab[aria-current="true"]::before {
  background:radial-gradient(ellipse at 42% 40%,#ffe8b9,#e2aa68); box-shadow:inset 0 3px 5px #6e462454,0 3px 6px #20120d6b;
}
.stage[data-paper-index][data-binding="2"] .region-tab .thumb-number {
  color:#73452d; font:400 1.13rem/1 Oranienbaum,Georgia,serif;
}
.stage[data-paper-index][data-binding="2"] #paper-contents .region-long { display:none; }
.stage[data-paper-index][data-binding="2"] #paper-contents .region-short { display:block; }
.stage[data-binding="2"] .region-tab small { display:none; }

.stage[data-paper-index][data-binding="3"] #paper-contents {
  display:block; min-height:0; width:min(292px,calc(100% - 34px)); inset-inline:0; margin-inline:auto;
}
.terem-index { position:relative; }
.terem-index summary {
  position:relative; min-height:50px; display:flex; align-items:center; justify-content:space-between;
  gap:14px; padding:6px 13px 7px 17px; cursor:pointer; list-style:none; color:#fff0d7;
  border:1px solid #ac7559; border-radius:0 3px 11px 11px;
  background:linear-gradient(#482d25,#6a483f 27%,#4c332a);
  box-shadow:inset 0 5px 6px #2e1a17bc,0 5px 9px #21130f92;
}
.terem-index summary::-webkit-details-marker { display:none; }
.terem-index summary::before {
  content:""; position:absolute; inset:3px auto 3px 5px; width:1px;
  background:repeating-linear-gradient(#e1b283 0 2px,transparent 2px 5px);
}
.terem-index summary small { display:block; color:#ecc69b; font-size:.64rem; line-height:1.25; }
.terem-index summary strong { font:400 1.16rem/1.1 Oranienbaum,Georgia,serif; }
.terem-index summary .icon { width:19px; transform:rotate(-90deg); }
.terem-index[open] summary .icon { transform:rotate(90deg); }
.terem-index summary:focus-visible { outline:2px solid #ffe2a7; outline-offset:2px; }
.terem-index-list {
  position:absolute; z-index:1; inset:auto 0 calc(100% + 7px); display:grid; padding:6px 9px;
  background:linear-gradient(145deg,#fae6be,#e8c699); border:1px solid #925f44; border-radius:8px;
  box-shadow:0 8px 22px #28170cb0;
}
.terem-index:not([open]) .terem-index-list { display:none; }
.stage[data-paper-index][data-binding="3"] .terem-index-list .region-tab {
  min-height:44px; display:flex; justify-content:space-between; align-items:center; text-align:left; width:100%;
  padding:5px 8px; gap:12px; color:#4c3121; background:transparent; box-shadow:none; border:0; border-radius:4px;
  border-bottom:1px solid #855b3936;
}
.stage[data-paper-index][data-binding="3"] .terem-index-list .region-tab[aria-current="true"],
.stage[data-paper-index][data-binding="3"] .terem-index-list .region-tab:hover { background:#d5ac7d; }
.stage[data-paper-index][data-binding="3"] .terem-index-list .region-tab:focus-visible { outline-color:#6c4530; outline-offset:-2px; }
.stage[data-paper-index][data-binding="3"] #paper-contents .terem-index-list .region-long { display:block; }
.stage[data-paper-index][data-binding="3"] #paper-contents .terem-index-list .region-short { display:none; }

@container game (min-width:1040px) {
  .stage[data-paper-index][data-binding="2"] #paper-contents {
    inset:clamp(130px,22cqh,228px) max(3px,calc(var(--edge) - 56px)) auto auto;
    width:clamp(48px,4.35cqw,65px); min-height:0;
    grid-template-columns:1fr; gap:8px;
  }
  .stage[data-paper-index][data-binding="2"] .region-tab {
    min-height:54px; padding:3px 2px 4px 5px; transform:translateX(calc(var(--bookmark-order,0) * 1px));
  }
  .stage[data-binding="2"] .region-tab::before {
    inset:0 2px 0 -3px; border-radius:4px 50% 50% 4px / 12px 29px 29px 12px;
    background:linear-gradient(90deg,#a97450,#f3d6a8 25%,#e2b881);
    box-shadow:inset 4px 0 6px #57352565,2px 4px 6px #25170f74;
  }
}

.terem-turn-sheet { position:absolute; transform-style:preserve-3d; }
.terem-turn-sheet .book-turn-face { inset:0; }
.terem-turn-sheet .book-turn-side::after {
  z-index:9;
  background:linear-gradient(var(--fold-angle),transparent 24%,#653b24 var(--fold-shadow),#fff0c4 96%);
  opacity:var(--crease-light);
}
.terem-turn-sheet .book-turn-back::after {
  background:linear-gradient(calc(var(--fold-angle) + 180deg),transparent 25%,#674531 var(--fold-shadow),#fff1d1 96%);
}
.book-turn[data-style^="terem-"] .book-turn-shadow { filter:blur(16px); }
.book-turn[data-style^="terem-"] .terem-snow-drift { animation:none; }
.terem-fold-front,.terem-fold-flap { position:absolute; }
.terem-fold-flap { transform-origin:0 0; filter:drop-shadow(0 8px 9px #27150c65); }
.terem-fold-back,.terem-fold-reverse { position:absolute; inset:0; }
.terem-fold-reverse { transform:scaleX(-1); }
.terem-fold-back::after {
  content:""; position:absolute; z-index:8; inset:0;
  background:linear-gradient(130deg,#69452b85,#ffebc27a 56%,#d4a57075 100%);
  opacity:var(--fold-glow);
}
.terem-calendar-print.board { inset:auto; position:absolute; transform-origin:50% 0; }
.terem-calendar-print :is(.book-casing,.book-sheets,.terem-head-edge,.terem-fore-edge) { display:none; }
.terem-calendar-print :is(.story-plane,.story-plinth) { animation:none!important; }
.terem-calendar-leaf { backface-visibility:hidden; }
.terem-calendar-leaf::after {
  content:""; position:absolute; z-index:8; pointer-events:none; inset:0 0 1.5%; border-radius:14px;
  background:linear-gradient(0deg,#6f44234d,transparent 60%,#fff0bd75);
  opacity:var(--calendar-shade);
}
.stage[data-binding="3"] .map-scroll[data-paginated] { touch-action:pinch-zoom; }

@container game (max-width:700px) {
  .physical-book[data-binding] [data-relief] .story-picture .story-plane[data-plane="action"] { inset-inline:1%; }
  .physical-book[data-binding] [data-relief][data-story-day="5"] .story-picture .story-plane[data-plane="action"] { inset-inline:3%; }
  body[data-world^="terem-"] #toolbar { min-height:54px; padding-inline:8px; }
  .stage[data-paper-index][data-binding]:where(:not([data-binding=""])) { --bookmark-row:57px; }
  .stage[data-paper-index][data-binding]:where(:not([data-binding=""])) #paper-contents { inset-inline:17px; gap:5px; }
  .stage[data-paper-index][data-binding="1"] .region-tab { min-height:calc(46px + var(--bookmark-order,0) * 3px); padding:5px 2px 8px; }
  .stage[data-paper-index][data-binding="2"] .region-tab { min-height:48px; }
  .stage[data-paper-index][data-binding="3"] #paper-contents { inset-inline:0; }
  .physical-book[data-binding] { --stage-box:0% 1.5% auto; --stage-height:min(60%,82cqw); --copy-left:7%; --copy-top:min(62%,86cqw); --copy-width:86%; }
  .physical-book[data-binding] .story-sheet-content::after { display:none; }
  .physical-book[data-binding] .book-casing { inset:-2px -4px -12px; border-radius:9px; }
  .terem-head-edge { display:none; }
  .terem-fore-edge { height:12px; bottom:-9px; }
}
@container game (max-width:700px) and (max-height:600px) {
  .physical-book[data-binding] { --stage-height:53%; --copy-top:55%; }
}
@container game (max-width:355px) {
  body[data-world^="terem-"] .toolbar [data-action="back"] span { display:none; }
}
