/* /css/tome.css */

/* Blackletter face for the tome's pages (served as-is; license forbids modifying the file) */
@font-face{
  font-family: "Schwabacher";
  src: url("/fonts/Schwabacher.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

.tome-main{ padding: 40px 16px 70px; }
.tome-stage{ max-width: 1200px; margin: 0 auto; text-align:center; }

.tome-scene{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap: 14px;
}

.tome-book{
  width: min(980px, 96vw);
  height: min(560px, 72vh);
  position: relative;
  perspective: 2200px;
}

.tome-side{
  position:absolute;
  top: 6%;
  bottom: 6%;
  width: 48%;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  outline:none;
}
.tome-left{ left: 2.5%; }
.tome-right{ right: 2.5%; }

/* Spine */
.tome-spine{
  position:absolute;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 92%;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(0,0,0,0.25), rgba(0,0,0,0.06), rgba(0,0,0,0.25));
  opacity: 0.55;
}

/* Page stacks (edges) */
.tome-stack{
  position:absolute;
  inset: 0;
  border-radius: 16px;
  overflow:hidden;
  box-shadow: 0 18px 36px rgba(0,0,0,0.14);
}
.tome-stack::before{
  content:"";
  position:absolute;
  inset:0;
  border-radius: 16px;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(42,31,20,0.05) 0px,
      rgba(42,31,20,0.05) 1px,
      rgba(244,241,234,0.0) 5px,
      rgba(244,241,234,0.0) 9px
    ),
    linear-gradient(180deg, #f2e6cf, #d6c6a7);
  filter: saturate(0.9);
  opacity: 0.95;
  box-shadow: inset 0 0 0 1px rgba(42,31,20,0.18);
}

/* Dark inner shadow near spine */
.tome-left .tome-stack::after,
.tome-right .tome-stack::after{
  content:"";
  position:absolute;
  top:0; bottom:0;
  width: 22px;
  opacity: 0.35;
}
.tome-left .tome-stack::after{
  right: 0;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,0.35));
}
.tome-right .tome-stack::after{
  left: 0;
  background: linear-gradient(90deg, rgba(0,0,0,0.35), transparent);
}

/* Visible page surfaces (parchment) */
.tome-surface{
  position:absolute;
  inset:0;
  border-radius: 16px;
  overflow:hidden;
  opacity: 0;
  transform: translateZ(30px);
  pointer-events:none;
  transition: opacity 250ms ease;
}

/* Medieval parchment */
.tome-parchment{
  height:100%;
  border-radius: 16px;
  position:relative;
  background:
    radial-gradient(circle at 18% 22%, rgba(120,90,40,0.08), transparent 40%),
    radial-gradient(circle at 75% 70%, rgba(120,90,40,0.06), transparent 45%),
    radial-gradient(circle at 40% 80%, rgba(90,60,20,0.05), transparent 50%),
    radial-gradient(circle at 50% 50%, transparent 60%, rgba(90,60,20,0.10) 100%),
    linear-gradient(180deg, #f3e6c8, #e6d2a8);
  box-shadow:
    0 18px 36px rgba(0,0,0,0.18),
    inset 0 0 0 1px rgba(60,40,20,0.18),
    inset 0 0 40px rgba(90,60,20,0.08);
}
.tome-parchment::after{
  content:"";
  position:absolute;
  inset:0;
  border-radius: 16px;
  pointer-events:none;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(90,60,20,0.015) 0px,
      rgba(90,60,20,0.015) 1px,
      transparent 3px,
      transparent 6px
    );
  opacity:0.35;
}
.tome-parchment::before{
  content:"";
  position:absolute;
  inset:0;
  border-radius:16px;
  pointer-events:none;
  background:
    radial-gradient(circle at 0% 50%, rgba(60,30,10,0.12), transparent 40%),
    radial-gradient(circle at 100% 50%, rgba(60,30,10,0.12), transparent 40%);
  opacity:0.35;
}

.tome-ink{
  position:absolute;
  inset: 28px 28px;
  text-align:left;
  color:#2a1f14;
  display:flex;
  flex-direction:column;
}

