/* 망포초 급식실 인터랙티브 영상 학습 — v2 (INT-1~4 모듈) */
:root {
  --ink: #2c3440;
  --green: #3f9e63;
  --green-deep: #2c7a4a;
  --orange: #f0813c;
  --red: #d9534f;
  --blue: #3b6fb6;
  --cream: #fdf7ec;
  --card: #ffffff;
  --line: #e8ddc9;
  --muted: #7a7264;
  --pw: 1000px; /* JS가 플레이어 실폭으로 갱신 */
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  line-height: 1.6;
}
.shell { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: 26px 0 60px; }

.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.eyebrow { margin: 0 0 4px; color: var(--green-deep); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.topbar h1 { margin: 0; font-size: clamp(20px, 3.4vw, 30px); letter-spacing: -.04em; }
.tracking { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
#connection-state { padding: 3px 10px; border-radius: 99px; background: #efe7d5; color: var(--muted); font-size: 12px; font-weight: 700; }
#score-display { color: var(--orange); font-size: 19px; letter-spacing: .02em; }

/* ── 플레이어 ── */
.stage-wrap { border: 1px solid var(--line); border-radius: 22px; background: var(--card); box-shadow: 0 14px 38px #6b5a3312; padding: 14px; }
.player { position: relative; overflow: hidden; border-radius: 14px; background: #000; aspect-ratio: 16 / 9; }
/* 영상은 센터 고정 1.08배 확대 — 가장자리(워터마크 포함)를 플레이어 밖으로 크롭 */
.player > video { display: block; width: 100%; height: 100%; transform: scale(1.08); transform-origin: center; }
/* 씬별 앵커 오버라이드: 약속1(차례 지키기) 구간 — 좌상단 타이틀이 잘리지 않게 좌상단 기준(아래·오른쪽 크롭) */
.player > video.anchor-tl { transform-origin: top left; }
.player video::cue { visibility: hidden; }

.caption-line {
  position: absolute; left: 50%; bottom: 4.5%; transform: translateX(-50%);
  max-width: 86%; padding: 7px 14px; border-radius: 10px;
  background: #10141bd9; color: #fff; font-size: clamp(12px, 1.9vw, 18px); font-weight: 600;
  text-align: center; white-space: pre-line; pointer-events: none; z-index: 3;
}

/* ── 인터랙션 스테이지 ── */
.int-stage { position: absolute; inset: 0; z-index: 5; opacity: 0; transition: opacity .6s ease; }
.int-stage.show { opacity: 1; }
.stage-bg { position: absolute; inset: 0; background-size: cover; background-position: center; }
#stage-bg2 { opacity: 0; transition: opacity .9s ease; }
#stage-bg2.show { opacity: 1; }
.vignette { position: absolute; inset: 0; opacity: 0; transition: opacity .6s ease; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, #10141b55 0%, #10141bcc 78%); }
.vignette.show { opacity: 1; }
.stage-content { position: absolute; inset: 0; }
.stage-banner {
  position: absolute; top: 3.5%; left: 50%; transform: translateX(-50%); z-index: 8;
  display: flex; align-items: center; gap: calc(var(--pw) * .012);
  max-width: 92%; padding: calc(var(--pw) * .008) calc(var(--pw) * .02);
  border-radius: 99px; background: #10141bd8; color: #fff;
  font-size: calc(var(--pw) * .019); font-weight: 800; white-space: nowrap;
  box-shadow: 0 6px 24px #0007; animation: drop-in .5s ease;
}
.stage-banner .count { padding: 2px calc(var(--pw) * .012); border-radius: 99px; background: var(--orange); font-size: calc(var(--pw) * .017); }
@keyframes drop-in { from { transform: translate(-50%, -26px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ── 리액션 클립 레이어 ── */
.rlayer { position: absolute; z-index: 7; opacity: 0; transition: opacity .45s ease; }
.rlayer.show { opacity: 1; }
.rlayer.full { inset: 0; }
.rlayer.full video { width: 100%; height: 100%; object-fit: cover; }
.rlayer.pip {
  right: 3%; bottom: 6%; width: 36%; aspect-ratio: 16 / 9;
  border: calc(var(--pw) * .004) solid #fff; border-radius: calc(var(--pw) * .016);
  overflow: hidden; box-shadow: 0 14px 40px #000a; background: #000;
}
.rlayer.pip video { width: 100%; height: 100%; object-fit: cover; }
.rlayer.pip.left { right: auto; left: 3%; }
.rlayer video { display: none; }
.rlayer video.on { display: block; transform: scale(1.08); transform-origin: center; }
.rcaption {
  position: absolute; left: 50%; bottom: 4%; transform: translateX(-50%); margin: 0;
  max-width: 92%; padding: 5px 12px; border-radius: 9px; background: #10141bd9; color: #fff;
  font-size: calc(var(--pw) * .015); font-weight: 700; white-space: nowrap;
}
.rlayer.full .rcaption { font-size: calc(var(--pw) * .017); }

/* ── 공용 패널·버튼 ── */
.pill { display: inline-block; margin: 0 0 10px; padding: 4px 12px; border-radius: 99px; background: #e5f3ea; color: var(--green-deep); font-size: calc(var(--pw) * .013); font-weight: 800; }
button { font-family: inherit; cursor: pointer; }
.primary, .secondary {
  padding: 12px 22px; border: 0; border-radius: 14px; font-size: 15px; font-weight: 800; letter-spacing: -.01em;
  transition: transform .12s ease, box-shadow .12s ease;
}
.primary { background: var(--green); color: #fff; box-shadow: 0 5px 0 var(--green-deep); }
.primary:hover { transform: translateY(-2px); }
.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--green-deep); }
.secondary { background: #f1ece0; color: var(--ink); box-shadow: 0 5px 0 #d8cfb9; }
.big { font-size: 17px; padding: 14px 26px; }
button:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
.fade-in { animation: fade-in .5s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ── INT-1 O/X 퀴즈 ── */
.quiz-wrap {
  position: absolute; inset: 0; display: grid; grid-template-columns: 1.05fr 1fr;
  gap: calc(var(--pw) * .02); align-items: center; padding: calc(var(--pw) * .045) calc(var(--pw) * .04) calc(var(--pw) * .03);
}
.quiz-illus { border-radius: calc(var(--pw) * .014); overflow: hidden; box-shadow: 0 12px 36px #0008; border: calc(var(--pw) * .003) solid #fff; }
.quiz-illus img { display: block; width: 100%; height: auto; }
.quiz-body { background: #fffffff2; border-radius: calc(var(--pw) * .016); padding: calc(var(--pw) * .024); box-shadow: 0 14px 40px #0007; }
.quiz-body h2 { margin: 0 0 calc(var(--pw) * .016); font-size: calc(var(--pw) * .022); line-height: 1.42; letter-spacing: -.03em; }
.ox { display: grid; grid-template-columns: 1fr 1fr; gap: calc(var(--pw) * .014); }
.ox button {
  padding: calc(var(--pw) * .014) 0; border: calc(var(--pw) * .003) solid var(--line); border-radius: calc(var(--pw) * .014);
  background: #fffdf8; font-size: calc(var(--pw) * .034); font-weight: 900; line-height: 1.1;
  transition: transform .12s, border-color .12s, background .12s;
}
.ox button small { display: block; font-size: calc(var(--pw) * .013); font-weight: 800; color: var(--muted); }
.ox button.o { color: var(--blue); }
.ox button.x { color: var(--red); }
.ox button:hover:not(:disabled) { transform: translateY(-3px); border-color: var(--green); }
.ox button.picked-correct { border-color: var(--green); background: #e5f3ea; }
.ox button.picked-wrong { border-color: var(--red); background: #fbecec; animation: shake .35s ease; }
.ox button:disabled { cursor: default; opacity: .9; }
.q-feedback { min-height: calc(var(--pw) * .04); margin: calc(var(--pw) * .012) 0 0; font-size: calc(var(--pw) * .016); font-weight: 700; }
.q-feedback.good { color: var(--green-deep); }
.q-feedback.bad { color: var(--red); }
.q-next { margin-top: calc(var(--pw) * .008); font-size: calc(var(--pw) * .016); padding: calc(var(--pw) * .011) calc(var(--pw) * .022); }

/* ── INT-2 분기 선택 ── */
.branch-wrap { position: absolute; inset: 0; padding: calc(var(--pw) * .05) calc(var(--pw) * .04); }
.branch-title {
  max-width: 55%; margin: 0 0 calc(var(--pw) * .02); color: #fff;
  font-size: calc(var(--pw) * .026); line-height: 1.35; letter-spacing: -.03em;
  text-shadow: 0 2px 14px #000c;
}
.branch-choices { display: grid; gap: calc(var(--pw) * .012); width: min(52%, 560px); }
.branch-choices button {
  padding: calc(var(--pw) * .014) calc(var(--pw) * .018); border: calc(var(--pw) * .0025) solid #ffffff66; border-radius: calc(var(--pw) * .014);
  background: #ffffffee; color: var(--ink); font-size: calc(var(--pw) * .018); font-weight: 800; text-align: left;
  box-shadow: 0 8px 26px #0007; transition: transform .12s, border-color .12s;
}
.branch-choices button:hover:not(:disabled) { transform: translateX(5px); border-color: var(--green); }
.branch-choices button:disabled { opacity: .45; cursor: default; }
.branch-choices button.correct { border-color: var(--green); background: #e5f3ea; }
.branch-explain {
  width: min(52%, 560px); background: #fffffff2; border-radius: calc(var(--pw) * .016);
  padding: calc(var(--pw) * .018); box-shadow: 0 14px 40px #0008;
}
.branch-explain img { display: block; width: 100%; border-radius: calc(var(--pw) * .01); margin-bottom: calc(var(--pw) * .012); }
.branch-explain p { margin: 0 0 calc(var(--pw) * .014); font-size: calc(var(--pw) * .017); font-weight: 700; line-height: 1.5; }
.branch-explain .primary { font-size: calc(var(--pw) * .016); padding: calc(var(--pw) * .011) calc(var(--pw) * .02); }

/* ── INT-3 급식실 탐정 ── */
.hot-zone { position: absolute; transform: translate(-50%, -50%); border: 0; border-radius: 50%; background: transparent; cursor: pointer; }
.hot-zone:focus-visible { outline: 3px dashed #fff; }
.hot-zone.hinting::after { content: ""; position: absolute; inset: 12%; border: calc(var(--pw) * .004) solid #ffffffcc; border-radius: 50%; animation: pulse 1.4s ease infinite; }
@keyframes pulse { 0% { transform: scale(.75); opacity: 1; } 100% { transform: scale(1.18); opacity: 0; } }
.found-ring {
  position: absolute; transform: translate(-50%, -50%); pointer-events: none;
  border: calc(var(--pw) * .005) solid #ffd84d; border-radius: 50%;
  box-shadow: 0 0 0 calc(var(--pw) * .003) #10141b55, 0 0 calc(var(--pw) * .03) #ffd84daa inset;
  animation: ring-pop .45s cubic-bezier(.2, 1.6, .4, 1);
}
.found-ring::after { content: "✓"; position: absolute; top: -14%; right: -8%; display: grid; place-items: center;
  width: calc(var(--pw) * .034); height: calc(var(--pw) * .034); border-radius: 50%; background: var(--green); color: #fff;
  font-size: calc(var(--pw) * .02); font-weight: 900; box-shadow: 0 4px 12px #0008; }
@keyframes ring-pop { from { transform: translate(-50%, -50%) scale(.4); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
.found-chip {
  position: absolute; transform: translate(-50%, 0); z-index: 9; pointer-events: none;
  padding: calc(var(--pw) * .007) calc(var(--pw) * .014); border-radius: 99px;
  background: #ffd84d; color: #4a3b12; font-size: calc(var(--pw) * .015); font-weight: 900; white-space: nowrap;
  box-shadow: 0 6px 18px #0008; animation: chip-life 2.4s ease forwards;
}
@keyframes chip-life { 0% { opacity: 0; translate: 0 10px; } 12% { opacity: 1; translate: 0 0; } 82% { opacity: 1; } 100% { opacity: 0; translate: 0 -8px; } }
.miss-ripple {
  position: absolute; transform: translate(-50%, -50%); pointer-events: none;
  width: calc(var(--pw) * .05); height: calc(var(--pw) * .05); border-radius: 50%;
  border: calc(var(--pw) * .0035) solid #ffffffbb; display: grid; place-items: center;
  color: #fff; font-size: calc(var(--pw) * .022); font-weight: 900; text-shadow: 0 1px 6px #000;
  animation: miss-life .8s ease forwards;
}
@keyframes miss-life { 0% { transform: translate(-50%, -50%) scale(.4); opacity: 1; } 100% { transform: translate(-50%, -50%) scale(1.25); opacity: 0; } }

/* ── INT-4 잔반 드래그 ── */
.drop-ring {
  position: absolute; transform: translate(-50%, -50%); border-radius: 50%; pointer-events: none;
  border: calc(var(--pw) * .004) dashed #ffd84d;
  box-shadow: 0 0 calc(var(--pw) * .04) #ffd84d55 inset; animation: target-breathe 2s ease infinite;
}
.drop-ring.armed { border-style: solid; animation: none; box-shadow: 0 0 0 calc(var(--pw) * .006) #ffd84d66, 0 0 calc(var(--pw) * .05) #ffd84d88 inset; }
@keyframes target-breathe { 0%,100% { opacity: .75; } 50% { opacity: .3; } }
.sprite {
  position: absolute; transform: translate(-50%, -50%); padding: 0; border: 0; background: none;
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab;
  filter: drop-shadow(0 5px 8px #0006);
  transition: left .45s cubic-bezier(.2, 1.4, .4, 1), top .45s cubic-bezier(.2, 1.4, .4, 1), opacity .6s ease;
}
.sprite img { display: block; width: 100%; pointer-events: none; }
.sprite.dragging { transition: none; cursor: grabbing; z-index: 10; filter: drop-shadow(0 14px 18px #0008) brightness(1.06); }
.sprite.selected { filter: drop-shadow(0 0 calc(var(--pw) * .01) #ffd84d) drop-shadow(0 5px 8px #0006); }
.sprite.placed { cursor: default; filter: drop-shadow(0 2px 4px #0005); }
.sparkle { position: absolute; pointer-events: none; color: #ffd84d; text-shadow: 0 0 8px #ffb300; animation: sparkle-fly 1s ease forwards; z-index: 11; }
@keyframes sparkle-fly {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.3) rotate(0deg); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.15) rotate(50deg); }
}

/* ── 시작/결과 오버레이 ── */
.overlay { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 4%; background: #1a2129ca; backdrop-filter: blur(3px); overflow: auto; }
.intro-box, .result-box { width: min(620px, 100%); max-height: 100%; overflow: auto; padding: clamp(18px, 4vw, 34px); border-radius: 20px; background: var(--card); text-align: center; box-shadow: 0 18px 50px #0007; }
.intro-box h2 { margin: 0 0 10px; font-size: clamp(17px, 2.8vw, 24px); line-height: 1.45; letter-spacing: -.03em; }
.intro-copy { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.intro-games { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
.intro-games span { padding: 9px 4px; border: 1px solid var(--line); border-radius: 12px; background: #fffdf8; font-size: 12.5px; font-weight: 800; color: var(--ink); }
.intro-games b { display: block; font-size: 19px; margin-bottom: 2px; }
.intro-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.intro-box .pill, .result-box .pill { font-size: 12px; }

.badge {
  display: inline-grid; place-items: center; gap: 2px; margin: 6px 0 10px; padding: 16px 26px;
  border-radius: 18px; background: linear-gradient(145deg, #ffe9a8, #ffd84d); color: #4a3b12;
  font-weight: 900; box-shadow: 0 10px 30px #d9a40766, inset 0 2px 0 #fff8; animation: badge-pop .6s cubic-bezier(.2, 1.5, .4, 1);
}
.badge .medal { font-size: 38px; line-height: 1.1; }
.badge .name { font-size: 18px; letter-spacing: -.02em; }
@keyframes badge-pop { from { transform: scale(.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.result-stars { margin: 2px 0 8px; font-size: 30px; letter-spacing: 6px; color: var(--orange); }
.result-box h2 { margin: 0 0 6px; font-size: clamp(17px, 2.7vw, 23px); }
.result-copy { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.result-list { margin: 0 0 14px; padding: 0; list-style: none; text-align: left; }
.result-list li { display: flex; gap: 8px; align-items: baseline; padding: 8px 4px; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.result-list li:last-child { border-bottom: 0; }
.result-list .mark { flex: none; font-weight: 900; }
.result-list .mark.ok { color: var(--green-deep); }
.result-list .mark.sub { color: var(--orange); }
.result-card { display: flex; flex-direction: column; gap: 2px; margin-bottom: 16px; padding: 12px; border-radius: 12px; background: #f6f1e5; }
.result-card span { color: var(--muted); font-size: 12px; font-weight: 700; }
.result-card strong { font-size: 15px; }

/* ── 컨트롤 바 ── */
.controls { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding: 0 2px; }
.ctrl { flex: none; min-width: 40px; height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 11px; background: #fffdf8; color: var(--ink); font-size: 14.5px; font-weight: 800; }
.ctrl:hover { border-color: var(--green); }
.ctrl.on { border-color: var(--green); background: #e5f3ea; color: var(--green-deep); }
.time { flex: none; min-width: 88px; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; text-align: center; }
.seek-bar { position: relative; flex: 1; height: 14px; border-radius: 99px; background: #ece4d2; cursor: pointer; }
.seek-watched { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 99px; background: #d3c5a4; }
.seek-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 99px; background: var(--green); }
.seek-markers { position: absolute; inset: 0; pointer-events: none; }
.seek-markers i { position: absolute; top: 50%; transform: translate(-50%, -50%); width: 11px; height: 11px; border: 2px solid #fff; border-radius: 50%; background: var(--orange); box-shadow: 0 1px 4px #0004; }
.seek-markers i.done { background: var(--green-deep); }

.qchips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.qchip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 99px; background: #fffdf8; color: var(--muted); font-size: 12.5px; font-weight: 700; }
.qchip.done { border-color: var(--green); background: #e5f3ea; color: var(--green-deep); }

.developer-note { display: flex; flex-direction: column; gap: 3px; margin-top: 18px; padding: 14px 18px; border: 1px dashed #d8cfb9; border-radius: 14px; color: var(--muted); font-size: 13px; }
.developer-note strong { color: var(--ink); font-size: 13.5px; }
.developer-note code { padding: 1px 5px; border-radius: 5px; background: #efe7d5; font-size: 12px; }

@media (max-width: 640px) {
  .overlay { position: fixed; z-index: 60; padding: 14px; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .tracking { flex-direction: row; align-items: center; gap: 10px; }
  .stage-wrap { padding: 10px; }
  .controls { flex-wrap: wrap; }
  .time { order: 5; }
  .intro-games { grid-template-columns: repeat(2, 1fr); }
  .quiz-wrap { grid-template-columns: 1fr 1.15fr; gap: calc(var(--pw) * .015); padding: calc(var(--pw) * .05) calc(var(--pw) * .025) calc(var(--pw) * .02); }
  .branch-title { max-width: 60%; }
  .branch-choices, .branch-explain { width: 58%; }
  .rlayer.pip { width: 40%; }
}
