/* ===== 서체 =====
 * Freesentation woff2 파일을 assets/fonts/ 에 넣으면 적용된다(assets/fonts/README.md 참고).
 * 파일이 없으면 시스템 서체로 표시된다.
 */
@font-face {
  font-family: 'Freesentation';
  src: url('../assets/fonts/Freesentation-4Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Freesentation';
  src: url('../assets/fonts/Freesentation-7Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --c-green: #00DC84;
  --c-cyan: #00b7ff;
  --c-ink: #000a14;
  --c-blue: #2870ff;
  --c-violet: #6f36ff;
  --c-danger: #ff4d6d;

  --holo-src: url('../assets/img/character.png');
  /* 홀로그램이 차지하는 영역: HUD 아래 ~ 자막 위 */
  --stage-top: 52px;
  --stage-bottom: 228px;
  --holo-ar: 0.6; /* 캐릭터 이미지 가로/세로 비율. 이미지 로드 후 JS 가 갱신 */

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);

  --font: 'Freesentation', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Pretendard', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--c-ink);
  color: #eaf6ff;
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; touch-action: manipulation; user-select: none; -webkit-user-select: none; }

button { font: inherit; }

/* ===== 배경 ===== */
.camera,
.fallback-bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}
.camera {
  object-fit: cover;
  background: var(--c-ink);
  opacity: 0;
  transition: opacity .6s ease;
}
body[data-camera="live"] .camera { opacity: 1; }

.fallback-bg {
  background: var(--c-ink) url('../assets/img/fallback-bg.jpg') center / cover no-repeat;
  opacity: 0;
  transition: opacity .6s ease;
}
body[data-camera="fallback"] .fallback-bg,
body[data-state="intro"] .fallback-bg,
body[data-state="ended"] .fallback-bg { opacity: 1; }
body[data-state="intro"] .fallback-bg,
body[data-state="ended"] .fallback-bg { filter: blur(6px) brightness(.55); transform: scale(1.06); }

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 45%, rgba(0, 10, 20, .55) 100%),
    linear-gradient(to bottom, rgba(0, 10, 20, .55) 0, transparent 18%, transparent 62%, rgba(0, 10, 20, .8) 100%);
}

