/* 元智 3D 校園實驗室：在首頁 3D 元件的樣式上，加入標題列、角色選單、API 面板與說話泡泡。 */
.lab {
  --panel-bg: rgba(5, 16, 42, .74);
  --panel-line: rgba(255, 255, 255, .16);
  --accent: #ff8a2a;
  --ok: #49d18a;
  --warn: #ffcf5a;
  --bad: #ff7a6b;
}

.lab-top {
  position: absolute;
  top: 14px;
  left: clamp(14px, 2.2vw, 28px);
  z-index: 3;
  max-width: min(520px, calc(100% - 200px));
  pointer-events: none;
}

.lab-top > * { pointer-events: auto; }

.lab-back {
  display: inline-block;
  margin-bottom: 6px;
  color: #cfe0ff;
  font-size: 13px;
  text-decoration: none;
}

.lab-back:hover, .lab-back:focus-visible { color: #ffffff; text-decoration: underline; }

.lab-top h1 {
  margin: 0;
  font-size: clamp(22px, 2.4vw, 32px);
  letter-spacing: .04em;
  line-height: 1.2;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .45);
}

.lab-sub {
  margin: 4px 0 8px;
  font-size: 13px;
  color: #e3eeff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .6);
}

.lab .lab-top .scene-clock {
  position: static;
  display: inline-block;
  max-width: 100%;
}

.panel-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 15px;
  letter-spacing: .06em;
}

.panel-title span {
  font-size: 11px;
  font-weight: 500;
  color: #a9bde4;
}

/* ---------- 角色選單 ---------- */
.cast-panel {
  position: absolute;
  left: clamp(14px, 2.2vw, 28px);
  top: 168px;
  z-index: 3;
  width: 318px;
  max-height: calc(100% - 168px - 150px);
  overflow-y: auto;
  padding: 14px;
  border-radius: 16px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-line);
  backdrop-filter: blur(8px);
  display: none;
}

.cast-panel[data-open] { display: block; }

.cast-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }

.cast-collapse {
  flex: none;
  min-height: 28px;
  padding: 3px 10px;
  border-radius: 100px;
  border: 1px solid rgba(255, 255, 255, .4);
  background: transparent;
  color: #ffffff;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.cast-collapse:hover, .cast-collapse:focus-visible { background: #ffffff; color: #07122d; outline: none; }

.cast-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.cast-pick {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 36px;
  padding: 5px 7px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .22);
  background: rgba(255, 255, 255, .06);
  color: #ffffff;
  font: inherit;
  font-size: 12.5px;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease;
}

.cast-pick:hover, .cast-pick:focus-visible { background: rgba(255, 255, 255, .16); outline: none; }
.cast-pick[aria-pressed="true"] { border-color: var(--accent); background: rgba(255, 138, 42, .22); }

.cast-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cast-swatch {
  flex: none;
  width: 14px;
  height: 18px;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--b) 0 35%, var(--a) 35% 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
}

.cast-card { margin-top: 12px; }

