/* SHELF · Library, stage 1 — the bookcase: the app's three columns (case, sidebar, lesson), the walnut case with its
   recessed back panel and boards, the slots, and a book's spine (cloth, a rounded sheen, gold bands, the title in gold
   foil). On a phone the case becomes a strip on one board. Tokens: primitive → semantic → component. */
:root {
  /* primitives */
  --walnut-900: #24130a; --walnut-700: #4a2a17; --walnut-500: #7a4a2a;
  --gold-hi: #f8e5a6; --gold: #d4a64c; --gold-lo: #9c7028;
  --paper-50: #fcf9f2; --paper-200: #efe8d8; --paper-400: #ddd3bf;
  --green-600: #1f9a68; --ink-900: #15171c;

  /* semantic: light */
  --bg-side: #f3f4f6; --bg-main: #ffffff; --ink: #16181d; --ink-2: #444a55; --muted: #6b7280; --line: #e3e5e9;
  --field: #ffffff; --field-line: #d7dae0; --pill: #eef0f3; --accent: var(--green-600); --ring: #2563eb; --hover: rgba(15, 23, 42, .06);
  --paper: var(--paper-50); --paper-ink: #15171b; --paper-muted: #6a655b; --sheet: #ffffff;
  --a-bg: #e9edf2; --a-ink: #22324a; --a-line: #2b3644; --a-teal: #40bb8f; --a-teal2: #2b9a7f; --a-mint: #cde8dd; --a-soft: #c8d1db; --a-warm: #f2b878; --a-card: #ffffff;

  /* component */
  --case-w: clamp(280px, 28.5vw, 440px);
  --side-w: clamp(260px, 24vw, 360px);
  --frame: 16px;
  --strip-h: clamp(150px, 23vh, 206px);
  color-scheme: light;
}

body { background: var(--bg-main); color: var(--ink); }

/* ------------------------------------------------------------------ frame */
.app { display: grid; height: 100vh; height: 100dvh; grid-template-columns: var(--case-w) var(--side-w) minmax(0, 1fr); grid-template-areas: "case side main"; }
.case { grid-area: case; }
.side { grid-area: side; }
.main { grid-area: main; }

/* ------------------------------------------------------------------ the bookcase */
.case {
  position: relative; z-index: 1; min-width: 0; --ring: #f6cd6a; user-select: none; -webkit-user-select: none;
  background:
    linear-gradient(90deg, rgba(255, 225, 190, .10), rgba(0, 0, 0, 0) 4%, rgba(0, 0, 0, 0) 96%, rgba(0, 0, 0, .35)),
    url(../shared/tex/walnut_v.webp) 30% 0 / 160% auto, var(--walnut-700);
  box-shadow: inset -1px 0 0 rgba(0, 0, 0, .5), 4px 0 18px rgba(0, 0, 0, .18);
}
.case::before { /* the recessed back panel */
  content: ''; position: absolute; inset: var(--frame) var(--frame) 18px var(--frame);
  background:
    linear-gradient(90deg, rgba(0, 0, 0, .55), rgba(0, 0, 0, .18) 9%, rgba(0, 0, 0, .12) 50%, rgba(0, 0, 0, .3) 92%, rgba(0, 0, 0, .55)),
    url(../shared/tex/walnut_v.webp) 70% 40% / 130% auto, var(--walnut-900);
  box-shadow: inset 0 10px 18px rgba(0, 0, 0, .55), inset 0 -4px 10px rgba(0, 0, 0, .35);
}
.case__scene {
  position: absolute; inset: var(--frame) var(--frame) 18px var(--frame);
}
.board {
  position: absolute; left: calc(var(--frame) * -1); right: calc(var(--frame) * -1); top: 0;
  background: linear-gradient(180deg, rgba(255, 228, 196, .22), rgba(255, 228, 196, 0) 22%, rgba(0, 0, 0, 0) 70%, rgba(0, 0, 0, .35)),
    url(../shared/tex/walnut_h.webp) 0 50% / 1600px 100%, var(--walnut-500);
  box-shadow: 0 7px 12px -2px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 230, 200, .28), inset 0 -1px 0 rgba(0, 0, 0, .5);
}

.books { position: absolute; left: 0; top: 0; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; }
.slot { position: absolute; left: 0; top: 0; transform-origin: 0 0; transition: transform .68s cubic-bezier(.22, 1.12, .36, 1); }
.slot.is-flat { transition-duration: .76s; }
.books.no-anim .slot { transition: none; }

