/* Last Ten — 스타일 */
:root {
  --bg: #06060b;
  --panel: rgba(13, 13, 22, 0.94);
  --panel-2: rgba(22, 21, 36, 0.96);
  --line: rgba(255, 255, 255, 0.09);
  --line-2: rgba(255, 255, 255, 0.16);
  --text: #ebe8f4;
  --muted: #9d99b0;
  --dim: #6c6880;
  --accent: #b9a8ff;
  --accent-2: #ffd98a;
  --accent-glow: rgba(185, 168, 255, 0.35);
  --danger: #ff5d6c;
  --ok: #7df0b0;
  --font: 'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  --pen: 'Nanum Pen Script', 'Gaegu', var(--font);
  --mono: 'Share Tech Mono', ui-monospace, 'Consolas', monospace;
  --serif: 'Noto Serif KR', 'Nanum Myeongjo', serif;
  --hand: 'Nanum Pen Script', var(--font);
}

* { box-sizing: border-box; }
/* 영상 위에 브라우저가 그리는 재생·대기 버튼을 감춘다 (휴대폰에서 영상이 바뀔 때 깜빡이던 것) */
video::-webkit-media-controls, video::-webkit-media-controls-enclosure, video::-webkit-media-controls-panel,
video::-webkit-media-controls-overlay-play-button, video::-webkit-media-controls-start-playback-button { display: none !important; -webkit-appearance: none; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; }
body { -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input { font: inherit; }
[hidden] { display: none !important; }
.tb-btn svg, .nav-back svg, .icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#app { position: fixed; inset: 0; overflow: hidden; background: radial-gradient(ellipse at center, #0d0c17 0%, #040407 70%); }
#stage {
  position: absolute; left: 50%; top: 50%;
  width: 1152px; height: 648px;
  transform-origin: center center;
  background: var(--bg);
  overflow: hidden;
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.8);
}
.noscript { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; }

/* ---------- 상단 바 ---------- */
/* 스테이지 1152x648 (16:9) — 장면 900x600 (10,40) · 오른쪽 패널 (922,40) */
#topbar {
  position: absolute; left: 10px; top: 0; width: 900px; height: 40px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 0 4px; z-index: 5;
}
.tb-left { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: 13px; color: var(--muted); }
.chip { padding: 3px 9px; border: 1px solid var(--line-2); border-radius: 999px; color: var(--accent); font-size: 12px; letter-spacing: 0.02em; white-space: nowrap; }
#tb-scene { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timer { display: flex; align-items: baseline; gap: 8px; font-family: var(--mono); }
.timer b { font-size: 22px; font-weight: 400; letter-spacing: 0.06em; color: #fff; text-shadow: 0 0 10px rgba(255, 255, 255, 0.3); }
.timer span { font-size: 12px; color: var(--muted); }
.timer.low b { color: var(--danger); text-shadow: 0 0 12px rgba(255, 93, 108, 0.6); animation: pulse 1s infinite; }

.tb-btn { position: relative; display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; font-size: 12.5px; color: var(--muted); transition: color .15s, background .15s; }
.tb-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.tb-btn.ping::after { content: ''; position: absolute; top: 4px; left: 20px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); }
.tb-btn.glow { color: var(--accent-2); }

