:root {
  color-scheme: light;
  --paper: #fff8eb;
  --white: #ffffff;
  --ink: #18234b;
  --muted: #68708a;
  --blue: #4865ee;
  --blue-dark: #283b9f;
  --coral: #ff6f61;
  --yellow: #ffd45c;
  --mint: #5bc9a5;
  --line: rgba(24, 35, 75, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
}

.sound-setup {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(24, 35, 75, 0.72);
  backdrop-filter: blur(14px);
  transition: opacity 220ms ease, visibility 220ms ease;
}

.sound-setup.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.sound-panel {
  display: grid;
  justify-items: center;
  width: min(480px, 100%);
  padding: clamp(28px, 5vw, 46px);
  border: 5px solid var(--white);
  border-radius: 30px;
  color: var(--ink);
  text-align: center;
  background: var(--paper);
  box-shadow: 0 24px 70px rgba(10, 16, 48, 0.32);
}

.speaker-mark {
  position: relative;
  width: 86px;
  height: 72px;
  margin-bottom: 12px;
}

.speaker-mark::before {
  content: "";
  position: absolute;
  top: 23px;
  left: 5px;
  width: 26px;
  height: 30px;
  border-radius: 8px 3px 3px 8px;
  background: var(--blue);
}

.speaker-mark::after {
  content: "";
  position: absolute;
  top: 10px;
  left: 25px;
  width: 0;
  height: 0;
  border-top: 26px solid transparent;
  border-right: 34px solid var(--blue);
  border-bottom: 26px solid transparent;
}

.speaker-mark i {
  position: absolute;
  top: 50%;
  left: 58px;
  border: 4px solid var(--coral);
  border-top-color: transparent;
  border-bottom-color: transparent;
  border-left-color: transparent;
  border-radius: 50%;
  transform: translateY(-50%);
}

.speaker-mark i:nth-child(1) { width: 20px; height: 38px; }
.speaker-mark i:nth-child(2) { width: 32px; height: 58px; }

.sound-label {
  margin: 0 0 5px;
  color: var(--blue);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.12em;
}

.sound-panel h2 {
  margin: 0;
  font-size: clamp(1.8rem, 5vw, 2.8rem);
}

.sound-panel > span {
  max-width: 350px;
  margin-top: 9px;
  color: var(--muted);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 0.9rem;
  line-height: 1.65;
}

#enableSoundButton {
  margin-top: 22px;
  padding: 13px 22px;
  border: 0;
  border-radius: 14px;
  color: var(--white);
  font: inherit;
  font-weight: 800;
  background: var(--blue);
  box-shadow: 0 8px 18px rgba(72, 101, 238, 0.24);
  cursor: pointer;
}

#enableSoundButton:disabled {
  cursor: wait;
  opacity: 0.65;
}

#soundError {
  min-height: 1.4em;
  margin-top: 10px;
  color: #c43e4a;
  font-size: 0.78rem;
}

body {
  color: var(--ink);
  font-family: "Arial Rounded MT Bold", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background:
    radial-gradient(circle at 5% 12%, rgba(255, 212, 92, 0.28) 0 80px, transparent 82px),
    radial-gradient(circle at 96% 3%, rgba(91, 201, 165, 0.22) 0 110px, transparent 112px),
    var(--paper);
  user-select: none;
  -webkit-user-select: none;
}

.shell {
  display: grid;
  width: 100%;
  height: 100vh;
  height: 100svh;
}

/* 斷線提示。連線正常時整顆隱藏 —— 待機畫面上只會有背景圖，別無他物。
   浮在畫面上方而非佔一列版面，這樣顯示/隱藏不會推動底下的背景圖。 */
.connection {
  position: fixed;
  z-index: 10000;
  top: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  color: var(--white);
  font-size: clamp(0.72rem, 1.2vw, 0.86rem);
  font-weight: 700;
  background: rgba(196, 62, 74, 0.86);
  backdrop-filter: blur(10px);
  transition: opacity 220ms ease, visibility 220ms ease;
}

.connection.connected {
  visibility: hidden;
  opacity: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.25);
}

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #000;
}

.stage.has-video {
  position: fixed;
  inset: 0;
  z-index: 9999;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  border: 0;
  border-radius: 0;
  background: #000;
  box-shadow: none;
}

body.video-playing {
  overflow: hidden;
  background: #000;
}

#mainVideo {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 300ms ease;
}

.stage.has-video #mainVideo {
  opacity: 1;
  object-fit: contain;
}

/* 待機畫面 = 一張滿版背景圖，沒有文字也沒有圖示。 */
.idle-state {
  position: absolute;
  inset: 0;
  background: #000;
  transition: opacity 220ms ease;
}

/* cover 會裁切以填滿螢幕；若不想讓圖被裁掉，改成 contain（四周會留黑邊）。 */
#idleImage {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.stage.has-video .idle-state {
  opacity: 0;
}

.finished-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 30px;
  text-align: center;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 212, 92, 0.34) 0 65px, transparent 67px),
    radial-gradient(circle at 82% 82%, rgba(91, 201, 165, 0.28) 0 95px, transparent 97px),
    var(--paper);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.stage.finished .idle-state {
  opacity: 0;
}

.stage.finished .finished-state {
  opacity: 1;
}

.finished-mark {
  position: relative;
  width: clamp(64px, 9vw, 100px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 10px 24px rgba(91, 201, 165, 0.24);
}

.finished-mark i {
  position: absolute;
  top: 28%;
  left: 25%;
  width: 48%;
  height: 28%;
  border-bottom: 7px solid var(--white);
  border-left: 7px solid var(--white);
  transform: rotate(-45deg);
}

.finished-state p {
  margin: 18px 0 6px;
  font-size: clamp(2rem, 5vw, 4rem);
  font-weight: 900;
}

.finished-state span {
  color: var(--muted);
  font-size: clamp(0.9rem, 1.8vw, 1.2rem);
  font-weight: 700;
}

.playing-badge {
  position: absolute;
  z-index: 3;
  right: 16px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--white);
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(24, 35, 75, 0.68);
  opacity: 0;
  backdrop-filter: blur(10px);
  transition: opacity 220ms ease;
}

.stage.has-video .playing-badge {
  opacity: 1;
}

.playing-badge i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mint);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