.cast-title { margin: 0; font-size: 18px; }
.cast-sub { margin: 2px 0 6px; font-size: 12px; color: #ffcf9a; }
.cast-intro { margin: 0 0 10px; font-size: 13px; line-height: 1.6; color: #dfe8fb; }

.cast-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.cast-actions button {
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 100px;
  border: 1px solid rgba(255, 255, 255, .55);
  background: rgba(4, 20, 55, .5);
  color: #ffffff;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

.cast-actions button:hover, .cast-actions button:focus-visible { background: #ffffff; color: #07122d; outline: none; }

/* ---------- API 面板 ---------- */
.lab-toggles {
  position: absolute;
  top: 14px;
  right: clamp(14px, 2.2vw, 28px);
  z-index: 4;
  display: flex;
  gap: 8px;
}

.lab-toggles button {
  min-height: 36px;
  padding: 7px 14px;
  border-radius: 100px;
  border: 1px solid rgba(255, 255, 255, .55);
  background: rgba(4, 20, 55, .6);
  color: #ffffff;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.lab-toggles button[aria-expanded="true"] { background: var(--accent); border-color: var(--accent); color: #07122d; font-weight: 700; }

.api-panel {
  position: absolute;
  top: 62px;
  right: clamp(14px, 2.2vw, 28px);
  bottom: 128px;
  z-index: 3;
  width: 340px;
  overflow-y: auto;
  padding: 14px;
  border-radius: 16px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-line);
  backdrop-filter: blur(8px);
  display: none;
}

.api-panel[data-open] { display: block; }

.api-top { display: flex; justify-content: space-between; align-items: flex-start; }

.api-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .4);
  background: transparent;
  color: #ffffff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.api-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.api-card {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .1);
}

.api-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.api-head h3 { margin: 0; font-size: 14px; }

.api-status {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: #cfe0ff;
}

.api-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
}

.api-status[data-state="ok"]::before { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.api-status[data-state="error"]::before { background: var(--bad); }
.api-status[data-state="idle"]::before { background: #8391ad; }

.api-provider { margin: 3px 0 0; font-size: 11.5px; color: #a9bde4; }
.api-value { margin: 6px 0; font-size: 14px; font-weight: 700; color: #ffffff; }
.api-role { margin: 0; font-size: 12.5px; line-height: 1.6; color: #d6e1f7; }
.api-link { display: inline-block; margin-top: 6px; font-size: 12px; color: #ffcf9a; }

.api-howto { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--panel-line); }
.api-howto h3 { margin: 0 0 8px; font-size: 14px; }
.api-howto ol { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 12.5px; line-height: 1.65; color: #d6e1f7; }
.api-howto strong { color: #ffffff; }

/* ---------- 說話泡泡 ---------- */
.speech-bubble {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  max-width: 260px;
  padding: 8px 12px;
  border-radius: 14px;
  background: #ffffff;
  color: #10203f;
  font-size: 14px;
  line-height: 1.45;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .3);
  pointer-events: none;
  transition: opacity .2s linear;
}

.speech-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: #ffffff;
  transform: translateX(-50%) rotate(45deg);
}

.speech-bubble[hidden] { display: none; }

.lab-noscript { position: fixed; inset: 40% 0 auto; text-align: center; color: #ffffff; }

/* ---------- 窄螢幕：面板改由按鈕開關 ---------- */
@media (max-width: 900px) {
  .lab-top { max-width: calc(100% - 28px); }
  .lab-sub { display: none; }
  .lab-toggles { top: auto; bottom: 168px; }
  .cast-panel, .api-panel {
    display: none;
    top: 96px;
    left: 12px;
    right: 12px;
    bottom: auto;
    width: auto;
    max-height: calc(100% - 96px - 220px);
  }
  .cast-panel[data-open], .api-panel[data-open] { display: block; }
  .cast-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .lab .scene-hud { bottom: 40px; }
}

@media (max-width: 520px) {
  .cast-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lab .hud-controls { max-height: 112px; overflow-y: auto; }
  .lab .scene-status { bottom: 8px; font-size: 10.5px; }
}

/* ---------- 角色轉盤 ---------- */
.cast-dial { --dial-r: clamp(108px, 30vmin, 150px); }

.dial-center {
  position: absolute;
  left: clamp(14px, 2.2vw, 28px);
  bottom: 176px;
  z-index: 5;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #ffffff;
  font: inherit;
  cursor: pointer;
  transition: left .35s ease, bottom .35s ease, width .35s ease, height .35s ease, transform .35s ease;
}

.dial-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #0b1838 0 52%, transparent 53%), conic-gradient(var(--a, #4b4f55) 0 50%, var(--b, #17120f) 50% 100%);
  border: 3px solid #ffffff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .45), 0 0 0 3px rgba(255, 138, 42, .55);
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}

.dial-name {
  position: absolute;
  left: 50%;
  top: calc(100% + 4px);
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .8);
}

.dial-center:focus-visible .dial-face { box-shadow: 0 0 0 4px #ffb067; }

.dial-backdrop {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: rgba(3, 10, 30, .5);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}

.dial-ring { position: absolute; inset: 0; z-index: 6; pointer-events: none; }

.dial-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: conic-gradient(var(--a) 0 50%, var(--b) 50% 100%);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .4), inset 0 0 0 2px rgba(255, 255, 255, .85);
  color: #ffffff;
  font: inherit;
  cursor: pointer;
  pointer-events: none;
  opacity: 0;
  transform: translate(0, 0) scale(.3);
  transition: transform .35s cubic-bezier(.2, .9, .3, 1.2), opacity .25s ease;
  transition-delay: calc(var(--i) * 18ms);
}

.dial-glyph {
  position: absolute;
  inset: 7px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(8, 18, 45, .82);
  font-size: 15px;
  font-weight: 800;
}

.dial-label {
  position: absolute;
  left: 50%;
  top: calc(100% + 3px);
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 11.5px;
  font-weight: 700;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .9);
}

.dial-dot[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--accent), 0 4px 12px rgba(0, 0, 0, .4), inset 0 0 0 2px #ffffff; }
.dial-dot:hover .dial-glyph, .dial-dot:focus-visible .dial-glyph { background: #ffffff; color: #07122d; }
.dial-dot:focus-visible { outline: none; }

.dial-tip {
  position: absolute;
  left: 50%;
  top: calc(50% + var(--dial-r) + 44px);
  z-index: 6;
  margin: 0;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 12px;
  color: #e3eeff;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}

/* 轉盤展開：大圓移到畫面中央，小圓點從中心散開成一圈 */
.cast-dial[data-state="ring"] .dial-backdrop { opacity: 1; pointer-events: auto; }
.cast-dial[data-state="ring"] .dial-tip { opacity: 1; }
.cast-dial[data-state="ring"] .dial-dot {
  pointer-events: auto;
  opacity: 1;
  transform: translate(calc(var(--x) * var(--dial-r)), calc(var(--y) * var(--dial-r))) scale(1);
}
.cast-dial[data-state="ring"] .dial-center {
  left: 50%;
  bottom: 50%;
  z-index: 7;
  width: 96px;
  height: 96px;
  transform: translate(-50%, 50%);
}
.cast-dial[data-state="ring"] .dial-face { font-size: 34px; }
.cast-dial[data-state="ring"] .dial-name { top: calc(100% + 6px); font-size: 14px; }
.cast-dial[data-state="ring"] .dial-name::after { content: "　點中間看介紹"; font-weight: 500; color: #ffcf9a; }

/* 完整面板打開時不顯示大圓 */
.cast-dial[data-state="panel"] .dial-center { opacity: 0; pointer-events: none; }

@media (max-width: 900px) {
  .dial-center { bottom: 226px; width: 58px; height: 58px; }
  .dial-face { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .dial-center, .dial-dot, .dial-backdrop, .dial-tip { transition: none; }
}

/* ---------- 圓點選單（2026-10-23） ---------- */
.hud-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  padding: 6px 8px 4px;
  border-radius: 22px;
  background: rgba(3, 14, 40, .55);
  border: 1px solid rgba(255, 255, 255, .18);
  backdrop-filter: blur(6px);
  pointer-events: auto;
}

.hud-dot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 46px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #ffffff;
  font: inherit;
  cursor: pointer;
}

.hud-dot-face {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(4, 20, 55, .6);
  border: 1px solid rgba(255, 255, 255, .55);
  transition: background-color .15s ease, color .15s ease, transform .15s ease;
}

.hud-dot-face svg { width: 19px; height: 19px; }
.hud-dot-label { font-size: 10.5px; line-height: 1.2; color: #dfe8fb; white-space: nowrap; }
.hud-dot[data-active="true"] .hud-dot-face { background: var(--accent); border-color: var(--accent); color: #07122d; }
.hud-dot:hover .hud-dot-face, .hud-dot:focus-visible .hud-dot-face { background: #ffffff; color: #07122d; transform: translateY(-2px); }
.hud-dot:focus-visible { outline: none; }

.menu-sheet { position: absolute; inset: 0; z-index: 8; display: grid; place-items: center; }
.menu-sheet[hidden] { display: none; }
.menu-backdrop { position: absolute; inset: 0; background: rgba(3, 10, 30, .5); backdrop-filter: blur(3px); }

.menu-card {
  position: relative;
  width: min(420px, calc(100% - 32px));
  max-height: min(70vh, 560px);
  overflow-y: auto;
  padding: 16px;
  border-radius: 20px;
  background: rgba(7, 20, 52, .94);
  border: 1px solid rgba(255, 255, 255, .2);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .45);
  transform: scale(.94);
  transition: transform .18s ease; /* 只動大小、不做透明度：畫面很忙時動畫可能延遲，選單仍要立刻看得到 */
}

.menu-sheet[data-open] .menu-card { transform: none; }
.menu-head { display: flex; align-items: center; gap: 10px; }
.menu-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #07122d; }
.menu-icon svg { width: 18px; height: 18px; }
.menu-head h2 { flex: 1; margin: 0; font-size: 17px; }

.menu-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .4);
  background: transparent;
  color: #ffffff;
  font-size: 18px;
  cursor: pointer;
}

.menu-note { margin: 8px 0 12px; font-size: 12.5px; line-height: 1.6; color: #b9cbec; }
.menu-note:empty { display: none; }
.menu-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.menu-group { grid-column: 1 / -1; margin: 6px 0 0; font-size: 11.5px; color: #ffcf9a; letter-spacing: .06em; }

.menu-option {
  min-height: 42px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(255, 255, 255, .06);
  color: #ffffff;
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}

.menu-option:hover, .menu-option:focus-visible { background: rgba(255, 255, 255, .16); outline: none; }
.menu-option[aria-checked="true"] { border-color: var(--accent); background: rgba(255, 138, 42, .25); box-shadow: inset 0 0 0 1px var(--accent); }

@media (max-width: 900px) {
  .hud-dots { justify-content: center; }
  .hud-dot { width: 42px; }
  .hud-dot-face { width: 34px; height: 34px; }
}

@media (max-width: 520px) {
  .menu-options { grid-template-columns: minmax(0, 1fr); }
}

/* 爆笑事件通知：畫面上方中央，九秒後自動收起 */
.event-toast {
  position: absolute;
  top: 84px;
  left: 50%;
  z-index: 6;
  width: min(360px, calc(100% - 32px));
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(7, 20, 52, .92);
  border: 1px solid rgba(255, 138, 42, .7);
  box-shadow: 0 14px 34px rgba(0, 0, 0, .4);
  color: #ffffff;
  transform: translateX(-50%);
  animation: event-toast-in .28s ease both;
}
.event-toast[hidden] { display: none; }
.event-toast p { margin: 0; }
.event-toast-kicker { font-size: 11px; letter-spacing: .08em; color: #ffcf9a; }
.event-toast-title { margin-top: 2px !important; font-size: 16px; font-weight: 800; }
.event-toast-text { margin-top: 4px !important; font-size: 12.5px; line-height: 1.6; color: #c9d7f2; }
.event-toast-actions { display: flex; gap: 8px; margin-top: 10px; }
.event-toast-go {
  flex: 1;
  min-height: 36px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #07122d;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.event-toast-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .4);
  background: transparent;
  color: #ffffff;
  font-size: 18px;
  cursor: pointer;
}
@keyframes event-toast-in { from { transform: translate(-50%, -10px); } to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) { .event-toast { animation: none; } }
@media (max-width: 900px) { .event-toast { top: 64px; } }
