/* 中場影片：首頁的電視移到畫面中間放大，影片在玻璃裡播（tv.js）。機身 assets/shelf/tv-full.webp 玻璃是挖空的 */
.viewer:has(> .stage-video) { transform: none; background: transparent; transition: background 0.5s ease, opacity 0s 0.72s; } /* 關掉：底先淡掉、電視飛回去，最後才整個收掉（時間見 tv.js 的 leave） */
.viewer.open:has(> .stage-video) { background: #000; transition: opacity 0s; animation: tvx-bg 0.6s ease; } /* 書櫃慢慢暗下去 */
@keyframes tvx-bg { from { background: transparent; } }
.viewer:has(> .stage-video) .v-head { opacity: 0; transition: opacity 0.35s; }
.viewer.open:has(> .stage-video) .v-head { opacity: 1; animation: hm-fade 0.4s 0.25s both; }
body.tv-away .wall .tv { visibility: hidden; }
.stage.stage-video { padding: 0; overflow: hidden; container-type: size; }
.tvx-lay { position: relative; width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; } /* 版面在這層排（size 查詢只能改裡面的東西） */
/* 手機直拿：整個 viewer 轉 90°，電視橫著放大，把手機轉過來看（自動旋轉鎖住也能看）；手機本來就橫拿就不轉 */
.viewer:has(> .stage-video) { transform-origin: 0 0; }
@media (orientation: portrait) and (max-width: 600px) {
  .viewer:has(> .stage-video), .viewer.open:has(> .stage-video) { left: 0; right: auto; width: 100dvh; height: 100vw; margin: 0; transform: translateX(100vw) rotate(90deg);
    padding: 0 env(safe-area-inset-bottom, 0px) 0 env(safe-area-inset-top, 0px); } /* 轉過去之後：左邊 = 瀏海、右邊 = Home 橫條 */
  .viewer:has(> .stage-video) .v-head { height: 45px; padding-top: 0; }
}
.tvx-noise { position: absolute; inset: 0; opacity: 0; transition: opacity 0.45s; background: radial-gradient(90% 60% at 50% 45%, transparent 20%, rgba(0,0,0,.72) 100%), url(../assets/records/grain.webp) 0 0 / 230px; }
.viewer.open .tvx-noise { opacity: 0.17; }
/* 機身 1068×648；寬度受畫面寬、高一起限制（橫拿手機也放得下） */
.tvx { position: relative; flex: none; width: min(100cqw - 12px, (100cqh - 180px) * 1068 / 648, 900px); aspect-ratio: 1068 / 648; transform-origin: 0 0; }
/* 兩層：下面是首頁電視的分身（一模一樣，含往下變黑），上面是完整的機身 + 玻璃。
   打開時上層淡入、關掉時上層淡出，所以離開和回到書櫃的那一刻跟原本的電視完全相同，不會閃 */
.tvx-home { position: absolute; inset: 0; pointer-events: none; }
.tvx-home .tv { transform: none !important; transition: none; animation: none !important; }
.tvx-full { position: absolute; inset: 0; filter: drop-shadow(0 14px 26px rgba(0,0,0,.9)); }
.tvx-body { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.tvx-body.g { mix-blend-mode: normal; }
.tvx-glass { position: absolute; left: 26.2%; top: 10.4%; width: 66.4%; height: 79.4%; overflow: hidden; isolation: isolate; border-radius: 12% / 14%; background: #000; cursor: pointer; }
.tvx-glass video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; filter: saturate(.86) contrast(1.06) brightness(1.04); opacity: 0; transition: opacity 0.5s; }
.tvx.on .tvx-glass video { opacity: 1; }
/* 噪點、掃描線、青色調、玻璃的暗角和反光 */
.tvx-grain { position: absolute; inset: 0; pointer-events: none; background: url(../assets/records/grain.webp) 0 0 / 130px; mix-blend-mode: overlay; opacity: 0.68; animation: tvx-grain 0.5s steps(1) infinite; }
.tvx-grain.b { mix-blend-mode: screen; opacity: 0.14; background-size: 170px; animation-duration: 0.37s; } /* 黑的地方 overlay 吃不到 */
@keyframes tvx-grain { 0% { background-position: 0 0; } 17% { background-position: -31px 22px; } 34% { background-position: 24px -38px; } 51% { background-position: -47px -13px; } 68% { background-position: 41px 33px; } 85% { background-position: -12px 47px; } } /* 移花紋不移圖層：移圖層會連圓角遮罩一起動，看得到一個框 */
.tvx-scan { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(rgba(81,153,177,.1), rgba(81,153,177,.1)), repeating-linear-gradient(0deg, rgba(0,0,0,.07) 0 1px, transparent 1px 3px); }
.tvx-shine { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(75% 75% at 50% 48%, transparent 62%, rgba(0,0,0,.62) 100%), linear-gradient(155deg, rgba(255,255,255,.1), transparent 30%); }
/* 還沒播 / 轉圈 / 播完：雪花 + 中間的鍵 */
.tvx-static { position: absolute; inset: 0; pointer-events: none; background: url(../assets/records/grain.webp) 0 0 / 90px; opacity: 0; transition: opacity 0.3s; animation: tvx-grain 0.22s steps(1) infinite; }
.tvx.wait .tvx-static { opacity: 0.32; }
/* 暫停時的螢幕字：錄影機 OSD（像素三角 + 左上 PLAY / STOP），帶一點紅藍錯位 */
.tvx-big { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px; opacity: 0; pointer-events: none; transition: opacity 0.2s; filter: drop-shadow(-1.5px 0 rgba(255,70,60,.6)) drop-shadow(1.5px 0 rgba(70,200,255,.65)) drop-shadow(0 0 7px rgba(220,240,245,.4)); }
.tvx-big svg { width: 100%; height: 100%; fill: #e9efec; shape-rendering: crispEdges; }
.tvx-osd { position: absolute; left: 9%; top: 15%; font: 700 clamp(13px, 4vw, 17px)/1 "Chivo Mono", monospace; font-synthesis: weight; letter-spacing: .1em; color: #e9efec; opacity: 0; transition: opacity 0.2s; pointer-events: none; text-shadow: -1px 0 rgba(255,70,60,.6), 1px 0 rgba(70,200,255,.65), 0 0 6px rgba(220,240,245,.45); }
.tvx.paused .tvx-big, .tvx.paused .tvx-osd { opacity: 1; }
.tvx.paused .tvx-osd { animation: tvx-blink 1.1s steps(1) infinite; }
@keyframes tvx-blink { 55% { opacity: 0.25; } }
.tvx-msg { position: absolute; left: 0; right: 0; bottom: 12%; text-align: center; font: 400 11px/1.5 "Chivo Mono", var(--serif-tc); color: #cfcfcf; pointer-events: none; }
/* 控制列：沒有面板，直接浮在黑底噪點上。背光的調頻刻度 = 進度軸，跟機身上一樣的圓旋鈕 = 按鍵 */
.tvx-ctl { position: relative; flex: none; width: min(100% - 40px, 600px); margin-top: 26px; opacity: 0; transition: opacity 0.4s; font: 400 12px/1 "Chivo Mono", monospace; color: #8eafc5; }
.viewer.open .tvx-ctl.in { opacity: 1; }
.tvx-dial { position: relative; --p: 0%; }
/* 背光：指針附近亮起來，像老收音機的燈泡 */
.tvx-dial::before { content: ""; position: absolute; inset: -14px -20px; pointer-events: none; background: radial-gradient(130px 34px at calc(20px + (100% - 40px) * var(--n, 0)) 50%, rgba(120,190,212,.34), transparent 75%), radial-gradient(70% 60% at 50% 50%, rgba(81,153,177,.13), transparent 100%); }
.tvx-ticks { position: absolute; left: 8px; right: 8px; top: 9px; height: 13px; pointer-events: none; opacity: .85;
  background: repeating-linear-gradient(90deg, #a9c6d2 0 1px, transparent 1px calc((100% - 1px) / 8)) 0 100% / 100% 13px no-repeat, repeating-linear-gradient(90deg, rgba(142,175,197,.6) 0 1px, transparent 1px calc((100% - 1px) / 48)) 0 100% / 100% 6px no-repeat;
  filter: blur(.25px); }
.tvx-seek { -webkit-appearance: none; appearance: none; position: relative; display: block; width: 100%; height: 48px; margin: 0; background: transparent; cursor: pointer; touch-action: none; --p: 0%; }
.tvx-seek::-webkit-slider-runnable-track { height: 1px; margin-top: 0; background: linear-gradient(90deg, rgba(142,175,197,.9) var(--p), rgba(142,175,197,.28) var(--p)); }
.tvx-seek::-moz-range-track { height: 1px; background: linear-gradient(90deg, rgba(142,175,197,.9) var(--p), rgba(142,175,197,.28) var(--p)); }
.tvx-seek::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 38px; margin-top: -19px; border: 0; border-radius: 0; background: radial-gradient(1.6px 17px at 50% 50%, #fff3de 0 55%, rgba(255,226,180,.55) 80%, transparent 100%); filter: drop-shadow(0 0 5px rgba(255,200,140,.8)); }
.tvx-seek::-moz-range-thumb { width: 16px; height: 38px; border: 0; border-radius: 0; background: radial-gradient(1.6px 17px at 50% 50%, #fff3de 0 55%, rgba(255,226,180,.55) 80%, transparent 100%); }
.tvx-seek:focus-visible { outline: 1px dotted var(--blue); outline-offset: 4px; }
.tvx-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-top: 10px; }
.tvx-row .t { order: -1; justify-self: start; color: #a9c6d2; letter-spacing: 0.03em; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; text-shadow: 0 0 8px rgba(120,190,212,.5); opacity: .9; }
.tvx-row button { display: flex; flex-direction: column; align-items: center; gap: 9px; min-width: 60px; color: #8eafc5; }
.tvx-row .rp { justify-self: end; }
.tvx-row small { font: 400 10px/1 "Chivo Mono", monospace; letter-spacing: .16em; margin-right: -.16em; opacity: .9; }
/* 旋鈕：照機身上那幾顆的光（左上亮、右下糊掉的影子），外圈一條刻線，播放時轉過去 */
.knob { position: relative; width: 62px; height: 62px; border-radius: 50%; display: grid; place-items: center; color: #10232c;
  background: radial-gradient(circle at 36% 30%, #c2d3d9 0, #a3b9c2 26%, #7d98a4 56%, #547280 82%, #3a5764 100%);
  box-shadow: 0 0 0 3px #0b1e28, 0 0 0 4px rgba(98,158,182,.35), 5px 9px 16px 3px rgba(0,0,0,.9), inset -4px -6px 9px rgba(8,26,36,.5), inset 2px 2px 5px rgba(225,240,245,.35); transition: filter 0.15s; }
.rp .knob { width: 46px; height: 46px; }
.knob::before { content: ""; position: absolute; inset: 0; border-radius: 50%; background: url(../assets/records/grain.webp) 0 0 / 90px; mix-blend-mode: overlay; opacity: .75; }
.knob::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: linear-gradient(#10232c, #10232c) 50% 4px / 2px 8px no-repeat; opacity: .7; transform: rotate(-50deg); transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1); filter: blur(.3px); }
.down .knob::after { transform: rotate(50deg); }
.rp:active .knob::after { transform: rotate(-310deg); }
.tvx-row button:active .knob { filter: brightness(.85); }
.knob svg { position: relative; width: 19px; height: 19px; fill: currentColor; opacity: .88; filter: blur(.2px); }
.rp .knob svg { width: 16px; height: 16px; }
/* 手機本來就橫拿：不要卡在 430 寬，整個畫面都給電視 */
@media (orientation: landscape) and (max-height: 600px) {
  .viewer:has(> .stage-video) { width: 100%; padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
}
/* 橫的版面（真的橫拿、或直拿被轉過來）：電視在左邊盡量大，控制在右邊直排 */
@container (min-aspect-ratio: 3 / 2) {
  .tvx-lay { flex-direction: row; gap: clamp(14px, 4cqw, 34px); padding: 0 clamp(10px, 3cqw, 28px); }
  .tvx { width: min(100cqw - 250px, (100cqh - 22px) * 1068 / 648, 900px); }
  .tvx-ctl { width: 196px; margin: 0; }
  .tvx-row { grid-template-columns: 1fr 1fr; row-gap: 16px; margin-top: 14px; }
  .tvx-row .t { grid-column: 1 / -1; justify-self: center; order: 0; }
  .tvx-row .pp { justify-self: center; } .tvx-row .rp { justify-self: center; align-self: end; }
  .knob { width: 56px; height: 56px; } .rp .knob { width: 44px; height: 44px; }
}
@container (min-aspect-ratio: 3 / 2) and (max-height: 300px) { .tvx-row small { display: none; } .tvx-row { row-gap: 10px; margin-top: 8px; } }
/* 進度軸自己處理拖曳（轉過 90° 的 range 在 iPhone 上方向會錯），input 只留給鍵盤 */
.tvx-dial { touch-action: none; cursor: pointer; }
.tvx-seek { pointer-events: none; }
