/* ===== 全域 Reset ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ===== Screen 系統 ===== */
.screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  z-index: 1;
}

.screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.blackout {
  background: #000;
  z-index: 50;
}

/* ===== Preloader ===== */
#preloader-screen {
  background: #000;
  z-index: 100;
  flex-direction: column;
}

.preloader-content {
  text-align: center;
  padding: 2rem;
}

.preloader-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin-bottom: 2rem;
  opacity: 0.7;
}

.preloader-bar-container {
  width: 200px;
  height: 3px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  margin: 0 auto 1rem;
  overflow: hidden;
}

.preloader-bar {
  height: 100%;
  width: 0%;
  background: #fff;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.preloader-text {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.4);
  letter-spacing: 0.1em;
}

.btn-start {
  margin-top: 2rem;
  padding: 0.8rem 2.5rem;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 10px;
  background: transparent;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  animation: pulse-text 1.5s ease-in-out infinite;
  -webkit-tap-highlight-color: transparent;
}

/* ===== 來電介面 ===== */
#screen-incoming-call {
  background: linear-gradient(180deg, #0d0d1a 0%, #1a1a2e 60%, #0f3460 100%);
  flex-direction: column;
  justify-content: space-between;
  padding: 0;
}

.call-interface {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
}

/* 大頭貼佔上方 50% */
.caller-avatar-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex: 1;
  padding-top: env(safe-area-inset-top, 20px);
}

.caller-avatar {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.35);
  object-fit: cover;
  background: rgba(255,255,255,0.08);
  box-shadow: 0 0 40px rgba(79, 139, 255, 0.3);
}

/* 名字 + 來電中 — 中間區域 */
.caller-info {
  text-align: center;
  padding: 1.5rem 2rem;
  width: 100%;
}

.caller-name {
  font-size: 2rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.call-status {
  font-size: 1rem;
  color: rgba(255,255,255,0.6);
  animation: pulse-text 2s ease-in-out infinite;
}

@keyframes pulse-text {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* 接聽按鈕 — 底部 */
.call-actions {
  padding-bottom: calc(10vh + env(safe-area-inset-bottom, 0px));
  display: flex;
  justify-content: center;
  width: 100%;
}

.btn-answer {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: none;
  background: #4caf50;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: ring-pulse 1.5s ease-in-out infinite;
  -webkit-tap-highlight-color: transparent;
}

@keyframes ring-pulse {
  0% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.5); }
  70% { box-shadow: 0 0 0 20px rgba(76, 175, 80, 0); }
  100% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0); }
}

.btn-answer:active {
  transform: scale(0.92);
}

/* ===== 耳機選擇 ===== */
#screen-earphone-choice {
  background: #000;
  flex-direction: column;
}

.choice-container {
  text-align: center;
  padding: 2rem;
  width: 100%;
  max-width: 360px;
}

.choice-prompt {
  font-size: 1.1rem;
  line-height: 1.8;
  margin-bottom: 2.5rem;
  color: rgba(255,255,255,0.85);
}

.choice-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.btn-choice {
  padding: 1rem 2rem;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 12px;
  background: transparent;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn-choice:active {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.6);
}

/* ===== 主遊戲畫面 ===== */
#screen-game {
  background: #000;
}

#camera-video {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  transform: scaleX(1);
}

/* 前鏡頭鏡像 */
#camera-video.front-camera {
  transform: scaleX(-1);
}

#fx-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

/* ===== 字幕 ===== */
.subtitle-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 1.5rem 1.5rem calc(1.5rem + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  z-index: 10;
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
}

.subtitle-bar.visible {
  opacity: 1;
}

#subtitle-text {
  font-size: 1.05rem;
  line-height: 1.7;
  text-align: center;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

/* ===== 文字覆蓋層（結局B 逐字）===== */
.text-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  pointer-events: none;
}

.text-overlay.active {
  display: flex;
}

.text-overlay .reveal-char {
  font-size: 2.5rem;
  font-weight: 700;
  opacity: 0;
  color: #fff;
  text-shadow: 0 0 20px rgba(255,0,0,0.6);
  animation: char-reveal 0.3s forwards;
}

@keyframes char-reveal {
  from { opacity: 0; transform: scale(1.5); }
  to { opacity: 1; transform: scale(1); }
}

/* ===== 結束畫面 ===== */
#screen-end {
  background: #000;
  flex-direction: column;
}

.end-content {
  text-align: center;
}

.end-call-info {
  opacity: 0;
  animation: fade-in 1s 0.5s forwards;
}

.end-caller {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.end-duration {
  font-size: 1rem;
  color: rgba(255,255,255,0.5);
  margin-bottom: 0.3rem;
}

.end-status {
  font-size: 0.9rem;
  color: rgba(255,255,255,0.4);
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== 權限 Overlay ===== */
.permission-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.permission-overlay.active {
  display: flex;
}

.permission-card {
  text-align: center;
  padding: 2rem;
  max-width: 300px;
}

.permission-card p {
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: 1.5rem;
  color: rgba(255,255,255,0.8);
}

.btn-permission {
  padding: 0.8rem 2.5rem;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 10px;
  background: transparent;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-permission:active {
  background: rgba(255,255,255,0.15);
}

/* ===== Canvas 特效用 CSS ===== */

/* 暗角 */
.vignette-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.7) 100%);
  z-index: 3;
  pointer-events: none;
}

/* 紅閃 */
.flash-red {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(180, 0, 0, 0.4);
  z-index: 15;
  pointer-events: none;
  animation: flash-fade 0.3s forwards;
}

@keyframes flash-fade {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* 白閃 */
.flash-white {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(255, 255, 255, 0.9);
  z-index: 15;
  pointer-events: none;
  animation: flash-fade 0.4s forwards;
}

/* 畫面抖動 */
.screen-shake {
  animation: shake 0.15s infinite;
}

@keyframes shake {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-3px, 2px); }
  50% { transform: translate(3px, -2px); }
  75% { transform: translate(-2px, -3px); }
  100% { transform: translate(2px, 3px); }
}

/* 全畫面故障 */
.glitch-effect {
  animation: glitch 0.1s infinite;
}

@keyframes glitch {
  0% { filter: none; }
  20% { filter: hue-rotate(90deg) saturate(3); }
  40% { filter: invert(0.8); }
  60% { filter: hue-rotate(-90deg) brightness(1.5); }
  80% { filter: saturate(0) contrast(3); }
  100% { filter: none; }
}

/* 電流邊框 */
.electric-border {
  box-shadow:
    inset 0 0 30px rgba(100, 180, 255, 0.3),
    inset 0 0 60px rgba(100, 180, 255, 0.1);
  animation: electric-pulse 0.2s infinite alternate;
}

@keyframes electric-pulse {
  from { box-shadow: inset 0 0 30px rgba(100, 180, 255, 0.3); }
  to { box-shadow: inset 0 0 50px rgba(100, 180, 255, 0.5), 0 0 20px rgba(100, 180, 255, 0.2); }
}

/* 離線文字 */
.offline-text {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1rem;
  color: rgba(255,255,255,0.3);
  z-index: 30;
  opacity: 0;
  animation: offline-fade 2s 1s forwards;
}

@keyframes offline-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
