/* 格物之學 — 書房。顏色與字體全部沿用 nature.css 的變數。 */

.study { position: relative; z-index: 1; }

/* ── 找書列與走道列 ─────────────────────────────── */
.study-bar, .study-nav {
  display: flex; align-items: center; gap: .6rem;
  padding: .4rem 1rem;
}
.study-bar { border-bottom: 1px solid var(--line-soft); }
.study-nav { border-top: 1px solid var(--line-soft); }
.study-bar .chips, .study-nav .chips { flex: 1; min-width: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.study-bar .chips::-webkit-scrollbar, .study-nav .chips::-webkit-scrollbar { display: none; }
.study-bar .chip, .study-nav .chip { flex: none; }

/* 兩條列上的按鈕都不畫框：平常只是字，滑過淡淡一層，選中墊一筆水彩。
   框線留給真的要按下去做事的按鈕，列上才不會擠滿一格一格的方塊。 */
.study-bar .chip, .study-nav .chip {
  min-height: 32px; padding: .15rem .65rem; gap: .35rem;
  border-color: transparent; font-size: .86rem;
}
.study-bar .chip:hover, .study-nav .chip:hover {
  border-color: transparent; background: color-mix(in srgb, var(--ink) 6%, transparent);
}
.study-bar .chip[aria-pressed="true"], .study-nav .chip[aria-current="true"] {
  border-color: color-mix(in srgb, var(--ink) 35%, transparent);
  background: color-mix(in srgb, var(--butter) 26%, transparent);
}
/* 科別｜必選修｜還不懂：中間一條細直線分組 */
.study-bar .chips-gap { flex: none; align-self: center; width: 1px; height: 1.1rem; margin: 0 .35rem; background: var(--line); }
.study-bar .chips { gap: .15rem; }
.study-nav .chips { gap: .1rem; }
.study-nav .chip .dot { width: .55em; height: .5em; }

.study-search {
  flex: none; width: 10rem; padding: .3rem .8rem .3rem 2rem;
  font: inherit; font-size: .9rem; color: var(--ink);
  background: var(--surface) no-repeat .7rem 50% / .95rem
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cg fill='none' stroke='%23857B6C' stroke-width='1.4' stroke-linecap='round'%3E%3Ccircle cx='6.8' cy='6.8' r='4.6'/%3E%3Cpath d='M10.3 10.4l3.6 3.4'/%3E%3C/g%3E%3C/svg%3E");
  border: 1px solid var(--line); border-radius: 999px 880px 940px 860px;
}
.study-search:focus-visible { outline: 1.5px dashed var(--accent); outline-offset: 2px; }
.study-count { flex: none; font-size: .85rem; color: var(--ink-soft); white-space: nowrap; }
.study-count:empty { display: none; }
.study-bar .study-hint-open { margin-left: auto; color: var(--ink-soft); }
.study-bar .study-hint-open::before { content: "?"; display: inline-grid; place-items: center; width: 1.15rem; height: 1.15rem; border: 1px solid currentColor; border-radius: 50%; font-size: .72rem; }

/* ── 房間 ───────────────────────────────────────── */
.study-scroller {
  cursor: default;
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
  outline: none;
}
.study-box { position: relative; }
/* 牆面的墨線濾鏡很貴：整間房自成一層，畫一次之後捲動只是搬動 */
.study-stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.room-zone { position: absolute; top: 0; overflow: visible; pointer-events: none; }
.floor-mark { font: 500 13px var(--font-sans); fill: var(--ink-soft); }

/* ── 書 ─────────────────────────────────────────── */
.book {
  position: absolute; display: block; padding: 0; margin: 0;
  background: none; border: 0; cursor: pointer; color: var(--ink);
  transition: transform .18s ease, opacity .18s ease;
  transform-origin: 50% 100%;
}
.book-art { position: absolute; inset: 0; overflow: visible; }
.book-wash { opacity: .56; }
.book-wash2 { opacity: .2; }
:root[data-theme="dark"] .book-wash { opacity: .42; }
.book-title {
  position: absolute; left: 50%; top: 13px; bottom: 14px; transform: translateX(-50%);
  writing-mode: vertical-rl; text-orientation: mixed;
  font-family: var(--font-read); font-size: 13.5px; line-height: 1.16; letter-spacing: .04em;
  white-space: normal; text-align: start; max-height: calc(100% - 27px);
  pointer-events: none;
}
.book:hover, .book:focus-visible { transform: translateY(-11px) rotate(-.8deg); z-index: 5; }
.book:focus-visible { outline: 1.5px dashed var(--accent); outline-offset: 2px; }
.book.is-dim { cursor: default; opacity: .45; }
.book.is-near { transform: translateY(-9px) rotate(-.8deg); z-index: 5; outline: 1.5px dashed var(--accent); outline-offset: 2px; }
.book.is-taken, .paper.is-taken { visibility: hidden; }
.book.is-flying, .paper.is-flying { z-index: 18; pointer-events: none; visibility: visible; }

/* 走動的人與書梯都不吃滑鼠，點得到後面的書 */
.study-walker, .study-ladder { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; will-change: transform; }
.study-walker { z-index: 12; }
.study-ladder { z-index: 11; }

/* 報紙 */
.paper {
  position: absolute; display: flex; flex-direction: column; padding: 4px 7px 6px; margin: 0;
  background: none; border: 0; color: var(--ink); cursor: pointer; text-align: left;
  transform-origin: 50% 0; transition: transform .18s ease;
}
.paper-art { position: absolute; left: 0; top: 0; overflow: visible; }
.paper > span { position: relative; }
.paper-mast { font-family: var(--font-read); font-size: 11.5px; line-height: 15px; letter-spacing: .1em; }
.paper-date { margin-top: 5px; font-size: 8.5px; line-height: 11px; color: var(--ink-soft); }
.paper-title {
  margin-top: 2px; font-family: var(--font-read); font-size: 11.5px; line-height: 1.32;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; overflow: hidden;
}
.paper:hover, .paper:focus-visible { transform: rotate(-2deg) translateY(2px); z-index: 5; }
.paper:focus-visible, .paper.is-near { outline: 1.5px dashed var(--accent); outline-offset: 2px; }
.rack-all { margin-left: auto; font: 500 12px var(--font-sans); color: var(--accent-ink); white-space: nowrap; }

/* 書籤與 ✓ */
.book-mark { display: none; position: absolute; pointer-events: none; }
.book.is-stuck .book-mark {
  display: block; right: 4px; top: -9px; width: 7px; height: 26px;
  background: var(--warn); opacity: .9;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 84%, 0 100%);
}
.book.is-got .book-mark {
  display: flex; align-items: center; justify-content: center;
  left: 50%; bottom: 13px; width: 14px; height: 14px; margin-left: -7px;
  border-radius: 50%; background: var(--ok); color: #fff; font: 700 9px/1 var(--font-sans);
}
.book.is-got .book-mark::before { content: "✓"; }

