/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #0095D9;       /* 品牌藍 - 主背景 */
  --blue-light: #00C0F0; /* 換人畫面背景 */
  --yellow: #FFD700;     /* 金黃 - 主按鈕/重點文字 */
  --red: #FF4444;        /* 警示紅 - 最後5秒 */
  --black: #1A1A1A;
  --dark: #0D0D0D;
  --white: #FFFFFF;
  --font: 'Noto Sans TC', 'Helvetica Neue', Arial, sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--blue);
  font-family: var(--font);
  color: var(--white);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ===== APP CONTAINER ===== */
#app {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

/* ===== SCREEN ===== */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;        /* prevents GPU layer bleed-through on iOS Safari */
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0s 0.25s;
  z-index: 1;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  pointer-events: all;
  transition: opacity 0.25s ease, visibility 0s 0s;
  z-index: 5;
}

/* ===== LOGO / BRAND ===== */
.brand-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 32px;
}

.brand-tag {
  font-size: 13px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.8);
  font-weight: 700;
}

.brand-title {
  font-size: 38px;
  font-weight: 900;
  color: var(--yellow);
  text-align: center;
  line-height: 1.1;
  text-shadow: 0 2px 12px rgba(0,0,0,0.25);
}

.brand-subtitle {
  font-size: 16px;
  color: rgba(255,255,255,0.65);
  letter-spacing: 1px;
}

/* ===== BUTTONS ===== */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: none;
  border-radius: 20px;
  font-family: var(--font);
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, opacity 0.12s;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.btn:active { transform: scale(0.96); }

/* 主要行動按鈕 — 金黃底、深色字 */
.btn-primary {
  background: var(--yellow);
  color: var(--black);
  font-size: 26px;
  padding: 22px 48px;
  border-radius: 24px;
  box-shadow: 0 6px 30px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 380px;
}

.btn-primary:active {
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

/* 次要按鈕 — 白色半透明 */
.btn-secondary {
  background: rgba(255,255,255,0.18);
  border: 2px solid rgba(255,255,255,0.4);
  color: var(--white);
  font-size: 20px;
  padding: 16px 32px;
  border-radius: 18px;
  width: 100%;
  max-width: 380px;
}

.btn-ghost {
  background: transparent;
  color: rgba(255,255,255,0.5);
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
}

/* 金黃按鈕（預覽頁確認） */
.btn-yellow {
  background: var(--yellow);
  color: var(--black);
  font-size: 20px;
  padding: 16px 32px;
  border-radius: 20px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 380px;
}

/* 藍底白字按鈕（QR頁換人） */
.btn-blue {
  background: var(--blue);
  color: var(--white);
  font-size: 22px;
  padding: 18px 36px;
  border-radius: 20px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 380px;
}

/* ===== SCREEN: START ===== */
#screen-start {
  background: #FFFFFF;
  gap: 0;
  justify-content: center;
}

/* 大頭佛工作室 logo */
.start-logo {
  width: 300px;
  height: auto;
  margin-bottom: 16px;
}

.start-logo.small {
  width: 300px;
  height: auto;
  margin-bottom: 12px;
}

/* Override brand text colours for light background */
#screen-start .brand-tag,
#screen-name .brand-tag {
  color: rgba(0,0,0,0.45);
}

#screen-start .brand-title {
  color: #8B6914;
  text-shadow: none;
}

#screen-start .brand-subtitle,
#screen-name .brand-subtitle {
  color: rgba(0,0,0,0.4);
}

.start-desc {
  font-size: 17px;
  color: rgba(0,0,0,0.65);
  text-align: center;
  max-width: 320px;
  line-height: 1.6;
  margin-bottom: 36px;
}

.start-desc em {
  color: #8B6914;
  font-style: normal;
  font-weight: 700;
}

/* ===== SCREEN: NAME INPUT ===== */
#screen-name {
  background: #FFFFFF;
  gap: 0;
}

.name-prompt {
  text-align: center;
  margin-bottom: 28px;
}

.name-title {
  font-size: 28px;
  font-weight: 900;
  color: #1A1A1A;
  margin-bottom: 6px;
}

.name-subtitle {
  font-size: 15px;
  color: rgba(0,0,0,0.4);
  letter-spacing: 1px;
}

.name-input-wrap {
  width: 100%;
  max-width: 380px;
  margin-bottom: 24px;
}

