:root {
  --bg: #1b1d2a;
  --panel: #242738;
  --panel-2: #2e3247;
  --accent: #ffb454;
  --accent-2: #6cc4ff;
  --text: #e8eaf2;
  --muted: #9aa0b5;
  --ok: #7ddc8a;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
  background: var(--bg); color: var(--text);
}

/* ── 로그인 화면 ── */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #2b2f47, var(--bg));
}
.auth-card {
  width: 360px; background: var(--panel); border: 1px solid #333850;
  border-radius: 16px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.auth-card input {
  width: 100%; padding: 12px 14px; margin-bottom: 12px; border-radius: 10px;
  border: 1px solid #3a3f59; background: var(--panel-2); color: var(--text); font-size: 14px;
}
.auth-card button {
  width: 100%; padding: 12px; border: none; border-radius: 10px; cursor: pointer;
  background: var(--accent); color: #241a00; font-weight: 700; font-size: 15px;
}
.auth-card button:hover { filter: brightness(1.05); }
.auth-toggle { text-align: center; margin-top: 14px; font-size: 13px; color: var(--muted); }
.auth-toggle a { color: var(--accent-2); cursor: pointer; text-decoration: none; }
.auth-err { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.oauth { margin-top: 16px; }
.oauth-divider { position: relative; text-align: center; margin: 6px 0 12px; }
.oauth-divider::before { content: ""; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: #3a3f59; }
.oauth-divider span { position: relative; background: var(--panel); padding: 0 10px; color: var(--muted); font-size: 12px; }
.oauth-btns { display: flex; gap: 8px; }
.oauth-btn { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid #3a3f59; cursor: pointer; font-weight: 700; font-size: 13px; color: #241a00; }
.oauth-btn.google { background: #fff; }
.oauth-btn.naver { background: #03c75a; color: #fff; }
.oauth-btn.kakao { background: #fee500; }
.oauth-btn:hover { filter: brightness(0.96); }

/* ── 게임 화면 ── */
#game { position: fixed; inset: 0; }
.hud {
  position: fixed; top: 12px; left: 12px; z-index: 5;
  background: rgba(36,39,56,.85); border: 1px solid #3a3f59; border-radius: 10px;
  padding: 8px 12px; font-size: 13px; color: var(--muted);
}
.hud b { color: var(--text); }
.topbar { position: fixed; top: 12px; right: 12px; z-index: 5; display: flex; gap: 8px; }
.topbar button {
  background: var(--panel-2); color: var(--text); border: 1px solid #3a3f59;
  border-radius: 8px; padding: 8px 12px; cursor: pointer; font-size: 13px;
}
.topbar button:hover { border-color: var(--accent); }

/* ── 대화 시 큰 캐릭터 얼굴 (VN 스타일) ── */
.big-portrait {
  position: fixed; right: 380px; left: auto; bottom: 0; z-index: 15;  /* 우측 대화창(380px) 왼쪽 라인에 붙임 */
  height: 78vh; max-height: 840px; pointer-events: none; display: none;
  filter: drop-shadow(0 12px 34px rgba(0,0,0,.65));
  -webkit-mask-image: linear-gradient(to bottom, #000 82%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 82%, transparent 100%);
  animation: portrait-in .3s ease;
}
.big-portrait.show { display: block; }
@keyframes portrait-in { from { transform: translateY(30px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── 우측 채팅 패널 ── */
.panel {
  position: fixed; top: 0; right: 0; height: 100%; width: 380px; z-index: 20;
  background: var(--panel); border-left: 1px solid #3a3f59; display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .22s ease;
}
.panel.open { transform: translateX(0); }
.panel-head {
  padding: 14px 16px; border-bottom: 1px solid #3a3f59; display: flex; align-items: center; gap: 12px;
  background: linear-gradient(180deg, #2b2f45, var(--panel));
}
.panel-head .portrait-img {
  width: 84px; height: 84px; border-radius: 14px; object-fit: cover; object-position: top center;
  border: 2px solid var(--accent); background: #1b1d2a; flex: 0 0 auto;
  box-shadow: 0 6px 18px rgba(0,0,0,.4); animation: pop-in .28s ease;
}
@keyframes pop-in { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.panel-head .portrait-meta { flex: 1; min-width: 0; }
.panel-head .who { font-weight: 800; font-size: 18px; }
.panel-head .role { color: var(--muted); font-size: 12px; margin-top: 2px; }
.panel-head .x { cursor: pointer; color: var(--muted); font-size: 22px; align-self: flex-start; }
.panel-head .x:hover { color: var(--text); }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 10px 12px; border-radius: 12px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #241a00; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); }
.msg.system { align-self: center; color: var(--muted); font-size: 12px; background: transparent; }
.composer { padding: 12px; border-top: 1px solid #3a3f59; display: flex; gap: 8px; }
.composer textarea {
  flex: 1; resize: none; height: 44px; border-radius: 10px; border: 1px solid #3a3f59;
  background: var(--panel-2); color: var(--text); padding: 10px; font-size: 14px; font-family: inherit;
}
.composer button { background: var(--accent); color: #241a00; border: none; border-radius: 10px; padding: 0 16px; cursor: pointer; font-weight: 700; }

/* ── 프롤로그 / 모달 오버레이 ── */
.overlay {
  position: fixed; inset: 0; z-index: 40; display: none;
  align-items: center; justify-content: center; background: rgba(10,11,18,.78);
}
.overlay.open { display: flex; }
.dialogue {
  width: min(680px, 92vw); background: var(--panel); border: 1px solid #3a3f59; border-radius: 16px;
  padding: 28px; box-shadow: 0 24px 80px rgba(0,0,0,.6);
}
.dialogue .speaker { color: var(--accent); font-weight: 700; margin-bottom: 8px; }
.dialogue .line { font-size: 17px; line-height: 1.7; min-height: 90px; }
.dialogue .next { margin-top: 18px; text-align: right; color: var(--muted); font-size: 13px; }
.dialogue .next button {
  background: var(--accent); color: #241a00; border: none; border-radius: 10px;
  padding: 10px 18px; cursor: pointer; font-weight: 700; font-size: 14px;
}

/* ── 책장(문서) 모달 ── */
.modal-card {
  width: min(720px, 94vw); max-height: 80vh; overflow: hidden; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid #3a3f59; border-radius: 16px;
}
.modal-card .head { padding: 18px 20px; border-bottom: 1px solid #3a3f59; display: flex; justify-content: space-between; align-items: center; }
.modal-card .head h3 { margin: 0; }
.modal-card .body { padding: 16px 20px; overflow-y: auto; }
.doc-item { padding: 12px; border: 1px solid #3a3f59; border-radius: 10px; margin-bottom: 10px; cursor: pointer; }
.doc-item:hover { border-color: var(--accent); }
.doc-item .t { font-weight: 700; }
.doc-item .m { color: var(--muted); font-size: 12px; margin-top: 4px; }
.doc-view pre { white-space: pre-wrap; word-break: break-word; font-family: inherit; line-height: 1.6; }
.empty { color: var(--muted); text-align: center; padding: 30px 0; }
