/* The dictionary shelf (shelf.html), wabi-sabi: a clay-plaster wall in soft shoji light, one
   weathered cedar plank with a live edge on two iron pegs, a river stone and a lopsided pot with
   a single branch, and the four books standing face-out. Each cover is the book page itself in
   ?cover mode, in an iframe. */
:root {
  --wall: #d7cfc1;
  --wall-hi: #e9e3d7;
  --wall-lo: #c0b4a1;
  --sumi: #2a2620;
  --ink-2: #6e6458;
  --cedar: #8c7a66;
  --cedar-lo: #5e5041;
  --washi: #efe9dc;
  --bh: min(calc((92vh - 190px) / 3), 290px, 14vw);   /* book height: two planks of five fit under the title */
  --bw: calc(var(--bh) * 540 / 740);   /* book width, the covers' proportions */
  --bd: calc(var(--bh) * .07);         /* book thickness */
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--sumi); font-family: 'EB Garamond', serif; overflow: hidden; -webkit-font-smoothing: antialiased;
  /* a clay-plaster wall (tsuchikabe), as in ことば帖: mottled, with flecks of straw */
  background-color: var(--wall);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='420' height='420'%3E%3Cfilter id='s'%3E%3CfeTurbulence stitchTiles='stitch' type='fractalNoise' baseFrequency='.9 .04' numOctaves='1' seed='8'/%3E%3CfeColorMatrix values='0 0 0 0 .55 0 0 0 0 .45 0 0 0 0 .28 0 0 0 2.4 -1.95'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23s)'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='600' height='600'%3E%3Cfilter id='m'%3E%3CfeTurbulence stitchTiles='stitch' type='fractalNoise' baseFrequency='.006' numOctaves='4' seed='3'/%3E%3CfeColorMatrix values='0 0 0 0 .42 0 0 0 0 .36 0 0 0 0 .27 0 0 0 .55 -.12'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23m)'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence stitchTiles='stitch' type='fractalNoise' baseFrequency='.8' numOctaves='2' seed='1'/%3E%3CfeColorMatrix values='0 0 0 0 .3 0 0 0 0 .26 0 0 0 0 .2 0 0 0 .35 -.12'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E"),
    radial-gradient(70% 60% at 22% 12%, var(--wall-hi), transparent 70%),
    radial-gradient(120% 90% at 50% 50%, transparent 55%, var(--wall-lo) 100%);
  background-size: 420px 420px, cover, 180px 180px, auto, auto;
  background-repeat: repeat, no-repeat, repeat, no-repeat, no-repeat;
  background-attachment: fixed;
}

