:root {
  --ink: #f3e9d8;
  --ink-dim: rgba(243, 233, 216, 0.62);
  --glass: rgba(24, 20, 28, 0.42);
  --glass-strong: rgba(18, 15, 22, 0.78);
  --warm: #f2b866;
  --line: rgba(243, 233, 216, 0.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0d0b12;
  color: var(--ink);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#scene:active { cursor: grabbing; }

.hidden { display: none !important; }

/* ── 입장/퇴장 ── */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 40px;
  padding: 0 16px;
  background: radial-gradient(ellipse at 50% 60%, #241a20 0%, #0d0b12 70%);
  z-index: 10;
  transition: opacity 1.2s ease;
}
.overlay.fade { opacity: 0; pointer-events: none; }

.intro-text { text-align: center; }
.intro-text p {
  margin: 0.35em 0;
  font-size: clamp(22px, 5vw, 34px);
  font-weight: 300;
  letter-spacing: 0.04em;
  opacity: 0;
  animation: rise 1.6s ease forwards;
}
.intro-text p:nth-child(2) { animation-delay: 0.9s; }
.intro-text .sub { font-size: clamp(14px, 3.4vw, 17px); color: var(--ink-dim); }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.door-button {
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: linear-gradient(#3a3036, #2a2228);
  border: 1px solid rgba(242, 184, 102, 0.35);
  border-radius: 6px;
  padding: 14px 28px;
  cursor: pointer;
  box-shadow: 0 0 40px rgba(242, 184, 102, 0.12);
  opacity: 0;
  animation: rise 1.2s ease 1.8s forwards;
}
.door-button:hover { border-color: rgba(242, 184, 102, 0.7); }

.hint {
  margin: 0;
  font-size: 13px;
  color: var(--ink-dim);
  text-align: center;
  opacity: 0;
  animation: rise 1.2s ease 2.4s forwards;
}

/* ── HUD ── */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }

.hud-top {
  position: absolute;
  top: 14px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.hud-right { display: flex; gap: 8px; }

.chip {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.chip.button { cursor: pointer; pointer-events: auto; }
.chip.button:hover { background: var(--glass-strong); }

.presence {
  position: absolute;
  left: 16px;
  bottom: 86px;
  font-size: 13px;
  color: var(--ink-dim);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

.toast {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  font-size: 14px;
  color: var(--ink);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
  opacity: 0;
  transition: opacity 0.6s ease;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

/* 함께 맞는 순간 (동틀 녘 등) */
.moment {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translateX(-50%);
  text-align: center;
  font-size: clamp(17px, 4vw, 22px);
  font-weight: 300;
  line-height: 1.6;
  color: var(--ink);
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.7);
  opacity: 0;
  transition: opacity 1.6s ease;
  width: calc(100vw - 32px);
}
.moment.show { opacity: 1; }
.moment small { display: block; font-size: 0.68em; color: var(--ink-dim); }

/* 마음 보내기 */
.emote-row {
  position: absolute;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 6px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-radius: 14px;
  pointer-events: auto;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.emote-row button {
  font-size: 22px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}
.emote-row button:hover { background: rgba(255, 255, 255, 0.08); }

/* 헤드셋: 옥상 라디오 */
.panel {
  position: absolute;
  right: 16px;
  bottom: 84px;
  width: min(280px, calc(100vw - 32px));
  padding: 12px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-radius: 14px;
  pointer-events: auto;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.panel-title { margin: 2px 4px 6px; font-size: 14px; }
.panel { max-height: min(62vh, 560px); overflow-y: auto; scrollbar-width: thin; }
.panel-sub { margin: 10px 4px 6px; font-size: 12px; color: var(--warm); }
.panel-sub em { font-style: normal; color: var(--ink-dim); margin-left: 4px; font-size: 11px; }
.yt-form { display: flex; gap: 6px; margin: 6px 0 8px; }
.yt-form input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  user-select: text;
}
.yt-form button { width: auto !important; display: block !important; margin: 0 !important; padding: 7px 12px !important; border: 1px solid var(--line) !important; }
.file-pick { display: block; margin-bottom: 4px; cursor: pointer; }
.file-pick input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.file-pick span { display: block; padding: 8px 10px; font-size: 13px; border-radius: 10px; color: var(--ink); }
.file-pick:hover span { background: rgba(255, 255, 255, 0.06); }

/* 유튜브 미니 플레이어 */
.yt-mini {
  position: absolute;
  left: 16px;
  top: 60px;
  width: min(220px, 46vw);
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  pointer-events: auto;
}
.yt-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 5px 6px 5px 10px; font-size: 11px; color: var(--ink-dim); }
.yt-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.yt-head button { font: inherit; color: var(--ink); background: transparent; border: 0; cursor: pointer; padding: 2px 6px; }
.yt-frame { position: relative; aspect-ratio: 16 / 9; background: #000; }
.yt-frame iframe, .yt-frame > div { position: absolute; inset: 0; width: 100%; height: 100%; }

/* 사진 */
.flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 25; transition: opacity 0.35s ease; }
.flash.on { opacity: 0.85; transition: none; }
.photo {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(420px, calc(100vw - 32px));
  height: fit-content;
  padding: 12px 12px 14px;
  background: #f4efe6;
  border-radius: 6px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  z-index: 26;
  text-align: center;
  animation: fade-in 0.4s ease;
}
.photo img { display: block; width: 100%; max-height: 60vh; object-fit: contain; border-radius: 2px; -webkit-touch-callout: default; user-select: auto; -webkit-user-select: auto; }
.photo-hint { margin: 10px 0 8px; font-size: 11px; color: #6b645a; }
.photo-actions { display: flex; gap: 8px; justify-content: center; }
.photo-actions .chip { color: #2a2420; background: #e6ded0; border-color: #d4cab8; }
.panel-note { margin: 8px 4px 0; font-size: 11px; color: var(--ink-dim); }
.panel button {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 4px;
  cursor: pointer;
}
.panel button:hover { background: rgba(255, 255, 255, 0.06); }
.panel button.on { border-color: rgba(242, 184, 102, 0.55); background: rgba(242, 184, 102, 0.08); }
.panel button b { font-weight: 500; font-size: 14px; }
.panel button small { grid-column: 1; font-size: 11px; color: var(--ink-dim); }
.panel button i { grid-column: 2; grid-row: 1 / span 2; font-style: normal; font-size: 11px; color: var(--warm); }
.panel button.off { display: block; text-align: center; color: var(--ink-dim); font-size: 13px; }

/* 엘리베이터 층 안내판 */
.directory {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  width: min(340px, calc(100vw - 32px));
  padding: 18px 16px 12px;
  background: rgba(16, 13, 18, 0.86);
  border: 1px solid rgba(243, 233, 216, 0.14);
  border-radius: 14px;
  z-index: 8;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fade-in 0.6s ease;
}
.dir-label { margin: 0 4px 4px; font-size: 11px; letter-spacing: 0.18em; color: var(--ink-dim); }
.dir-title { margin: 0 4px 14px; font-size: 19px; font-weight: 400; }
.floor {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 12px 12px;
  margin-bottom: 8px;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.floor .num {
  font-family: ui-monospace, "Consolas", monospace;
  font-size: 22px;
  color: #ff9a3c;
  min-width: 42px;
}
.floor .what { display: flex; flex-direction: column; gap: 2px; }
.floor b { font-weight: 500; font-size: 15px; }
.floor small { font-size: 12px; color: var(--ink-dim); }
.floor.open { cursor: pointer; border-color: rgba(242, 184, 102, 0.45); }
.floor.open:hover { background: rgba(242, 184, 102, 0.1); }
.floor.open small { color: #9fd8a8; }
.floor.closed { opacity: 0.45; cursor: not-allowed; }
.floor.closed .num { color: var(--ink-dim); }
.floor.here { opacity: 0.55; cursor: default; border-style: dashed; }
.floor.here .num { color: var(--ink-dim); }

.prompt {
  position: fixed;
  left: 50%;
  bottom: 48px;
  transform: translateX(-50%);
  z-index: 8;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--glass-strong);
  border: 1px solid rgba(242, 184, 102, 0.5);
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  animation: fade-in 0.4s ease;
}
.prompt kbd {
  font: inherit;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  margin-right: 6px;
  color: var(--ink-dim);
}

.climb {
  position: fixed;
  left: 50%;
  bottom: 36px;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--ink-dim);
  z-index: 6;
  pointer-events: none;
}

.actions {
  position: absolute;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  pointer-events: auto;
  max-width: calc(100vw - 32px);
}
.act {
  font: inherit;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  white-space: nowrap;
}
.act:hover { background: var(--glass-strong); }
/* 접고 펼치는 행동 메뉴 */
.action-items { display: flex; gap: 8px; }
.actions:not(.open) .action-items { display: none; }
.act.toggle b { font-weight: 500; }
.actions.open .act.toggle { padding: 8px 12px; position: sticky; left: 0; z-index: 1; background: var(--glass-strong); }
.act.on { border-color: rgba(242, 184, 102, 0.6); }
.act span {
  font-size: 11px;
  color: var(--ink-dim);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}
.act b { font-weight: 400; font-size: 13px; }

/* ── 109 안내: 위험한 행동이 반복될 때만 뜬다 ── */
.care-card {
  position: fixed;
  inset: 0;
  margin: auto;
  height: fit-content;
  width: min(340px, calc(100vw - 32px));
  padding: 24px 22px 20px;
  text-align: center;
  background: rgba(28, 22, 26, 0.88);
  border: 1px solid rgba(242, 184, 102, 0.3);
  border-radius: 14px;
  box-shadow: 0 0 60px rgba(242, 184, 102, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 30;
  animation: fade-in 0.8s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.care-title { margin: 0 0 10px; font-size: 20px; font-weight: 400; }
.care-body { margin: 0 0 14px; font-size: 14px; line-height: 1.6; color: var(--ink-dim); }
.care-line { margin: 0 0 18px; font-size: 14px; }
.care-line b { color: var(--warm); font-weight: 600; }
.care-actions { display: flex; gap: 8px; justify-content: center; }
.care-actions a { text-decoration: none; }

.debug {
  position: fixed;
  left: 16px;
  top: 56px;
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 12px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  z-index: 6;
}
.debug input[type="range"] { width: 200px; }

@media (max-width: 640px) {
  .act span { display: none; }
  .act { padding: 9px 10px; }
  .act b { font-size: 12px; }
  .presence { bottom: 84px; }
  .actions.open { overflow-x: auto; justify-content: flex-start; scrollbar-width: none; }
  .emote-row { bottom: 128px; }
  .panel { right: 16px; bottom: 128px; }
  .hint { font-size: 12px; }
}
