/* ═══════════════════════════════════════════════════════════════
   龙之变 / THE LOONG VARIATIONS
   ═══════════════════════════════════════════════════════════════ */

:root{
  --bg:      #0a0908;
  --bg-lift: #131110;
  --ink:     #e9e3d6;
  --ink-2:   #a49c8d;
  --ink-3:   #6b6459;
  --rule:    rgba(233,227,214,.13);
  --rule-2:  rgba(233,227,214,.07);
  --gold:    #c9a227;

  --serif: "Baskerville","Hoefler Text","Palatino Linotype","Book Antiqua",Georgia,serif;
  --zh:    "Songti SC","STSong","Source Han Serif SC","Noto Serif CJK SC","SimSun",serif;
  --sans:  "Helvetica Neue","Inter",-apple-system,"Segoe UI",Arial,sans-serif;

  --cols: 6;
  --rows: 5;
  --gap:  2px;

  --rail: 340px;      /* right reading column  */
  --foot: 86px;       /* ledger height          */

  /* both written by JS from the measured grid */
  --stage-w: 900px;
  --stage-h: 675px;

  /* cells need not be square: a block only ever turns on ONE axis,
     so its depth only has to match that axis — hence two depths. */
  --tw: calc((var(--stage-w) - (var(--cols) - 1) * var(--gap)) / var(--cols));
  --th: calc((var(--stage-h) - (var(--rows) - 1) * var(--gap)) / var(--rows));
  --dw: calc(var(--tw) / 2);
  --dh: calc(var(--th) / 2);

  --ease: cubic-bezier(.62,.02,.16,1);
}

*,*::before,*::after{ box-sizing:border-box; }

html,body{ height:100%; }

body{
  margin:0;
  background:var(--bg);
  color:var(--ink);
  font-family:var(--serif);
  -webkit-font-smoothing:antialiased;
  overflow-x:hidden;
}

/* ambient light + film grain ------------------------------------ */
body::before{
  content:""; position:fixed; inset:0; pointer-events:none; z-index:1;
  background:
    radial-gradient(120% 90% at 46% 40%, rgba(255,240,214,.055), transparent 62%),
    radial-gradient(140% 120% at 50% 50%, transparent 40%, rgba(0,0,0,.62) 100%);
}
body::after{
  content:""; position:fixed; inset:-50%; pointer-events:none; z-index:2;
  opacity:.17; mix-blend-mode:overlay;
  background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/></filter><rect width='200' height='200' filter='url(%23n)'/></svg>");
}

/* shared micro-label -------------------------------------------- */
.eyebrow,.record__eyebrow,.sheet__eyebrow,.act,.tally__row,.arc__meta dt{
  font-family:var(--sans);
  font-size:9.5px;
  letter-spacing:.24em;
  text-transform:uppercase;
  font-weight:400;
}

/* ── entry veil ─────────────────────────────────────────────── */
.veil{
  position:fixed; inset:0; z-index:90;
  background:var(--bg);
  display:grid; place-items:center;
  transition:opacity 1.1s ease, visibility 1.1s;
}
.veil.is-gone{ opacity:0; visibility:hidden; }
.veil__inner{ text-align:center; }
.veil__zh{
  font-family:var(--zh); font-weight:400;
  font-size:clamp(44px,7vw,86px); letter-spacing:.34em;
  margin:0 0 0 .34em; color:var(--ink);
}
.veil__en{
  font-size:13px; letter-spacing:.42em; text-transform:uppercase;
  font-family:var(--sans); color:var(--ink-3); margin:18px 0 40px;
}
.veil__bar{ width:190px; height:1px; background:var(--rule); margin:0 auto; overflow:hidden; }
.veil__bar i{ display:block; height:100%; width:0; background:var(--gold); transition:width .3s linear; }
.veil__note{
  font-family:var(--sans); font-size:9.5px; letter-spacing:.24em;
  text-transform:uppercase; color:var(--ink-3); margin-top:20px;
}

