* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  background: #0b0d12;
  overflow: hidden;
  font-family: 'Pretendard', 'Malgun Gothic', system-ui, sans-serif;
  color: #e8eaf0;
}

/* 화면을 가운데 정렬, 이미지 비율(약 2:1) 유지 */
#viewport {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 이미지 + 오버레이가 함께 들어가는 무대. 줌 transform이 여기에 걸림 */
#stage {
  position: relative;
  width: 100%;
  max-width: 100vw;
  max-height: 100vh;
  aspect-ratio: 1920 / 946;
  transition: transform .55s cubic-bezier(.22,.61,.36,1);
  transform-origin: 50% 50%;
  will-change: transform;
}

#stage img.slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

/* 어둡게 처리되는 SVG 오버레이 (클릭 영역만 구멍) */
#dim {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;   /* 어두운 부분은 클릭 통과 안 시킴(아래 hotspot이 받음) */
  transition: opacity .4s ease;
}
#dim path { transition: d .45s ease; }

/* 실제 클릭 받는 투명 영역 */
.hotspot {
  position: absolute;
  cursor: pointer;
  border-radius: 8px;
  z-index: 5;
  box-shadow: 0 0 0 2px rgba(120,190,255,.9),
              0 0 18px 4px rgba(80,160,255,.55);
  animation: pulse 1.6s ease-in-out infinite;
}
.hotspot::after {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 12px;
  border: 2px solid rgba(120,190,255,.55);
  animation: ring 1.6s ease-out infinite;
}
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 2px rgba(120,190,255,.9), 0 0 16px 3px rgba(80,160,255,.45); }
  50%     { box-shadow: 0 0 0 2px rgba(150,205,255,1), 0 0 26px 8px rgba(80,160,255,.75); }
}
@keyframes ring {
  0%   { transform: scale(.96); opacity: .8; }
  100% { transform: scale(1.18); opacity: 0; }
}

/* 핫스팟 우측하단 표시 아이콘 (커서 / 휠 화살표) */
.hotspot .indicator {
  position: absolute;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.45));
}
/* 클릭형: 커서가 영역 우측하단 모서리를 가리키도록 */
.hotspot.click .indicator {
  width: clamp(26px, 2.6vw, 46px);
  right: -6px;
  bottom: calc(-1 * clamp(26px, 2.6vw, 46px) + 8px);
}
/* 휠형: 영역 하단에 절반 걸치는 큰 빨간 화살표 + 안내 문구 */
.wheel-cue {
  --arrow: clamp(56px, 6vw, 120px);
  position: absolute;
  left: 50%;
  top: 100%;                 /* 영역의 아래쪽 모서리 */
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}
.wheel-cue .indicator {
  position: static;
  width: var(--arrow);
  margin-top: calc(var(--arrow) * -0.667);   /* 화살표가 모서리에 절반 걸치도록 */
  animation: bob 1.1s ease-in-out infinite;
}
.wheel-cue .wheel-text {
  background: rgba(0,0,0,.75);
  color: #fff;
  font-weight: 700;
  font-size: clamp(15px, 1.7vw, 28px);
  padding: 7px 18px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0,0,0,.45);
}
.hotspot.wheel { animation: none; box-shadow: 0 0 0 2px rgba(226,29,29,.85), 0 0 18px 4px rgba(226,29,29,.45); }
.hotspot.wheel::after { border-color: rgba(226,29,29,.5); }
@keyframes bob {
  0%,100% { transform: translateY(0); }
  50%     { transform: translateY(7px); }
}

/* 핫스팟 등장 페이드인 */
#hotspots { transition: opacity .5s ease; }

/* 클릭 영역 없을 때 안내 */
#stage.click-anywhere { cursor: pointer; }