.name-input {
  width: 100%;
  padding: 20px 24px;
  font-size: 28px;
  font-family: var(--font);
  font-weight: 700;
  color: #1A1A1A;
  background: #fff;
  border: 3px solid rgba(0,0,0,0.1);
  border-radius: 20px;
  outline: none;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  -webkit-appearance: none;
}

.name-input:focus {
  border-color: var(--yellow);
  box-shadow: 0 4px 24px rgba(255,215,0,0.3);
}

.name-input::placeholder {
  color: rgba(0,0,0,0.25);
  font-weight: 400;
}

/* ===== SCREEN: RECORD ===== */
#screen-record {
  padding: 0;
  background: var(--dark);
}

#video-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  border-radius: 0;
}

.record-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.record-top {
  padding: 48px 24px 16px;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.countdown-ring {
  position: relative;
  width: 100px;
  height: 100px;
}

.countdown-ring svg {
  position: absolute;
  inset: 0;
  transform: rotate(-90deg);
}

.countdown-ring circle {
  fill: none;
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.9s linear, stroke 0.3s;
}

.countdown-ring .track { stroke: rgba(255,255,255,0.2); }
.countdown-ring .progress { stroke: var(--yellow); }

.countdown-number {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 900;
  color: var(--white);
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
  transition: color 0.3s;
}

.countdown-number.danger { color: var(--red); }
.countdown-ring.danger .progress { stroke: var(--red); }

.record-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  padding: 6px 16px;
  border-radius: 20px;
  pointer-events: none;
}

.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

.rec-label {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--white);
}

.record-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px 24px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, transparent 100%);
}

.record-hint {
  font-size: 15px;
  color: rgba(255,255,255,0.7);
  text-align: center;
}

.btn-stop {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: 4px solid var(--white);
  backdrop-filter: blur(8px);
  pointer-events: all;
  transition: transform 0.12s, background 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-stop:active { transform: scale(0.9); background: rgba(255,255,255,0.3); }

.btn-stop-inner {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--white);
}

/* ===== SCREEN: PREVIEW ===== */
#screen-preview {
  background: var(--blue);
  padding: 0;
  justify-content: flex-start;
  align-items: stretch;
}

#preview-wrapper {
  width: 100%;
  height: 54vh;
  flex-shrink: 0;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Flip the entire wrapper so video content is mirrored but controls outside are normal */
  transform: scaleX(-1);
  position: relative;
}

#preview-video {
  height: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  display: block;
  /* No transform here — wrapper handles the flip */
}

/* Tap overlay — covers video, handles play/pause tap */
#preview-tap-overlay {
  position: absolute;
  inset: 0;
  cursor: pointer;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  /* counter-flip so the icon itself is not mirrored */
  transform: scaleX(-1);
}

/* Play/pause icon shown in centre of video */
#preview-play-icon {
  font-size: 52px;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 2px 16px rgba(0,0,0,0.6);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

#preview-play-icon.visible {
  opacity: 1;
}

.preview-controls {
  width: 100%;
  padding: 14px 24px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: var(--blue);
}

.preview-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--yellow);
  text-align: center;
}

.trim-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.trim-label {
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.trim-label span { color: var(--yellow); font-weight: 700; }

#trim-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--yellow) 0%, var(--yellow) var(--pct, 100%), rgba(255,255,255,0.2) var(--pct, 100%));
  outline: none;
  cursor: pointer;
}

#trim-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  cursor: pointer;
}

.preview-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 380px;
}

/* ===== SCREEN: UPLOADING ===== */
#screen-uploading {
  background: var(--blue);
  gap: 32px;
}

.upload-icon {
  font-size: 64px;
  animation: spin-bounce 1.5s ease-in-out infinite;
}

@keyframes spin-bounce {
  0% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.15) rotate(180deg); }
  100% { transform: scale(1) rotate(360deg); }
}

.upload-title {
  font-size: 28px;
  font-weight: 900;
  color: var(--yellow);
  text-align: center;
}

.upload-subtitle {
  font-size: 16px;
  color: rgba(255,255,255,0.75);
  text-align: center;
}

.progress-bar-wrap {
  width: 100%;
  max-width: 320px;
  height: 10px;
  background: rgba(255,255,255,0.2);
  border-radius: 5px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--yellow);
  border-radius: 5px;
  animation: progress-pulse 2s ease-in-out infinite;
  width: 0%;
  transition: width 0.5s;
}