/* ── masthead ───────────────────────────────────────────────── */
.masthead{
  position:fixed; top:38px; left:44px; z-index:20;
  display:flex; align-items:baseline; gap:20px;
}
.masthead__zh{
  font-family:var(--zh); font-weight:400; margin:0;
  font-size:30px; letter-spacing:.22em; line-height:1;
  color:var(--ink);
}
.masthead__en{ display:flex; flex-direction:column; gap:5px; padding-left:20px; border-left:1px solid var(--rule); }
.masthead__en .ttl{
  font-size:12.5px; letter-spacing:.3em; text-transform:uppercase;
  font-family:var(--sans); color:var(--ink-2);
}
.masthead__en .sub{
  font-size:9.5px; letter-spacing:.16em; text-transform:uppercase;
  font-family:var(--sans); color:var(--ink-3);
}

/* ── stage ──────────────────────────────────────────────────── */
.stage{
  position:relative; z-index:5;
  min-height:100vh;
  padding:132px calc(var(--rail) + 56px) calc(var(--foot) + 52px) 56px;
  display:flex; flex-direction:column;
  align-items:center; justify-content:center; gap:30px;
}

/* the block is capped by *both* the free width and the free height,
   so it always sits whole inside the frame */
.monolith{
  position:relative;
  width:min(100%, 880px, (100vh - 268px) * 4 / 3);
}

.monolith__light{
  position:absolute; inset:-14% -10% -22%;
  pointer-events:none; z-index:-1;
  background:radial-gradient(58% 52% at 50% 42%, rgba(255,236,200,.10), transparent 70%);
}
/* the block's cast shadow — grounds it as an object */
.monolith__base{
  position:absolute; left:6%; right:6%; bottom:-30px; height:44px;
  pointer-events:none;
  background:radial-gradient(50% 100% at 50% 0%, rgba(0,0,0,.72), transparent 72%);
  filter:blur(7px);
}

/* ── the grid of cubes ──────────────────────────────────────── */
.grid{
  display:grid;
  grid-template-columns:repeat(var(--cols),1fr);
  grid-template-rows:repeat(var(--rows),1fr);
  gap:var(--gap);
  aspect-ratio:1448 / 1086;   /* the source plate, not the cell count */
  perspective:1700px;
  perspective-origin:50% 44%;
  transform-style:preserve-3d;
  box-shadow:0 40px 90px -30px rgba(0,0,0,.9);
}

.cell{
  position:relative;
  appearance:none; -webkit-appearance:none;
  background:none; border:none; padding:0; margin:0; font:inherit; color:inherit;
  transform-style:preserve-3d;
  cursor:pointer;
  -webkit-tap-highlight-color:transparent;
}
.cell:focus-visible{ outline:none; }
.cell:focus-visible .mark{ border-color:rgba(233,227,214,.7); }

/* hover lift lives on its own layer so it never fights the rotation */
.lift{
  position:absolute; inset:0;
  transform-style:preserve-3d;
  transition:transform .5s var(--ease);
}
.cell:hover .lift,
.cell:focus-visible .lift{ transform:translateZ(18px); }

.cube{
  position:absolute; inset:0;
  transform-style:preserve-3d;
  transition:transform 820ms var(--ease);
  will-change:transform;
}

.face{
  position:absolute; inset:0;
  backface-visibility:hidden;
  background-repeat:no-repeat;
  background-size:calc(var(--cols) * 100%) calc(var(--rows) * 100%);
  box-shadow:inset 0 0 0 1px rgba(0,0,0,.42);
}

/* ── block geometry ──────────────────────────────────────────
   A cell is w × h. A block turning about Y is a w × h × w prism;
   one turning about X is w × h × h. In each case the four faces in
   the rotation plane are exactly cell-sized (so the image crop fits
   them all), and the two end caps are square — sized to the depth.  */

/* Y-axis block: depth = w -------------------------------------- */
.ax-y .f-front { transform:                translateZ(var(--dw)); }
.ax-y .f-right { transform:rotateY( 90deg) translateZ(var(--dw)); }
.ax-y .f-backY { transform:rotateY(180deg) translateZ(var(--dw)); }
.ax-y .f-left  { transform:rotateY(-90deg) translateZ(var(--dw)); }
/* caps span w across and w deep */
.ax-y .f-top,
.ax-y .f-bottom{
  top:50%; height:var(--tw); margin-top:calc(var(--tw) / -2);
}
.ax-y .f-top   { transform:rotateX( 90deg) translateZ(var(--dh)); }
.ax-y .f-bottom{ transform:rotateX(-90deg) translateZ(var(--dh)); }

