/* 메인 페이지 (3D 방) */
:root {
  --ink: #2b2118;
  --muted: #7b6a5a;
  --glass: rgba(255, 250, 244, 0.84);
  --line: rgba(60, 40, 20, 0.12);
  --accent: #16a34a;
  --card: rgba(255, 251, 246, 0.97);
  --chip-on: #ffffff;
  --bg: radial-gradient(120% 90% at 25% 15%, #fbf6ef 0%, #efe3d3 55%, #e0cfba 100%);
}
/* 연구실: 어둡고 푸른 빛 */
body[data-room="lab"] {
  --ink: #e6f6ff;
  --muted: #8fb3c7;
  --glass: rgba(9, 18, 28, 0.74);
  --line: rgba(103, 232, 249, 0.28);
  --accent: #22d3ee;
  --card: rgba(8, 15, 24, 0.95);
  --chip-on: rgba(34, 211, 238, 0.22);
  --bg: radial-gradient(120% 90% at 30% 20%, #10202e 0%, #071019 55%, #02060b 100%);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#room { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; }
#room:active { cursor: grabbing; }
#room.hovering { cursor: pointer; }


/* 물건 위 이름표 */
#pins { position: fixed; inset: 0; pointer-events: none; }
.pin {
  position: absolute; left: 0; top: 0;
  display: flex; align-items: center; gap: 5px;
  padding: 5px 10px 5px 8px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--glass); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 4px 14px rgba(60, 40, 20, 0.14);
  color: var(--ink); font: inherit; font-size: 13px; font-weight: 700; white-space: nowrap;
  pointer-events: auto; cursor: pointer;
  transition: opacity 0.2s, background 0.15s;
  will-change: transform;
}
.pin .e { font-size: 15px; line-height: 1; }
.pin.on { background: var(--chip-on); border-color: var(--accent); }
.pin.main { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (max-width: 560px) {
  .pin { padding: 5px 7px; }
  .pin .n { display: none; }
  .pin.main .n, .pin.on .n { display: inline; }
}

/* 마우스를 올렸을 때 설명 */
.tip {
  position: fixed; left: 0; top: 0; z-index: 5; max-width: 240px;
  padding: 8px 11px; border-radius: 12px; background: rgba(43, 33, 24, 0.9); color: #fff;
  font-size: 13px; line-height: 1.4; pointer-events: none;
}
.tip b { display: block; font-size: 14px; }

.hint {
  position: fixed; left: 50%; top: calc(18px + env(safe-area-inset-top)); transform: translateX(-50%);
  padding: 8px 14px; border-radius: 999px; background: rgba(43, 33, 24, 0.82); color: #fff;
  font-size: 13px; font-weight: 600; pointer-events: none; animation: hint 6s ease forwards; max-width: calc(100vw - 110px); text-align: center;
}
@keyframes hint { 0% { opacity: 0; } 10%, 80% { opacity: 1; } 100% { opacity: 0; } }

/* 바로가기 */
.quick {
  position: fixed; left: 0; right: 0; bottom: calc(14px + env(safe-area-inset-bottom));
  display: flex; gap: 8px; padding: 0 16px; overflow-x: auto; justify-content: center;
  scrollbar-width: none;
}
.quick::-webkit-scrollbar { display: none; }
@media (max-width: 720px) { .quick { justify-content: flex-start; } }
.chip {
  flex: none; padding: 9px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 2px 10px rgba(60, 40, 20, 0.08);
  color: var(--ink); font: inherit; font-size: 14px; font-weight: 700; text-decoration: none; cursor: pointer;
}
.chip:active { transform: scale(0.97); }
.chip:focus-visible, .pin:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip.on { background: var(--chip-on); border-color: var(--accent); }

/* 소개 카드 */
.card {
  position: fixed; left: 50%; bottom: calc(68px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(420px, calc(100vw - 32px)); max-height: 60vh; overflow: auto;
  padding: 18px 18px 16px; border: 1px solid var(--line); border-radius: 20px;
  background: var(--card); color: var(--ink); box-shadow: 0 14px 44px rgba(0, 0, 0, 0.22);
  animation: card-in 0.22s ease;
}
@keyframes card-in { from { opacity: 0; transform: translate(-50%, 10px); } }
.card-close {
  position: absolute; top: 10px; right: 10px; width: 32px; height: 32px; border: 0; border-radius: 10px;
  background: var(--line); color: var(--ink); font-size: 15px; cursor: pointer;
}
.card-head { display: flex; align-items: center; gap: 8px; padding-right: 36px; }
.card-emoji { font-size: 26px; }
.card-head h2 { margin: 0; font-size: 19px; }
.card-soon { padding: 3px 8px; border-radius: 999px; background: #fde68a; color: #78350f; font-size: 12px; font-weight: 800; }
.card-desc { margin: 10px 0 0; color: var(--muted); font-size: 14px; line-height: 1.55; }
.card-body:empty { display: none; }
.card-body { margin-top: 12px; display: grid; gap: 8px; }
.card-section { padding: 10px 12px; border: 1px solid var(--line); border-radius: 14px; font-size: 14px; }
.card-section b { display: block; margin-bottom: 3px; }
.card-section span { color: var(--muted); font-size: 13px; }
.card-btn {
  display: block; margin-top: 14px; padding: 12px; border-radius: 14px;
  background: var(--ink); color: #fff; text-align: center; text-decoration: none; font-weight: 800;
}

.loading {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center;
  color: var(--muted); font-weight: 700; transition: opacity 0.5s; pointer-events: none;
}
.loading.done { opacity: 0; }
.loading.failed { color: var(--ink); }

/* 신발을 눌러 다른 페이지로 갈 때: 다가가며 흐려짐 */
body.leaving #room { opacity: 0; transition: opacity 0.6s ease 0.15s; }
body.leaving .quick, body.leaving #pins { opacity: 0; transition: opacity 0.25s; }

/* 📚 책 목록 (카드 안) */
.book-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.book-list li { padding-top: 8px; border-top: 1px dashed var(--line); }
.book-list li:first-child { padding-top: 0; border-top: 0; }
.book-list strong { display: block; font-size: 14px; }
.book-list small { display: block; margin-top: 2px; color: var(--muted); font-size: 12.5px; }
.book-list p { margin: 4px 0 0; font-size: 13px; line-height: 1.5; }

/* 크게 보는 창 (지도·이력서) */
.viewer { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom)); background: rgba(0, 0, 0, 0.35); }
.viewer-box { width: min(980px, 100%); height: min(760px, 100%); display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--line); border-radius: 20px; background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); animation: card-in 0.22s ease; }
.viewer-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 12px 16px; border-bottom: 1px solid var(--line); }
.viewer-emoji { font-size: 22px; }
.viewer-head h2 { margin: 0; font-size: 17px; flex: 1; }
.viewer-open { padding: 7px 11px; border-radius: 10px; background: var(--ink); color: var(--card); font-size: 13px; font-weight: 800; text-decoration: none; white-space: nowrap; }
.viewer-close { width: 34px; height: 34px; border: 0; border-radius: 10px; background: var(--line); color: var(--ink); font-size: 15px; cursor: pointer; }
.viewer-body { position: relative; flex: 1; min-height: 0; }
.viewer-map, .viewer-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #f1ede6; }
.viewer-note { margin: 0; padding: 9px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.place-pop b { display: block; font-size: 14px; }
.place-pop small { color: #6b7280; }
.place-pop p { margin: 6px 0 0; }

/* 🔑 로그인 */
.login { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(20, 14, 8, 0.45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.login-card { width: min(340px, 100%); display: grid; gap: 10px; padding: 22px 20px 18px; border-radius: 22px; background: #fffaf3; color: #2b2118; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); animation: card-in 0.22s ease; }
.login-key { font-size: 38px; animation: key-wiggle 1.6s ease-in-out infinite; }
@keyframes key-wiggle { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }
.login-card h2 { margin: 0; font-size: 19px; }
.login-card p { margin: 0; color: #7b6a5a; font-size: 13.5px; line-height: 1.5; }
.login-card input { width: 100%; padding: 12px 14px; border: 1px solid rgba(60, 40, 20, 0.18); border-radius: 12px; background: #fff; color: inherit; font: inherit; font-size: 16px; }
.login-card input:focus { outline: 2px solid #16a34a; outline-offset: 1px; }
.login-card .login-error { min-height: 1.2em; color: #dc2626; font-weight: 700; }
.login-submit { padding: 13px; border: 0; border-radius: 14px; background: #2b2118; color: #fff; font: inherit; font-weight: 800; font-size: 16px; cursor: pointer; }
.login-submit:disabled { opacity: 0.55; }
.login-cancel { padding: 8px; border: 0; background: none; color: #7b6a5a; font: inherit; font-size: 14px; cursor: pointer; }

/* 방이 바뀔 때 번쩍 */
.warp { position: fixed; inset: 0; z-index: 40; pointer-events: none; opacity: 0; transition: opacity 0.45s ease; }
.warp.on { opacity: 1; }
.warp.cool { background: radial-gradient(circle at 50% 55%, rgba(186, 230, 253, 0.98) 0%, rgba(34, 211, 238, 0.75) 30%, rgba(2, 6, 23, 0.98) 72%); }
.warp.warm { background: radial-gradient(circle at 50% 55%, rgba(255, 247, 237, 0.98) 0%, rgba(253, 186, 116, 0.7) 35%, rgba(120, 72, 40, 0.95) 80%); }

/* ⟲ 처음 보던 방향으로 */
.view-home {
  position: fixed; top: calc(14px + env(safe-area-inset-top)); right: 14px; z-index: 6;
  width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: var(--ink); font: inherit; font-size: 21px; line-height: 1; cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.view-home:active { transform: scale(0.95); }
body.leaving .view-home { opacity: 0; transition: opacity 0.25s; }
