:root {
  --glass-bg: rgba(18, 24, 34, 0.56);
  --glass-border: rgba(255, 255, 255, 0.22);
  --accent: #ff6b6b;
  --accent-teal: #2b8a9c;
  --text-main: #ffffff;
  --text-sub: rgba(255, 255, 255, 0.82);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #121821;
  color: var(--text-main);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, -apple-system, sans-serif;
  touch-action: none;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: #121821;
}

#cameraVideo {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#stageCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* Welcome Overlay */
.welcome-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 25%, rgba(43, 138, 156, 0.45), rgba(14, 19, 28, 0.88));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.welcome-card {
  width: 100%;
  max-width: 390px;
  padding: 24px 20px 22px;
  border-radius: 26px;
  background: rgba(25, 33, 46, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.welcome-preview {
  width: 132px;
  height: 132px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, rgba(255, 255, 255, 0.2), rgba(43, 138, 156, 0.25));
  display: flex;
  align-items: center;
  justify-content: center;
  animation: clayBob 2.2s steps(6, end) infinite;
}

.welcome-preview img {
  width: 118px;
  height: 118px;
  object-fit: contain;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.35));
}

@keyframes clayBob {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-6px) rotate(1.5deg); }
}

.welcome-card h1 {
  margin: 0 0 8px;
  font-size: 1.38rem;
  letter-spacing: 0.03em;
}

.welcome-desc {
  margin: 0 0 14px;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text-sub);
}

.welcome-tips {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 18px;
  padding: 11px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.07);
  font-size: 0.8rem;
  text-align: left;
  color: #e9f2f7;
}

.welcome-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-primary,
.btn-secondary {
  width: 100%;
  border: none;
  border-radius: 15px;
  padding: 14px 16px;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease;
}

.btn-primary {
  background: linear-gradient(135deg, #ff786b, #e84c5a);
  color: #fff;
  box-shadow: 0 10px 24px rgba(232, 76, 90, 0.38);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.btn-primary:active,
.btn-secondary:active {
  transform: scale(0.97);
}

.https-notice {
  margin: 12px 0 0;
  padding: 9px 10px;
  border-radius: 11px;
  background: rgba(255, 196, 61, 0.16);
  border: 1px solid rgba(255, 196, 61, 0.4);
  font-size: 0.76rem;
  line-height: 1.45;
  color: #ffe7a8;
  text-align: left;
}

/* Top Bar */
.top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(12px + var(--safe-top)) 12px 10px;
  pointer-events: none;
}

.bar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.icon-pill,
.icon-btn {
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: #fff;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

.icon-pill {
  height: 40px;
  padding: 0 13px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.05rem;
}

.icon-btn.active,
.icon-pill.active {
  background: rgba(43, 138, 156, 0.78);
  border-color: rgba(155, 232, 245, 0.65);
}

.icon-pill:active,
.icon-btn:active {
  transform: scale(0.92);
}

/* Recording Badge */
.rec-badge {
  position: absolute;
  top: calc(62px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 22;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px;
  border-radius: 999px;
  background: rgba(214, 34, 52, 0.88);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.rec-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fff;
  animation: blinkDot 1s infinite;
}

@keyframes blinkDot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

/* Toast */
.toast {
  position: absolute;
  top: calc(64px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 35;
  max-width: calc(100vw - 32px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(18, 24, 34, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff;
  font-size: 0.83rem;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: none;
}

/* Show UI restore button */
.show-ui-btn {
  position: absolute;
  top: calc(14px + var(--safe-top));
  right: 14px;
  z-index: 30;
  padding: 8px 13px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: rgba(18, 24, 34, 0.5);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
}

/* Settings Drawer */
.settings-panel {
  position: absolute;
  top: calc(60px + var(--safe-top));
  right: 12px;
  z-index: 28;
  width: min(310px, calc(100vw - 24px));
  max-height: calc(100dvh - 220px);
  overflow-y: auto;
  padding: 14px 15px 15px;
  border-radius: 20px;
  background: rgba(20, 27, 38, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-header h2 {
  margin: 0;
  font-size: 0.92rem;
}

.close-x {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
}

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 11px;
  font-size: 0.8rem;
  color: var(--text-sub);
}

.setting-row label {
  display: flex;
  justify-content: space-between;
}

.setting-row select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 0.84rem;
}

.setting-row select option {
  background: #1c2432;
  color: #fff;
}

.setting-row input[type="range"] {
  width: 100%;
  accent-color: #53c3d6;
}

.setting-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 8px 0 12px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 0.76rem;
  cursor: pointer;
}

.setting-footer {
  display: flex;
  gap: 8px;
}

.btn-mini {
  flex: 1;
  padding: 8px 10px;
  border-radius: 11px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.11);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

/* Bottom Bar */
.bottom-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 10px calc(14px + var(--safe-bottom));
  background: linear-gradient(to top, rgba(12, 16, 24, 0.72), rgba(12, 16, 24, 0));
  pointer-events: none;
}

.action-strip {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 4px;
  scrollbar-width: none;
  pointer-events: auto;
}

.action-strip::-webkit-scrollbar {
  display: none;
}

.action-chip {
  flex: 0 0 auto;
  padding: 8px 13px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

.action-chip.active {
  background: rgba(43, 138, 156, 0.85);
  border-color: rgba(162, 238, 250, 0.75);
}

.action-chip:active {
  transform: scale(0.93);
}

.capture-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  pointer-events: auto;
}

.shutter-btn {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.16);
  padding: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  transition: transform 0.1s ease;
}

.shutter-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.1s ease;
}

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

.capture-side-btn {
  min-width: 68px;
  height: 44px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
}

.capture-side-btn.recording {
  background: rgba(214, 34, 52, 0.88);
  border-color: rgba(255, 190, 196, 0.75);
}

.capture-side-btn:active {
  transform: scale(0.93);
}

.ui-hidden .ui-chrome {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