/* ---------- 장면 ---------- */
#view {
  position: absolute; left: 10px; top: 40px; width: 900px; height: 600px;
  overflow: hidden; border-radius: 4px; background: #000;
  box-shadow: 0 0 0 1px var(--line), 0 18px 60px rgba(0, 0, 0, 0.6);
}
#scene { position: absolute; inset: 0; }
#scene img.bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 1; transition: opacity 380ms ease; pointer-events: none; }
#scene img.bg:not([src]) { opacity: 0 !important; }
#scene img.bg.next { z-index: 1; }
#view.dim #scene img.bg, #view.dim #overlays { filter: brightness(.45); transition: filter .5s; }
#scene img.bg, #overlays { transition: opacity 380ms ease, filter .5s; }
#overlays { position: absolute; inset: 0; pointer-events: none; }
/* z-index 1: 장면이 서서히 바뀔 때 새 배경(.next, z-index 1)에 가려지지 않게 — 같은 층이라 문서 순서대로 배경 위·색 보정(#grade) 아래 */
#overlays .overlay { position: absolute; z-index: 1; object-fit: contain; transition: translate .3s cubic-bezier(.2, .8, .3, 1.25); }
#overlays .overlay.dragging { transition: none; filter: drop-shadow(0 12px 14px rgba(0, 0, 0, .55)); }
#overlays .overlay.pulled { opacity: 0; transition: translate .26s ease-in, opacity .26s ease-in; }
#overlays .overlay.yank { animation: plugYank .52s cubic-bezier(.4, 0, .8, .6) forwards; }
@keyframes plugYank { 0% { translate: 0 0; rotate: 0deg; scale: 1; opacity: 1; } 30% { translate: 0 -12px; rotate: -6deg; scale: 1.08; opacity: 1; } 100% { translate: 120px -260px; rotate: 28deg; scale: .9; opacity: 0; } }
.hotspot.is-drag { cursor: grab; touch-action: none; }
.hotspot.is-drag:active { cursor: grabbing; }
#overlays .overlay.glow { animation: glow 2.4s ease-in-out infinite; }
#hotspots { position: absolute; inset: 0; }
.hotspot { position: absolute; border-radius: 10px; cursor: pointer; transition: background .2s, box-shadow .2s; }
.hotspot:hover { background: radial-gradient(closest-side, rgba(255, 255, 255, 0.07), transparent); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05); }
#scene.has-item .hotspot { cursor: copy; }
#scene.busy .hotspot, #scene.busy .nav-arrow, #scene.busy .nav-back { pointer-events: none; }
#scene.busy .nav-arrow, #scene.busy .nav-back { opacity: 0.25; }
#scene.show-hotspots .hotspot { box-shadow: inset 0 0 0 1.5px rgba(255, 217, 138, 0.55); background: rgba(255, 217, 138, 0.06); }
.hs-id { position: absolute; left: 3px; top: 2px; font: 11px var(--mono); color: var(--accent-2); text-shadow: 0 0 3px #000; pointer-events: none; }
.debug-rect { position: absolute; border: 1px dashed #0ff; background: rgba(0, 255, 255, 0.1); pointer-events: none; z-index: 50; }

.nav-arrow { position: absolute; top: 50%; width: 56px; height: 120px; margin-top: -60px; opacity: 0.55; transition: opacity .2s, transform .2s; z-index: 2; }
.nav-arrow::before { content: ''; position: absolute; top: 50%; left: 50%; width: 26px; height: 26px; border: solid #fff; border-width: 0 0 4px 4px; filter: drop-shadow(0 0 6px rgba(0, 0, 0, .9)); }
.nav-arrow.left { left: 6px; }
.nav-arrow.left::before { transform: translate(-30%, -50%) rotate(45deg); }
.nav-arrow.right { right: 6px; }
.nav-arrow.right::before { transform: translate(-70%, -50%) rotate(-135deg); }
.nav-arrow:hover { opacity: 1; }
.nav-arrow.left:hover { transform: translateX(-3px); }
.nav-arrow.right:hover { transform: translateX(3px); }
.nav-back { position: absolute; left: 50%; bottom: 6px; width: 120px; height: 40px; margin-left: -60px; display: grid; place-items: center; opacity: 0.6; z-index: 2; color: #fff; }
.nav-back svg { width: 34px; height: 34px; stroke-width: 2.6; filter: drop-shadow(0 0 6px #000); }
.nav-back:hover { opacity: 1; }

/* ---------- 효과 ---------- */
#fx { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.fx-layer { position: absolute; inset: 0; }
.fx-flash { background: #fff; animation: flash 700ms ease-out forwards; }
.fx-red { background: radial-gradient(ellipse at center, transparent 30%, rgba(160, 0, 20, 0.75)); animation: flash 900ms ease-out forwards; }
.fx-dark { background: #000; animation: flash 900ms ease-in-out forwards; }
#view.fx-shake { animation: shake 480ms cubic-bezier(.36, .07, .19, .97); }
#view.fx-glitch #scene { animation: glitch 500ms steps(2) ; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
@keyframes shake { 10%, 90% { transform: translate(-2px, 1px); } 20%, 80% { transform: translate(4px, -2px); } 30%, 50%, 70% { transform: translate(-6px, 2px); } 40%, 60% { transform: translate(6px, -1px); } }
@keyframes glitch { 0% { filter: none; transform: none; } 25% { filter: hue-rotate(60deg) contrast(1.6); transform: translateX(-6px); } 50% { filter: invert(.15); transform: translateX(5px) skewX(3deg); } 75% { filter: hue-rotate(-40deg) saturate(2); transform: translateX(-2px); } 100% { filter: none; transform: none; } }
@keyframes pulse { 50% { opacity: .45; } }
@keyframes glow { 50% { filter: drop-shadow(0 0 10px rgba(255, 255, 255, .7)); } }

/* ---------- 대사창 ---------- */
#dialog {
  position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%);
  width: 600px; min-height: 104px; padding: 18px 28px 22px;
  background: linear-gradient(180deg, rgba(6, 6, 12, 0.88), rgba(3, 3, 8, 0.94));
  border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  z-index: 8; cursor: pointer;
  animation: dlgIn .18s ease-out;
}
@keyframes dlgIn { from { opacity: 0; transform: translate(-50%, 6px); } }
.dlg-who { font-size: 14px; font-weight: 700; color: var(--accent); margin-bottom: 8px; letter-spacing: .04em; min-height: 1em; }
.dlg-text { font-size: 17px; line-height: 1.65; white-space: pre-line; word-break: keep-all; }
.dlg-next { position: absolute; right: 18px; bottom: 12px; width: 0; height: 0; border: 6px solid transparent; border-top-color: var(--muted); opacity: 0; }
#dialog.done .dlg-next { opacity: 1; animation: bob 1s infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }
#dialog.no-who .dlg-who { display: none; }
#dialog.is-narr .dlg-text { color: #cfcade; font-style: italic; }
#dialog.is-unknown .dlg-who { color: #e7e7e7; }
#dialog.is-unknown .dlg-text { color: #f1eef8; text-shadow: 0 0 12px rgba(185, 168, 255, 0.35); }
#dialog.is-sys .dlg-who { color: var(--accent-2); }
#dialog.is-phone .dlg-who { color: #8fd3ff; }
#dialog.is-shout .dlg-text { font-size: 21px; font-weight: 700; color: #fff; }

/* ---------- 토스트 ---------- */
#toasts { position: absolute; left: 0; right: 0; top: 14px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 9; }
.toast { display: flex; align-items: center; gap: 8px; padding: 7px 14px 7px 10px; border-radius: 999px; background: rgba(250, 248, 255, 0.95); color: #17151f; font-size: 13px; font-weight: 500; box-shadow: 0 6px 24px rgba(0, 0, 0, .45); opacity: 0; transform: translateY(-8px); transition: opacity .3s, transform .3s; }
.toast.in { opacity: 1; transform: none; }
.toast img { width: 22px; height: 22px; object-fit: contain; border-radius: 4px; background: #222; }
.toast.is-note { background: rgba(255, 217, 138, 0.96); }
.toast.is-bad { background: rgba(255, 93, 108, 0.95); color: #fff; }
.toast.is-good { background: rgba(125, 240, 176, 0.95); }

/* ---------- 확대 보기 ---------- */
#layer-popup { position: absolute; inset: 0; z-index: 7; pointer-events: none; }
#layer-popup > * { pointer-events: auto; }
.popup { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, 0.72); opacity: 0; transition: opacity .2s; cursor: pointer; }
.popup.in { opacity: 1; }
.popup-frame { position: relative; display: grid; place-items: center; overflow: hidden; }
.popup.is-full .popup-frame { width: 900px; height: 600px; }
.popup.is-full .popup-img { width: 100%; height: 100%; object-fit: contain; }
.popup.is-item .popup-img { max-width: 560px; max-height: 470px; object-fit: contain; filter: drop-shadow(0 10px 30px rgba(0, 0, 0, .7)); }
.popup-img { transition: transform .25s ease; }
.popup-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; cursor: pointer; }
.popup-tools { position: absolute; right: 12px; top: 12px; display: flex; gap: 6px; }
.popup-caption { position: absolute; left: 0; right: 0; bottom: 18px; text-align: center; font-size: 14px; color: var(--muted); }
.icon-btn { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: rgba(20, 20, 30, .8); border: 1px solid var(--line-2); font-size: 15px; color: var(--text); transition: background .15s; }
.icon-btn:hover { background: rgba(60, 56, 90, .9); }

/* ---------- 인벤토리 ---------- */
#side { position: absolute; left: 922px; top: 40px; width: 220px; height: 600px; display: flex; flex-direction: column; gap: 10px; z-index: 5; }
.side-menu { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.side-menu .tb-btn { flex-direction: column; justify-content: center; gap: 4px; padding: 10px 4px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); font-size: 12px; }
.side-menu .tb-btn.ping::after { left: auto; right: 8px; top: 8px; }
.inv-label { margin-top: 6px; font-size: 12px; color: var(--dim); letter-spacing: .2em; }
#inv-slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.slot { width: 100%; aspect-ratio: 1; border-radius: 8px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; transition: border-color .15s, background .15s, transform .15s; }
.slot img { width: 78%; height: 78%; object-fit: contain; pointer-events: none; }
.slot.filled:hover { border-color: var(--line-2); background: rgba(255, 255, 255, 0.08); }
.slot.selected { border-color: var(--accent); background: rgba(185, 168, 255, 0.16); box-shadow: 0 0 0 1px var(--accent), 0 0 18px var(--accent-glow); }
.slot.new { animation: newItem 1.2s ease-out; }
@keyframes newItem { 0% { transform: scale(1.25); box-shadow: 0 0 24px var(--accent-2); } 100% { transform: none; } }
#inv-info { flex: 1; min-height: 0; padding: 12px; border-radius: 10px; background: rgba(255, 255, 255, 0.025); border: 1px solid var(--line); font-size: 12.5px; line-height: 1.6; color: var(--muted); overflow: hidden; }
.inv-name { color: var(--text); font-weight: 700; font-size: 13.5px; }
.inv-desc { margin: 4px 0 10px; word-break: keep-all; }
.inv-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.inv-tip { color: var(--dim); font-size: 12px; }

/* ---------- 버튼 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 88px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line-2); background: rgba(255, 255, 255, 0.05); font-size: 14px; color: var(--text); transition: background .15s, border-color .15s, transform .1s; }
.btn:hover { background: rgba(255, 255, 255, 0.1); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(180deg, #7a68e0, #5b49c4); border-color: rgba(185, 168, 255, .6); }
.btn.primary:hover { background: linear-gradient(180deg, #8a79ee, #6655d2); }
.btn.ghost { background: transparent; }
.btn.small { min-width: 0; padding: 3px 9px; font-size: 12px; border-radius: 6px; }
.btn.danger { border-color: rgba(255, 93, 108, .5); color: #ffb3ba; }
.btn-row { display: flex; justify-content: center; gap: 10px; margin-top: 18px; }

/* ---------- 모달 ---------- */
#layer-modal { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
/* isolation: 창마다 자기 층을 갖게 — 앞 창 안의 z-index 가 뒤에 뜬 창(확인 창 등) 위로 올라오지 않도록 */
.modal { position: absolute; inset: 0; isolation: isolate; display: grid; place-items: center; background: rgba(0, 0, 0, 0.55); opacity: 0; transition: opacity .2s; pointer-events: auto; }
.modal.in { opacity: 1; }
.modal.in-view { inset: auto; left: 10px; top: 40px; width: 900px; height: 600px; }
.modal-box { position: relative; min-width: 320px; max-width: 860px; max-height: 620px; padding: 24px 28px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line-2); box-shadow: 0 24px 80px rgba(0, 0, 0, .7); transform: translateY(8px) scale(.98); transition: transform .2s; }
.modal.in .modal-box { transform: none; }
.modal-title { font-size: 16px; font-weight: 700; margin: 0 30px 14px 0; line-height: 1.5; word-break: keep-all; }
.modal-x { position: absolute; right: 12px; top: 12px; width: 30px; height: 30px; }
.confirm { width: 380px; text-align: center; }
.confirm-text { margin: 6px 0 0; line-height: 1.7; white-space: pre-line; word-break: keep-all; color: #d9d5e6; }

/* ---------- 전체 화면 레이어 ---------- */
#layer-screen { position: absolute; inset: 0; z-index: 15; pointer-events: none; }
.screen { position: absolute; inset: 0; pointer-events: auto; opacity: 0; transition: opacity .4s ease; }
.screen.in { opacity: 1; }
#cover { position: absolute; inset: 0; background: #000; z-index: 30; opacity: 0; pointer-events: none; transition: opacity .6s ease; }
#cover.on { opacity: 1; pointer-events: auto; }
#dialog.over-cover { z-index: 31; }

/* ---------- 세로 화면 안내 ---------- */
#app::after { content: '화면을 가로로 돌리면 더 크게 플레이할 수 있어요'; position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); padding: 6px 12px; border-radius: 999px; background: rgba(20, 20, 30, .85); color: var(--muted); font-size: 12px; white-space: nowrap; pointer-events: none; display: none; }
@media (orientation: portrait) and (max-width: 700px) { #app::after { display: block; } }

/* ---------- 반응: 애니메이션 줄이기 ---------- */
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
