/* =========================================================================
   卫星露天咖啡馆 · 首页首屏
   浅色：纸色桌面上的唱片机；深色：格林尼治星空（第四步实现，目前为占位）。
   ========================================================================= */

.cafe-hero {
  --ch-paper: var(--background);
  --ch-ink: var(--cafe-ink, #2a241d);
  /* 机身的木纹由 cafe-leaves.js 生成，这两个颜色只在木纹上叠一层受光 */
  --ch-wood-a: hsl(40 60% 96% / 0.16);
  --ch-wood-b: hsl(25 40% 18% / 0.12);
  --ch-edge: hsl(30 20% 30% / 0.22);
  --ch-well-a: hsl(30 18% 22% / 0);
  --ch-well-b: hsl(30 18% 22% / 0.28);
  --ch-metal: hsl(32 8% 70%);
  --ch-metal-dark: hsl(30 6% 42%);
  --ch-record: hsl(24 12% 9%);
  --ch-groove: rgba(255, 255, 255, 0.045);
  --ch-glow: 226, 172, 120;
  --ch-label: hsl(24 58% 40%);
  --ch-label-ink: hsl(40 40% 95%);
  --ch-platter: hsl(28 10% 18%);
  --ch-strobe: rgba(255, 255, 255, 0.32);

  position: relative;
  box-sizing: border-box;
  width: var(--ch-vw, 100vw);
  min-height: 100vh;
  min-height: 100svh;
  margin: -16px 0 32px calc(-1 * var(--ch-left, 0px));
  padding: 88px clamp(20px, 5vw, 72px) 72px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--ch-paper);
  color: var(--ch-ink);
  overflow: hidden;
}

/* ---------------- 顶栏 */

.ch-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  /* 右侧给固定在视口右上角的深浅色按钮留出位置 */
  padding: 22px calc(clamp(20px, 5vw, 72px) + 48px) 22px clamp(20px, 5vw, 72px);
}
.ch-brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.ch-brand img { width: 28px; height: 28px; }
.ch-brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.ch-brand-name { font-family: var(--cafe-serif); font-weight: 900; font-size: 17px; letter-spacing: 0.04em; white-space: nowrap; }
@media (max-width: 480px) { .ch-clock-place { display: none; } }
.ch-brand-sub { font-family: var(--cafe-serif); font-size: 12px; color: var(--text-p3); }
.ch-clock {
  margin-left: auto;
  font-family: var(--cafe-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--text-p2);
  font-variant-numeric: tabular-nums;
}
/* 深浅色按钮：固定在视口右上角，滚动时保持可见 */
.ch-theme {
  position: fixed;
  top: 19px;
  right: clamp(20px, 5vw, 72px);
  z-index: 950;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--cafe-rule);
  border-radius: 50%;
  background: color-mix(in srgb, var(--background) 72%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: var(--text-p2);
  cursor: pointer;
  transition: opacity 0.4s ease, visibility 0.4s, color 0.2s, border-color 0.2s;
}
.ch-theme:hover { color: var(--cafe-caramel); border-color: var(--cafe-caramel); }
.ch-theme svg { width: 16px; height: 16px; }
/* 桌面端滚过首屏后，左栏（自带深浅色按钮）会出现，这里的按钮随之淡出，避免重复 */
@media (min-width: 1024px) {
  html.cafe-hero-off .ch-theme { opacity: 0; visibility: hidden; }
}

/* ---------------- 向下滚动时：首屏淡出并缓慢下沉，底部渐变到页面底色 */

.cafe-hero { --ch-p: 0; }
/* 只在深色模式需要：星空的蓝黑色渐变到文章区的咖啡色底。浅色模式首屏和页面同为纸色 */
.cafe-hero::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 30vh;
  background: linear-gradient(to bottom, transparent, var(--background));
  pointer-events: none;
  display: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .cafe-hero::after { display: block; }
}
:root[data-theme="dark"] .cafe-hero::after { display: block; }
.ch-sky {
  opacity: calc(1 - var(--ch-p) * 0.9);
  transform: translateY(calc(var(--ch-p) * 22%));
  will-change: opacity, transform;
}
.ch-light {
  opacity: calc(1 - var(--ch-p) * 0.75);
  transform: translateY(calc(var(--ch-p) * 12%));
}
.ch-top { opacity: calc(1 - var(--ch-p) * 1.6); }
/* 减少动态效果（cafe-prefs.js 设置的类）：滚动时不做视差位移 */
html.cafe-reduce-motion .ch-sky,
html.cafe-reduce-motion .ch-light { transform: none; }