@keyframes progress-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ===== SCREEN: QR CODE ===== */
#screen-qrcode {
  background: var(--yellow);
  gap: 20px;
}

.qr-title {
  font-size: 28px;
  font-weight: 900;
  color: var(--black);
  text-align: center;
  line-height: 1.2;
}

.qr-subtitle {
  font-size: 16px;
  color: rgba(0,0,0,0.65);
  text-align: center;
}

.qr-box {
  background: var(--white);
  padding: 16px;
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.2);
}

.qr-box img {
  display: block;
  width: 220px;
  height: 220px;
  border-radius: 8px;
}

.qr-name-block {
  text-align: center;
  line-height: 1.5;
}

.qr-name {
  font-size: 22px;
  font-weight: 900;
  color: var(--black);
}

.qr-deadline {
  font-size: 13px;
  color: rgba(0,0,0,0.55);
  font-weight: 600;
  margin-top: 2px;
}

.qr-hint {
  font-size: 13px;
  color: rgba(0,0,0,0.45);
  text-align: center;
  max-width: 260px;
  line-height: 1.5;
}

.qr-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 380px;
  margin-top: 8px;
}

/* ===== SCREEN: END ===== */
#screen-end {
  background: var(--blue);
  gap: 24px;
}

.end-emoji { font-size: 80px; }

.end-title {
  font-size: 32px;
  font-weight: 900;
  color: var(--yellow);
  text-align: center;
}

.end-subtitle {
  font-size: 17px;
  color: rgba(255,255,255,0.85);
  text-align: center;
  line-height: 1.6;
}

.btn-restart {
  position: absolute;
  bottom: 24px;
  right: 24px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.4);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 10px;
  font-family: var(--font);
  cursor: pointer;
}

.btn-restart:active { opacity: 0.7; }

/* ===== TOAST ===== */
#toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: rgba(0,0,0,0.9);
  border: 1px solid var(--yellow);
  color: var(--white);
  padding: 14px 28px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  z-index: 9999;
  transition: transform 0.3s ease;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

#toast.show { transform: translateX(-50%) translateY(0); }

/* ===== CAMERA WAITING ===== */
.camera-waiting {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--dark);
  z-index: 2;
}

.camera-waiting .spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255,215,0,0.2);
  border-top-color: var(--yellow);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.camera-waiting p { color: rgba(255,255,255,0.7); font-size: 16px; }

/* ===== CAMERA READY OVERLAY ===== */
.ready-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.85) 38%, transparent 70%);
}

.ready-overlay.hidden { display: none; }

.ready-hint {
  font-size: 22px;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
  text-align: center;
  line-height: 1.4;
  margin-bottom: 24px;
}

.ready-hint span {
  display: block;
  font-size: 15px;
  color: rgba(255,255,255,0.45);
  font-weight: 400;
  margin-top: 4px;
}

.btn-go {
  width: 100%;
  padding: 32px 0;
  border-radius: 0;
  border: none;
  border-top: 3px solid rgba(255,215,0,0.3);
  background: var(--yellow);
  color: var(--black);
  font-size: 40px;
  font-weight: 900;
  font-family: var(--font);
  line-height: 1.1;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-go span {
  display: block;
  font-size: 17px;
  font-weight: 500;
  opacity: 0.6;
  margin-top: 4px;
  letter-spacing: 2px;
}

.btn-go:active {
  background: #e6c200;
  transform: scaleY(0.97);
}

/* ===== 3-2-1 START COUNTDOWN ===== */
.start-countdown {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}

.start-countdown.hidden { display: none; }

.start-countdown-number {
  font-size: 200px;
  font-weight: 900;
  line-height: 1;
  color: var(--white);
  text-shadow: 0 0 60px rgba(255,215,0,0.6), 0 4px 24px rgba(0,0,0,0.6);
  animation: countdown-pop 0.9s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.start-countdown-number.go {
  font-size: 120px;
  color: var(--yellow);
  text-shadow: 0 0 80px rgba(255,215,0,0.9), 0 4px 24px rgba(0,0,0,0.6);
}

.start-countdown-hint {
  font-size: 22px;
  font-weight: 700;
  color: rgba(255,255,255,0.8);
  letter-spacing: 2px;
}

@keyframes countdown-pop {
  0%   { transform: scale(1.6); opacity: 0; }
  30%  { transform: scale(0.95); opacity: 1; }
  70%  { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.7); opacity: 0; }
}