/* 篩選時，其他書退到背景 */
.is-filtering .book.is-off { opacity: .16; }
.is-filtering .book.is-hit { transform: translateY(-4px); }

/* 實驗室的門 */
.lab-door { position: absolute; display: block; color: var(--ink); text-decoration: none; transition: transform .18s ease; transform-origin: 0 100%; }
.lab-door:hover { transform: skewY(-.8deg); }
.lab-door:focus-visible { outline: 1.5px dashed var(--accent); outline-offset: 2px; }
.lab-door-sign {
  position: absolute; left: 50%; top: 4px; transform: translateX(-50%) rotate(-1deg);
  padding: 0 .55rem; font: 400 15px/24px var(--font-read); letter-spacing: .14em; white-space: nowrap;
  background: var(--surface); border: 1px solid color-mix(in srgb, var(--ink) 70%, transparent);
}

/* ── 公佈欄上的贊助海報（廣告版位） ───────────────── */
.wall-ad {
  position: absolute; display: flex; flex-direction: column; color: var(--ink); text-decoration: none;
  transform: rotate(-1.2deg); transform-origin: 50% 0; transition: transform .18s ease;
}
.wall-ad:hover { transform: rotate(-2.2deg) translateY(2px); }
.wall-ad:focus-visible { outline: 1.5px dashed var(--accent); outline-offset: 3px; }
.wall-ad > .paper-art { position: absolute; left: 0; top: 0; overflow: visible; }
.wall-ad-pin {
  position: absolute; left: 50%; top: -5px; width: 11px; height: 11px; margin-left: -5px;
  border-radius: 50%; background: var(--s-chem); box-shadow: inset -2px -2px 0 rgba(0, 0, 0, .18);
}
.wall-ad-label {
  position: absolute; right: 8px; top: 30px; z-index: 1;
  font-size: 9.5px; letter-spacing: .2em; color: var(--ink-faint);
}
.wall-ad-body {
  position: relative; flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 8px;
  padding: 44px 16px 16px; text-align: center; line-height: 1.45;
}
.wall-ad-body b { font: 400 17px/1.35 var(--font-read); color: var(--ink); }
.wall-ad-body span { font-size: 12px; color: var(--ink-soft); }
.wall-ad-body em { font-style: normal; font-size: 12.5px; font-weight: 500; color: var(--accent-ink); }
.wall-ad-body img { width: 100%; height: 100%; object-fit: contain; }
.wall-ad.is-live .wall-ad-body { padding: 36px 10px 10px; }