/* Title takes only what it needs */
.tome-page-title{
  flex: 0 0 auto;
  margin:0 0 14px;
}

/* Text gets the remaining height */
.tome-type{
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  white-space: pre-wrap;

  /* prevent span-built typing from overflowing */
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* typed characters behave like normal text */
.ink-char{
  display: inline;
  white-space: pre-wrap;

  opacity: 0;
  color: rgba(42,31,20,0.65);
  animation: inkDry 420ms ease-out forwards;
}
@keyframes inkDry{
  0%{ opacity: 0; color: rgba(42,31,20,0.55); filter: blur(0.6px); }
  40%{ opacity: 0.85; color: rgba(42,31,20,0.85); filter: blur(0.2px); }
  100%{ opacity: 1; color: rgba(42,31,20,0.95); filter: blur(0px); }
}

/* Ink dot */
.tome-type.is-typing::after{
  content:"";
  display:inline-block;
  width: 5px;
  height: 5px;
  margin-left: 3px;
  border-radius: 999px;
  background: rgba(42,31,20,0.35);
  filter: blur(0.2px);
  transform: translateY(-1px);
  animation: inkDot 700ms ease-in-out infinite;
}
@keyframes inkDot{
  0%,100%{ opacity: 0.15; transform: translateY(-1px) scale(0.95); }
  50%{ opacity: 0.45; transform: translateY(-1px) scale(1.05); }
}

/* --- Section sigil (IN FLOW under text) --- */
.tome-sigil-wrap{
  margin-top: 14px;
  display:flex;
  justify-content:flex-end;
  align-items:flex-end;
  pointer-events:none;

  /* reveal animation clips only the image, not the whole page */
  overflow:hidden;
}

.tome-sigil{
  width: min(150px, 50%);
  height: auto;
  max-width: 100%;
  opacity: 0;
  transform: translateY(6px) scale(0.995);
  filter: saturate(0.95) contrast(1.05) blur(0.25px);
  clip-path: inset(0 100% 0 0);
}

.tome-sigil.is-visible{
  opacity: 1;
  transform: translateY(0) scale(1);
  clip-path: inset(0 0 0 0);
}
.tome-sigil.is-writing{
  animation: sigilWrite 950ms cubic-bezier(.2,.9,.2,1) forwards;
}
@keyframes sigilWrite{
  0%{
    opacity: 0;
    clip-path: inset(0 100% 0 0);
    transform: translateY(6px) scale(0.995);
    filter: blur(0.9px) saturate(0.9) contrast(1.05);
  }
  55%{ opacity: 1; filter: blur(0.35px) saturate(0.95) contrast(1.05); }
  100%{
    opacity: 1;
    clip-path: inset(0 0 0 0);
    transform: translateY(0) scale(1);
    filter: blur(0.25px) saturate(0.95) contrast(1.05);
  }
}
@media (prefers-reduced-motion: reduce){
  .tome-sigil.is-writing{ animation: none !important; }
  .tome-sigil{
    opacity: 1;
    clip-path: inset(0 0 0 0);
    transform: none;
    filter: none;
  }
}

/* Flip overlay */
.tome-flip{
  position:absolute;
  inset:0;
  border-radius: 16px;
  transform-style: preserve-3d;
  transform-origin: left center;
  opacity: 0;
  pointer-events:none;
}
.tome-flip-front, .tome-flip-back{
  position:absolute; inset:0;
  border-radius:16px;
  backface-visibility:hidden;
  background:
    radial-gradient(circle at 20% 10%, rgba(0,0,0,0.06), transparent 40%),
    linear-gradient(180deg, #f7edd7, #ecd9b9);
  box-shadow:
    0 18px 36px rgba(0,0,0,0.18),
    inset 0 0 0 1px rgba(42,31,20,0.18);
}
.tome-flip-back{ transform: rotateY(180deg); }

.tome-book.is-flipping .tome-flip{
  opacity: 1;
  animation: flipForward 520ms cubic-bezier(.2,.9,.2,1) forwards;
}
@keyframes flipForward{
  from{ transform: translateZ(40px) rotateY(0deg); }
  to{ transform: translateZ(40px) rotateY(-180deg); }
}

/* Controls */
.tome-controls{
  display:flex;
  gap: 10px;
  align-items:center;
  justify-content:center;
}
.tome-btn{
  background:#2a1f14;
  color:#f4f1ea;
  border:1px solid rgba(244,241,234,0.20);
  border-radius: 10px;
  padding: 10px 12px;
  font-weight:bold;
  letter-spacing:0.5px;
}
.tome-btn:hover{ background:#332619; }
.tome-btn:disabled{ opacity: 0.45; cursor:not-allowed; }
.tome-help{ color:#5c4631; font-size: 0.95em; }

/* Pager */
.tome-pager{
  display:flex;
  align-items:center;
  gap: 10px;
  background: rgba(244,241,234,0.85);
  color:#2a1f14;
  border: 1px solid rgba(42,31,20,0.18);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight:bold;
  letter-spacing:0.4px;
}
.tome-pager-label{ color:#5c4631; font-weight:700; }
.tome-pager-input{
  width: 80px;
  border-radius: 10px;
  border: 1px solid rgba(42,31,20,0.22);
  padding: 6px 8px;
  background: #fffaf0;
  color:#2a1f14;
  font-weight: 700;
}
.tome-pager-input:focus{
  outline: none;
  box-shadow: 0 0 0 2px rgba(139,46,46,0.18);
  border-color: rgba(139,46,46,0.35);
}
.tome-pager-go{ padding: 8px 12px; border-radius: 999px; }

/* COVER (front) */
.tome-cover{
  position:absolute;
  inset:0;
  border-radius: 16px;
  overflow:hidden;
  transform: translateZ(40px);
  opacity: 0;
  pointer-events:none;
}
.tome-cover-face{
  width:100%;
  height:100%;
  border-radius:16px;
  position:relative;
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,0.10), transparent 40%),
    radial-gradient(circle at 80% 20%, rgba(255,255,255,0.06), transparent 45%),
    linear-gradient(145deg, #5b1c1c, #2d0d0d);
  box-shadow:
    0 18px 42px rgba(0,0,0,0.38),
    inset 0 0 0 2px rgba(244,241,234,0.14);
}
.tome-cover-glint{
  position:absolute;
  inset:-40% -30%;
  transform: rotate(20deg);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.14), transparent);
  opacity: 0.0;
  transition: opacity 400ms ease;
}
.tome-right:hover .tome-cover-glint{ opacity: 0.55; }

.tome-cover-emblem{
  position:absolute;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 120px;
  border-radius: 999px;
  border: 2px solid rgba(230,197,122,0.75);
  box-shadow: 0 0 0 8px rgba(0,0,0,0.10) inset;
  display:flex;
  align-items:center;
  justify-content:center;
  color:#e6c57a;
  font-size: 34px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.35);
}
.tome-cover-title{
  position:absolute;
  bottom: 14%;
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  color:#e6c57a;
  letter-spacing: 4px;
  text-transform: uppercase;
  text-shadow: 0 3px 12px rgba(0,0,0,0.40);
  text-align:center;
}
.tome-cover-title .top{ font-size: 22px; opacity: 0.9; }
.tome-cover-title .mid{ font-size: 58px; line-height: 1.05; }
.tome-cover-title .sub{ font-size: 14px; opacity: 0.9; }

/* Inside cover (front) */
.tome-insidecover{
  position:absolute;
  inset:0;
  border-radius: 16px;
  overflow:hidden;
  transform: translateZ(30px);
  opacity: 0;
  pointer-events:none;
}
.tome-inside-leather{
  position:absolute;
  inset:0;
  border-radius:16px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,0.05), transparent 45%),
    radial-gradient(circle at 80% 70%, rgba(0,0,0,0.18), transparent 45%),
    linear-gradient(145deg, #3a2216, #24150d);
  box-shadow:
    0 18px 36px rgba(0,0,0,0.18),
    inset 0 0 0 1px rgba(244,241,234,0.10);
}

