/* 3_sy 双轨卡片空间 · 蒸汽朋克双舱 (v3)

   结构（舞台自下而上）：
     .sy-well            凹槽：窗口的深色底，在轨道 iframe 下面
     .sy-pipes           蒸汽管：连接上下两舱，在 iframe 下面，轨道骑在管子上
     iframe.sy-frame     轨道本体（透明底，只画卡片）
     .sy-frame-outline   黄铜舱框：上舱 / 下舱，盖在 iframe 上面

   舱框、凹槽、管路的位置全部由 sy-card.js 用同一套弹簧驱动，
   不再靠 CSS transition 去追 iframe。
   这个文件只管这张卡；不改全站 grid 的列宽、行高或 gap。 */

.sy-card {
  --sy-iron: #17110a;
  --sy-brass-hi: #f3d58a;
  --sy-brass: #c98b3a;
  --sy-brass-lo: #7a4a14;
  --sy-paper: #f5ecd9;
  --sy-pad: 10px; /* 舞台底部留白：给舱框的硬阴影，避免被裁掉 */

  grid-column: 1 / -1;
  grid-row: auto;
  position: relative;
  display: block;
  width: 100%;
  height: var(--sy-stage-height, 570px);
  min-width: 0;
  max-height: none;
  align-self: stretch;
  overflow: visible;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  cursor: default;
}

/* 整行横向舞台：舱框、管路、轨道一起横向滚动。 */
.sy-scroll {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  overscroll-behavior-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(201, 139, 58, .55) transparent;
  touch-action: pan-x pan-y;
  background: transparent;
}

.sy-scene {
  position: relative;
  width: max(100%, calc(var(--sy-slot-width, 280px) * 2 + var(--sy-scene-gap, 24px)));
  height: 100%;
  margin-inline: auto;
  flex: 0 0 auto;
  overflow: hidden;
  background: transparent;
  isolation: isolate;
}

/* 轨道 iframe：背景全透明，只画真实的轨道和卡片。 */
.sy-frame {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: calc(100% - var(--sy-pad));
  border: 0;
  background: transparent;
  pointer-events: none;
}

/* ---------- 凹槽：窗口的深色底 ---------- */
.sy-well {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--sy-slot-width, 280px);
  height: var(--sy-slot-height, 190px);
  border-radius: 4px;
  background:
    repeating-linear-gradient(90deg, rgba(243, 213, 138, .04) 0 1px, transparent 1px 13px),
    radial-gradient(120% 95% at 50% 38%, #2b2218 0%, #181209 68%, #0d0905 100%);
  box-shadow: inset 0 0 22px rgba(0, 0, 0, .65);
  pointer-events: none;
  will-change: transform;
}
.sy-well--bottom {
  top: calc((var(--sy-slot-height, 190px) + var(--sy-scene-gap, 24px)) * 2);
}