.ch-down {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  padding: 6px 10px;
  border: 0;
  background: none;
  font-family: var(--cafe-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--text-p3);
  cursor: pointer;
}
.ch-down::after {
  content: "";
  display: block;
  width: 1px;
  height: 22px;
  margin: 8px auto 0;
  background: currentColor;
  opacity: 0.6;
}
.ch-down:hover { color: var(--cafe-caramel); }

/* ---------------- 场景切换：浅色唱片机，深色星空 */

.ch-stage { position: relative; width: 100%; max-width: 1240px; margin: 0 auto; }
.ch-dark { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ch-light { display: none; }
  :root:not([data-theme="light"]) .ch-dark { display: block; }
}
:root[data-theme="dark"] .ch-light { display: none; }
:root[data-theme="dark"] .ch-dark { display: block; }

/* ---------------- 浅色：唱片机 */

.ch-light {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 1fr);
  gap: clamp(36px, 6vw, 96px);
  align-items: center;
}

/* 阳光：纸色底上一片暖色的亮光，颜色和位置跟随本地时间（变量由 cafe-leaves.js 设置） */
.cafe-hero {
  background:
    radial-gradient(ellipse 75% 70% at var(--ch-sun-x, 60%) 0%, rgba(var(--ch-sun, 255, 240, 215), var(--ch-sun-glow, 0.3)), transparent 70%),
    var(--ch-paper);
}

/* 树影：两块低分辨率画布拉伸铺满首屏，正片叠底压暗下面的一切；底部渐隐 */
.ch-leaves {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, #000 72%, transparent);
  mask-image: linear-gradient(to bottom, #000 72%, transparent);
}
.ch-leaves-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  mix-blend-mode: multiply;
  transition: opacity 2s ease, transform 2s ease;
}
/* 随时间变化的色调：整层颜色正片叠底，压在内容上、树影下（变量由 cafe-leaves.js 设置） */
.ch-wash {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(var(--ch-wash, 255, 255, 255), var(--ch-wash-a, 0)), rgba(var(--ch-wash, 255, 255, 255), calc(var(--ch-wash-a, 0) * 0.65)));
  mix-blend-mode: multiply;
  -webkit-mask-image: linear-gradient(to bottom, #000 72%, transparent);
  mask-image: linear-gradient(to bottom, #000 72%, transparent);
}
/* 左上角的红色桌布（静态画布，见 cafe-leaves.js），垫在最底下 */
.ch-cloth {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ch-leaves,
  :root:not([data-theme="light"]) .ch-wash,
  :root:not([data-theme="light"]) .ch-cloth { display: none; }
}
:root[data-theme="dark"] .ch-leaves,
:root[data-theme="dark"] .ch-wash,
:root[data-theme="dark"] .ch-cloth { display: none; }

.ch-deck {
  position: relative;
  isolation: isolate;
  width: min(100%, calc((100svh - 200px) * 640 / 520));
  aspect-ratio: 640 / 520;
  justify-self: end;
}
/* 唱片机落在纸面上的投影：静态的一层，光从左上来 */
.ch-deck::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 2% 1% 0.5% 2%;
  border-radius: 4% / 5%;
  box-shadow:
    22px 32px 46px hsl(30 35% 22% / 0.22),
    5px 9px 12px hsl(30 35% 22% / 0.18);
}
.ch-deck > svg,
.ch-deck > canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
/* 木纹垫在机身下面，按机身的圆角裁切 */
.ch-deck > .ch-wood {
  left: calc(4 / 640 * 100%);
  top: calc(4 / 520 * 100%);
  width: calc(632 / 640 * 100%);
  height: calc(512 / 520 * 100%);
  border-radius: calc(26 / 640 * 100%) / calc(26 / 520 * 100%);
  background: hsl(32 40% 70%);
}
/* 唱片画布只负责显示，点击交给下面的按钮和上面的唱片点击区域 */
.ch-deck > canvas { pointer-events: none; }