/* Back cover + inside back cover */
.tome-backcover{
  position:absolute;
  inset:0;
  border-radius: 16px;
  overflow:hidden;
  transform: translateZ(40px);
  opacity: 0;
  pointer-events:none;
}
.tome-backcover-face{
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,0.08), transparent 40%),
    radial-gradient(circle at 80% 20%, rgba(255,255,255,0.05), transparent 45%),
    linear-gradient(145deg, #4a1515, #240909);
}
.tome-backinside{
  position:absolute;
  inset:0;
  border-radius: 16px;
  overflow:hidden;
  transform: translateZ(30px);
  opacity: 0;
  pointer-events:none;
}

/* --------------------------
   STATE SYSTEM
   -------------------------- */

.tome-book[data-state="closed"] .tome-left{ opacity: 0; pointer-events:none; }
.tome-book[data-state="closed"] .tome-right{ opacity: 1; pointer-events:auto; }
.tome-book[data-state="closed"] .tome-cover{ opacity: 1; pointer-events:auto; }
.tome-book[data-state="closed"] .tome-right .tome-surface{ opacity: 0; }

.tome-book[data-state="open-coverflipped"] .tome-left{ opacity: 1; pointer-events:auto; }
.tome-book[data-state="open-coverflipped"] .tome-right{ opacity: 1; pointer-events:auto; }
.tome-book[data-state="open-coverflipped"] .tome-cover{ opacity: 0; pointer-events:none; }
.tome-book[data-state="open-coverflipped"] .tome-left .tome-insidecover{ opacity: 1; }
.tome-book[data-state="open-coverflipped"] .tome-left .tome-surface{ opacity: 0; }
.tome-book[data-state="open-coverflipped"] .tome-right .tome-surface{ opacity: 1; }