/* ---------- 蒸汽管：连接上下两舱 ---------- */
.sy-pipes {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
}
.sy-pipe-shadow { fill: none; stroke: #0f0a04; stroke-linecap: butt; }
.sy-pipe-body   { fill: none; stroke: var(--sy-brass); stroke-linecap: butt; }
.sy-pipe-shine  { fill: none; stroke: rgba(255, 238, 178, .72); stroke-linecap: round; }
.sy-pipe-ring   { fill: none; stroke: #2a1a0a; stroke-linecap: butt; }
.sy-pipe-ringhi { fill: none; stroke: var(--sy-brass-hi); stroke-linecap: butt; }
.sy-flange      { stroke: #2a1a0a; stroke-linecap: round; }
.sy-flange-hi   { stroke: var(--sy-brass-hi); stroke-linecap: round; }

/* ---------- 黄铜舱框：上舱 / 下舱 ---------- */
.sy-frame-outline {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  width: var(--sy-slot-width, 280px);
  height: var(--sy-slot-height, 190px);
  border: 3px solid var(--sy-iron);
  border-radius: 4px;
  background: transparent;
  /* 纯色黄铜环 + 与普通作品卡一致的硬阴影；渐变版本在下面 @supports 里叠上去 */
  box-shadow:
    inset 0 0 0 6px var(--sy-brass),
    6px 6px 0 rgba(0, 0, 0, .7);
  pointer-events: none;
  transform: translate3d(0, 0, 0);
  will-change: transform;
}
.sy-frame-outline--top { top: 0; }
.sy-frame-outline--bottom {
  top: calc((var(--sy-slot-height, 190px) + var(--sy-scene-gap, 24px)) * 2);
}

/* 内侧凹槽线 + 轻微暗角，让窗口有深度 */
.sy-frame-outline::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(12, 8, 3, .9);
  border-radius: 1px;
  box-shadow: inset 0 0 16px rgba(0, 0, 0, .45);
  pointer-events: none;
}

@supports ((-webkit-mask-composite: xor) or (mask-composite: exclude)) {
  /* 黄铜环做成渐变：整块渐变铺满，再用 mask 把中间掏空，窗口里仍然是透明的 */
  .sy-frame-outline::before {
    content: "";
    position: absolute;
    inset: 0;
    padding: 6px;
    border-radius: 1px;
    background: linear-gradient(135deg,
      var(--sy-brass-hi) 0%, var(--sy-brass) 26%, var(--sy-brass-lo) 50%,
      var(--sy-brass) 74%, var(--sy-brass-hi) 100%);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask-composite: exclude;
    pointer-events: none;
  }
}

/* 铆钉：四角 + 四边中点 */
.sy-rivets {
  position: absolute;
  inset: 0;
  pointer-events: none;
  --rv: radial-gradient(circle at 50% 50%, #fff3cc 0 .9px, #6c4513 1.4px 2.4px, rgba(0, 0, 0, .4) 2.6px 3px, transparent 3.2px);
  background:
    var(--rv) left top / 6px 6px no-repeat,
    var(--rv) right top / 6px 6px no-repeat,
    var(--rv) left bottom / 6px 6px no-repeat,
    var(--rv) right bottom / 6px 6px no-repeat,
    var(--rv) center top / 6px 6px no-repeat,
    var(--rv) center bottom / 6px 6px no-repeat,
    var(--rv) left center / 6px 6px no-repeat,
    var(--rv) right center / 6px 6px no-repeat;
}

/* 编号铭牌：挂在舱框上沿 / 下沿 */
.sy-plate {
  position: absolute;
  z-index: 2;
  top: -3px;
  left: 16px;
  padding: 2px 7px 3px;
  border: 1px solid var(--sy-brass-lo);
  border-top-width: 0;
  border-radius: 0 0 3px 3px;
  background: linear-gradient(#2b2013, #17110a);
  color: var(--sy-brass-hi);
  font: 800 8px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 1.4px;
  white-space: nowrap;
  box-shadow: 0 2px 3px rgba(0, 0, 0, .45);
}
.sy-frame-outline--bottom .sy-plate {
  top: auto;
  bottom: -3px;
  border-top-width: 1px;
  border-bottom-width: 0;
  border-radius: 3px 3px 0 0;
  box-shadow: 0 -2px 3px rgba(0, 0, 0, .45);
}

/* 齿轮：上舱右上角顺时针，下舱左下角逆时针 */
.sy-gear {
  position: absolute;
  z-index: 2;
  width: 30px;
  height: 30px;
  color: var(--sy-brass);
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .6));
  animation: sy-spin 14s linear infinite;
}
.sy-gear--top { top: -3px; right: -3px; }
.sy-gear--bottom {
  bottom: -3px;
  left: -3px;
  width: 26px;
  height: 26px;
  animation-direction: reverse;
  animation-duration: 11s;
}
@keyframes sy-spin { to { transform: rotate(360deg); } }
.sy-card.is-offscreen .sy-gear { animation-play-state: paused; }

/* JS 接管之后：第一次量到轨道位置之前先藏起来，量到再淡入，避免舱框先闪在左上角 */
.sy-rig:not(.is-ready) .sy-frame-outline,
.sy-rig:not(.is-ready) .sy-well,
.sy-rig:not(.is-ready) .sy-pipes { opacity: 0; }
.sy-rig .sy-frame-outline,
.sy-rig .sy-well,
.sy-rig .sy-pipes { transition: opacity .35s ease; }

/* ---------- 操作铭牌：三个状态拉杆 + 压力表 ---------- */
.sy-info {
  position: absolute;
  right: 14px;
  bottom: calc(var(--sy-pad) + 14px);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100% - 28px);
  margin: 0;
  padding: 6px 8px;
  border: 1px solid var(--sy-brass-lo);
  border-radius: 4px;
  background: linear-gradient(#2d2214, #17110a);
  color: var(--sy-brass-hi);
  box-shadow:
    inset 0 1px 0 rgba(243, 213, 138, .28),
    0 5px 14px rgba(0, 0, 0, .45);
  cursor: default;
  pointer-events: auto;
}
.sy-info .card-title {
  color: var(--sy-brass-hi);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .6px;
  white-space: nowrap;
}

.sy-gauge { width: 26px; height: 26px; flex: none; }
.sy-needle {
  transform: rotate(var(--sy-needle, 0deg));
  transform-origin: 16px 16px;
  transition: transform .7s cubic-bezier(.3, 1.5, .5, 1);
}

.sy-buttons { display: inline-flex; align-items: center; gap: 6px; }

.sy-state-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  padding: 5px 8px;
  border: 1px solid var(--sy-iron);
  border-radius: 3px;
  background: linear-gradient(#f3e3b6, #c9a45a);
  color: #2a1a08;
  font: 900 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .8px;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--sy-iron);
  transition: transform .12s ease, box-shadow .12s ease, background .16s ease;
}
.sy-state-btn em { font-style: normal; font-size: 8px; opacity: .6; }
.sy-state-btn:hover { background: linear-gradient(#fff2c9, #d8b468); }
.sy-state-btn:active { transform: translateY(2px); box-shadow: 0 0 0 var(--sy-iron); }
.sy-state-btn:focus-visible { outline: 2px solid #f4bd3c; outline-offset: 2px; }
.sy-state-btn.is-active {
  background: linear-gradient(#ffd66b, #e09a1e);
  transform: translateY(2px);
  box-shadow: 0 0 0 var(--sy-iron), 0 0 10px rgba(255, 196, 74, .55);
}

.sy-code {
  padding: 4px 6px;
  border: 1px solid rgba(201, 139, 58, .5);
  border-radius: 3px;
  color: rgba(243, 213, 138, .85);
  font: 800 8px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .8px;
  white-space: nowrap;
}

@media (max-width: 680px) {
  .sy-info { right: 8px; bottom: calc(var(--sy-pad) + 8px); gap: 6px; max-width: calc(100% - 16px); padding: 5px; }
  .sy-info .card-title { display: none; }
  .sy-gauge { width: 22px; height: 22px; }
  .sy-state-btn { min-height: 26px; padding: 5px 6px; font-size: 8px; letter-spacing: .5px; }
  .sy-code { font-size: 7px; }
  .sy-plate { left: 12px; font-size: 7px; letter-spacing: 1px; }
  .sy-gear--top { width: 24px; height: 24px; }
  .sy-gear--bottom { width: 22px; height: 22px; }
}

@media (max-width: 390px) {
  .sy-info { gap: 5px; }
  .sy-state-btn { padding-inline: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  .sy-gear { animation: none; }
  .sy-needle,
  .sy-state-btn,
  .sy-rig .sy-frame-outline,
  .sy-rig .sy-well,
  .sy-rig .sy-pipes { transition: none; }
}