/* window light falling across the wall: a soft, slanted patch with the shoji lattice in it */
.light { position: fixed; left: 2vw; top: -8vh; width: min(48vw, 640px); height: 74vh; pointer-events: none; opacity: .55; filter: blur(16px); mix-blend-mode: screen;
  transform: skewX(-14deg);
  background:
    repeating-linear-gradient(90deg, transparent 0 calc(25% - 5px), rgba(0,0,0,.9) calc(25% - 5px) 25%),
    repeating-linear-gradient(0deg, transparent 0 calc(20% - 5px), rgba(0,0,0,.9) calc(20% - 5px) 20%),
    rgba(255,246,222,.55);
  -webkit-mask: radial-gradient(closest-side, #000 60%, transparent); mask: radial-gradient(closest-side, #000 60%, transparent); }
.branch { position: fixed; top: -50px; right: -40px; width: min(50vw, 600px); pointer-events: none; opacity: .1; filter: blur(4px); transform-origin: 100% 0; }

.top { position: fixed; top: 8vh; left: 0; right: 0; text-align: center; z-index: 5; }
/* the title: an editorial roman with the first word in italic, the languages as a small spaced line */
.top h1 { margin: 0; font: 500 clamp(34px, 4.4vw, 58px)/1 'Cormorant Garamond', serif; letter-spacing: .005em; color: var(--sumi); font-feature-settings: 'liga', 'dlig', 'kern'; }
.top h1 em { font-style: italic; font-weight: 500; letter-spacing: -.01em; margin-right: .04em; color: #9b3a2a; }
.top .langs { margin: 14px 0 0; display: flex; justify-content: center; align-items: baseline; gap: .7em; font: 500 13px 'EB Garamond', serif; letter-spacing: .22em; text-transform: uppercase; color: var(--ink-2); }
.top .langs span[lang] { font-family: 'Shippori Mincho', serif; letter-spacing: .12em; text-transform: none; }
.top .langs i { font-style: normal; opacity: .45; letter-spacing: 0; }

/* ---------------------------------------------------------------- the shelf */
/* the shelf lives in the space between the title block and the credit, so the two never meet */
.wall { position: fixed; left: 0; right: 0; top: calc(8vh + 112px); bottom: 52px; display: grid; place-items: center; }
.tiers { display: flex; flex-direction: column; align-items: center; gap: 0; max-width: 100vw; }
.shelf-wrap { max-width: 100vw; overflow-x: auto; overflow-y: visible; padding: calc(var(--bh) * .12) 60px calc(var(--bh) * .2); scrollbar-width: none; scroll-snap-type: x mandatory; }
.shelf-wrap::-webkit-scrollbar { display: none; }
.shelf { position: relative; width: max-content; margin: 0 auto; }
.books { display: flex; align-items: flex-end; gap: calc(var(--bw) * .15); padding: 0 calc(var(--bw) * .14) 0 calc(var(--bw) * .2); perspective: 1600px; }

.book { position: relative; display: block; flex: 0 0 auto; width: var(--bw); height: var(--bh); transform-style: preserve-3d; transform: rotateY(-16deg); transform-origin: 50% 100%; cursor: pointer; scroll-snap-align: center; outline: none; text-decoration: none; }
.book .front { position: absolute; inset: 0; overflow: hidden; border-radius: 2px 3px 3px 2px; box-shadow: 0 1px 0 rgba(0,0,0,.12); background: #ccc4b6; }
.book .front .cover-img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; user-select: none; }
.book .front::after { /* the window light catching the cover as it turns */
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, rgba(255,248,230,.12) 48%, transparent 60%); background-size: 240% 100%; background-position: 100% 0; transition: background-position .9s ease;
}
.book:hover .front::after, .book:focus-visible .front::after { background-position: 0 0; }
/* the right-hand side: page edges for the left-to-right books, the stitched spine for the thread-bound Japanese and Chinese ones */
.book .side { position: absolute; left: 100%; top: 0; width: var(--bd); height: 100%; transform-origin: 0 50%; transform: rotateY(90deg);
  background: repeating-linear-gradient(90deg, #eee6d5 0 1px, #ddd1bb 1px 2px), #e9dfcb; box-shadow: inset 0 0 0 1px rgba(0,0,0,.06), inset 0 6px 6px -4px rgba(0,0,0,.18), inset 0 -6px 6px -4px rgba(0,0,0,.18); }
.book.rtl .side { background: linear-gradient(90deg, #26324a, #2e3b52 40%, #26324a); }
.book.rtl.zh .side { background: linear-gradient(90deg, #6e1f17, #8f2a20 40%, #6e1f17); }   /* 拼音字典: cinnabar cloth, also sewn on the right */
.book.rtl .side::after { content: ''; position: absolute; left: 35%; top: 0; bottom: 0; border-left: 2px solid rgba(233,225,204,.8); }
.book .top-edge { position: absolute; left: 0; top: 0; width: 100%; height: var(--bd); transform-origin: 50% 0; transform: rotateX(90deg); background: repeating-linear-gradient(0deg, #eee6d5 0 1px, #ddd1bb 1px 2px); }
.book::after { /* a soft contact shadow on the plank */
  content: ''; position: absolute; left: -2%; right: -14%; bottom: -5px; height: 14px; border-radius: 50%; background: radial-gradient(closest-side, rgba(40,28,16,.4), transparent); transform: translateZ(-40px); pointer-events: none;
}

/* the things that keep the shelf from being tidy */
.stone { flex: 0 0 auto; opacity: .95; width: calc(var(--bh) * .3); margin-right: calc(var(--bw) * .02); margin-bottom: -2px; filter: drop-shadow(4px 3px 3px rgba(40,28,16,.3)); }
.vase { flex: 0 0 auto; width: calc(var(--bh) * .56); margin-left: calc(var(--bw) * .08); margin-bottom: -3px; filter: drop-shadow(6px 4px 5px rgba(40,28,16,.3)); transform-origin: 50% 100%; }

/* one cedar plank, grey with age, its front a live edge (the bark line, cut in shelf.js) */
.plank { position: relative; margin: -2px calc(var(--bw) * -.06) 0; height: calc(var(--bh) * .13); }
.plank::before { /* the top surface, seen from just above */
  content: ''; position: absolute; left: 0; right: 0; bottom: 100%; height: calc(var(--bh) * .05); transform-origin: 50% 100%; transform: perspective(500px) rotateX(55deg);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='700' height='40'%3E%3Cfilter id='w'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.003 .4' numOctaves='3' seed='11' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .25 0 0 0 0 .2 0 0 0 0 .14 0 0 0 .7 -.2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23w)'/%3E%3C/svg%3E"),
    linear-gradient(180deg, #a69580, #8f7d68);
  background-size: 700px 100%, auto; }
.face { position: absolute; inset: 0;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='700' height='60'%3E%3Cfilter id='w'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.0018 .16' numOctaves='4' seed='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .2 0 0 0 0 .15 0 0 0 0 .1 0 0 0 2.6 -1.05'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23w)'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='500' height='60'%3E%3Cfilter id='v'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.01 .9' numOctaves='2' seed='9' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .95 0 0 0 0 .9 0 0 0 0 .82 0 0 0 1.4 -.72'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23v)'/%3E%3C/svg%3E"),
    radial-gradient(ellipse 22px 9px at 31% 50%, rgba(50,36,24,.75), rgba(70,52,36,.35) 55%, transparent 75%),
    radial-gradient(ellipse 14px 6px at 89% 44%, rgba(50,36,24,.7), rgba(70,52,36,.3) 55%, transparent 75%),
    radial-gradient(ellipse 60px 30px at 31% 50%, transparent 40%, rgba(60,44,30,.18) 55%, transparent 70%),
    linear-gradient(180deg, #a08e78, var(--cedar) 35%, #7a6853 75%, var(--cedar-lo));
  background-size: 700px 100%, 500px 100%, auto, auto, auto, auto;
  box-shadow: inset 0 1px 0 rgba(255,240,220,.25); }
.plank::after { /* its shadow on the wall */
  content: ''; position: absolute; left: 4%; right: 4%; top: 30%; height: 160%; z-index: -1; background: rgba(60,45,30,.45); filter: blur(20px); border-radius: 50%; }
.peg { position: absolute; top: 88%; width: calc(var(--bh) * .03); height: calc(var(--bh) * .05); background: linear-gradient(90deg, #2b2621, #4a423a 45%, #24201c); border-radius: 0 0 2px 2px; z-index: -1; box-shadow: 2px 4px 6px rgba(40,28,16,.35); }
.peg.l { left: 18%; } .peg.r { right: 18%; }

/* washi labels, lettered in ink and stuck a little crooked on the plank (placed under each book by shelf.js) */
.tags { position: absolute; inset: 0; }
.tag { position: absolute; top: 50%; translate: -50% -50%; display: flex; align-items: baseline; gap: 7px; padding: 2px 10px 3px; white-space: nowrap;
  font: 400 calc(var(--bh) * .034) 'EB Garamond', serif; color: var(--sumi); letter-spacing: .04em;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.05 .6' numOctaves='2' seed='2'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .42 0 0 0 0 .3 0 0 0 .5 -.15'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E"),
    var(--washi);
  box-shadow: 0 1px 2px rgba(40,28,16,.3);
  clip-path: polygon(1% 4%, 30% 0, 62% 6%, 99% 1%, 100% 92%, 70% 100%, 34% 95%, 0 100%); }
.tag b { font: 500 calc(var(--bh) * .036) 'Shippori Mincho', serif; letter-spacing: .06em; }
.tag:nth-child(1) { rotate: -1.2deg; } .tag:nth-child(2) { rotate: .8deg; } .tag:nth-child(3) { rotate: -.5deg; } .tag:nth-child(4) { rotate: 1.4deg; } .tag:nth-child(5) { rotate: -.9deg; }
.notes .tag:nth-child(1) { rotate: .9deg; } .notes .tag:nth-child(2) { rotate: -1.1deg; } .notes .tag:nth-child(3) { rotate: .4deg; } .notes .tag:nth-child(4) { rotate: -.7deg; } .notes .tag:nth-child(5) { rotate: 1.2deg; }
.cup { flex: 0 0 auto; width: calc(var(--bh) * .34); margin-right: calc(var(--bw) * .06); margin-bottom: -2px; overflow: visible; filter: drop-shadow(4px 3px 3px rgba(40,28,16,.3)); }

.credit { position: fixed; left: 0; right: 0; bottom: 12px; margin: 0; text-align: center; font: italic 15.5px 'EB Garamond', serif; color: rgba(42,38,32,.55); letter-spacing: .04em; }
.credit a { color: #9b3a2a; text-decoration: none; border-bottom: 1px solid rgba(155,58,42,.35); }

/* the pull-out: the chosen book comes off the shelf and fills the view */
.veil { position: fixed; inset: 0; background: var(--wall); opacity: 0; pointer-events: none; z-index: 40; }

@media (max-width: 760px) {
  :root { --bh: min(calc((95vh - 300px) / 2.3), 200px); }
  .wall { top: calc(5vh + 118px); bottom: 44px; place-items: start center; overflow-y: auto; }
  .top { top: 5vh; padding: 0 16px; }
  .top .langs { flex-wrap: wrap; gap: .45em; font-size: 11.5px; letter-spacing: .16em; }
  .shelf-wrap { padding: 22px 30px 34px; }
  .light { width: 90vw; }
}

/* ---------------------------------------------------------------- the books speak */
.tiers { transform-style: flat; }   /* flat: in 3D the angled books slip behind the plank for clicks */
.wall { perspective: 1800px; }
.book { touch-action: pan-y; }
.bubble { position: fixed; z-index: 30; pointer-events: none; max-width: min(340px, 80vw); padding: 9px 16px 10px; white-space: normal;
  font: 500 19px/1.3 'Cormorant Garamond', serif; color: var(--sumi); letter-spacing: .02em;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.05 .6' numOctaves='2' seed='4'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .42 0 0 0 0 .3 0 0 0 .45 -.15'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E"),
    #f5f0e4;
  box-shadow: 0 6px 16px rgba(40,28,16,.22), 0 1px 2px rgba(40,28,16,.2);
  clip-path: polygon(0 3%, 40% 0, 100% 2%, 99% 96%, 56% 100%, 50% 100%, 1% 98%); }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -9px; width: 14px; height: 10px; margin-left: -7px; background: #f5f0e4; clip-path: polygon(0 0, 100% 0, 40% 100%); }
.bubble.lang-ja, .bubble.lang-zh { font: 500 20px/1.35 'Shippori Mincho', serif; }
.bubble.lang-ko { font: 500 19px/1.35 'Shippori Mincho', 'Apple SD Gothic Neo', serif; }
.bubble.lang-es, .bubble.lang-fr { font-style: italic; }
.tag { transition: box-shadow .3s, translate .3s; }
.tag.on { box-shadow: 0 0 0 1.5px rgba(155,58,42,.55), 0 2px 4px rgba(40,28,16,.3); }
.tag.kin { box-shadow: 0 0 0 1px rgba(155,58,42,.3), 0 1px 2px rgba(40,28,16,.3); }
.voices { position: fixed; right: 18px; bottom: 12px; z-index: 20; appearance: none; background: none; border: 1px solid rgba(42,38,32,.22); border-radius: 999px; padding: 4px 12px 5px 10px; cursor: pointer;
  display: flex; align-items: center; gap: 8px; font: italic 14px 'EB Garamond', serif; color: rgba(42,38,32,.65); }
.voices i { width: 7px; height: 7px; border-radius: 50%; background: #9b3a2a; box-shadow: 0 0 0 3px rgba(155,58,42,.15); }
.voices.off i { background: transparent; border: 1px solid rgba(42,38,32,.4); box-shadow: none; }
.voices:hover { color: var(--sumi); border-color: rgba(42,38,32,.5); }
.hear { position: fixed; left: 0; right: 0; bottom: 36px; margin: 0; text-align: center; font: italic 14px 'EB Garamond', serif; color: rgba(42,38,32,.45); letter-spacing: .04em; pointer-events: none; transition: opacity .6s; }
@media (pointer: coarse) { .voices, .hear { display: none; } }

/* the book on its way to the middle of the screen, and its cover opening */
.lift { position: fixed; inset: 0; z-index: 50; perspective: 1800px; pointer-events: none; }
.lift-book { position: absolute; transform-style: preserve-3d; filter: drop-shadow(0 18px 30px rgba(40,28,16,.35)); }
.lift-pages { position: absolute; inset: 1.5% 1% 1.5% 1%; background: repeating-linear-gradient(90deg, #f6f1e4 0 3px, #ece5d3 3px 4px); box-shadow: inset 0 0 40px rgba(80,55,25,.18); border-radius: 2px; }
.lift-cover { position: absolute; inset: 0; transform-style: preserve-3d; }
.lift-cover img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.lift-cover.inside img { opacity: 0; }
.lift-cover.inside { background: #e6dcc4; box-shadow: inset 0 0 40px rgba(80,55,25,.25); }
