/* SHOWROOM FIVE — the binding.
   Register: cold paper, dark room, one raking light from the left.
   Faces: Spectral (display) + Karla (text). Neutral — deliberately not any of the five. */

:root {
  --room: #060709;
  --room-lit: #161A22;
  --paper: #E8E6DF;
  --paper-bright: #F2F0E9;
  --paper-dim: #D7D4CA;
  --paper-deep: #BDBAAF;
  --ink: #1E2126;
  --ink-soft: #4A4F59;
  --label: #4E5A66;        /* cold slate — AA on paper */
  --hairline: #A9AFB9;
  --moon: #A9B0BA;         /* room-side text */
  --well: #0C0E12;
  --ease-turn: cubic-bezier(.30,.58,.28,1);  /* the one ease token — pure ease-out, no overshoot */
  --dur-turn: 950ms;
  --dur-enter: 900ms;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { height: 100%; }

body {
  min-height: 100%;
  background:
    radial-gradient(130% 100% at 6% 18%, var(--room-lit) 0%, #0B0D12 46%, var(--room) 100%);
  color: var(--moon);
  font-family: 'Karla', sans-serif;
  font-size: 16px;
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* the raking light itself — one shaft from the left */
.rake {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: linear-gradient(112deg, rgba(203,213,228,0.15) 0%, rgba(203,213,228,0.05) 28%, transparent 54%);
}

#grain { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; opacity: .05; }

.masthead, main, .colophon { position: relative; z-index: 2; }

/* ---------- masthead ---------- */

.masthead { text-align: center; padding: 14px 20px 0; }

.mast-brand {
  font-size: 11px; letter-spacing: .34em; text-transform: uppercase;
  color: var(--hairline); font-weight: 500;
}
.mast-brand span { color: var(--moon); }

.mast-title {
  font-family: 'Spectral', serif; font-weight: 500; font-style: italic;
  font-size: clamp(26px, 3.2vw, 42px);
  color: #DDE1E8; letter-spacing: .01em; margin-top: 6px;
}

.mast-note { font-size: 13px; color: #7C838F; margin-top: 6px; max-width: 74ch; margin-inline: auto; }

.kbd {
  display: inline-block; min-width: 20px; text-align: center;
  border: 1px solid #3A404B; border-radius: 4px; padding: 0 4px; margin: 0 3px;
  font-size: 11px; color: var(--moon); background: rgba(255,255,255,.03);
}

/* ---------- stage & book ---------- */

.stage { display: flex; flex-direction: column; align-items: center; padding: 36px 16px 14px; }

.book-perspective { perspective: 3200px; perspective-origin: 50% 46%; }

.book {
  position: relative;
  height: min(64vh, 620px);
  aspect-ratio: 1.56;
  max-width: 94vw;
  transform-style: preserve-3d;
}

/* binding boards — the heavy cover under the pages */
.boards {
  position: absolute; inset: -13px -15px -17px -15px; z-index: 0;
  background: linear-gradient(112deg, #1D2028 0%, #14161C 40%, #0F1116 100%);
  border-radius: 4px 10px 10px 4px;
  box-shadow:
    46px 70px 110px rgba(0,0,0,.72),
    14px 24px 44px rgba(0,0,0,.55),
    inset 1px 1px 0 rgba(210,220,235,.10);
}

/* fore-edges — the stacked sheets */
.fore-edge { position: absolute; z-index: 1; pointer-events: none; }
.fore-edge--r {
  top: 5px; bottom: -7px; right: -8px; width: 8px;
  background: repeating-linear-gradient(to bottom, var(--paper-dim) 0 2px, #9C9A90 2px 3px);
  transform: skewY(1.2deg);
  border-radius: 0 2px 2px 0;
}
.fore-edge--b {
  left: 6px; right: -6px; bottom: -8px; height: 8px;
  background: repeating-linear-gradient(to right, var(--paper-dim) 0 3px, #9C9A90 3px 4px);
  transform: skewX(1.2deg);
  border-radius: 0 0 3px 3px;
}

.page {
  position: absolute; top: 0; height: 100%; width: 50%; z-index: 2;
  overflow: hidden;
}

.page--left {
  left: 0;
  background: linear-gradient(112deg, var(--paper-bright) 0%, var(--paper) 58%, #DFDCD3 92%, #D3D0C6 100%);
  border-radius: 3px 0 0 3px;
  padding: clamp(22px, 4.2%, 44px) clamp(24px, 5%, 52px);
}

.page--right {
  right: 0;
  background: linear-gradient(112deg, #CFCCC2 0%, #E2DFD6 9%, var(--paper) 30%, #E1DED5 78%, #D2CFC5 100%);
  border-radius: 0 3px 3px 0;
  display: flex; flex-direction: column;
  padding: clamp(18px, 3.6%, 36px) clamp(20px, 4.2%, 42px);
}

/* gutter shadow at the spine */
.gutter {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 96px;
  transform: translateX(-50%); z-index: 3; pointer-events: none;
  background: linear-gradient(90deg, transparent 0%, rgba(8,10,14,.20) 42%, rgba(8,10,14,.34) 50%, rgba(8,10,14,.16) 58%, transparent 100%);
}

/* index tabs — five paper tabs along the top of the right board (pass-1 upgrade) */
.tabs {
  position: absolute; top: -24px; left: 53%; right: 1.5%; height: 24px; z-index: 1;
  display: flex; gap: 3px; align-items: flex-end;
}
.tab {
  flex: 1; height: 17px; cursor: pointer;
  font-family: 'Karla', sans-serif; font-weight: 700; font-size: 10px;
  letter-spacing: .14em; color: #565B63;
  background: linear-gradient(112deg, #B4B1A6 0%, #9C998F 100%);
  border: 0; border-radius: 3px 3px 0 0;
  padding-bottom: 2px;
  box-shadow: inset 1px 1px 0 rgba(255,255,255,.28), 3px 0 5px rgba(4,5,7,.3);
  transition: height .3s var(--ease-turn), background-color .3s var(--ease-turn);
}
.tab:hover { height: 22px; }
.tab:focus-visible { outline: 2px solid var(--moon); outline-offset: 2px; }
.tab[aria-current="true"] {
  height: 24px; color: var(--ink);
  background: linear-gradient(112deg, var(--paper-bright) 0%, var(--paper-dim) 100%);
}

/* shadow the turning leaf casts on the base pages */
.turn-shade {
  position: absolute; inset: 0; z-index: 4; pointer-events: none; opacity: 0;
  background: linear-gradient(90deg, transparent 30%, rgba(6,8,11,.38) 50%, rgba(6,8,11,.16) 72%, transparent 95%);
}

/* running heads — printed page chrome (pass-2 upgrade) */
.runhead {
  position: absolute; top: 11px;
  font-size: 9px; font-weight: 700; letter-spacing: .26em; text-transform: uppercase;
  color: rgba(30,33,38,.40); pointer-events: none;
}
.runhead--l { left: 22px; }
.runhead--r { right: 22px; text-align: right; }
.card .runhead { display: none; }

/* ---------- left page copy ---------- */

.study { height: 100%; display: flex; flex-direction: column; color: var(--ink); }

.study-no {
  font-size: 11px; letter-spacing: .30em; text-transform: uppercase;
  color: var(--label); font-weight: 700;
}

.study-name {
  font-family: 'Spectral', serif; font-weight: 600;
  font-size: clamp(28px, 3.6vw, 46px); line-height: 1.04;
  color: var(--ink); margin-top: 14px; letter-spacing: -0.01em;
}

.study-register {
  font-family: 'Spectral', serif; font-style: italic; font-weight: 400;
  font-size: clamp(15px, 1.35vw, 18px); line-height: 1.45;
  color: var(--ink-soft); margin-top: 12px; max-width: 34ch;
}

.study-rule { height: 1px; background: linear-gradient(90deg, var(--ink) 0%, rgba(30,33,38,.16) 70%, transparent); margin: clamp(14px, 2.4vh, 26px) 0; }

.tech-label {
  font-size: 10px; letter-spacing: .28em; text-transform: uppercase;
  color: var(--label); font-weight: 700;
}

.study-tech {
  font-size: clamp(13px, 1.15vw, 15px); line-height: 1.6;
  color: var(--ink); margin-top: 9px; max-width: 46ch;
}

.study-foot { margin-top: auto; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }

.step {
  font-family: 'Karla', sans-serif; font-weight: 700; font-size: 12px;
  letter-spacing: .18em; text-transform: uppercase;
  color: var(--paper-bright); background: var(--ink);
  border: 1px solid var(--ink); border-radius: 2px;
  padding: 11px 18px; cursor: pointer;
  transition: background .25s var(--ease-turn), transform .25s var(--ease-turn);
}
.step:hover { background: #2C313A; transform: translateY(-1px); }
.step:focus-visible { outline: 2px solid var(--label); outline-offset: 3px; }

.study-ordinal {
  font-family: 'Spectral', serif; font-weight: 500; font-size: clamp(30px, 3vw, 44px);
  color: rgba(30,33,38,.14); line-height: 1; user-select: none;
}

/* ---------- right page: the cut window ---------- */

.cut {
  position: relative; flex: 1; min-height: 0;
  background: var(--well);
  border-radius: 2px;
  /* recess under a left-raking light: left+top inner walls in shadow, faint catch on the right */
  box-shadow:
    inset 14px 8px 22px -8px rgba(2,3,5,.62),
    inset 3px 2px 4px rgba(2,3,5,.5),
    inset -3px -2px 7px rgba(226,230,238,.07);
}

.cut iframe {
  position: absolute; top: 0; left: 0; border: 0; background: transparent;
  transform-origin: 0 0;
  opacity: 0; transition: opacity .45s var(--ease-turn);
}
.cut iframe.is-lit { opacity: 1; }

/* the incoming study's name, printed in the darkness of the well */
.cut .well-word {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 10px; letter-spacing: .34em; text-transform: uppercase; color: #3B4048;
}

/* the paper lip around the cut — bevel drawn over the frame edge */
.cut-bevel {
  position: absolute; inset: 0; pointer-events: none; border-radius: 2px;
  border: 1px solid rgba(10,12,15,.55);
  box-shadow:
    0 0 0 1px rgba(255,255,255,.5),           /* lit paper lip */
    -2px -1px 0 1px rgba(120,117,108,.35),    /* upper-left lip shading */
    inset 10px 6px 16px -8px rgba(2,3,5,.55);
}

/* the empty well shown on a turning leaf (iframe unloaded) */
.cut--well { display: block; }
.cut--well .well-word {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 10px; letter-spacing: .34em; text-transform: uppercase; color: #3B4048;
}

.plate {
  margin-top: 12px; flex: none;
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-soft); font-weight: 500;
  display: flex; justify-content: space-between; gap: 10px;
  white-space: nowrap; overflow: hidden;
}
.plate b { color: var(--ink); font-weight: 700; letter-spacing: .18em; }
.plate span { overflow: hidden; text-overflow: ellipsis; }

/* ---------- the turning leaf ---------- */

.leaf {
  position: absolute; top: 0; right: 0; width: 50%; height: 100%; z-index: 5;
  transform-origin: left center;
  transform-style: preserve-3d;
  display: none;
}
.leaf.is-live { display: block; }

.leaf-face {
  position: absolute; inset: 0; backface-visibility: hidden; overflow: hidden;
  border-radius: 0 3px 3px 0;
}

.leaf-front {
  background: linear-gradient(112deg, #CFCCC2 0%, #E2DFD6 9%, var(--paper) 30%, #E1DED5 78%, #D2CFC5 100%);
  display: flex; flex-direction: column;
  padding: clamp(18px, 3.6%, 36px) clamp(20px, 4.2%, 42px);
}

.leaf-back {
  transform: rotateY(180deg);
  background: linear-gradient(112deg, var(--paper-bright) 0%, var(--paper) 58%, #DFDCD3 92%, #D3D0C6 100%);
  border-radius: 3px 0 0 3px;
  padding: clamp(22px, 4.2%, 44px) clamp(24px, 5%, 52px);
}

.leaf .curl { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* ---------- corners & folio ---------- */

.corner {
  position: absolute; bottom: -2px; width: 52px; height: 52px; z-index: 6;
  background: transparent; border: 0; cursor: pointer; padding: 0;
}
.corner span {
  position: absolute; inset: 0; display: block;
  transition: transform .3s var(--ease-turn);
}
.corner--next { right: -2px; }
.corner--next span {
  background: linear-gradient(315deg, var(--paper-dim) 50%, transparent 50.5%);
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  filter: drop-shadow(-3px -3px 3px rgba(8,10,13,.28));
}
.corner--prev { left: -2px; }
.corner--prev span {
  background: linear-gradient(45deg, var(--paper-dim) 50%, transparent 50.5%);
  clip-path: polygon(0 0, 100% 100%, 0 100%);
  filter: drop-shadow(3px -3px 3px rgba(8,10,13,.28));
}
.corner:hover span { transform: scale(1.18); }
.corner:focus-visible { outline: 2px solid var(--moon); outline-offset: 2px; }
.corner[disabled] { display: none; }

.folio {
  margin-top: 14px; font-size: 11px; letter-spacing: .3em; text-transform: uppercase;
  color: var(--hairline); text-align: center;
}
.folio b { color: #D6DAE1; font-weight: 700; }

/* ---------- entrance choreography (one curve, one ladder) ---------- */

.masthead, .book-perspective, .folio, .colophon {
  animation: settle var(--dur-enter) var(--ease-turn) both;
}
.book-perspective { animation-delay: .15s; }
.folio { animation-delay: .35s; }
.colophon { animation-delay: .5s; }

@keyframes settle {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* ---------- colophon ---------- */

.colophon { text-align: center; padding: 0 20px 14px; }
.colophon-spine {
  font-family: 'Spectral', serif; font-style: italic; font-size: 15px; color: #8B93A0;
}
.colophon-meta { font-size: 12px; color: #656C78; margin-top: 6px; letter-spacing: .04em; }
.colophon-meta a { color: var(--moon); text-decoration: underline; text-underline-offset: 3px; }
.colophon-meta a:hover { color: #E4E8EE; }
.colophon-meta a:focus-visible { outline: 2px solid var(--moon); outline-offset: 3px; }

.noscript-note { text-align: center; color: var(--moon); padding: 40px 20px; }

/* ---------- step inside ---------- */

.inside { position: fixed; inset: 0; z-index: 50; background: var(--room); }
.inside iframe { width: 100%; height: 100%; border: 0; display: block; background: var(--well); }

.inside-close {
  position: fixed; top: 14px; right: 14px; z-index: 51;
  display: flex; align-items: center; gap: 8px;
  font-family: 'Karla', sans-serif; font-weight: 700; font-size: 12px;
  letter-spacing: .16em; text-transform: uppercase;
  color: #E7EAEF; background: rgba(8,10,13,.82);
  border: 1px solid #3C424D; border-radius: 3px;
  padding: 10px 14px; cursor: pointer;
  backdrop-filter: blur(4px);
}
.inside-close:hover { background: rgba(24,28,35,.92); border-color: #59616E; }
.inside-close:focus-visible { outline: 2px solid #C8CFDA; outline-offset: 3px; }

body.is-inside { overflow: hidden; }

/* ---------- mobile stack (≤820px): the book becomes a card sequence ---------- */

.stack { display: none; }

@media (max-width: 820px) {
  .stage { display: none; }
  .hint-desk { display: none; }

  .stack {
    display: flex; flex-direction: column; gap: 34px;
    padding: 26px 18px 40px; max-width: 560px; margin: 0 auto;
  }

  .card {
    background: linear-gradient(112deg, var(--paper-bright) 0%, var(--paper) 55%, #DCD9D0 100%);
    border-radius: 3px;
    box-shadow: 18px 26px 54px rgba(0,0,0,.6), inset 1px 1px 0 rgba(255,255,255,.5);
    padding: 24px 22px 22px;
    color: var(--ink);
    position: relative;
  }
  /* the card's own board edge */
  .card::before {
    content: ""; position: absolute; inset: -7px -8px -9px -8px; z-index: -1;
    background: linear-gradient(112deg, #1C1F27 0%, #101218 100%);
    border-radius: 5px;
  }

  .card .study-name { font-size: 30px; }
  .card .study-register { font-size: 15px; max-width: none; }
  .card .study-tech { font-size: 13.5px; max-width: none; }
  .card .study-rule { margin: 16px 0; }

  .card-cut {
    position: relative; height: 430px; margin: 18px 0 14px;
    background: var(--well); border-radius: 2px; overflow: hidden;
    box-shadow:
      inset 10px 6px 18px -8px rgba(2,3,5,.6),
      inset -2px -2px 6px rgba(226,230,238,.06),
      0 0 0 1px rgba(255,255,255,.45);
  }
  .card-cut iframe {
    position: absolute; top: 0; left: 0; border: 0; transform-origin: 0 0; background: transparent;
    opacity: 0; transition: opacity .45s var(--ease-turn);
  }
  .card-cut iframe.is-lit { opacity: 1; }
  .card-cut .well-word {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    font-size: 10px; letter-spacing: .3em; text-transform: uppercase; color: #3B4048;
  }

  .card .study-foot { margin-top: 4px; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .masthead, .book-perspective, .folio, .colophon { animation: none; }
  .step, .corner span, .tab, .cut iframe, .card-cut iframe { transition: none; }
  .leaf { display: none !important; }
  .turn-shade { opacity: 0 !important; }
}