.ch-wood-a { stop-color: var(--ch-wood-a); }
.ch-wood-b { stop-color: var(--ch-wood-b); }
.ch-well-a { stop-color: var(--ch-well-a); }
.ch-well-b { stop-color: var(--ch-well-b); }
.ch-body { stroke: var(--ch-edge); stroke-width: 1; }
.ch-bevel { fill: none; stroke: hsl(0 0% 100% / 0.45); stroke-width: 1; }
.ch-arm-plate { fill: var(--ch-wood-b); stroke: var(--ch-edge); }
.ch-arm-plate-ring { fill: none; stroke: var(--ch-edge); stroke-dasharray: 2 4; }
.ch-rest { fill: var(--ch-metal-dark); }
.ch-rest-cup { stroke: var(--ch-metal-dark); stroke-width: 3; stroke-linecap: round; }
.ch-power { fill: hsl(30 10% 60%); transition: fill 0.3s; }
.ch-power.is-on { fill: var(--cafe-caramel); }
.ch-engrave { font-family: var(--cafe-mono); font-size: 10px; letter-spacing: 0.12em; fill: hsl(28 30% 20% / 0.72); }
.ch-model { font-size: 9px; }
/* 机身上的转速标记：只是印刷的文字，不像按钮 */
.ch-marks { pointer-events: none; }
.ch-marks .ch-engrave { font-size: 9px; }
.ch-speed { font-size: 10px !important; fill: hsl(30 14% 30% / 0.72); }
.ch-speed-off { fill: hsl(30 14% 30% / 0.38); }
.ch-rpm { fill: hsl(30 14% 30% / 0.38); }
.ch-speed-lamp { fill: hsl(30 10% 70%); transition: fill 0.3s; }
.ch-speed-lamp.is-on { fill: var(--cafe-caramel); }
.ch-pitch { fill: hsl(30 14% 30% / 0.18); }
.ch-pitch-knob { fill: hsl(34 20% 90%); stroke: var(--ch-edge); }

