/* 3D 示意元件（public/js/viewer3d.js）。色彩與字型依日本風格版 jp.css／common.css。
   頁面若已定義 --blue、--ink 等變數會沿用，沒有就用下面的預設值。 */
.v3d {
  --v3d-blue: var(--blue, #283f85);
  --v3d-deep: var(--deep, #20356e);
  --v3d-ink: var(--ink, #17243a);
  --v3d-muted: var(--muted, #66758b);
  --v3d-line: var(--line, #dce3ed);
  --v3d-pale: var(--pale, #f5f7fa);
  --v3d-sky: var(--sky, #4770b8);
  --v3d-active: #edf2fb;
  --v3d-focus: #4c85d3;
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  border: 1px solid var(--v3d-line);
  background: #fff;
  color: var(--v3d-ink);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  font-size: 15px;
  line-height: 1.7;
  text-align: left;
}
.v3d *, .v3d *::before, .v3d *::after { box-sizing: border-box; }
.v3d button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
.v3d :focus-visible { outline: 3px solid var(--v3d-focus); outline-offset: 3px; }
.v3d [hidden] { display: none !important; }

/* ── 舞台 ── */
.v3d-stage {
  position: relative;
  min-width: 0;
  min-height: 480px;
  overflow: hidden;
  background: linear-gradient(130deg, #f4f7fc 0%, #eaf0fa 100%);
  border-bottom: 3px solid var(--v3d-blue);
}
.v3d-stage::after { /* 與首頁主視覺相同的斜向淡色帶 */
  content: "";
  position: absolute;
  width: 130px;
  height: 160%;
  right: 12%;
  top: -30%;
  background: #dae4f580;
  transform: rotate(30deg);
  pointer-events: none;
}
.v3d-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}
.v3d-canvas:active { cursor: grabbing; }
.v3d-canvas:focus-visible { outline-offset: -4px; }

.v3d-badge {
  position: absolute;
  z-index: 3;
  top: 16px;
  left: 16px;
  padding: 5px 11px;
  background: var(--v3d-blue);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  line-height: 1.4;
  pointer-events: none;
}
.v3d-hint {
  position: absolute;
  z-index: 3;
  right: 16px;
  bottom: 12px;
  margin: 0;
  max-width: calc(100% - 32px);
  font-size: 11px;
  letter-spacing: .06em;
  color: #6c7d99;
  pointer-events: none;
}
.v3d-message {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
}
.v3d-message-text {
  margin: 0;
  max-width: 26em;
  color: var(--v3d-blue);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .04em;
}
.v3d[data-state="idle"] .v3d-message-text,
.v3d[data-state="loading"] .v3d-message-text { color: #6c7d99; font-weight: 400; }

/* 不支援 WebGL 或載入失敗：舞台縮成上方一則說明，下方以文字步驟為主 */
.v3d[data-state="fallback"],
.v3d[data-state="error"] { grid-template-columns: minmax(0, 1fr); }
.v3d[data-state="fallback"] .v3d-stage,
.v3d[data-state="error"] .v3d-stage { height: auto; min-height: 0; }
.v3d[data-state="fallback"] .v3d-message,
.v3d[data-state="error"] .v3d-message { position: relative; padding: 56px 24px 22px; }
.v3d[data-state="fallback"] .v3d-panel,
.v3d[data-state="error"] .v3d-panel { border-left: 0; }
.v3d[data-state="fallback"] .v3d-controls-main,
.v3d[data-state="error"] .v3d-controls-main { grid-template-columns: repeat(2, minmax(0, 180px)); }
.v3d[data-state="fallback"] .v3d-controls-sub,
.v3d[data-state="error"] .v3d-controls-sub,
.v3d[data-state="fallback"] [data-action="play"],
.v3d[data-state="error"] [data-action="play"],
.v3d[data-state="fallback"] .v3d-progress,
.v3d[data-state="error"] .v3d-progress { display: none; }

/* ── 標籤 ── */
.v3d-labels { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.v3d-label {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  will-change: transform;
}
.v3d-label::before { /* 錨點 */
  content: "";
  position: absolute;
  left: -4px;
  top: -4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--v3d-sky);
  box-shadow: 0 0 0 2px #fff;
}
.v3d-label-text {
  position: absolute;
  top: -12px;
  left: 12px;
  padding: 2px 8px 2px 7px;
  background: #ffffffeb;
  border-left: 3px solid var(--v3d-blue);
  box-shadow: 0 2px 10px #1426541a;
  color: var(--v3d-ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
}
.v3d-label-left .v3d-label-text {
  left: auto;
  right: 12px;
  padding: 2px 7px 2px 8px;
  border-left: 0;
  border-right: 3px solid var(--v3d-blue);
}

/* ── 說明面板 ── */
.v3d-panel {
  min-width: 0;
  padding: 26px 28px 22px;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--v3d-line);
}
.v3d-title {
  margin: 0 0 10px;
  color: var(--v3d-blue);
  font-size: 21px;
  font-weight: 700;
  line-height: 1.45;
  letter-spacing: .03em;
}
.v3d-title::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 19px;
  margin-right: 11px;
  background: var(--v3d-blue);
  vertical-align: -2px;
}
.v3d-summary { margin: 0; color: var(--v3d-muted); font-size: 13px; line-height: 1.9; }

.v3d-steps { list-style: none; margin: 16px 0 18px; padding: 0; border-top: 1px solid var(--v3d-line); }
.v3d-steps li { border-bottom: 1px solid var(--v3d-line); }
.v3d-step {
  display: flex;
  gap: 12px;
  width: 100%;
  padding: 12px 10px 12px 12px;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background .2s;
}
.v3d-step:hover { background: var(--v3d-pale); }
.v3d-step[aria-current="step"] { background: var(--v3d-active); border-left-color: var(--v3d-blue); }
.v3d-step-no { flex-shrink: 0; padding-top: 1px; color: #8ba0c4; font-size: 12px; font-weight: 700; letter-spacing: .08em; }
.v3d-step[aria-current="step"] .v3d-step-no { color: var(--v3d-blue); }
.v3d-step-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.v3d-step-text strong { color: var(--v3d-ink); font-size: 14px; }
.v3d-step[aria-current="step"] .v3d-step-text strong { color: var(--v3d-blue); }
.v3d-step-text span { color: var(--v3d-muted); font-size: 12.5px; line-height: 1.8; }

/* ── 按鈕（同 common.css 的 .btn：直角、粗體、主色實心／外框） ── */
.v3d-controls { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.v3d-controls-main { display: grid; grid-template-columns: 1fr 1.35fr 1fr; gap: 8px; }
.v3d-controls-sub { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.v3d-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 46px;
  padding: 8px 12px;
  border: 1px solid var(--v3d-blue);
  border-radius: 0;
  background: #fff;
  color: var(--v3d-blue);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.v3d-btn:hover:not(:disabled) { background: #edf2fa; }
.v3d-btn.v3d-primary { background: var(--v3d-blue); color: #fff; }
.v3d-btn.v3d-primary:hover:not(:disabled) { background: #192d67; }
.v3d-btn.v3d-text {
  min-height: 40px;
  padding: 6px 2px;
  border-color: transparent;
  background: transparent;
  font-size: 12.5px;
}
.v3d-btn.v3d-text:hover:not(:disabled) { background: transparent; text-decoration: underline; text-underline-offset: 5px; }
.v3d-btn:disabled { opacity: .4; cursor: default; }
.v3d-icon { display: inline-flex; width: 16px; height: 16px; flex-shrink: 0; }
.v3d-icon svg { width: 100%; height: 100%; }
.v3d-load { min-width: 180px; }

.v3d-progress { position: relative; height: 3px; margin-top: 14px; background: #e4eaf3; overflow: hidden; }
.v3d-progress-bar { position: absolute; inset: 0; background: var(--v3d-sky); transform: scaleX(0); transform-origin: left; }
.v3d-tick { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: #fff; }

.v3d-notice { margin: 14px 0 0; color: #8392a8; font-size: 11px; line-height: 1.8; }
.v3d-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ── 響應式 ── */
@media (max-width: 960px) {
  .v3d { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
  .v3d-stage { min-height: 440px; }
  .v3d-panel { padding: 20px 18px 18px; }
  .v3d-title { font-size: 19px; }
}
@media (max-width: 760px) {
  .v3d { grid-template-columns: minmax(0, 1fr); }
  .v3d-stage { min-height: 0; height: clamp(320px, 105vw, 460px); }
  .v3d-panel { border-left: 0; padding: 18px 16px 16px; }
  .v3d-title { font-size: 18px; }
  .v3d-badge { top: 12px; left: 12px; font-size: 11px; }
  .v3d-hint { right: 12px; bottom: 10px; font-size: 10.5px; }
  .v3d-label-text { font-size: 11px; }
  .v3d-step { padding-block: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .v3d *, .v3d *::before, .v3d *::after { transition: none !important; }
}
@media print {
  .v3d { grid-template-columns: 1fr; }
  .v3d-stage, .v3d-controls, .v3d-progress { display: none; }
}
