/* FOLIO // LOUPE — v4 page features: darkroom, folding spine, light table */

@property --amb { syntax: "<color>"; inherits: true; initial-value: rgb(255 176 108); }

/* ========================================================= idea 4 · lamp == */
.sheet__right { display: flex; align-items: center; gap: 22px; }
.lamp {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 6px;
  border: 0;
  border-radius: 10px;
  background: none;
  cursor: pointer;
  font: 600 10.5px/1 var(--sans);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}
.lamp__lab { transition: color 0.4s ease; }
.lamp[aria-checked="false"] .lamp__lab--day,
.lamp[aria-checked="true"] .lamp__lab--dark { color: var(--ink); }
.lamp__track {          /* the brass base plate with its slot */
  position: relative;
  inline-size: 44px;
  block-size: 22px;
  border-radius: 999px;
  background: linear-gradient(180deg, #e7dccd, #f7f1e8);
  box-shadow: inset 0 1.5px 3px rgb(60 40 20 / 0.28), 0 1px 0 rgb(255 255 255 / 0.85), 0 0 0 1px rgb(110 85 60 / 0.18);
}
.lamp__track::before {  /* slot */
  content: "";
  position: absolute;
  inset: 50% 9px auto;
  block-size: 3px;
  translate: 0 -50%;
  border-radius: 3px;
  background: rgb(40 28 18 / 0.45);
}
.lamp__lever {          /* the toggle lever pivots in the slot */
  position: absolute;
  inset-inline-start: 50%;
  inset-block-end: 50%;
  inline-size: 3px;
  block-size: 15px;
  margin-inline-start: -1.5px;
  border-radius: 2px;
  transform-origin: 50% 100%;
  rotate: -42deg;
  background: linear-gradient(90deg, #8f8272, #d9cfc1 55%, #8f8272);
  transition: rotate 0.5s cubic-bezier(0.34, 1.5, 0.64, 1);
}
.lamp__knob {
  position: absolute;
  inset-inline-start: 50%;
  inset-block-start: -7px;
  inline-size: 11px;
  block-size: 11px;
  translate: -50% 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f3a97f, #c4552b 58%, #8b3818);
  box-shadow: 0 1.5px 2px rgb(60 30 10 / 0.45);
  transition: box-shadow 0.5s ease;
}
.lamp[aria-checked="true"] .lamp__lever { rotate: 42deg; }
.lamp[aria-checked="true"] .lamp__knob { box-shadow: 0 1.5px 2px rgb(0 0 0 / 0.5), 0 0 10px 2px rgb(255 150 90 / 0.55); }
.lamp:active .lamp__knob { scale: 0.9; }

/* the darkroom */
:root[data-theme="dark"] {
  --paper: #141210;
  --paper-2: #1c1916;
  --linen: #191613;
  --ink: #ece4d8;
  --ink-soft: #bdb1a2;
  --muted: #9d9081;
  --accent-ink: #e8875a;
  --hair: rgb(255 228 196 / 0.12);
  color-scheme: dark;
}
:root[data-theme="dark"] .lamp__track {
  background: linear-gradient(180deg, #24201b, #2e2822);
  box-shadow: inset 0 1.5px 3px rgb(0 0 0 / 0.6), 0 1px 0 rgb(255 255 255 / 0.06), 0 0 0 1px rgb(255 228 196 / 0.10);
}
body, .spine, .plate, .spine::after { transition: background-color 0.6s ease, color 0.6s ease; }
:root[data-theme="dark"] .spine::before { opacity: 0.25; }
:root[data-theme="dark"] .spine { background: var(--grain), repeating-linear-gradient(0deg, rgb(255 230 200 / 0.025) 0 1px, transparent 1px 3px), repeating-linear-gradient(90deg, rgb(255 230 200 / 0.02) 0 1px, transparent 1px 3px), var(--linen); }
:root[data-theme="dark"] .plate {
  background: linear-gradient(180deg, #1f1b18, #191613);
  box-shadow: 0 0 0 1px rgb(255 214 170 / 0.10), inset 0 1px 0 rgb(255 255 255 / 0.04);
}
/* 3200 K backlight that borrows the frame's edge colour, breathing slowly */
.plate { isolation: isolate; transition: --amb 1.2s ease; }
.plate::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  box-shadow:
    0 0 50px 4px color-mix(in srgb, var(--amb) 55%, transparent),
    0 0 140px 30px color-mix(in srgb, var(--amb) 22%, transparent);
  transition: opacity 0.8s ease;
}
:root[data-theme="dark"] .plate::before { opacity: 1; animation: backlight 6s ease-in-out infinite alternate; }
@keyframes backlight { from { opacity: 0.78; } to { opacity: 1; } }
:root[data-theme="dark"] .contact__strip { background-color: #0f0d0b; }
:root[data-theme="dark"] .frame { box-shadow: inset 0 0 0 1px rgb(239 230 218 / 0.12); }

/* ================================================= idea 3 · folding spine == */
.spine__shade {
  position: absolute !important;
  inset: 0;
  z-index: 2 !important;
  pointer-events: none;
  background: linear-gradient(90deg, rgb(25 15 5 / 0) 8%, rgb(25 15 5 / 0.48));
  opacity: 0;
  transition: opacity 0.95s ease;
}
.spine__crease {
  position: absolute !important;
  z-index: 3 !important;
  inset-block-start: 50%;
  inset-inline-end: -14px;
  inline-size: 28px;
  block-size: 84px;
  translate: 0 -50%;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
}
.spine__crease::before {   /* the visible tab on the crease */
  content: "";
  position: absolute;
  inset: 10px 7px;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--paper-2), var(--paper));
  box-shadow: 0 0 0 1px var(--hair), 0 6px 14px -6px rgb(40 25 10 / 0.45);
  opacity: 0.6;
  transition: opacity 0.25s ease, scale 0.3s cubic-bezier(0.34, 1.5, 0.64, 1);
}
.spine__crease-line {
  position: absolute;
  inset: 26px 13px;
  border-radius: 2px;
  background: var(--accent);
}
.spine__crease:is(:hover, :focus-visible)::before { opacity: 1; scale: 1.08; }
.spine__crease:focus-visible { outline: 3px solid var(--accent-ink); outline-offset: 2px; }
@media (max-width: 900px) { .spine__crease, .spine__shade { display: none; } }

@media (min-width: 901px) {
  .spread {
    --spine-w: max(300px, 26vw);
    grid-template-columns: var(--spine-w) minmax(0, 1fr);
    transition: grid-template-columns 0.95s cubic-bezier(0.22, 0.8, 0.2, 1);
  }
  .spine {
    z-index: 4;
    width: var(--spine-w);
    transform-origin: 0 50%;
    /* flattening back: a soft overshoot, like paper settling */
    transition: transform 0.85s cubic-bezier(0.3, 1.28, 0.5, 1), filter 0.85s ease;
  }
  :root[data-folded] .spread { grid-template-columns: calc(var(--spine-w) * 0.52) minmax(0, 1fr); }
  :root[data-folded]:not([data-peek]) .spine {
    transform: perspective(1800px) rotateY(-65deg);
    filter: drop-shadow(16px 0 22px rgb(40 25 10 / 0.30));
    transition: transform 0.95s cubic-bezier(0.22, 0.8, 0.2, 1), filter 0.95s ease;
  }
  :root[data-folded]:not([data-peek]) .spine__shade { opacity: 1; }
  :root[data-folded][data-peek] .spine { filter: drop-shadow(18px 0 26px rgb(40 25 10 / 0.35)); }
}

/* ============================================== idea 5 · the light table == */
.lt {
  --ink: #2a2520;
  --ink-soft: #5a5047;
  --muted: #6e6359;
  --paper-2: #f7f2eb;
  --hair: rgb(110 85 60 / 0.2);
  position: absolute;
  z-index: 6;
  inset: clamp(8px, 1vw, 14px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px 16px;
  overflow: hidden;
  border-radius: 12px;
  color: var(--ink);
  background:
    repeating-linear-gradient(0deg, rgb(120 90 60 / 0.045) 0 1px, transparent 1px 40px),
    repeating-linear-gradient(90deg, rgb(120 90 60 / 0.045) 0 1px, transparent 1px 40px),
    radial-gradient(120% 100% at 50% 38%, #fffdf8, #f5ecdf 68%, #eadcc7);
  box-shadow: inset 0 0 0 1px rgb(110 85 60 / 0.18), inset 0 0 80px rgb(255 255 255 / 0.7);
}
.lt[hidden] { display: none; }
.lt__head { display: flex; align-items: center; gap: 16px; min-height: 44px; }
.lt__title { margin: 0; font: 600 11.5px/1 var(--sans); letter-spacing: 0.24em; text-transform: uppercase; }
.lt__title span { color: var(--muted); font-weight: 450; letter-spacing: 0.08em; text-transform: none; }
.lt__hint { margin: 0 0 0 auto; font-size: 12px; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.lt__hint kbd { min-width: 20px; }
.lt__close {
  display: grid;
  place-items: center;
  inline-size: 44px;
  block-size: 44px;
  margin-inline-start: 6px;
  border: 0;
  border-radius: 50%;
  background: #2a2520;
  color: #f7f2ea;
  cursor: pointer;
}
.lt__close svg { inline-size: 20px; block-size: 20px; }
.lt__close:focus-visible { outline: 3px solid var(--accent-ink, #9f3f1a); outline-offset: 3px; }
.lt__strips {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: 9px;
}
.lt__strip {
  position: relative;
  display: grid;
  grid-template-columns: 136px minmax(0, 1fr);
  align-items: stretch;
  min-height: 0;
  padding: 10px 12px;
  border-radius: 3px;
  background:
    radial-gradient(circle, #f4ecdf 0 2.1px, transparent 2.6px) 7px 2.5px / 13px 6px repeat-x,
    radial-gradient(circle, #f4ecdf 0 2.1px, transparent 2.6px) 7px calc(100% - 2.5px) / 13px 6px repeat-x,
    #1f1b17;
  box-shadow: 0 8px 16px -10px rgb(40 25 10 / 0.7);
}
.lt__label {
  display: grid;
  align-content: center;
  gap: 3px;
  padding-inline-end: 10px;
  color: #efe6da;
  font: 500 11px/1.25 var(--mono);
  letter-spacing: 0.04em;
}
.lt__label b { color: #f0a274; font-weight: 500; }
.lt__edge {
  position: absolute;
  inset-inline-start: 12px;
  inset-block-end: 9px;
  color: rgb(240 162 116 / 0.65);
  font: 500 8px/1 var(--mono);
  letter-spacing: 0.12em;
  white-space: nowrap;
}
.lt__frames { display: flex; gap: 8px; min-width: 0; overflow: hidden; }
.lt__frame {
  position: relative;
  flex: 0 0 auto;
  block-size: 100%;
  aspect-ratio: 16 / 9;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.08);
  cursor: pointer;
  transition: filter 0.25s ease;
}
.lt__frame:focus-visible { outline: 3px solid #f6efe4; outline-offset: 3px; }
@media (hover: hover) { .lt__frame:hover { filter: brightness(1.08); } }
.lt[data-loupe] :is(.lt__strips, .lt__frame) { cursor: none; }
.lt__ring {
  position: absolute;
  inset: -7px -8px;
  overflow: visible;
  pointer-events: none;
}
.lt__ring path {
  fill: none;
  stroke: #d0592a;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
}
.lt__push { position: absolute; z-index: 8; transform-origin: 0 0; background-repeat: no-repeat; border-radius: 2px; pointer-events: none; }

/* the loupe cursor */
.lt__loupe {
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: 0;
  z-index: 5;
  inline-size: 110px;
  block-size: 110px;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  box-shadow: 0 0 0 4px #f7f0e5, 0 0 0 5px rgb(110 85 60 / 0.35), 0 20px 34px -12px rgb(30 18 8 / 0.6);
}
.lt[data-loupe] .lt__loupe { opacity: 1; }
.lt__loupe-cv { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; border-radius: 50%; }
.lt__loupe::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(ellipse 34% 20% at 33% 19%, rgb(255 255 255 / 0.7), rgb(255 255 255 / 0) 70%),
    radial-gradient(circle, rgb(255 255 255 / 0) 64%, rgb(255 255 255 / 0.1) 86%, rgb(0 0 0 / 0.25) 100%);
  box-shadow: inset 2px 0 3px rgb(215 85 45 / 0.5), inset -2px 0 3px rgb(70 140 230 / 0.4), inset 0 2px 4px rgb(255 255 255 / 0.35);
}
.lt__loupe-tag {
  position: absolute;
  inset-inline-start: 50%;
  inset-block-start: calc(100% + 10px);
  translate: -50% 0;
  padding: 4px 8px 3px;
  border-radius: 6px;
  background: #262320;
  color: #f5f1e8;
  font: 500 10.5px/1 var(--mono);
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.lt__loupe-tag:empty { display: none; }

/* small screens: the light table takes the whole screen */
@media (max-width: 900px) {
  .lt { position: fixed; inset: 0; z-index: 60; border-radius: 0; padding: 10px 12px 14px; }
  .lt__hint { display: none; }
  .lt__title { margin-inline-end: auto; }
  .lt__strips { grid-template-rows: none; grid-auto-rows: 84px; overflow-y: auto; }
  .lt__strip { grid-template-columns: 74px minmax(0, 1fr); }
  .lt__frames { overflow-x: auto; scrollbar-width: none; }
  .lt__edge { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  :root[data-theme="dark"] .plate::before { animation: none; }
  .spread, .spine { transition: none !important; }
}

/* light table fit */
.lt__strip { grid-template-columns: 156px minmax(0, 1fr); }
.lt__label { white-space: nowrap; }
.lt__frames { justify-content: space-between; }
@media (max-width: 900px) { .lt__strip { grid-template-columns: 74px minmax(0, 1fr); } .lt__label { white-space: normal; } .lt__frames { justify-content: flex-start; } }
@media (max-width: 900px) { .lt__title span { display: none; } }

/* ================================================== motion switch == */
.motion {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: none;
  cursor: pointer;
  font: 600 10.5px/1 var(--sans);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--hair);
  transition: box-shadow 0.3s ease, color 0.3s ease;
}
.motion__i { width: 22px; height: 11px; color: var(--accent); }
.motion[aria-checked="true"] .motion__i path { stroke-dasharray: 4 3; animation: motion-wave 1.2s linear infinite; }
@keyframes motion-wave { to { stroke-dashoffset: -14; } }
.motion__val { color: var(--ink); min-width: 3.4em; text-align: left; }
.motion__auto {
  margin-left: -2px;
  padding: 3px 5px 2px;
  border-radius: 4px;
  font: 500 9px/1 var(--mono);
  letter-spacing: 0.06em;
  text-transform: none;
  color: var(--muted);
  background: rgb(110 85 60 / 0.10);
}
.motion:not([data-auto]) .motion__auto { display: none; }
@media (hover: hover) { .motion:hover { box-shadow: inset 0 0 0 1px var(--accent); color: var(--ink); } }
.motion:focus-visible { outline: 3px solid var(--accent-ink); outline-offset: 3px; }
@media (max-width: 1180px) { .motion__lab { display: none; } }
@media (max-width: 900px) {
  .sheet__right { gap: 8px; margin-left: auto; }
  .motion { padding: 0 10px; }
  .motion__auto { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .motion[aria-checked="true"] .motion__i path { animation: none; }
}

/* ================================================== motion invite == */
.invite {
  position: fixed;
  z-index: 70;
  top: 84px;
  right: clamp(16px, 3.4vw, 64px);
  width: min(360px, calc(100vw - 32px));
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 12px;
  padding: 16px 18px 16px 16px;
  border-radius: 14px;
  color: #2a2520;
  background: linear-gradient(180deg, #fcf9f4, #efe7dc);
  box-shadow: 0 0 0 1px rgb(110 85 60 / 0.24), inset 0 1.5px 1px rgb(255 255 255 / 0.95), 0 24px 44px -18px rgb(40 25 10 / 0.55);
}
.invite[hidden] { display: none; }
.invite::before {             /* a little tab pointing at the MOTION switch */
  content: "";
  position: absolute;
  top: -6px;
  right: var(--tab, 120px);
  width: 12px;
  height: 12px;
  rotate: 45deg;
  background: #fcf9f4;
  box-shadow: -1px -1px 0 rgb(110 85 60 / 0.24);
}
.invite__i { width: 26px; height: 13px; margin-top: 3px; color: #c4552b; }
.invite__txt { margin: 0; font-size: 13.5px; line-height: 1.45; color: #433b34; }
.invite__txt b { display: block; font-weight: 600; color: #2a2520; margin-bottom: 2px; }
.invite__acts { grid-column: 2; display: flex; flex-wrap: wrap; gap: 8px; }
.invite__go, .invite__stay {
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font: 600 13px/1 var(--sans);
}
.invite__go { background: #2a2520; color: #f7f2ea; box-shadow: 0 6px 14px -8px rgb(30 20 10 / 0.6); }
.invite__stay { background: none; color: #433b34; box-shadow: inset 0 0 0 1px rgb(110 85 60 / 0.3); }
@media (hover: hover) {
  .invite__go:hover { background: #3a332c; }
  .invite__stay:hover { box-shadow: inset 0 0 0 1px #c4552b; }
}
.invite :focus-visible { outline: 3px solid #9f3f1a; outline-offset: 3px; }
@media (max-width: 900px) {
  .invite { top: auto; bottom: 14px; right: 16px; }
  .invite::before { display: none; }
}

/* v5.1 · the spine never covers the sheet
   Peeking widens the column again, and unfolding makes room before the page
   lands; folding lets the page turn first, then the column follows. */
@media (min-width: 901px) {
  .spread { transition: grid-template-columns 0.5s cubic-bezier(0.3, 0.7, 0.2, 1); }
  :root[data-folded][data-peek] .spread { grid-template-columns: var(--spine-w) minmax(0, 1fr); }
  :root[data-folded]:not([data-peek]) .spread { transition: grid-template-columns 0.8s cubic-bezier(0.22, 0.8, 0.2, 1) 0.22s; }
  .spine { transition: transform 0.8s cubic-bezier(0.3, 1.12, 0.5, 1) 0.1s, filter 0.8s ease 0.1s; }
}
