/* Public "coffee table" viewer. Applied only when <body> has .folio-stage
   (public book pages). The table, grain, mug and light are drawn in CSS and
   an inline SVG noise filter made for Folio: no third-party images. */
body.folio-stage {
  --wood-a: #5a3a22;
  --wood-b: #3d2616;
  --wood-c: #6e4a2c;
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='600' height='240'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='0.004 0.09' numOctaves='4' seed='7'/><feColorMatrix values='0 0 0 0 0.16  0 0 0 0 0.09  0 0 0 0 0.04  0 0 0 0.55 0'/></filter><rect width='100%25' height='100%25' filter='url(%23g)'/></svg>");
}
body.folio-stage .studio-shell,
.stage-intro {
  background:
    radial-gradient(ellipse 70% 55% at 50% 38%, rgba(255, 214, 160, .20), transparent 70%),
    radial-gradient(ellipse 120% 90% at 50% 50%, transparent 55%, rgba(0, 0, 0, .55)),
    var(--grain),
    repeating-linear-gradient(90deg, rgba(0,0,0,.10) 0 1px, transparent 1px 180px),
    linear-gradient(180deg, var(--wood-c), var(--wood-a) 45%, var(--wood-b));
  background-size: auto, auto, 600px 240px, auto, auto;
}
body.folio-stage .reading-room::before,
body.folio-stage .ambient { display: none; }
body.folio-stage .topbar,
body.folio-stage .reader-bar { background: rgba(20, 12, 7, .42); border-color: rgba(255, 230, 200, .10); }

/* No editing or format options for visitors. */
body.folio-stage .format-rail,
body.folio-stage #uploadButton,
body.folio-stage #fileInput,
body.folio-stage .build-tag,
body.folio-stage .drop-message { display: none !important; }
body.folio-stage .workspace { grid-template-columns: 1fr 72px; }
body.folio-stage .info-dialog li:nth-child(2) { display: none; }
@media (max-width: 920px) { body.folio-stage .workspace { grid-template-columns: 1fr 58px; } }
@media (max-width: 620px) {
  body.folio-stage .workspace { grid-template-columns: minmax(0, 1fr) auto; }
  body.folio-stage .reader-tools { grid-column: 1 / -1; justify-content: center; }
}

/* Reader stays hidden behind the table until the book is opened. */
body.folio-stage.stage-closed .studio-shell { opacity: 0; }
body.folio-stage .studio-shell { transition: opacity .6s ease .15s; }

.stage-intro {
  position: fixed; inset: 0; z-index: 100; overflow: hidden;
  display: grid; place-items: center;
  transition: opacity .7s ease .55s, visibility 0s linear 1.3s;
}
.stage-intro.open { opacity: 0; visibility: hidden; pointer-events: none; }

/* A coffee mug seen from above: round cup, cream rim, and a handle drawn as ONE
   continuous stroked ring whose inner half sits behind the cup body. Because the
   ring is a single element and its left part is always inside the cup circle,
   both arms meet the rim at every size with no gap or seam. */