.book {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block; container-type: size;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
}
.book__lift { position: absolute; inset: 0; transform-style: preserve-3d; transform-origin: 50% 100%; transition: transform .4s cubic-bezier(.2, 1.35, .4, 1), opacity .25s; }

/* faces */
.book__spine {
  position: absolute; inset: 0; overflow: hidden; border-radius: 3px 3px 2px 2px; backface-visibility: hidden;
  background: url(../shared/tex/cloth.png) 0 0 / 96px 96px, var(--c);
  background-blend-mode: overlay;
  box-shadow: 4px 1px 8px rgba(0, 0, 0, .5), inset 0 0 0 1px rgba(0, 0, 0, .28);
  transition: box-shadow .25s;
}
.book__spine::after { /* the round of the spine: a soft sheen a third of the way in, shadow at both edges */
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, .46) 0%, rgba(0, 0, 0, .12) 7%, rgba(255, 255, 255, .06) 16%, rgba(255, 245, 230, .26) 29%, rgba(255, 255, 255, .08) 41%, rgba(255, 255, 255, 0) 55%, rgba(0, 0, 0, .12) 78%, rgba(0, 0, 0, .48) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, .08), rgba(0, 0, 0, 0) 14%, rgba(0, 0, 0, 0) 88%, rgba(0, 0, 0, .28));
}
.book__bands { position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(var(--gold), var(--gold)) 0 calc(5% + 0px) / 100% 2px no-repeat,
    linear-gradient(var(--gold-lo), var(--gold-lo)) 0 calc(5% + 6px) / 100% 1.5px no-repeat,
    linear-gradient(var(--gold-lo), var(--gold-lo)) 0 calc(95% - 6px) / 100% 1.5px no-repeat,
    linear-gradient(var(--gold), var(--gold)) 0 95% / 100% 2px no-repeat;
}
.book__title {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(90deg); white-space: nowrap; pointer-events: none;
  font-family: 'Cormorant', Georgia, serif; font-weight: 600; letter-spacing: .01em; line-height: 1;
  background: linear-gradient(180deg, var(--gold-hi) 0%, var(--gold) 42%, var(--gold-lo) 58%, #e9c779 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.book__title { font-size: clamp(11px, min(46cqw, calc((100cqh - 64px) / (var(--len) * .45))), 36px); }

/* ------------------------------------------------------------------ sidebar */
.side { position: relative; z-index: 3; display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 16px 20px 16px; background: var(--bg-side); border-right: 1px solid var(--line); }
.side__top { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
.logo { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; border-radius: 8px; padding: 4px 4px 4px 0; }
.logo svg { width: 30px; height: 30px; }
.logo__word { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.side__tools { display: flex; gap: 2px; color: var(--ink-2); }

/* ------------------------------------------------------------------ main: the lesson */
.main { position: relative; z-index: 2; min-width: 0; overflow-y: auto; overflow-x: hidden; contain: strict; padding: 34px clamp(24px, 4.6vw, 72px) 64px clamp(40px, 6vw, 96px); background: var(--bg-main); outline: none; }

/* ------------------------------------------------------------------ phones: strip on top, sheet below */
.app[data-layout="phone"] { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto var(--strip-h) minmax(0, 1fr); grid-template-areas: "side" "case" "main"; }
.app[data-layout="phone"] .side { padding: 6px 8px 0 14px; border-right: 0; border-bottom: 1px solid var(--line); }
.app[data-layout="phone"] .side__top { min-height: 52px; }
.app[data-layout="phone"] .case { --frame: 0px; box-shadow: inset 0 10px 14px -6px rgba(0, 0, 0, .55); }
.app[data-layout="phone"] .case::before { inset: 0 0 16px 0; }
.app[data-layout="phone"] .case::after { /* the board the books stand on */
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 16px; z-index: 1;
  background: linear-gradient(180deg, rgba(255, 228, 196, .25), rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, .35)), url(../shared/tex/walnut_h.webp) 0 50% / 1600px 100%, var(--walnut-500);
  box-shadow: 0 -1px 0 rgba(0, 0, 0, .4); }
.case__scene[data-mode="strip"] { inset: 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; overscroll-behavior-x: contain; z-index: 2; }
.case__scene[data-mode="strip"]::-webkit-scrollbar { display: none; }
.case__scene[data-mode="strip"] .book { touch-action: pan-x; }
.app[data-layout="phone"] .main { padding: 22px 18px calc(96px + env(safe-area-inset-bottom)); }

@media (prefers-reduced-motion: reduce) {
  .slot, .book__lift { transition-duration: 1ms !important; }
}

/* touch: fingertip-sized rows and fields */
@media (pointer: coarse) {
  .logo { min-height: 44px; }
}