/* X-axis block: depth = h -------------------------------------- */
.ax-x .f-front { transform:                translateZ(var(--dh)); }
.ax-x .f-bottom{ transform:rotateX(-90deg) translateZ(var(--dh)); }
.ax-x .f-backX { transform:rotateX(180deg) translateZ(var(--dh)); }
.ax-x .f-top   { transform:rotateX( 90deg) translateZ(var(--dh)); }
/* caps span h across and h deep */
.ax-x .f-left,
.ax-x .f-right {
  left:50%; width:var(--th); margin-left:calc(var(--th) / -2);
}
.ax-x .f-left  { transform:rotateY(-90deg) translateZ(var(--dw)); }
.ax-x .f-right { transform:rotateY( 90deg) translateZ(var(--dw)); }

/* faces that carry no image are the cut edge of the block —
   warm stone, not a hole */
.f-stone{
  background-image:
    linear-gradient(178deg,#4a4137 0%,#2e2822 46%,#1b1714 100%);
  box-shadow:inset 0 0 0 1px rgba(0,0,0,.55);
}

/* selection frame — sits flat on the front plane, does not rotate */
.mark{
  position:absolute; inset:0;
  border:1px solid transparent;
  transition:border-color .45s ease, box-shadow .45s ease;
  pointer-events:none;
}
/* the frame rides just in front of the block's resting face */
.ax-y .mark{ transform:translateZ(calc(var(--dw) + 1px)); }
.ax-x .mark{ transform:translateZ(calc(var(--dh) + 1px)); }

.cell.is-marked .mark{
  border-color:rgba(201,162,39,.85);
  box-shadow:0 0 22px -4px rgba(201,162,39,.5);
}

.cell.is-turning{ z-index:8; }

/* ── prompt line ────────────────────────────────────────────── */
.prompt{
  margin:0; font-family:var(--sans);
  font-size:9.5px; letter-spacing:.32em; text-transform:uppercase;
  color:var(--ink-3);
  transition:opacity 1s ease;
}
.prompt.is-hidden{ opacity:0; }

/* ── reading column ─────────────────────────────────────────── */
.record{
  position:fixed; top:0; right:0; bottom:0; z-index:20;
  width:var(--rail);
  border-left:1px solid var(--rule);
  background:linear-gradient(270deg, rgba(19,17,16,.92), rgba(10,9,8,.55));
  backdrop-filter:blur(3px);
  display:flex; align-items:center;
}
.record__scroll{
  width:100%; max-height:100%; overflow-y:auto;
  padding:52px 38px;
}
.record__scroll::-webkit-scrollbar{ width:2px; }
.record__scroll::-webkit-scrollbar-thumb{ background:var(--rule); }

.record__eyebrow{ color:var(--ink-3); margin:0 0 14px; }
.record__name{
  margin:0; font-weight:400; font-size:38px; letter-spacing:.01em;
  line-height:1.05; color:var(--ink);
}
.record__origin{
  margin:8px 0 0; font-style:italic; font-size:15px; color:var(--gold);
  letter-spacing:.04em;
}

.record__swatches{ display:flex; gap:0; margin:24px 0 30px; height:3px; }
.record__swatches i{ flex:1; display:block; }

.record__list{ margin:0; }
.record__list dt{
  font-family:var(--sans); font-size:9px; letter-spacing:.22em;
  text-transform:uppercase; color:var(--ink-3);
  padding-top:15px; border-top:1px solid var(--rule-2); margin-top:15px;
}
.record__list dt:first-child{ border-top:none; margin-top:0; padding-top:0; }
.record__list dd{
  margin:7px 0 0; font-size:15.5px; line-height:1.5; color:var(--ink);
}
.record__list dd.q{ font-style:italic; color:var(--ink-2); }

.record__note{
  margin:26px 0 0; padding-top:18px; border-top:1px solid var(--rule-2);
  font-size:13.5px; line-height:1.65; color:var(--ink-2); font-style:italic;
}
.record__note:empty{ display:none; }

.record.is-swap .record__scroll{ animation:swap .5s ease; }
@keyframes swap{ from{ opacity:0; transform:translateY(7px);} to{ opacity:1; transform:none;} }

/* ── ledger ─────────────────────────────────────────────────── */
.ledger{
  position:fixed; left:0; right:var(--rail); bottom:0; z-index:20;
  padding:0 56px 22px;
  background:linear-gradient(0deg, rgba(10,9,8,.96) 42%, transparent);
}
.ledger__spectrum{
  display:flex; height:2px; margin-bottom:16px;
  border-top:1px solid var(--rule-2); padding-top:0;
}
.ledger__spectrum i{
  display:block; height:2px; min-width:0;
  transition:flex-grow .7s var(--ease), opacity .5s ease;
}
.ledger__row{
  display:flex; align-items:center; justify-content:space-between; gap:30px;
}
.ledger__tally{
  display:flex; flex-wrap:wrap; gap:0 18px;
  font-family:var(--sans); font-size:9.5px; letter-spacing:.2em;
  text-transform:uppercase; color:var(--ink-3);
}
.tally__row{ display:flex; align-items:center; gap:7px; }
.tally__row b{ font-weight:400; color:var(--ink-2); }
.tally__dot{ width:5px; height:5px; border-radius:50%; display:block; }

.ledger__acts{ display:flex; gap:0; flex-shrink:0; }
.act{
  appearance:none; background:none; border:none; cursor:pointer;
  color:var(--ink-3); padding:6px 15px;
  border-left:1px solid var(--rule-2);
  transition:color .3s ease;
}
.act:first-child{ border-left:none; }
.act:hover,.act:focus-visible{ color:var(--gold); outline:none; }

/* ── sheets (archive / about) ───────────────────────────────── */
.sheet{
  position:fixed; inset:0; z-index:60;
  background:rgba(8,7,6,.985);
  backdrop-filter:blur(6px);
  animation:sheetIn .55s var(--ease);
}
.sheet[hidden]{ display:none; }
@keyframes sheetIn{ from{opacity:0;} to{opacity:1;} }

.sheet__scroll{ height:100%; overflow-y:auto; padding:110px 8vw 120px; }
.sheet--narrow .sheet__scroll{ padding-left:max(8vw,calc(50vw - 330px)); padding-right:max(8vw,calc(50vw - 330px)); }

.sheet__close{
  position:fixed; top:38px; right:44px; z-index:2;
  appearance:none; background:none; border:none; cursor:pointer;
  font-family:var(--sans); font-size:9.5px; letter-spacing:.24em;
  text-transform:uppercase; color:var(--ink-2); padding:8px;
  transition:color .3s ease; outline:none;
  border-bottom:1px solid transparent;
}
.sheet__close:hover{ color:var(--gold); }
.sheet__close:focus-visible{ color:var(--gold); border-bottom-color:var(--gold); }

.sheet__head{ max-width:660px; margin:0 0 76px; }
.sheet__eyebrow{ color:var(--ink-3); margin:0 0 16px; }
.sheet__title{
  font-family:var(--zh); font-weight:400; margin:0 0 26px;
  font-size:clamp(38px,5vw,60px); letter-spacing:.06em;
}
#archive .sheet__title{ font-family:var(--serif); letter-spacing:0; }
.sheet__lede{ font-size:18px; line-height:1.68; color:var(--ink-2); margin:0 0 26px; max-width:62ch; }
.sheet__lede em{ color:var(--ink); font-style:italic; }
.sheet__disclosure{
  font-family:var(--sans); font-size:10.5px; letter-spacing:.11em; line-height:1.9;
  color:var(--gold); border-top:1px solid var(--rule); padding-top:18px; margin:0;
  max-width:62ch;
}
.sheet__prose p{ font-size:18px; line-height:1.78; color:var(--ink-2); margin:0 0 24px; max-width:64ch; }
.sheet__prose em{ color:var(--ink); font-style:italic; }
.sheet__prose hr{ border:none; border-top:1px solid var(--rule); margin:44px 0 28px; }
.sheet__colophon{ font-size:13.5px !important; line-height:1.8 !important; color:var(--ink-3) !important; }
.sheet__colophon strong{ color:var(--gold); font-weight:400; }

/* archive index ------------------------------------------------- */
.sheet__index{
  display:grid; grid-template-columns:repeat(auto-fill,minmax(320px,1fr));
  gap:0 56px;
}
.arc{
  padding:30px 0 32px; border-top:1px solid var(--rule-2);
  break-inside:avoid;
}
.arc__top{ display:flex; align-items:baseline; gap:14px; margin-bottom:4px; }
.arc__no{
  font-family:var(--sans); font-size:9.5px; letter-spacing:.14em;
  color:var(--ink-3); min-width:24px;
}
.arc__name{ font-size:25px; margin:0; font-weight:400; letter-spacing:.01em; }
.arc__badge{
  font-family:var(--sans); font-size:8.5px; letter-spacing:.2em;
  text-transform:uppercase; color:var(--gold); margin-left:auto;
  white-space:nowrap;
}
.arc__origin{ font-style:italic; color:var(--gold); font-size:14px; margin:0 0 6px 38px; }
.arc__quote{
  margin:14px 0 16px 38px; font-size:16px; line-height:1.6;
  color:var(--ink); font-style:italic;
}
.arc__quote::before{ content:"“"; }
.arc__quote::after{ content:"”"; }
.arc__meta{ margin:0 0 0 38px; }
.arc__meta dt{ color:var(--ink-3); margin-top:11px; }
.arc__meta dd{ margin:3px 0 0; font-size:14px; line-height:1.5; color:var(--ink-2); }
/* CJK is never set in synthetic italic */
.arc__cn{ font-family:var(--zh); font-style:normal; letter-spacing:.02em; }
.arc__colors{ display:flex; gap:5px; align-items:center; margin-top:9px; }
.arc__colors i{ width:16px; height:3px; display:block; }

/* ── persistent AI mark ─────────────────────────────────────── */
.ai-mark{
  margin:34px 0 0; padding-top:16px;
  border-top:1px solid var(--rule-2);
  font-family:var(--sans); font-size:8.5px; letter-spacing:.2em;
  text-transform:uppercase; line-height:1.9; color:var(--ink-3);
}
.ai-mark::before{ content:"◈  "; color:var(--gold); }

/* ── responsive ─────────────────────────────────────────────── */
@media (max-width:1180px){
  :root{ --rail:296px; }
  .stage{ padding-right:calc(var(--rail) + 34px); padding-left:34px; }
  .ledger{ padding-left:34px; padding-right:34px; }
  .masthead{ left:34px; }
}

@media (max-width:940px){
  :root{ --rail:0px; --foot:0px; }
  body{ overflow-y:auto; }

  .masthead{ position:static; padding:34px 24px 0; flex-direction:column; gap:12px; align-items:flex-start; }
  .masthead__en{ padding-left:0; border-left:none; }

  .stage{ min-height:auto; padding:40px 18px 34px; gap:26px; }
  .monolith{ width:100%; }
  .grid{ perspective:1700px; }

  .record{
    position:static; width:auto; border-left:none;
    border-top:1px solid var(--rule); background:var(--bg-lift);
  }
  .record__scroll{ padding:38px 24px; max-height:none; }

  .ledger{
    position:static; right:auto; padding:26px 24px 34px;
    background:var(--bg); border-top:1px solid var(--rule);
  }
  .ledger__row{ flex-direction:column; align-items:flex-start; gap:22px; }
  .ledger__acts{ flex-wrap:wrap; margin-left:-15px; }
  .act:first-child{ border-left:none; }

  .sheet__scroll{ padding:92px 24px 90px; }
  .sheet--narrow .sheet__scroll{ padding-left:24px; padding-right:24px; }
  .sheet__close{ top:22px; right:20px; }
  .sheet__index{ grid-template-columns:1fr; }
}

@media (prefers-reduced-motion:reduce){
  .cube{ transition-duration:220ms; }
  .lift{ transition:none; }
  body::after{ display:none; }
}