/* 唱片的点击区域：只覆盖唱片本身 */
.ch-record-hit {
  position: absolute;
  left: calc((250 - 200) / 640 * 100%);
  top: calc((262 - 200) / 520 * 100%);
  width: calc(400 / 640 * 100%);
  height: calc(400 / 520 * 100%);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.ch-record-hit:active { cursor: grabbing; }
.ch-record-hit:focus-visible { outline: 2px solid var(--cafe-caramel); outline-offset: 6px; }

/* 唱臂 */
.ch-arm-layer { pointer-events: none; overflow: visible; }
.ch-arm {
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  transform-box: view-box;
  transform-origin: 0 0;
  transform: translate(548px, 96px) rotate(0deg);
  transition: transform 0.9s cubic-bezier(0.45, 0, 0.25, 1);
}
/* 唱臂的影子：一份模糊的副本，位置由脚本和唱臂同步 */
.ch-arm-shadow {
  pointer-events: none;
  transform-box: view-box;
  transform-origin: 0 0;
  transform: translate(548px, 96px) rotate(0deg);
}
/* 外层只负责抬起、落下时影子的偏移和浓淡 */
.ch-arm-shadow-off {
  transform-box: view-box;
  transform: translate(12px, 18px);
  opacity: 0.55;
  transition: transform 0.35s ease, opacity 0.35s ease;
}
.ch-arm-shadow-off.is-down { transform: translate(3px, 5px); opacity: 0.8; }
.ch-arm-shadow * { fill: hsl(30 30% 12% / 0.32) !important; stroke: hsl(30 30% 12% / 0.32) !important; }
.ch-arm-shadow .ch-arm-tube { fill: none !important; stroke-width: 7; }
.ch-arm.is-dragging { cursor: grabbing; }
.ch-arm:focus-visible { outline: none; }
.ch-arm:focus-visible .ch-arm-hub { stroke: var(--cafe-caramel); stroke-width: 3; }
.ch-arm-hit { stroke: transparent; stroke-width: 30; stroke-linecap: round; }
.ch-arm-weight { fill: var(--ch-metal-dark); }
.ch-arm-tube { fill: none; stroke: var(--ch-metal); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.ch-arm-hub { fill: var(--ch-metal); stroke: var(--ch-metal-dark); stroke-width: 1.5; }
.ch-arm-hub-cap { fill: var(--ch-metal-dark); }
.ch-head { fill: hsl(30 8% 22%); }
.ch-head-lift { fill: var(--ch-metal); }
.ch-cart { fill: var(--cafe-caramel); }

/* ---------------- 浅色：右侧的排版（站名，然后是正在放的歌） */

.ch-info { min-width: 0; max-width: 480px; }
.ch-ident-logo { display: block; width: clamp(52px, 4.6vw, 68px); height: clamp(52px, 4.6vw, 68px); }
.ch-ident-name {
  margin: 20px 0 0;
  padding: 0;
  border: 0;
  font-family: var(--cafe-serif);
  font-weight: 900;
  font-size: clamp(36px, 4.1vw, 66px);
  line-height: 1.08;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: var(--ch-ink);
}
.ch-ident-sub {
  margin: 16px 0 0;
  font-family: var(--cafe-serif);
  font-size: 16px;
  letter-spacing: 0.04em;
  color: var(--text-p2);
}

.ch-now {
  margin-top: clamp(32px, 7vh, 72px);
  padding-top: 22px;
  border-top: 1px solid var(--cafe-rule);
}
.ch-now p { margin: 0; }
.ch-now-head { min-height: 1.5em; }
.ch-state { font-family: var(--cafe-mono); font-size: 11px; letter-spacing: 0.16em; color: var(--cafe-caramel); }
.ch-track { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-top: 6px !important; }
.ch-title { font-family: var(--cafe-serif); font-weight: 700; font-size: 20px; color: var(--ch-ink); }
.ch-artist { font-family: var(--cafe-mono); font-size: 12px; letter-spacing: 0.04em; color: var(--text-p3); }

/* 歌词：只显示当前一句，用较大的衬线字 */
.ch-lyric { min-height: 3.4em; margin-top: 22px; }
.ch-ly-cur {
  font-family: var(--cafe-serif);
  font-weight: 500;
  font-size: clamp(22px, 2vw, 28px);
  line-height: 1.45;
  color: var(--ch-ink);
}
.ch-ly-cur.is-hint { font-size: 15px; color: var(--text-p3); }
.ch-ly-trans { margin-top: 8px !important; font-family: var(--cafe-serif); font-size: 15px; line-height: 1.6; color: var(--text-p3); }
.ch-ly-trans:empty { display: none; }
.ch-lyric.is-in p { animation: ch-lyric-in 0.6s ease both; }
.ch-lyric.is-in .ch-ly-trans { animation-delay: 0.1s; }
@keyframes ch-lyric-in { from { opacity: 0; transform: translateY(5px); } }

.ch-note {
  margin: 20px 0 0 !important;
  padding-left: 10px;
  border-left: 2px solid var(--cafe-caramel);
  font-family: var(--cafe-serif);
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-p2);
}
.ch-note[hidden] { display: none; }

html.cafe-reduce-motion .ch-lyric.is-in p { animation: none; }

/* 浅色首屏右侧已经有站名，左上角的小站名不再重复显示 */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .ch-top .ch-brand { visibility: hidden; }
}
:root[data-theme="light"] .ch-top .ch-brand { visibility: hidden; }

/* ---------------- 唱片机上的切歌键：低矮的胶囊形按键，按下时下沉 1 像素 */