.tome-book[data-state="open"] .tome-left{ opacity: 1; pointer-events:auto; }
.tome-book[data-state="open"] .tome-right{ opacity: 1; pointer-events:auto; }
.tome-book[data-state="open"] .tome-cover{ opacity: 0; pointer-events:none; }
.tome-book[data-state="open"] .tome-left .tome-insidecover{ opacity: 0; }
.tome-book[data-state="open"] .tome-left .tome-surface{ opacity: 1; }
.tome-book[data-state="open"] .tome-right .tome-surface{ opacity: 1; }

.tome-book[data-state="open-backinside"] .tome-left{ opacity: 1; pointer-events:auto; }
.tome-book[data-state="open-backinside"] .tome-right{ opacity: 1; pointer-events:auto; }
.tome-book[data-state="open-backinside"] .tome-left .tome-surface{ opacity: 1; }
.tome-book[data-state="open-backinside"] .tome-right .tome-surface{ opacity: 0; }
.tome-book[data-state="open-backinside"] .tome-right .tome-backinside{ opacity: 1; }

.tome-book[data-state="closed-back"] .tome-right{ opacity: 0; pointer-events:none; }
.tome-book[data-state="closed-back"] .tome-left{ opacity: 1; pointer-events:auto; }
.tome-book[data-state="closed-back"] .tome-left .tome-surface{ opacity: 0; }
.tome-book[data-state="closed-back"] .tome-left .tome-insidecover{ opacity: 0; }
.tome-book[data-state="closed-back"] .tome-left .tome-backcover{ opacity: 1; pointer-events:auto; }

@media (max-width: 820px){
  .tome-ink{ inset: 20px 18px; }
  .tome-type{ font-size: 15px; }
}

.tome-toggle {
  min-width: 180px;
  text-align: center;
}

.tome-toggle[aria-pressed="true"] {
  box-shadow: 0 0 10px rgba(120, 90, 40, 0.25);
}

.tome-toggle i {
  margin-right: 6px;
}

.tome-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tome-controls-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.tome-controls-secondary {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Optional: make it feel like a "mode toggle" */
.tome-toggle {
  min-width: 200px;
  text-align: center;
}

/* Font mode: blackletter (default). Class lives on <body> so the
   hidden pagination measurer gets the same font and size. */
.tome-font-blackletter .tome-page-title,
.tome-font-blackletter .tome-type{
  font-family: "Schwabacher", serif;
}
.tome-font-blackletter .tome-type{
  font-size: 1.15em;
  line-height: 1.45;
}
@media (max-width: 820px){
  .tome-font-blackletter .tome-type{ font-size: 16px; }
}
