/* 屋根裏の音楽部屋 ── 棚の大写し・盤・針・札（2026-11-06）
   動きは attic-shelf.js が Web Animations API で付ける。ここは見た目と、動かさない状態を持つ。
   色（背表紙・ラベル）は JS が --spine / --spine-ink / --label を渡す */
:root {
  --shelf-h: clamp(90px, 22vh, 180px);   /* 背表紙の列の高さ（背景の棚の、上の板と中の棚板のあいだに収める） */
  --shelf-bg-w: max(100vw, calc((100vh - var(--bar-h)) * 1.7917)); /* 背景（cover）の見えている幅。2752×1536 */
  --shelf-bg-x: calc((100vw - var(--shelf-bg-w)) / 2 + var(--shelf-bg-w) * .095); /* 背景の左の側板の内側まで */
  --shelf-board2-y: 11%;         /* 下の板の上面から、画面の下までの割合 */
  --shelf-board-y: 55.5%;        /* 背景の中の棚板の上面（高さ約 44%）から、画面の下までの割合 */
  --stage-s: min(24vh, 62vw, 260px); /* 取り出したジャケットの一辺 */
  --shelf-spin: 1.8s;            /* 盤の 1 周（33⅓ 回転） */
  --shelf-fade: 350ms;           /* 棚 → 部屋 の切り替え（JS が動かす設定に合わせて書き換える） */
  --shelf-wood: #5a3b22;
  --shelf-open-min-h: 0px;       /* 棚を開いている間、部屋（body）に持たせる最低の高さ。額縁（iframe）が body に合わせて伸びる。狭い幅だけ下で上げる */
  --shelf-head-ink: #fbe9cc;     /* 棚の見出し・閉じるの文字（暗い木の上で読める明るい色） */
  --shelf-head-shade: rgba(14, 8, 3, .55); /* 見出しの帯の下地 */
}
body.shelf-open { box-sizing: border-box; min-height: var(--shelf-open-min-h); }

/* 土台: 上のバー（z-index 20）の下・部屋（#room）の外に重ねる。クリックは下の部屋に抜けない */
.shelf-root { position: fixed; top: var(--bar-h); left: 0; right: 0; bottom: 0; z-index: 15; display: flex; flex-direction: column;
  background: rgba(20, 14, 10, .94); color: var(--ink); transition: background-color var(--shelf-fade) ease, opacity .4s ease; }
.shelf-root[hidden] { display: none; }
.shelf-root.phase-room { background: transparent; }
.shelf-root.out { opacity: 0; }

.shelf-pane-shelf { position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0; transition: opacity var(--shelf-fade) ease;
  /* 描いた空の棚。cover ＋ 縦 43.8% 揃えなので、どの画面の形でも中の棚板は高さ約 44% に来る */
  background-color: #3a2414; background-image: linear-gradient(rgba(12, 7, 3, .16), rgba(12, 7, 3, .16)), url("shelf/shelf-bg-1600.webp");
  background-position: 0 0, 50% 43.8%; background-size: auto, cover; background-repeat: no-repeat; }
.shelf-root.phase-room .shelf-pane-shelf { opacity: 0; pointer-events: none; }

.shelf-head { position: relative; z-index: 2; color: var(--shelf-head-ink); background: var(--shelf-head-shade); font-weight: 600; text-shadow: 0 1px 3px rgba(0, 0, 0, .9); display: flex; align-items: center; gap: 12px; padding: 10px 16px; font-size: 14px; letter-spacing: .08em; }
.shelf-head-title { flex: 1; }
.shelf-close { background: rgba(14, 8, 3, .6); color: var(--shelf-head-ink); border: 1px solid rgba(251, 233, 204, .7); border-radius: 14px; padding: 2px 14px; font-size: 13px; line-height: 20px; cursor: pointer; }
.shelf-close:hover { background: rgba(251, 233, 204, .28); }