/* ================= 영역지정 모드 ================= */
#picker .editbox {
  position: absolute;
  z-index: 82;
  pointer-events: none;            /* 그리기는 picker가 받음 */
  border: 2px solid #7abeff;
  background: rgba(120,190,255,.14);
  border-radius: 6px;
}
#picker .editbox.wheel { border-color: #e21d1d; background: rgba(226,29,29,.14); }
#picker .editbox .tag {
  position: absolute; top: -10px; left: 6px;
  background: #7abeff; color: #06243f;
  font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: 999px;
}
#picker .editbox.wheel .tag { background: #e21d1d; color: #fff; }
#picker .editbox .del {
  position: absolute; top: -12px; right: -12px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #ff5252; color: #fff; border: 2px solid #fff;
  font-size: 15px; line-height: 1; cursor: pointer;
  pointer-events: auto; z-index: 90;        /* picker 위에서 클릭 받기 */
  display: flex; align-items: center; justify-content: center;
}
#picker .editbox .del:hover { background: #ff1f1f; }

/* 편집 툴바 */
#editBar {
  position: fixed;
  top: 16px; left: 50%;
  transform: translateX(-50%) translateY(-12px);
  display: none;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: rgba(20,24,33,.94);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  z-index: 100;
  font-size: 13px;
  opacity: 0;
  transition: opacity .2s, transform .2s;
}
#editBar.on { display: flex; opacity: 1; transform: translateX(-50%) translateY(0); }
#editBar #editTitle { font-weight: 700; color: #cfe4ff; }
#editBar .lbl { opacity: .65; }
#editBar .sep { width: 1px; height: 20px; background: rgba(255,255,255,.14); }
#editBar button {
  background: rgba(255,255,255,.06); color: #e8eaf0;
  border: 1px solid rgba(255,255,255,.14); border-radius: 8px;
  padding: 6px 11px; cursor: pointer; font-size: 13px;
}
#editBar button:hover { background: rgba(120,190,255,.18); }
#editBar .seg.sel { background: #7abeff; color: #06243f; border-color: #7abeff; font-weight: 700; }
#editBar #typeWheel.sel { background: #e21d1d; color: #fff; border-color: #e21d1d; }
#editBar .primary { background: #2a7d3f; border-color: #2a7d3f; font-weight: 700; }
#editBar .primary:hover { background: #34924a; }

/* 편집 중에는 재생 효과(어둡게) 끄기 */
body.editing #dim { opacity: 0 !important; }
body.editing #picker { background: rgba(0,0,0,.04); }

/* ================= 마지막 페이지 "다시 하시겠습니까?" 팝업 ================= */
#endPopup {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.55);
}
#endPopup.on { display: flex; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
#endPopup .card {
  background: #ffffff;
  color: #1b1f2a;
  width: min(90vw, 380px);
  border-radius: 16px;
  padding: 30px 26px 22px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  animation: pop .28s cubic-bezier(.22,1.2,.36,1);
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#endPopup .msg {
  font-size: 21px;
  font-weight: 700;
  margin-bottom: 22px;
}
#endPopup .btns { display: flex; gap: 10px; }
#endPopup .btns button {
  flex: 1;
  padding: 12px 0;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
}
#endPopup .ok { background: #2a7d3f; color: #fff; }
#endPopup .ok:hover { background: #34924a; }
#endPopup .cancel { background: #eef0f4; color: #444; border-color: #d8dce4; }
#endPopup .cancel:hover { background: #e2e5ec; }

/* ================= 내보내기 확인 박스 ================= */
#exportBox {
  position: fixed; inset: 0; z-index: 210;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,.55);
}
#exportBox.on { display: flex; }
#exportBox .inner {
  background: #fff; color: #1b1f2a;
  width: min(92vw, 640px); max-height: 80vh;
  border-radius: 14px; padding: 22px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