.stage-mug {
  position: absolute; right: 9%; top: 12%; width: clamp(84px, 12vw, 140px); aspect-ratio: 1;
  isolation: isolate;
}
.stage-mug::before {
  content: ""; position: absolute; inset: 0; z-index: 1; border-radius: 50%;
  background:
    radial-gradient(circle at 40% 36%, rgba(255,235,210,.28), transparent 26%),
    radial-gradient(closest-side, #241309 0 66%, #3e2212 72%, #f1ebe1 75% 92%, #d6ccbd 97%, #bfb3a2 100%);
  box-shadow: 14px 20px 26px rgba(0,0,0,.42), inset 0 0 0 1px rgba(0,0,0,.08);
}
.stage-mug::after {
  content: ""; position: absolute; z-index: 0; left: 70%; top: 31%; width: 46%; height: 38%;
  box-sizing: border-box; border: clamp(7px, 1.1vw, 11px) solid #e9e2d6; border-radius: 50%;
  box-shadow: 10px 12px 14px -6px rgba(0,0,0,.35);
}
.stage-pen {
  position: absolute; left: 6%; top: 18%; width: clamp(120px, 18vw, 220px); height: 9px; border-radius: 5px;
  background: linear-gradient(180deg, #1b1b1d, #3a3a40 45%, #111); transform: rotate(-24deg);
  box-shadow: 8px 14px 14px rgba(0,0,0,.4);
}
.stage-pen::after { content: ""; position: absolute; right: -14px; top: 1px; border-left: 16px solid #c9a96a; border-top: 3.5px solid transparent; border-bottom: 3.5px solid transparent; }

.stage-book {
  position: relative; border: 0; padding: 0; background: none; cursor: pointer;
  width: min(62vw, 360px); aspect-ratio: var(--cover-ratio, .77);
  transform: rotate(-5deg);
  transition: transform 1.1s cubic-bezier(.2, .8, .2, 1);
  animation: stage-breathe 4.5s ease-in-out infinite;
}
@media (min-width: 900px) { .stage-book { width: min(30vw, 420px); } }
.stage-book:focus-visible { outline: 2px solid var(--accent, #d3b98a); outline-offset: 10px; }
.stage-book .cover {
  position: absolute; inset: 0; border-radius: 2px 5px 5px 2px; overflow: hidden;
  background: #222 center / cover no-repeat;
  box-shadow: inset 6px 0 10px -4px rgba(0,0,0,.45), inset -1px 0 0 rgba(255,255,255,.15);
}
.stage-book .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.stage-book .cover .fallback { position: absolute; inset: 0; display: grid; place-items: center; padding: 18%; text-align: center; font: 600 clamp(18px, 3vw, 30px)/1.15 "Playfair Display", serif; color: #f4efe4; background: linear-gradient(150deg, #3b2c22, #17110c); }
.stage-book .cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(115deg, rgba(255,255,255,.22), transparent 35%, transparent 70%, rgba(0,0,0,.18)); }
/* Page block: a thin stack of page edges showing on the right and bottom. */
.stage-book .pages {
  position: absolute; inset: 0; border-radius: 2px 5px 5px 2px;
  background: repeating-linear-gradient(90deg, #efe8da 0 1px, #d8cfbe 1px 2px);
  transform: translate(var(--thick, 6px), var(--thick, 6px));
  box-shadow: 0 0 0 1px rgba(0,0,0,.10);
}
.stage-book .shadow {
  position: absolute; inset: 2% -2% -3% 1%; border-radius: 6px; background: rgba(0,0,0,.5);
  filter: blur(18px); transform: translate(14px, 22px);
}
body[data-theme="magazine"] .stage-book { --thick: 2px; }
body[data-theme="antique"] .stage-book { --thick: 9px; }
@keyframes stage-breathe { 50% { transform: rotate(-5deg) translateY(-1.2%); } }

.stage-intro.opening .stage-book { animation: none; transform: rotate(0deg) scale(1.12); }
.stage-intro.opening .stage-mug,
.stage-intro.opening .stage-pen,
.stage-intro.opening .stage-caption { opacity: 0; transition: opacity .4s ease; }

.stage-caption {
  position: absolute; left: 0; right: 0; bottom: max(28px, env(safe-area-inset-bottom)); text-align: center;
  display: grid; gap: 6px; color: #f6eee2; text-shadow: 0 2px 12px rgba(0,0,0,.6); pointer-events: none;
}
.stage-caption strong { font: 600 clamp(20px, 3.2vw, 30px)/1.1 "Playfair Display", serif; }
.stage-caption span { font: 500 12px/1 "DM Sans", sans-serif; letter-spacing: .2em; text-transform: uppercase; color: #e8cfa2; animation: stage-pulse 2.2s ease-in-out infinite; }
@keyframes stage-pulse { 50% { opacity: .45; } }

/* Locked book: closed book plus the sleek password card on the table. */
.stage-intro.locked { grid-template-columns: auto auto; gap: clamp(24px, 6vw, 90px); align-content: center; justify-content: center; }
.stage-intro.locked .stage-book { cursor: default; width: min(30vw, 380px); }
.stage-gate { position: relative; z-index: 2; }
.stage-gate .book-gate {
  width: min(380px, calc(100vw - 32px));
  background: rgba(20, 12, 7, .72); border-color: rgba(255, 230, 200, .16);
  backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 30px 60px rgba(0,0,0,.45);
}
@media (max-width: 760px) {
  .stage-intro.locked { grid-template-columns: 1fr; justify-items: center; gap: 18px; align-content: start; padding: 64px 0 96px; overflow-y: auto; }
  .stage-intro.locked .stage-book { width: min(46vw, 210px); }
}

@media (prefers-reduced-motion: reduce) {
  .stage-book, .stage-caption span { animation: none; }
  .stage-book, .stage-intro { transition-duration: .01s; transition-delay: 0s; }
}