/* ── 櫃子上的字 ──────────────────────────────────── */
.case-head { position: absolute; top: 10px; line-height: 1.3; }
.case-head { scroll-margin-left: 1rem; }
.case-name { margin: 0; display: flex; align-items: baseline; gap: .4rem; flex-wrap: wrap; font-family: var(--font-read); font-size: 18px; }
.case-name .scale-drop { align-self: center; }
.case-meta { font: 400 11.5px var(--font-sans); color: var(--ink-soft); white-space: nowrap; }
.case-blurb { margin: .2rem 0 0; font-size: 12.5px; color: var(--ink-soft); }
.shelf-tag {
  position: absolute; padding: 0 5px; line-height: 15px; height: 15px;
  background: var(--surface); border: 1px solid color-mix(in srgb, var(--ink) 55%, transparent);
  font-size: 10px; color: var(--ink-soft); white-space: nowrap; pointer-events: none;
  z-index: 2;
}

/* ── 書桌那一面牆 ────────────────────────────────── */
.desk-vase { position: absolute; left: 610px; top: 0; width: 320px; height: 356px; pointer-events: none; }
.desk-vase .deco { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; z-index: 0; }

/* ── 可以關掉的提示 ──────────────────────────────── */
.study-title { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.study-hint {
  position: fixed; z-index: 30; left: 1rem; bottom: 4.4rem; width: min(320px, calc(100vw - 2rem));
  padding: 14px 18px 12px;
  background: var(--surface); border: 1px solid color-mix(in srgb, var(--ink) 70%, transparent);
  border-radius: 4px 7px 5px 8px;
  transform: rotate(-.5deg);
  line-height: 1.5;
  max-height: calc(100dvh - 9rem); overflow-y: auto;
}
.study-hint[hidden] { display: none; }
.study-hint h2 { font-size: 26px; margin: 0 2rem 4px 0; }
.study-hint-close {
  position: absolute; top: 4px; right: 4px; width: 44px; height: 44px; padding: 0;
  background: none; border: 0; color: var(--ink-soft); font: 400 24px/1 var(--font-sans); cursor: pointer;
}
.study-hint-close:hover { color: var(--ink); }
.study-hint-close:focus-visible { outline: 1.5px dashed var(--accent); outline-offset: -4px; }
.study-hint-open { flex: none; }
.wall-lede { margin: 0 0 8px; font-family: var(--font-read); font-size: 14.5px; color: var(--ink-soft); }
.wall-key { display: flex; flex-wrap: wrap; gap: 3px 10px; font-size: 12.5px; margin-bottom: 6px; }
.key-item { display: inline-flex; align-items: center; gap: 4px; }
.key-swatch { width: 11px; height: 15px; border: 1px solid var(--ink); opacity: .7; }
.wall-hint { margin: 0; font-size: 12px; color: var(--ink-soft); }
.wall-progress { margin: 6px 0 0; font-size: 12.5px; font-weight: 500; }

/* ── 滑過書背的小標籤 ────────────────────────────── */
.book-tip {
  position: absolute; z-index: 20; max-width: 230px; padding: 6px 10px;
  display: flex; flex-direction: column; gap: 1px;
  background: var(--surface); border: 1px solid var(--ink);
  border-radius: 4px 7px 5px 8px;
  font-size: 12.5px; line-height: 1.45; color: var(--ink-soft);
  pointer-events: none;
}
.book-tip[hidden] { display: none; }
.book-tip b { font-family: var(--font-read); font-weight: 400; font-size: 15px; color: var(--ink); }
.book-tip em { font-style: normal; color: var(--accent-ink); font-weight: 500; }

/* ── 翻開的書 ────────────────────────────────────── */
.open-book {
  width: min(900px, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem);
  padding: 0; border: 0; background: transparent; color: var(--ink); overflow: auto;
}
.open-book::backdrop { background: color-mix(in srgb, var(--dusk) 55%, transparent); }
.open-book[open] { animation: book-open .24s ease both; }
@keyframes book-open { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
.spread {
  position: relative; display: grid; grid-template-columns: 1fr 1fr;
  background: var(--surface);
  border: 1.2px solid var(--ink); border-radius: 4px 9px 6px 10px;
  border-left: 9px solid color-mix(in srgb, var(--uc) 62%, var(--surface));
  border-right: 9px solid color-mix(in srgb, var(--uc) 62%, var(--surface));
}
.page { position: relative; padding: 1.6rem 1.7rem 1.4rem; min-width: 0; line-height: 1.6; }
.page-left {
  overflow: hidden; display: flex; flex-direction: column; min-height: 25rem;
  border-right: 1px solid var(--line);
  background: linear-gradient(to left, color-mix(in srgb, var(--ink) 7%, transparent), transparent 2.2rem);
}
.page-right { background: linear-gradient(to right, color-mix(in srgb, var(--ink) 7%, transparent), transparent 2.2rem); }
.page-deco { position: absolute; right: 0; bottom: 0; width: 72%; height: auto; pointer-events: none; z-index: 0; overflow: visible; }
.page-deco .wc { mix-blend-mode: var(--wc-blend); }
.page-left > :not(.page-deco) { position: relative; z-index: 1; }
.spread-title { margin: .9rem 0 .35rem; font-size: clamp(1.6rem, 3.4vw, 2.1rem); }
.spread-sub { margin: 0 0 .5rem; }
.spread-status { margin: 0; font-size: .92rem; font-weight: 500; color: var(--accent-ink); }
.spread-actions { margin-top: auto; padding-top: 1.1rem; display: flex; flex-wrap: wrap; gap: .5rem; }
.spread-actions .btn { background-color: var(--surface); }

.toc-title { margin: 0 0 .35rem; font-family: var(--font-read); font-size: 1.15rem; }
.toc { list-style: none; counter-reset: toc; margin: 0; padding: 0; }
.toc li { counter-increment: toc; border-bottom: 1px dotted var(--line); }
.toc a, .toc li > span {
  display: grid; grid-template-columns: 1.3rem 5.2rem 1fr; align-items: baseline; gap: .2rem;
  padding: .3rem 0; color: inherit; text-decoration: none;
}
.toc a::before, .toc li > span::before { content: counter(toc); font-size: .78rem; color: var(--ink-faint); }
.toc a:hover .toc-label { text-decoration: underline; text-underline-offset: 3px; }
.toc-label { font-family: var(--font-read); font-size: .98rem; }
.toc-hint { font-size: .76rem; color: var(--ink-soft); }
.near-title { margin-top: 1rem; font-size: 1rem; }
.near { gap: .35rem; }
.near .chip { font-size: .82rem; }
.spread-codes { margin: .9rem 0 0; font-size: .75rem; }

/* 攤開的報紙 */
.is-paper { width: min(640px, calc(100vw - 2rem)); }
.is-paper .spread { display: block; border-left-width: 1.2px; border-right-width: 1.2px; }
.newspaper { padding: 1.3rem 1.8rem 1.5rem; min-height: 0; }
.news-mast { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding-bottom: .4rem; border-bottom: 3px double var(--ink); }
.news-mast-name { font-family: var(--font-read); font-size: 1.65rem; letter-spacing: .24em; }
.news-mast-date { font-size: .85rem; color: var(--ink-soft); }
.news-head { margin: 1rem 0 .6rem; font-size: clamp(1.3rem, 3.2vw, 1.8rem); }
.news-summary { margin: .9rem 0 0; font-family: var(--font-read); font-size: 1.04rem; line-height: 1.75; }

.study-foot { padding: 1.2rem 0 1.6rem; color: var(--ink-faint); font-size: .85rem; text-align: center; }
.study-page > .ad-slot { margin-block: 1.6rem .4rem; }
.study-foot p { margin: 0 0 .5rem; }

@media (max-width: 719px) {
  /* 手機的人站在畫面下半，提示放上面才不會擋住他 */
  .study-hint { top: 10.75rem; bottom: auto; }
  .study-bar { flex-wrap: wrap; padding: .35rem .75rem; gap: .35rem .5rem; }
  .study-search { flex: 1; width: auto; min-width: 0; }
  .study-bar .chips { flex-basis: 100%; order: 2; }
  .study-nav { padding: .35rem .75rem; }
  .spread { grid-template-columns: 1fr; border-left-width: 6px; border-right-width: 6px; }
  .page { padding: 1.2rem 1.1rem 1rem; }
  .page-left { min-height: 15rem; border-right: 0; border-bottom: 1px solid var(--line); background: none; }
  .page-right { background: none; }
  .page-deco { width: 58%; }
}

@media (prefers-reduced-motion: reduce) {
  .book { transition: none; }
  .open-book[open] { animation: none; }
}