#exportBox p { font-size: 14px; line-height: 1.6; }
#exportBox textarea {
  width: 100%; flex: 1; min-height: 240px;
  font: 12px/1.5 ui-monospace, monospace;
  border: 1px solid #d8dce4; border-radius: 8px; padding: 10px; resize: vertical;
}
#exportBox .row { display: flex; gap: 8px; justify-content: flex-end; }
#exportBox .row button {
  padding: 9px 16px; border-radius: 8px; font-weight: 700; cursor: pointer;
  border: 1px solid #d8dce4; background: #eef0f4; color: #333;
}
#exportBox #exportCopy { background: #2a7d3f; color: #fff; border-color: #2a7d3f; }

/* ================= 배경음악 토글 버튼 ================= */
#bgmBtn {
  position: fixed;
  top: 14px; right: 16px;
  z-index: 120;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: rgba(20,24,33,.7);
  color: #fff;
  border: 1px solid rgba(255,255,255,.22);
  font-size: 18px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  opacity: .5;
  transition: opacity .2s;
}
#bgmBtn:hover { opacity: 1; }
#bgmBtn.off { color: #8a8f99; }
#bgmBtn.off::after {
  content: '';
  position: absolute; left: 8px; right: 8px; top: 50%;
  height: 2px; background: #ff5252; transform: rotate(-45deg);
}

/* ================= 시작 화면 ================= */
#startOverlay {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8,10,15,.93);
  transition: opacity .45s ease;
}
#startOverlay.hidden { opacity: 0; pointer-events: none; }
#startOverlay .box { text-align: center; color: #fff; padding: 24px; }
#startOverlay h1 { font-size: clamp(22px, 3.2vw, 40px); font-weight: 800; margin-bottom: 14px; }
#startOverlay p { opacity: .7; margin-bottom: 28px; font-size: clamp(13px, 1.6vw, 19px); }
#startBtn {
  background: #2a7d3f; color: #fff; border: none; border-radius: 999px;
  padding: 15px 46px; font-size: clamp(16px, 1.9vw, 23px); font-weight: 700;
  cursor: pointer; box-shadow: 0 10px 34px rgba(42,125,63,.5);
  transition: background .2s, transform .15s;
}
#startBtn:hover { background: #34924a; transform: translateY(-1px); }

/* 하단 컨트롤바 */
#bar {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: none;            /* 재생 중엔 숨김 (편집 모드일 때만 표시) */
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: rgba(20,24,33,.82);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 999px;
  z-index: 50;
  font-size: 14px;
  opacity: .35;
  transition: opacity .25s;
}
#bar:hover { opacity: 1; }
body.editing #bar { display: flex; }   /* 편집 모드에서만 하단 바 표시 */
#bar button {
  background: rgba(255,255,255,.06);
  color: #e8eaf0;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
}
#bar button:hover { background: rgba(120,190,255,.18); border-color: rgba(120,190,255,.4); }
#counter { min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; opacity:.9; }

/* 진행 점 */
#dots { display:flex; gap:5px; align-items:center; }
#dots .dot { width:7px; height:7px; border-radius:50%; background:rgba(255,255,255,.22); cursor:pointer; transition:all .2s; }
#dots .dot.active { background:#7abeff; transform:scale(1.35); }

/* ---- 좌표 도우미 (C키) ---- */
#picker {
  position: absolute;
  inset: 0;
  z-index: 80;
  cursor: crosshair;
  display: none;
  background: rgba(0,0,0,.15);
}
#picker.on { display: block; }
#picker .sel {
  position: absolute;
  border: 2px dashed #ffd166;
  background: rgba(255,209,102,.15);
}
#picker .readout {
  position: absolute;
  background: #1b1f2a;
  color: #ffd166;
  font: 12px/1.5 ui-monospace, monospace;
  padding: 6px 9px;
  border-radius: 6px;
  white-space: nowrap;
  border: 1px solid rgba(255,209,102,.4);
  pointer-events: none;
}
#pickerHint {
  position: fixed;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  background: rgba(255,209,102,.95);
  color: #1b1f2a;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  z-index: 90;
  display: none;
}
#pickerHint.on { display: block; }

#toast {
  position: fixed;
  bottom: 76px; left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: #2a7d3f;
  color: #fff;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 95;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
