:root {
  --bg: #000;
  --fg: #fff;
  --muted: rgba(255, 255, 255, 0.7);
  --accent: #00d4ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Noto Sans KR", Arial,
    sans-serif;
}

.app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  z-index: 1;
  transform: scaleX(-1); /* 거울 모드 */
}

.frame {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 14px;
  padding: 28px 18px;
  text-align: center;
  background: rgba(0, 0, 0, 0.65);
  z-index: 3; /* 시작 전에도 권한 안내가 보이게 */
}

.overlay__title {
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 800;
}

.overlay__desc {
  color: var(--muted);
  max-width: 52ch;
  line-height: 1.5;
}

.overlay__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.overlay__hint {
  color: var(--muted);
  font-size: 13px;
}

.btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: var(--fg);
  padding: 12px 16px;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(0, 212, 255, 0.5);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--ghost {
  background: rgba(0, 0, 0, 0.2);
  border-color: rgba(0, 212, 255, 0.45);
}

/* ── 카메라 켜진 뒤 하단 액션 바 ── */
.action-bar {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 18px;
  align-items: center;
  z-index: 10;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 50px;
  padding: 10px 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 300ms ease;
}

.action-bar:not([hidden]) {
  opacity: 1;
  pointer-events: auto;
}

/* 마우스 없을 때 살짝 숨기기 (전체화면 느낌) */
.app:not(:hover) .action-bar {
  opacity: 0;
}
.app:hover .action-bar:not([hidden]) {
  opacity: 1;
}

.action-btn {
  appearance: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms ease, transform 120ms ease;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.action-btn:active {
  transform: scale(0.9);
}

/* 캡쳐 버튼은 조금 더 크게 */
#btnCapture {
  width: 52px;
  height: 52px;
}

/* 캡쳐 플래시 효과 */
.flash-overlay {
  position: absolute;
  inset: 0;
  background: #fff;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transition: opacity 80ms ease-out;
}

.flash-overlay.active {
  opacity: 0.75;
  transition: none;
}

/* ── 케리커쳐 버튼 ── */
.action-btn--caricature {
  border-radius: 50%;
  background: rgba(255, 200, 60, 0.15);
  border: 1px solid rgba(255, 200, 60, 0.45);
}

.action-btn--caricature:hover {
  background: rgba(255, 200, 60, 0.3);
}

/* ── 케리커쳐 모달 ── */
.modal--caricature {
  max-width: 520px;
  gap: 14px;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal__header .modal__title {
  margin: 0;
}

.caricature-loading {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
}

.caricature-loading[hidden] { display: none; }

.caricature-result img {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  display: block;
}

/* ── 닮은꼴 버튼 ── */
.action-btn--lookalike {
  border-radius: 40px;
  padding: 8px 16px;
  background: linear-gradient(135deg, rgba(255,180,50,0.18) 0%, rgba(255,100,100,0.18) 100%);
  border: 1px solid rgba(255,180,50,0.5);
}

.action-btn--lookalike:hover {
  background: linear-gradient(135deg, rgba(255,180,50,0.32) 0%, rgba(255,100,100,0.32) 100%);
}

/* ── 닮은꼴 모달 ── */
.modal--lookalike {
  max-width: 480px;
  gap: 14px;
}

.lookalike-thumb {
  display: flex;
  justify-content: center;
}

.lookalike-thumb img {
  width: 90px;
  height: 70px;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid rgba(255,180,50,0.4);
}

.lookalike-result {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lookalike-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 14px;
  text-decoration: none;
  color: inherit;
  transition: background 150ms, border-color 150ms;
}

.lookalike-card:hover {
  background: rgba(255,180,50,0.1);
  border-color: rgba(255,180,50,0.35);
}

.lookalike-card__rank {
  font-size: 22px;
  font-weight: 900;
  color: rgba(255,180,50,0.8);
  width: 28px;
  flex-shrink: 0;
  text-align: center;
}

.lookalike-card__info {
  flex: 1;
  min-width: 0;
}

.lookalike-card__name {
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lookalike-card__reason {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.lookalike-card__arrow {
  color: var(--muted);
  font-size: 16px;
  flex-shrink: 0;
}

/* ── AI 버튼 ── */
.action-btn--ai {
  border-radius: 40px;
  padding: 8px 18px;
  background: linear-gradient(135deg, rgba(0,212,255,0.18) 0%, rgba(120,80,255,0.22) 100%);
  border: 1px solid rgba(0,212,255,0.45);
}

.action-btn--ai:hover {
  background: linear-gradient(135deg, rgba(0,212,255,0.32) 0%, rgba(120,80,255,0.36) 100%);
}

.ai-btn-label {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

/* ── 모달 공통 ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: #111;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  padding: 32px 28px 28px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 8px 48px rgba(0,0,0,0.7);
}

.modal__title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.modal__desc {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.6;
}

.modal__label {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.modal__input {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
  color: #fff;
  outline: none;
  transition: border-color 150ms;
}

.modal__input:focus {
  border-color: var(--accent);
}

.modal__hint {
  font-size: 12px;
  color: var(--muted);
}

.modal__hint a {
  color: var(--accent);
}

.modal__section-label {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
}

.modal__divider {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.08);
  margin: 4px 0;
}

.modal__row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.modal__row .modal__input {
  flex: 1;
}

.btn--icon {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}

.modal__actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.btn--danger {
  background: rgba(255, 80, 80, 0.1);
  border-color: rgba(255, 80, 80, 0.45);
  color: #ff6b6b;
  margin-left: auto;
}

.btn--danger:hover:not(:disabled) {
  background: rgba(255, 80, 80, 0.22);
  border-color: rgba(255, 80, 80, 0.7);
}

/* ── AI 결과 패널 ── */
.ai-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  pointer-events: none;
}

.ai-panel[hidden] {
  display: none;
}

.ai-panel__inner {
  pointer-events: auto;
  background: rgba(10,10,14,0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255,255,255,0.1);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.6);
  animation: slideUp 300ms cubic-bezier(0.22,1,0.36,1);
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.ai-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}

.ai-panel__title {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.ai-panel__close {
  appearance: none;
  background: rgba(255,255,255,0.08);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-panel__close:hover {
  background: rgba(255,255,255,0.16);
}

.ai-panel__thumb {
  padding: 14px 20px 0;
  flex-shrink: 0;
}

.ai-panel__thumb img {
  width: 80px;
  height: 60px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
}

.ai-panel__body {
  padding: 14px 20px 24px;
  overflow-y: auto;
  flex: 1;
}

/* 로딩 점 애니메이션 */
.ai-loading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
}

.ai-loading[hidden] {
  display: none;
}

.ai-loading__dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite ease-in-out both;
}

.ai-loading__dot:nth-child(2) { animation-delay: 0.2s; }
.ai-loading__dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40%            { transform: scale(1.1); opacity: 1;   }
}

.ai-loading__text {
  font-size: 13px;
  color: var(--muted);
  margin-left: 4px;
}

/* AI 분석 결과 */
.ai-result {
  font-size: 14px;
  line-height: 1.8;
  color: rgba(255,255,255,0.88);
  white-space: pre-wrap;
}

.ai-result h3 {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
  margin: 16px 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ai-result p {
  margin: 0 0 6px;
}

.ai-result .error {
  color: #ff6b6b;
  font-size: 13px;
}