/* 取り出したジャケット・内袋・盤（奥から 盤 → 内袋 → ジャケット） */
.shelf-stage-area { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; perspective: 1100px; }
.shelf-stage-area[hidden] { display: none; }
.shelf-stage { position: relative; width: var(--stage-s); height: var(--stage-s); margin-top: calc(var(--stage-s) * .7); transform-style: preserve-3d; }
.shelf-jacket, .shelf-sleeve { position: absolute; inset: 0; border-radius: 2px; box-shadow: 0 8px 22px rgba(0, 0, 0, .55); }
.shelf-jacket { z-index: 3; background: var(--spine); color: var(--spine-ink); overflow: hidden; }
.shelf-jacket-fallback { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .4em; padding: 10%; text-align: center; font-size: 14px; line-height: 1.4; }
.shelf-jacket-fallback b { font-size: 1.1em; }
.shelf-cover { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .3s ease; }
.shelf-cover.ready { opacity: 1; }
.shelf-sleeve { z-index: 2; background: #f4efe6; box-shadow: 0 4px 12px rgba(0, 0, 0, .4), inset 0 0 0 1px rgba(0, 0, 0, .08); }
.shelf-disc-stage { position: absolute; z-index: 1; left: 3%; top: 3%; width: 94%; height: 94%; }

/* 盤（SVG）── 内袋から出るときも、プレーヤーの上でも同じ絵 */
.disc-rot-wrap { width: 100%; height: 100%; }
.disc-svg { display: block; width: 100%; height: 100%; }
.d-body { fill: #14110f; }
.d-groove { fill: none; stroke: rgba(255, 255, 255, .07); stroke-width: .8; }
.d-sheen { fill: rgba(255, 255, 255, .09); }
.d-label { fill: var(--label, #c4956a); }
.d-ring { fill: none; stroke: rgba(0, 0, 0, .35); stroke-width: 1; }
.d-notch { fill: rgba(255, 255, 255, .85); }
.d-spindle { fill: #e9e4da; }

/* 背表紙の列（横に流せる） */
.shelf-caption { position: absolute; left: 0; right: 0; top: 11.5%; z-index: 1; min-height: 3em; padding: 2px 16px; text-align: center; font-size: 14px; line-height: 1.4; pointer-events: none; text-shadow: 0 1px 3px rgba(0, 0, 0, .8); }
.shelf-caption .kind { display: inline-block; margin-right: .6em; padding: 0 .6em; border: 1px solid rgba(196, 149, 106, .6); border-radius: 10px; font-size: 11px; vertical-align: 1px; }
.shelf-caption .hint { display: block; font-size: 12px; opacity: .7; }
/* PC 幅（481px 以上）: 42 盤を上下 2 段に分けて全部を一度に見せる。上の段は中の棚板の上、下の段は下の板の上面に立つ */
.shelf-row { position: absolute; left: max(0px, var(--shelf-bg-x)); right: max(0px, var(--shelf-bg-x)); top: 0; bottom: 0; z-index: 1; pointer-events: none; }
.shelf-tier { position: absolute; left: 0; right: 0; height: var(--shelf-h); box-sizing: border-box; padding: 0 8px; pointer-events: auto;
  display: flex; align-items: flex-end; gap: 3px; overflow-x: auto; overflow-y: visible; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.shelf-tier::-webkit-scrollbar { display: none; }
.shelf-tier-1 { bottom: var(--shelf-board-y); }
.shelf-tier-2 { bottom: var(--shelf-board2-y); }
.shelf-row.dim { opacity: .3; pointer-events: none; transition: opacity .3s ease; }
.shelf-spine { flex: 0 0 auto; width: var(--w, 34px); height: calc(var(--shelf-h) * var(--k, 1)); padding: 0; border: 0; border-radius: 2px 2px 0 0;
  background: var(--spine); color: var(--spine-ink); display: flex; flex-direction: column; align-items: center; overflow: hidden; cursor: pointer;
  box-shadow: inset -2px 0 0 rgba(0, 0, 0, .28), inset 1px 0 0 rgba(255, 255, 255, .14), 2px 0 5px rgba(0, 0, 0, .4); transition: transform .25s ease; }
.shelf-spine img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.shelf-spine-title { flex: 1; min-height: 0; padding: 6px 0; writing-mode: vertical-rl; font-size: 12px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shelf-spine:focus-visible { outline: 2px solid #ffdca0; outline-offset: 1px; }
.shelf-spine.picked { transform: translateY(-16px); }
.shelf-spine.taken { visibility: hidden; }

/* 北のプレーヤーの上の盤と針（部屋の中・#night の下） */
.shelf-fx { position: absolute; inset: 0; pointer-events: none; }
.shelf-fx.out { opacity: 0; transition: opacity .4s ease; }
.shelf-fly { position: absolute; aspect-ratio: 1; translate: -50% -50%; }
.shelf-tilt { width: 100%; height: 100%; }
.shelf-fly.spinning .disc-rot { animation: shelf-spin var(--shelf-spin) linear infinite; }
@keyframes shelf-spin { to { rotate: 360deg; } }
.shelf-arm { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; }
.arm-rot { transform-origin: 0 0; }
.arm-line { stroke: #b88a3e; stroke-width: 6; stroke-linecap: round; fill: none; }
.arm-head { fill: #a37a34; }
.arm-pivot { fill: #8a6a2e; }
.arm-shadow-line { stroke: #000; stroke-width: 6; stroke-linecap: round; fill: none; opacity: 0; }

/* 札 3 つ（盤が回っているあいだ・画面の上・人にかぶらないように 🌹 11/06） */
.shelf-pane-room { position: absolute; left: 0; right: 0; top: 0; padding: 10px 12px 0; display: flex; justify-content: center; pointer-events: none; }
.shelf-tags { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; opacity: 0; transition: opacity .5s ease; }
.shelf-root.tags-on .shelf-tags { opacity: 1; }
.shelf-root.tags-on .shelf-tag, .shelf-root.tags-on .shelf-stop { pointer-events: auto; }
/* 盤がかかっている間: 土台は部屋のクリックを通す（札と止めるボタンだけ受ける） */
.shelf-root.playing { pointer-events: none; }
.shelf-root.away .shelf-pane-room, .shelf-fx.away { display: none; }
.shelf-stop { padding: 10px 14px; border: 1px solid rgba(255, 250, 240, .7); border-radius: 22px; background: rgba(40, 28, 20, .85); color: var(--ink); font-size: 13px; cursor: pointer; }
.shelf-stop:hover, .shelf-stop:focus-visible { background: rgba(80, 56, 38, .95); }
.shelf-tag { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 22px; background: rgba(255, 250, 240, .96); color: var(--bubble-ink);
  font-size: 14px; text-decoration: none; box-shadow: 0 4px 14px rgba(0, 0, 0, .4); }
.shelf-tag:hover, .shelf-tag:focus-visible { background: #fff; outline: 2px solid #c4956a; }
.shelf-tag img { width: 22px; height: 22px; border-radius: 5px; }

/* 動かしている間だけ will-change（iPhone の負荷を抑える）。blur は重ねない */
.shelf-root.moving .shelf-jacket, .shelf-root.moving .shelf-sleeve, .shelf-root.moving .shelf-disc-stage,
.shelf-fx.moving .shelf-fly, .shelf-fx.moving .shelf-tilt, .shelf-fx.moving .arm-rot { will-change: transform; }

/* 中間の幅（481〜850px）: 21 本が 1 段に収まるよう、背表紙の幅だけ比例して縮める（段は 2 つのまま・横にあふれない） */
@media (min-width: 481px) and (max-width: 850px) {
  :root { --shelf-open-min-h: 760px; } /* 額縁が body に合わせて低くなっても題が読める高さ（481・600・850 幅で実測: 全部読める背表紙 38・37・37 / 42） */
  .shelf-spine { flex: 0 1 auto; min-width: 18px; }
  .shelf-spine-title { font-size: 11px; }
}
@media (max-width: 480px) {
  :root { --shelf-h: min(24vh, 200px); --shelf-open-min-h: 700px; }
  /* スマホ: 1 列の横スクロール。2 つの段は 1 本につなぐ */
  .shelf-row { top: auto; bottom: var(--shelf-board-y); height: calc(var(--shelf-h) + 22px); box-sizing: border-box; display: flex; align-items: flex-end; gap: 3px;
    padding: 22px 8px 0; overflow-x: auto; overflow-y: hidden; pointer-events: auto; scrollbar-width: none; }
  .shelf-row::-webkit-scrollbar { display: none; }
  .shelf-tier { display: contents; }
  /* 続きがあると分かる印: 右端を暗く・小さな文字 */
  .shelf-pane-shelf::before { content: ""; position: absolute; right: 0; bottom: var(--shelf-board-y); width: 36px; height: var(--shelf-h); z-index: 2; pointer-events: none;
    background: linear-gradient(to right, rgba(20, 10, 4, 0), rgba(20, 10, 4, .75)); -webkit-mask-image: linear-gradient(to top, #000 55%, transparent); mask-image: linear-gradient(to top, #000 55%, transparent); }
  .shelf-pane-shelf::after { content: "→ 横にすべらせる"; position: absolute; right: 12px; bottom: calc(var(--shelf-board-y) - 26px); z-index: 2; pointer-events: none;
    font-size: 11px; letter-spacing: .08em; color: var(--shelf-head-ink); text-shadow: 0 1px 3px rgba(0, 0, 0, .9); }
  .shelf-pane-shelf { background-image: linear-gradient(rgba(12, 7, 3, .16), rgba(12, 7, 3, .16)), url("shelf/shelf-bg-800.webp"); }
  /* 札は小さく・詰める（人と天窓にかぶらないように） */
  .shelf-pane-room { padding: 3px 8px 0; }
  .shelf-tags { gap: 6px; }
  .shelf-tag { padding: 2px 9px; gap: 5px; font-size: 12px; }
  .shelf-tag img { width: 16px; height: 16px; }
  .shelf-stop { padding: 2px 11px; font-size: 12px; }
  .shelf-spine-title { font-size: 11px; }
}
/* 動きを減らす設定: 盤は回さず、切り替えだけ */
@media (prefers-reduced-motion: reduce) {
  .shelf-fly.spinning .disc-rot { animation: none; }
  .shelf-spine, .shelf-row.dim, .shelf-cover { transition: none; }
}
