/* The bookshelf (member request, Ethan: "add a bookshelf to the lobby ... add a copy of the I Ching ... throw coins").
   See DESIGN.md "The bookshelf". A walnut case of spines under the section bar; books and the I Ching read on white
   paper; the coins are thrown on the letterboard's red felt. */
.bk {
  --bk-night: #000000; --bk-wood: #2e140b; --bk-side: #5a2c16; --bk-lip: #7a4124; --bk-board: #5a2c16; --bk-cream: #efe6d8;
  --bk-ink: #0b1a2e;
  position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h); z-index: 30; display: flex; flex-direction: column;
  background: var(--bk-night); color: var(--bk-ink); font-family: var(--font);
  opacity: 0; transition: opacity .18s;
  /* the pages are always paper and ink, dark mode too (like the chat) */
  --ink: #0b1a2e; --ink-2: #4a5f7d; --ink-3: #8694a9; --rule: #d2dcec; --note: #e6eeff; --note-ink: #0d254a; --paper: #fff; --red: #1259d3;
}
.bk.in { opacity: 1; }
body.tabs-on .bk { top: calc(var(--app-top, 0px) + var(--tabs-y, 0px)); height: calc(var(--app-h) - var(--tabs-y, 0px)); max-width: 760px; margin: 0 auto; }
body.in-books { background: #000000; }
.bk :focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }

.bk-top { flex: none; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2.2fr) minmax(0, 1fr); align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px; background: var(--bk-night); border-bottom: 3px solid var(--bk-side); }
body.tabs-on .bk-top { padding-top: 8px; }
.bk-title { margin: 0; text-align: center; color: #fff; font-size: 19px; font-weight: 700; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bk-back { justify-self: start; min-height: 40px; padding: 0 14px; border: 0; background: #3d1c0f; color: #fff; font-weight: 700; font-size: 15px; }
.bk-act { justify-self: end; }
.bk-add-btn { min-height: 40px; padding: 0 12px; border: 0; background: var(--red); color: #fff; font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.bk-add-btn svg { width: 15px; height: 15px; flex: none; }

.bk-body { position: relative; flex: 1; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; background: #fff; padding-bottom: var(--sab); }
.bk[data-view="shelf"] .bk-body { background: var(--bk-night); }
.bk[data-view="book"] .bk-body { background: #eef1f6; }
.bk-wait, .bk-gone { margin: 40px 20px; text-align: center; color: var(--ink-2); }
.bk[data-view="shelf"] .bk-gone { color: var(--bk-cream); }

/* ---------- the case ---------- */
/* Each shelf is 206px: 190 of room for the books, then the board (a lighter lip on its front edge). The spines stand
   on the boards: each one's top margin makes up the difference to its height. */
.bk-case { margin: 14px 10px 0; background: var(--bk-wood); border: solid var(--bk-side); border-width: 10px 10px 0; }
.bk-books { display: flex; flex-wrap: wrap; align-items: flex-start; align-content: flex-start; column-gap: 3px; padding: 0 8px; min-height: 618px;
  background: repeating-linear-gradient(to bottom, transparent 0 190px, var(--bk-lip) 190px 193px, var(--bk-board) 193px 206px); }
.bk-spine { position: relative; flex: none; width: var(--w); height: var(--h); margin: calc(190px - var(--h)) 0 16px; padding: 14px 0 9px; border: 0;
  background: linear-gradient(var(--fg), var(--fg)) 0 7px / 100% 2px no-repeat, var(--bg); color: var(--fg);
  display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 6px; transition: transform .16s ease-out; }
.bk-spine.band1 { background: linear-gradient(var(--fg), var(--fg)) 0 7px / 100% 2px no-repeat, linear-gradient(var(--fg), var(--fg)) 0 calc(100% - 28px) / 100% 2px no-repeat, var(--bg); }
.bk-spine.band2 { background: linear-gradient(var(--fg), var(--fg)) 0 0 / 100% 5px no-repeat, linear-gradient(var(--fg), var(--fg)) 0 calc(100% - 28px) / 100% 5px no-repeat, var(--bg); }
.bk-sp-t { writing-mode: vertical-rl; font-weight: 700; font-size: 14px; line-height: 1.15; max-height: calc(var(--h) - 52px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bk-sp-f { font-size: 10.5px; font-weight: 700; line-height: 1; opacity: .85; }
.bk-spine.pulled { transform: translateY(-16px); }
.bk-spine.fresh { animation: bk-shelved .5s ease-out; }
@keyframes bk-shelved { from { transform: translateY(-40px); opacity: 0; } }
@media (hover: hover) { .bk-spine:hover { transform: translateY(-6px); } }
/* the I Ching: a black thread-bound volume, white stitches down its edge, a red title slip */
.bk-spine.ich { --w: 64px; --h: 184px; --bg: #15110f; --fg: #efe6d8; background: #15110f; padding-top: 12px; }
.bk-spine.ich::before { content: ""; position: absolute; left: 6px; top: 8px; bottom: 8px; border-left: 2px dashed #efe6d8; opacity: .7; }
.bk-slip { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 30px; padding: 7px 0; background: #1150b8; color: #fff; font: 400 19px/1 "Songti SC", "STSong", "Noto Serif CJK SC", "Noto Serif SC", "SimSun", serif; }
.bk-slip b { font-weight: 400; }
.bk-spine.ich .bk-sp-t { font-size: 12.5px; }
.bk-empty { flex: 1 0 100%; height: 190px; margin: 0 0 16px; display: flex; align-items: flex-end; padding: 0 4px 12px; color: var(--bk-cream); font-size: 15px; line-height: 1.35; opacity: .85; }
.bk-foot { margin: 12px 16px 24px; color: var(--bk-cream); opacity: .75; font-size: 14px; text-align: center; }

/* a link (member request, henry): a red bookmark ribbon hangs from the top of the spine down over its foot, a notch
   cut in its tail */
.bk-spine.web::after, .bk-mini.web::before { content: ""; position: absolute; right: 7px; top: 0; width: 7px; height: calc(100% + 12px); z-index: 1;
  background: #1259d3; clip-path: polygon(0 0, 100% 0, 100% 100%, 50% calc(100% - 5px), 0 100%); pointer-events: none; }
.bk-spine.web { width: calc(var(--w) + 8px); padding-right: 14px; }
.bk-mini.web::before { right: 3px; width: 5px; height: calc(100% + 8px); }
.bk-mini.big.web::before { right: 7px; width: 9px; height: calc(100% + 16px); }

/* a little spine, in chat cards and the add form */
.bk-mini { flex: none; display: inline-block; position: relative; width: 16px; height: 44px; background: var(--bg, #0c2b5a); margin-right: 26px; }
.bk-mini::after { content: ""; position: absolute; left: 18px; bottom: 0; width: 11px; height: 36px; background: #15110f; }
.bk-mini.big { width: 34px; height: 96px; margin: 0 26px 16px 0; }
.bk-mini.big::after { left: 38px; width: 24px; height: 80px; }

/* ---------- adding a book ---------- */
.bk-pick { display: flex; align-items: center; width: 100%; padding: 14px 14px; border: 1.5px dashed var(--ink-3); background: var(--note); color: var(--ink-2); font: inherit; font-size: 15px; line-height: 1.3; text-align: left; }
.bk-pick b { color: var(--ink); font-size: 17px; }
.bk-pick .bk-mini { margin-right: 22px; }
.bk-or { margin: 2px 0 -4px; color: var(--ink-2); font-size: 14px; text-align: center; }
.bk-form { position: absolute; inset: 0; z-index: 3; display: flex; align-items: flex-end; background: rgba(28, 11, 6, .6); }
.bk-form-card { width: 100%; max-width: 560px; margin: 0 auto; background: #fff; color: var(--ink); padding: 18px 16px calc(14px + var(--sab)); border-radius: 20px 20px 0 0; display: grid; gap: 12px; }
.bk-form-file { display: flex; align-items: center; font-size: 15px; color: var(--ink-2); overflow-wrap: anywhere; line-height: 1.3; }
.bk-form-file b { color: var(--ink); }
.bk-form label, .ich-qlabel { display: block; font-weight: 700; font-size: 15px; }
.bk-opt { font-weight: 400; color: var(--ink-2); }
.bk-form input, .ich-q { display: block; width: 100%; margin-top: 6px; padding: 11px 12px; font-size: 17px; background: #fff; color: var(--ink); border: 1.5px solid var(--rule); border-radius: 10px; }
.bk-prog { height: 6px; background: var(--note); }
.bk-prog i { display: block; height: 100%; width: calc(var(--p, 0) * 100%); background: var(--red); transition: width .2s; }
.bk-form-row { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- reading a book ---------- */
.bk-head { max-width: 680px; margin: 0 auto; padding: 16px 14px 14px; }
.bk-head h2 { margin: 0; font-size: 22px; line-height: 1.25; overflow-wrap: anywhere; }
.bk-by { display: block; font-size: 16px; margin-top: 2px; }
.bk-who { display: block; font-size: 14px; color: var(--ink-2); margin-top: 4px; }
.bk-who b { color: var(--c, var(--ink)); }
.bk-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.bk-tool { min-width: 44px; min-height: 40px; padding: 0 12px; border: 0; background: var(--note); color: var(--note-ink); font-weight: 700; font-size: 18px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.bk-tool.wide { font-size: 15px; }
.bk-tool.danger { color: #b42318; }
.bk-pdf { width: calc(100% * var(--z, 1)); padding: 0 10px 20px; }
.bk-page { position: relative; width: 100%; max-width: calc(820px * var(--z, 1)); aspect-ratio: 1 / var(--a, 1.294); margin: 0 auto 10px; background: #fff; outline: 1px solid #d2dcec; }
.bk-page canvas { display: block; width: 100%; height: 100%; }
.bk-pn { position: absolute; left: 50%; top: 45%; transform: translateX(-50%); color: #c3ccd9; font-weight: 700; font-size: 28px; }
.bk-page.drawn .bk-pn { display: none; }
.bk-pageno { position: sticky; bottom: 12px; left: 12px; width: max-content; margin: 0 12px 12px auto; padding: 5px 10px; background: var(--ink); color: #fff; font-weight: 700; font-size: 13px; pointer-events: none; }
.bk-text { max-width: 660px; margin: 0 auto 30px; padding: 22px 20px 40px; background: #fff; font-size: 18px; line-height: 1.6; overflow-wrap: anywhere; }
.bk-text p { margin: 0 0 1em; }
.bk-text h2, .bk-text h3, .bk-text h4 { line-height: 1.25; margin: 1.3em 0 .5em; }
.bk-text code { font-size: .9em; background: var(--note); padding: 0 .2em; }
.bk-other { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 36px 20px; color: var(--ink-2); }
.bk-other .btn { text-decoration: none; max-width: 100%; overflow-wrap: anywhere; }
.bk-who a { color: inherit; }
/* a link book: the page's card, on paper */
.bk-link { max-width: 560px; margin: 18px auto 30px; padding: 26px 22px 22px; background: #fff; outline: 1px solid var(--rule); overflow-wrap: anywhere; }
.bk-link .bk-mini.big { margin: 0 0 22px; }
.bk-site { margin: 0 0 4px; color: var(--red); font-weight: 700; font-size: 15px; }
.bk-link h2 { margin: 0; font-size: 26px; line-height: 1.2; }
.bk-link .bk-by { color: var(--ink-2); margin-top: 6px; }
.bk-blurb { margin: 14px 0 0; font-size: 17px; line-height: 1.55; }
.bk-go { display: flex; justify-content: center; margin-top: 22px; text-decoration: none; font-size: 17px; }
.bk-url { margin: 8px 0 0; color: var(--ink-3); font-size: 13px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bk-link .bk-who { margin-top: 18px; padding-top: 12px; border-top: 1.5px solid var(--rule); }
.bk-link .bk-tools { margin-top: 10px; }

/* ---------- the I Ching ---------- */
.ich-seg { display: flex; margin: 14px 14px 0; }
.ich-seg button { flex: 1; min-height: 44px; border: 0; background: var(--note); color: var(--note-ink); font-weight: 700; font-size: 16px; }
.ich-seg button[aria-selected="true"] { background: var(--ink); color: #fff; }
.ich-cast { max-width: 520px; margin: 0 auto; padding: 4px 16px 28px; }
.ich-lead { margin: 12px 0 12px; font-size: 15px; line-height: 1.4; color: var(--ink-2); }
/* the coins are thrown on the letterboard's red felt, and the hexagram builds on it in white; changing lines go ink */
.ich-table { margin: 14px 0 0; padding: 20px 14px 14px; background: #1150b8; --hole: #1150b8; color: #fff; }
.ich-coins { cursor: pointer; }
.ich-coins { display: flex; justify-content: center; gap: 18px; }
.coin { position: relative; z-index: 2; width: 78px; height: 78px; perspective: 520px; }
.coin-in { position: absolute; inset: 0; transform-style: preserve-3d; }
.coin-f { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.coin-f.yang { transform: rotateX(180deg); }
.coin-f svg { display: block; width: 100%; height: 100%; }
.ich-sum { min-height: 1.4em; margin: 10px 0 0; text-align: center; font-weight: 700; font-size: 16px; line-height: 1.4; }
.ich-build { display: flex; flex-direction: column-reverse; gap: 6px; width: 230px; margin: 10px auto 16px; }
.ich-slot { display: grid; grid-template-columns: 16px 1fr 44px; align-items: center; gap: 10px; }
.ich-slot-n { font-size: 12px; line-height: 1; text-align: right; opacity: .7; }
.ich-slot-bar { height: 12px; background: rgba(255, 255, 255, .16); }
.ich-slot-v { font-weight: 700; font-size: 14px; line-height: 1; }
.ich-slot.next .ich-slot-bar { outline: 2px solid #fff; outline-offset: -2px; }
.ich-slot.on .ich-slot-bar { transform-origin: 50% 50%; animation: ich-draw .35s ease-out; }
.ich-slot.yang .ich-slot-bar { background: #fff; }
.ich-slot.yin .ich-slot-bar { background: linear-gradient(to right, #fff 0 42%, transparent 42% 58%, #fff 58%); }
.ich-slot.ch.yang .ich-slot-bar { background: #0b1a2e; }
.ich-slot.ch.yin .ich-slot-bar { background: linear-gradient(to right, #0b1a2e 0 42%, transparent 42% 58%, #0b1a2e 58%); }
.ich-slot.ch .ich-slot-v { color: #0b1a2e; }
@keyframes ich-draw { from { transform: scaleX(0); } }
.ich-throw { display: block; width: 100%; min-height: 52px; font-size: 18px; background: #fff; color: #1150b8; }

.ich-reading { max-width: 620px; margin: 0 auto; padding: 20px 18px 34px; }
.ich-asked { margin: 0; font-size: 14px; font-weight: 700; color: var(--ink-2); }
.ich-question { margin: 4px 0 18px; padding-left: 12px; border-left: 4px solid var(--red); font-size: 22px; line-height: 1.3; font-weight: 700; overflow-wrap: anywhere; }
.ich-pair { display: flex; align-items: center; gap: 16px; margin: 6px 0 16px; }
.ich-hex { display: block; color: var(--ink); }
.ich-hex.big { width: 136px; }
.ich-hex.small { width: 76px; color: var(--ink-2); }
.ich-becomes { font-size: 14px; font-weight: 700; color: var(--ink-2); }
.ich-name { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0; font-size: 28px; line-height: 1.15; }
h4.ich-name { font-size: 22px; }
.ich-n { color: var(--red); font-weight: 700; }
.ich-zh { font: 400 1.05em/1 "Songti SC", "STSong", "Noto Serif CJK SC", "Noto Serif SC", "SimSun", serif; }
.ich-tri { margin: 4px 0 0; font-size: 15px; color: var(--ink-2); }
.ich-gist { margin: 14px 0 6px; font-size: 19px; line-height: 1.4; font-weight: 700; }
.ich-reading h3 { margin: 24px 0 6px; font-size: 15px; color: var(--red); }
.ich-legge { margin: 0; font-size: 17px; line-height: 1.6; }
.lg-add { color: var(--ink-2); }
.ich-line { margin: 10px 0; padding: 10px 12px; background: var(--note); border-radius: 4px; }
.ich-line b { display: block; font-size: 14px; color: var(--note-ink); }
.ich-line p { margin: 4px 0 0; font-size: 17px; line-height: 1.55; }
.ich-still { margin: 20px 0 0; color: var(--ink-2); }
.ich-to { margin-top: 28px; padding-top: 4px; border-top: 1.5px solid var(--rule); }
.ich-end { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 28px; }
.ich-src { margin: 22px 0 0; font-size: 13px; line-height: 1.4; color: var(--ink-2); }
.ich-list + .ich-src { margin: 0 16px 24px; }
.ich-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; padding: 14px; }
.ich-cell { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 12px 4px 9px; border: 0; background: var(--note); color: var(--ink); }
.ich-cell .ich-hex { width: 38px; }
.ich-cell-n { font-weight: 700; font-size: 14px; line-height: 1; color: var(--red); }
.ich-cell-t { font-size: 12.5px; line-height: 1.2; text-align: center; overflow-wrap: anywhere; }
.ich-nav { display: flex; justify-content: space-between; gap: 8px; margin-top: 26px; }

/* ---------- chat cards ---------- */
.bk-card { display: flex; align-items: center; gap: 0; margin: 12px 4px; padding: 10px 12px; background: var(--paper); border: 1px solid var(--rule); border-radius: 10px; }
.bk-card .txt { flex: 1; min-width: 0; font-size: 15px; color: var(--ink-2); overflow-wrap: anywhere; margin-right: 12px; }
.bk-card .txt b { color: var(--ink); }
.bk-card .btn { flex: none; }
.ich-card { display: flex; gap: 14px; max-width: 480px; margin: 12px 4px; padding: 14px; background: #fff; border: 1.5px solid var(--rule); border-radius: 4px; color: var(--ink); }
.ich-card > .ich-hex { flex: none; align-self: flex-start; width: 58px; margin-top: 6px; }
.ich-card-body { flex: 1; min-width: 0; }
.ich-card-who { font-size: 14px; font-weight: 700; color: var(--ink-2); }
.ich-card-q { margin: 6px 0 8px; padding-left: 9px; border-left: 3px solid var(--red); font-size: 16px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.ich-card-name { margin-top: 2px; font-size: 19px; font-weight: 700; line-height: 1.25; }
.ich-card-gist { margin: 4px 0 0; font-size: 15px; line-height: 1.4; }
.ich-card-ch { margin: 6px 0 0; font-size: 14px; line-height: 1.35; color: var(--ink-2); }
.ich-card-ch b { color: var(--ink); }
.ich-card-go { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ich-card-go .btn.quiet, .ich-end .btn.quiet, .ich-nav .btn.quiet { background: var(--note); color: var(--note-ink); }

@media (prefers-reduced-motion: reduce) {
  .bk, .bk-spine { transition: none; }
  .bk-spine.fresh, .ich-slot.on .ich-slot-bar { animation: none; }
}
