:root {
  color-scheme: dark;
  --panel-bg: rgba(0, 0, 0, 0.62);
  --panel-border: rgba(255, 255, 255, 0.22);
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --accent: #38bdf8;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

* {
  -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none; /* Safari */
     -khtml-user-select: none; /* Konqueror HTML */
       -moz-user-select: none; /* Old versions of Firefox */
        -ms-user-select: none; /* Internet Explorer/Edge */
            user-select: none; /* Non-prefixed version, currently
                                  supported by Chrome, Edge, Opera and Firefox */
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #020617;
  font-family: "PingFang TC", "Noto Sans TC", Arial, sans-serif;
  color: var(--text-main);
}

body {
  display: grid;
  place-items: center;
}

.app-shell {
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top, #14213d 0%, #020617 70%);
}

.stage-frame {
  position: relative;
  width: min(94vw, calc(94vh * 16 / 9));
  height: min(94vh, calc(94vw * 9 / 16));
  max-width: 100vw;
  max-height: 100vh;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: clamp(16px, 2vw, 24px);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15), 0 30px 80px rgba(0, 0, 0, 0.45);
  background: #000;
  isolation: isolate;
}

.background-video,
.three-container,
.camera-preview,
.start-overlay,
.settings-panel,
.settings-button {
  position: absolute;
}

.background-video {
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.8) brightness(0.55);
}

.three-container {
  inset: 0;
  width: 100%;
  height: 100%;
}

.camera-preview,
.camera-overlay {
  right: clamp(10px, 1.5vw, 18px);
  bottom: clamp(10px, 1.5vw, 18px);
  width: clamp(128px, 20vw, 384px);
  aspect-ratio: 16 / 9;
  border-radius: clamp(12px, 1.5vw, 16px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.camera-preview {
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.28);
  background: #111;
  z-index: 2;
  transform: scaleX(-1);
}

.camera-overlay {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  background: transparent;
  transform: scaleX(-1);
}

.settings-button {
  top: clamp(10px, 1.5vw, 18px);
  right: clamp(10px, 1.5vw, 18px);
  z-index: 4;
  border: none;
  width: clamp(42px, 3.8vw, 56px);
  height: clamp(42px, 3.8vw, 56px);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.76);
  color: var(--text-main);
  font-size: clamp(1rem, 1.3vw, 1.2rem);
  cursor: pointer;
}

.settings-panel {
  top: clamp(58px, 6vw, 74px);
  right: clamp(10px, 1.5vw, 18px);
  z-index: 5;
  width: min(280px, 70vw);
  padding: clamp(14px, 1.8vw, 18px);
  border-radius: clamp(14px, 1.8vw, 18px);
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  border: 1px solid var(--panel-border);
  display: none;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.settings-panel.active {
  display: block;
}

.settings-panel h2 {
  margin: 0 0 10px;
  font-size: clamp(1rem, 1.4vw, 1.15rem);
}

.settings-panel label {
  display: block;
  margin-bottom: 6px;
  font-size: clamp(0.8rem, 1.05vw, 0.95rem);
  color: var(--text-muted);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 8px;
  font-size: clamp(0.85rem, 1.05vw, 0.95rem);
  color: var(--text-main);
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.settings-panel select,
.secondary-button {
  width: 100%;
  padding: clamp(8px, 1vw, 10px);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-main);
  font-size: clamp(0.85rem, 1.05vw, 0.95rem);
}

.secondary-button {
  margin-top: 10px;
  cursor: pointer;
}

.start-overlay {
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  cursor: pointer;
}

.start-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.start-card {
  width: min(78vw, 420px);
  padding: clamp(20px, 3vw, 32px);
  border-radius: clamp(20px, 3vw, 30px);
  background: rgba(2, 6, 23, 0.76);
  border: 1px solid rgba(255, 255, 255, 0.2);
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.start-card h1 {
  margin: 0 0 10px;
  font-size: clamp(1.4rem, 3.4vw, 2.2rem);
  font-weight: 700;
}

.start-card p {
  margin: 0;
  font-size: clamp(0.95rem, 1.35vw, 1.1rem);
  color: var(--text-muted);
}

.start-error {
  margin-top: clamp(10px, 1.2vw, 12px);
  color: #fda4af;
  font-size: clamp(0.9rem, 1.2vw, 1rem);
  line-height: 1.4;
}

@media (max-width: 768px) {
  .stage-frame {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    aspect-ratio: 9 / 16;
    border-radius: 0;
  }

  .camera-preview {
    width: clamp(92px, 18vw, 128px);
  }
}