.ch-key-a { stop-color: hsl(36 30% 94%); }
.ch-key-b { stop-color: hsl(32 20% 82%); }
.ch-key { cursor: pointer; outline: none; }
.ch-key-base { fill: hsl(30 14% 58% / 0.55); }
.ch-key-face { fill: url(#ch-key-grad); stroke: hsl(30 20% 30% / 0.28); stroke-width: 0.8; transition: stroke 0.2s; }
.ch-key-icon { fill: hsl(30 14% 28% / 0.72); transition: fill 0.2s; }
.ch-key-top { transform-box: fill-box; transition: transform 0.08s ease; }
.ch-key:hover .ch-key-icon { fill: var(--cafe-caramel); }
.ch-key:hover .ch-key-face { stroke: hsl(24 58% 40% / 0.55); }
.ch-key:active .ch-key-top { transform: translateY(1.3px); }
.ch-key:focus-visible .ch-key-face { stroke: var(--cafe-caramel); stroke-width: 1.6; }
.ch-track-label { font-size: 9px; }

/* ---------------- 深色：占位 */

/* 深色：全景星空铺满整个首屏，顶栏和"向下滚动"浮在上面 */
.ch-stage { position: static; }
.ch-sky { position: absolute; inset: 0; }
.cs-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: default;
  touch-action: pan-y;
}
.cs-caption {
  position: absolute;
  left: clamp(20px, 5vw, 72px);
  bottom: 24px;
  margin: 0;
  font-family: var(--cafe-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: hsl(36 30% 80% / 0.45);
  pointer-events: none;
}
.ch-top, .ch-down { z-index: 1; }
/* 顶栏是一整条横幅，空白处让鼠标穿过去，只有站名链接可以点 */
.ch-top { pointer-events: none; }
.ch-top a, .ch-top button { pointer-events: auto; }

/* 城市和时间统一显示在右上角（深浅两种模式相同），星空左下角不再重复显示 */
.cs-caption { display: none; }

/* 首页正文至少两屏高：文章很少时，首屏也能整个滚出视口，文章列表和页脚占满第二屏 */
#main.site-main:has(> .cafe-hero) { min-height: calc(200vh - 16px); min-height: calc(200svh - 16px); }

/* ---------------- 首屏在视口里时：隐藏左栏
   页面里有首屏时默认就隐藏（纯 CSS，第一次绘制就生效，不会先闪出来再淡出）；
   滚过首屏后脚本给 html 加上 cafe-hero-off，左栏再淡入。 */

.site-region--leftbar { transition: opacity 0.4s ease, visibility 0.4s; }
/* 只在左栏是一整列的宽屏上隐藏；768px 以下左栏是点按钮才拉出的抽屉，隐藏了就打不开菜单 */
@media (min-width: 769px) {
  html:has(.cafe-hero):not(.cafe-hero-off) .site-region--leftbar { opacity: 0; visibility: hidden; }
}

/* 首页第一屏时，小唱片机让位给大唱片机（只在浅色模式，深色首屏没有大唱片机） */
.cafe-player { transition: opacity 0.4s ease, transform 0.4s ease; }
.cafe-player.is-hero-hidden { opacity: 0; pointer-events: none; transform: translateY(8px); }
@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]):has(.cafe-hero):not(.cafe-hero-off) .cafe-player { opacity: 0; pointer-events: none; transform: translateY(8px); }
}
html[data-theme="light"]:has(.cafe-hero):not(.cafe-hero-off) .cafe-player { opacity: 0; pointer-events: none; transform: translateY(8px); }

/* ---------------- 窄屏 */

@media (max-width: 900px) {
  .cafe-hero { padding-top: 84px; padding-bottom: 80px; justify-content: flex-start; }
  .ch-light { grid-template-columns: 1fr; gap: 36px; }
  .ch-deck { width: 100%; justify-self: center; }
  .ch-info { max-width: none; }
  .ch-brand-sub { display: none; }
  .ch-clock { font-size: 11px; letter-spacing: 0.04em; }
}

html.cafe-reduce-motion .ch-arm { transition: none !important; }

/* ---------------- 音量推子 */
.ch-fader { cursor: ns-resize; touch-action: none; }
.ch-fader:focus-visible { outline: none; }
.ch-fader:focus-visible .ch-pitch-knob { stroke: var(--cafe-caramel); stroke-width: 2; }
.ch-fader-hit { fill: transparent; }
.ch-pitch-fill { fill: var(--cafe-caramel); opacity: 0.55; }
.ch-fader:hover .ch-pitch-knob { fill: hsl(34 30% 94%); }

/* ---------------- 星空：悬停天体时的名称提示 */
.cs-tip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 280px;
  padding: 7px 10px 8px;
  border: 1px solid hsl(30 40% 70% / 0.22);
  border-radius: 4px;
  background: hsl(225 30% 8% / 0.78);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.cs-tip.is-on { opacity: 1; }
.cs-tip strong { font-family: var(--cafe-serif); font-weight: 700; font-size: 14px; color: hsl(32 60% 82%); }
.cs-tip span { font-family: var(--cafe-mono); font-size: 10.5px; letter-spacing: 0.03em; line-height: 1.5; color: hsl(36 20% 80% / 0.75); }