/* ===== HUD ===== */
.hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  padding: calc(var(--safe-t) + 14px) 16px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  letter-spacing: .08em;
  color: rgba(234, 246, 255, .85);
  z-index: 5;
  opacity: 0;
  transition: opacity .4s ease;
}
body[data-state="live"] .hud { opacity: 1; }
.hud__signal { display: flex; align-items: center; gap: 8px; }
.hud__dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--c-green);
  box-shadow: 0 0 10px var(--c-green);
  animation: blink 1.4s steps(2, start) infinite;
}
body[data-camera="fallback"] .hud__dot { background: var(--c-cyan); box-shadow: 0 0 10px var(--c-cyan); }
.hud__channel { font-variant-numeric: tabular-nums; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== 홀로그램 ===== */
.stage {
  position: fixed;
  left: 0;
  right: 0;
  top: calc(var(--safe-t) + var(--stage-top));
  bottom: calc(var(--safe-b) + var(--stage-bottom));
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}
.holo {
  position: relative;
  height: 100%;
  max-height: calc(88vw / var(--holo-ar));
  aspect-ratio: var(--holo-ar);
  visibility: hidden;
}
body[data-state="live"] .holo { visibility: visible; }
/* aspect-ratio 미지원 구형 브라우저 */
@supports not (aspect-ratio: 1) {
  .holo { width: min(88vw, 36vh); height: min(calc(88vw * 5 / 3), 60vh); }
}

.holo__float {
  position: absolute;
  inset: 0;
  z-index: 2;
  /* 밝은 성분만 더해져 뒤의 카메라 영상이 비쳐 보이도록 */
  mix-blend-mode: screen;
}
body[data-state="live"] .holo__float { animation: float 4.6s ease-in-out 1.4s infinite; }

.holo__body {
  position: absolute;
  inset: 0;
  opacity: .78;
  filter: drop-shadow(0 0 10px rgba(0, 183, 255, .85)) drop-shadow(0 0 28px rgba(40, 112, 255, .55));
  transform-origin: 50% 100%;
}
body[data-state="live"] .holo__body { animation: materialize 1.3s cubic-bezier(.2, .7, .2, 1) both, flicker 7s linear 1.4s infinite; }

.holo__img,
.holo__tint,
.holo__scan,
.holo__sweep {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.holo__img {
  object-fit: contain;
  /* 원본 색을 지우고 청색 계열로 */
  filter: grayscale(1) brightness(1.25) contrast(1.05);
  opacity: .9;
}
.holo__tint,
.holo__scan,
.holo__sweep {
  -webkit-mask: var(--holo-src) center / contain no-repeat;
  mask: var(--holo-src) center / contain no-repeat;
}
.holo__tint {
  background: linear-gradient(180deg, rgba(90, 215, 255, .95) 0%, rgba(0, 183, 255, .9) 55%, rgba(40, 112, 255, .9) 100%);
  mix-blend-mode: multiply;
}
.holo__scan {
  background: repeating-linear-gradient(0deg, rgba(0, 10, 20, .55) 0 1px, transparent 1px 4px);
  animation: scan-move 1.2s linear infinite;
  opacity: .8;
}
.holo__sweep {
  background: linear-gradient(180deg, transparent 0%, rgba(160, 235, 255, .0) 40%, rgba(190, 240, 255, .75) 50%, rgba(160, 235, 255, 0) 60%, transparent 100%);
  background-size: 100% 300%;
  animation: sweep 3.6s linear infinite;
  mix-blend-mode: screen;
}

/* 이미 홀로그램 색으로 만든 이미지: 원본 색 유지, 스캔라인만 가볍게 */
body[data-colorize="off"] .holo__img { filter: none; opacity: 1; }
body[data-colorize="off"] .holo__tint { display: none; }
body[data-colorize="off"] .holo__scan { opacity: .45; }
body[data-colorize="off"] .holo__body { filter: drop-shadow(0 0 14px rgba(0, 183, 255, .6)); }

/* 말하는 중: 밝기 변화 */
body.is-speaking .holo__img { animation: talk .32s ease-in-out infinite alternate; }
body[data-colorize="off"].is-speaking .holo__img { animation-name: talk-color; }

.holo__beam {
  position: absolute;
  left: 50%;
  bottom: -3%;
  width: 92%;
  height: 34%;
  transform: translateX(-50%);
  background: linear-gradient(to top, rgba(0, 183, 255, .45), rgba(40, 112, 255, 0));
  clip-path: polygon(30% 100%, 70% 100%, 100% 0, 0 0);
  filter: blur(6px);
  opacity: 0;
  z-index: 1;
}
.holo__base {
  position: absolute;
  left: 50%;
  bottom: -5%;
  width: 62%;
  height: 7%;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(160, 235, 255, .95) 0%, rgba(0, 183, 255, .6) 35%, rgba(40, 112, 255, 0) 70%);
  box-shadow: 0 0 30px rgba(0, 183, 255, .7);
  opacity: 0;
  z-index: 3;
}
body[data-state="live"] .holo__beam { animation: beam-in .9s ease-out both, beam-pulse 3s ease-in-out 1s infinite; }
body[data-state="live"] .holo__base { animation: base-in .5s ease-out both, beam-pulse 3s ease-in-out 1s infinite; }

/* ===== 자막 ===== */
.caption {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--safe-b) + 92px);
  margin: 0 auto;
  max-width: 560px;
  min-height: 92px;
  padding: 12px 16px 14px;
  border: 1px solid rgba(0, 183, 255, .5);
  border-radius: 14px;
  background: rgba(0, 10, 20, .62);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 0 24px rgba(0, 183, 255, .18), inset 0 0 18px rgba(0, 183, 255, .08);
  z-index: 6;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .3s ease, transform .3s ease;
}
body[data-state="live"] .caption.is-visible { opacity: 1; transform: none; }
.caption__speaker {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--c-cyan);
}
.caption__text {
  margin: 0;
  font-size: clamp(16px, 4.4vw, 20px);
  line-height: 1.5;
  word-break: keep-all;
  overflow-wrap: anywhere;
  text-shadow: 0 0 8px rgba(0, 183, 255, .35);
}

/* ===== 조작 버튼 ===== */
.controls {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--safe-b) + 20px);
  margin: 0 auto;
  max-width: 560px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  z-index: 6;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}
body[data-state="live"] .controls { opacity: 1; pointer-events: auto; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid transparent;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: transform .12s ease, background-color .2s ease, opacity .2s ease;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: 2px solid var(--c-cyan); outline-offset: 3px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
.btn--lg { min-height: 58px; min-width: 220px; font-size: 18px; }
.btn--primary {
  background: linear-gradient(135deg, var(--c-cyan), var(--c-blue));
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .12) inset, 0 8px 28px rgba(0, 183, 255, .45);
}
.btn--ghost {
  background: rgba(0, 10, 20, .55);
  border-color: rgba(0, 183, 255, .55);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.btn--danger {
  background: rgba(255, 77, 109, .9);
}
body.is-done #btn-replay { border-color: var(--c-green); box-shadow: 0 0 18px rgba(0, 220, 132, .4); }

/* ===== 패널(시작·연결 중·종료) ===== */
.panel {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: calc(var(--safe-t) + 24px) 24px calc(var(--safe-b) + 24px);
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity .35s ease, visibility 0s linear .35s;
}
body[data-state="intro"] .panel--intro,
body[data-state="connecting"] .panel--connecting,
body[data-state="ended"] .panel--ended {
  opacity: 1;
  visibility: visible;
  transition: opacity .35s ease;
}
.panel--connecting { background: rgba(0, 10, 20, .55); }
.panel__eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: .24em;
  color: var(--c-cyan);
}
.panel__title {
  margin: 0;
  font-size: clamp(28px, 8vw, 40px);
  line-height: 1.25;
  font-weight: 700;
  word-break: keep-all;
}
.panel__desc {
  margin: 0 0 12px;
  font-size: 16px;
  line-height: 1.6;
  color: rgba(234, 246, 255, .8);
  word-break: keep-all;
}
.panel__note {
  margin: 4px 0 0;
  max-width: 320px;
  font-size: 13px;
  line-height: 1.5;
  color: rgba(234, 246, 255, .6);
  word-break: keep-all;
}

.spinner {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 3px solid rgba(0, 183, 255, .2);
  border-top-color: var(--c-cyan);
  animation: spin .9s linear infinite;
}

/* ===== 알림 ===== */
.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-t) + 48px);
  transform: translate(-50%, -8px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(0, 10, 20, .8);
  border: 1px solid rgba(0, 183, 255, .4);
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
  word-break: keep-all;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ===== 애니메이션 ===== */
@keyframes materialize {
  0%   { opacity: 0; transform: scaleY(.02) scaleX(.6); filter: brightness(3) blur(4px); }
  35%  { opacity: .9; transform: scaleY(1.04) scaleX(.94); filter: brightness(2) blur(1px); }
  45%  { opacity: .25; }
  55%  { opacity: .85; }
  62%  { opacity: .4; }
  100% { opacity: .78; transform: none; }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-2.2%); }
}
@keyframes flicker {
  0%, 100%   { opacity: .78; }
  41%        { opacity: .78; }
  42%        { opacity: .5; transform: translateX(1.5px); }
  43%        { opacity: .78; transform: none; }
  78%        { opacity: .78; }
  79%        { opacity: .58; transform: translateX(-1px) skewX(-1deg); }
  80%        { opacity: .78; transform: none; }
}
@keyframes scan-move { to { background-position: 0 4px; } }
@keyframes sweep {
  0%   { background-position: 0 100%; }
  100% { background-position: 0 -200%; }
}
@keyframes talk { to { filter: grayscale(1) brightness(1.45) contrast(1.05); } }
@keyframes talk-color { to { filter: brightness(1.25); } }
@keyframes beam-in { from { opacity: 0; transform: translateX(-50%) scaleX(.2); } to { opacity: 1; transform: translateX(-50%); } }
@keyframes base-in { from { opacity: 0; transform: translateX(-50%) scale(.3); } to { opacity: 1; transform: translateX(-50%); } }
@keyframes beam-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .7; } }
@keyframes blink { to { visibility: hidden; } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  body[data-state="live"] .holo__float,
  .holo__scan,
  .holo__sweep,
  body.is-speaking .holo__img { animation: none !important; }
  body[data-state="live"] .holo__body { animation: materialize .01s both !important; }
}

/* 가로 화면: 캐릭터와 자막이 겹치지 않도록 */
@media (orientation: landscape) and (max-height: 520px) {
  :root { --stage-top: 40px; --stage-bottom: 150px; }
  .caption { bottom: calc(var(--safe-b) + 76px); min-height: 0; padding: 8px 14px; }
  .controls { bottom: calc(var(--safe-b) + 12px); }
  .btn { min-height: 46px; }
}
