:root {
  --bg: #0C0C10;
  --bg-deep: #08080B;
  --ink: #EFEEEA;
  --ink-dim: #96959B;
  --card-bg: rgba(20, 14, 20, 0.56);
  --card-border: rgba(239, 238, 234, 0.12);
  --card-border-hover: rgba(196, 89, 110, 0.44);
  --accent: #9C3145;
  --accent-ink: #C4596E;
  --char: #C9A96E;
  --header-h: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

#app {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -webkit-touch-callout: none;
}

#input-name {
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100%;
}

body {
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", "Segoe UI", sans-serif;
  font-weight: 400;
  line-height: 1.78;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  position: relative;
  background: transparent;
  overflow-x: hidden;
}

/* ---------- 배경 ---------- */
.bg-art {
  position: fixed;
  inset: 0;
  max-width: 480px;
  margin: 0 auto;
  z-index: 0;
  overflow: hidden;
  background: var(--bg-deep);
}

.bg-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 20%;
  display: block;
}

.bg-veil {
  position: fixed;
  inset: 0;
  max-width: 480px;
  margin: 0 auto;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(9, 7, 11, .70) 0%, rgba(11, 8, 12, .84) 42%, rgba(8, 8, 11, .95) 100%),
    linear-gradient(90deg, rgba(8, 8, 11, .24), rgba(70, 18, 34, .08), rgba(8, 8, 11, .32));
  opacity: 1;
  transition: opacity .45s ease;
}

/* ---------- Story Room header ---------- */
.story-room-bar {
  position: sticky;
  top: 0;
  z-index: 35;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 13px 8px 10px;
  background: rgba(12, 12, 16, .90);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--card-border);
}

.room-back {
  flex: 0 0 24px;
  width: 24px;
  color: var(--ink);
  font-family: system-ui, sans-serif;
  font-size: 32px;
  line-height: 1;
  text-decoration: none;
  text-align: center;
  opacity: .88;
}

.room-avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 22%;
  border: 1px solid rgba(239, 238, 234, .18);
}

.room-meta {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.room-character {
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
}

.room-title-button {
  width: fit-content;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-dim);
  font-family: inherit;
  font-size: 11.5px;
  line-height: 1.45;
  cursor: pointer;
  text-align: left;
}

#room-title {
  display: block;
  max-width: 210px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.room-edit-mark { font-size: 10px; color: var(--accent-ink); }

.room-phase {
  flex: 0 0 auto;
  color: var(--char);
  font-size: 9.5px;
  letter-spacing: .16em;
}

.room-title-editor {
  position: absolute;
  top: calc(100% + 7px);
  left: 54px;
  right: 12px;
  display: flex;
  gap: 7px;
  padding: 9px;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  background: rgba(12, 12, 16, .97);
  box-shadow: 0 12px 28px rgba(0,0,0,.28);
}
.room-title-editor input {
  min-width: 0; flex: 1; padding: 8px 9px; border-radius: 7px; border: 1px solid var(--card-border);
  background: rgba(239,238,234,.04); color: var(--ink); font-family: inherit; font-size: 12px; outline: none;
  user-select: text; -webkit-user-select: text;
}
.room-title-editor input:focus { border-color: rgba(196,89,110,.6); }
.room-title-editor button {
  padding: 7px 9px; border-radius: 7px; border: 1px solid var(--card-border); background: none; color: var(--ink-dim);
  font-family: inherit; font-size: 11px; cursor: pointer;
}
.room-title-editor button:first-of-type { border-color: rgba(196,89,110,.45); color: var(--ink); }

/* ---------- 화면 전환 ---------- */
.screen {
  display: none;
  min-height: calc(100vh - var(--header-h));
  flex-direction: column;
  opacity: 0;
  position: relative;
  z-index: 2;
}
.screen.active { display: flex; }
.screen.fade-in { animation: fadeIn .5s ease forwards; }
.screen.fade-out { animation: fadeOut .35s ease forwards; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* ---------- 배경 감상 ---------- */
.btn-peek {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  right: 14px;
  z-index: 40;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 12, 16, .62);
  border: 1px solid var(--card-border);
  border-radius: 50%;
  color: var(--ink-dim);
  cursor: pointer;
}
.btn-peek:hover { border-color: var(--card-border-hover); color: var(--ink); }
#app.peeking .btn-peek { border-color: var(--accent); color: var(--accent); }
@media (min-width: 481px) {
  .btn-peek { right: calc(50% - 240px + 14px); }
}

.story-wrap, .center-card, .title-copy, .title-art, .result-reader { transition: opacity .4s ease; }
#app.peeking .bg-veil { opacity: .28; }
#app.peeking .story-wrap,
#app.peeking .center-card,
#app.peeking .title-copy,
#app.peeking .title-art,
#app.peeking .result-reader { opacity: 0; pointer-events: none; }

/* ---------- 공통 ---------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 22px 20px;
  backdrop-filter: blur(10px);
}
.center-card { margin: auto 20px; text-align: center; }
.hidden { display: none !important; }

/* ---------- 타이틀 ---------- */
#screen-title { padding: 0; }
.title-art {
  position: relative;
  width: 100%;
  height: 54vh;
  min-height: 310px;
  overflow: hidden;
  background: var(--bg-deep);
}
.title-art img { width: 100%; height: 100%; object-fit: cover; object-position: center 20%; display: block; }
.img-fallback { display: none; width: 100%; height: 100%; align-items: center; justify-content: center; color: var(--ink-dim); font-size: 14px; }
.title-art-fade {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 74%;
  background: linear-gradient(to bottom, rgba(12,12,16,0) 0%, rgba(12,12,16,.97) 94%);
}
.title-copy {
  position: relative;
  margin-top: -42px;
  padding: 0 28px 44px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.genre-tag { font-size: 11px; letter-spacing: .24em; color: var(--ink-dim); margin: 0; }
.char-name { font-size: 38px; font-weight: 700; margin: 4px 0 6px; letter-spacing: .06em; }
.title-line { font-size: 14px; color: var(--ink-dim); margin: 0 0 18px; line-height: 1.9; max-width: 320px; white-space: pre-line; }

/* ---------- 버튼 ---------- */
.btn-primary {
  width: 100%;
  max-width: 320px;
  padding: 14px 20px;
  background: rgba(156, 49, 69, .14);
  border: 1px solid rgba(196, 89, 110, .42);
  border-radius: 10px;
  color: var(--ink);
  font-family: inherit;
  font-size: 14.5px;
  letter-spacing: .035em;
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease, opacity .2s ease;
}
.btn-primary:hover:not(:disabled) { border-color: var(--accent); background: rgba(156, 49, 69, .27); }
.btn-primary:disabled { opacity: .35; cursor: not-allowed; }
.btn-ghost {
  width: 100%; max-width: 320px; padding: 12px 18px; border-radius: 9px;
  background: none; border: 1px solid var(--card-border); color: var(--ink-dim); font-family: inherit; cursor: pointer;
}

/* ---------- 이름 입력 ---------- */
.prompt-text { font-size: 17px; margin: 0 0 22px; }
#input-name {
  width: 100%; max-width: 320px; padding: 12px 14px;
  background: rgba(12, 12, 16, .48); border: 1px solid var(--card-border); border-radius: 8px;
  color: var(--ink); font-family: inherit; font-size: 15px; text-align: center; outline: none; margin-bottom: 16px;
}
#input-name:focus { border-color: var(--accent); }
#input-name::placeholder { color: rgba(239, 238, 234, .30); }
.input-hint { font-size: 12px; color: var(--ink-dim); opacity: .7; margin: -8px 0 16px; }

/* ---------- PROLOGUE Reader ---------- */
.story-wrap {
  display: flex;
  flex-direction: column;
  padding: 34px 24px 64px;
  flex: 1;
}

.chapter-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 26px;
  scroll-margin-top: calc(var(--header-h) + 16px);
}
.chapter-kicker {
  margin: 0;
  color: var(--char);
  font-size: 10.5px;
  letter-spacing: .24em;
}
.step-progress {
  margin: 0;
  color: var(--ink-dim);
  font-size: 10.5px;
  letter-spacing: .14em;
}

.reader-scene { margin: 0; padding: 0; }
.scene-text,
.line-text,
.question-text,
.reaction-text {
  word-break: keep-all;
}
.scene-text {
  color: var(--ink);
  font-size: 15.5px;
  line-height: 1.62;
  margin: 0;
}
.line-text {
  color: var(--ink);
  font-size: 15.5px;
  line-height: 1.62;
  margin: 0;
  min-height: 0;
}
.line-text:not(:empty) { margin-top: 12px; }
.question-text {
  color: var(--ink-dim);
  font-size: 14px;
  line-height: 1.62;
  margin: 14px 0 0;
  white-space: pre-line;
}
.scene-text p,
.line-text p,
.reaction-text p {
  margin: 0 0 .55em;
  line-height: 1.62;
  white-space: pre-line;
}
.scene-text p:last-child,
.line-text p:last-child,
.reaction-text p:last-child { margin-bottom: 0; }
.line-text .whisper-seg {
  font-size: 14px;
  letter-spacing: .06em;
  color: var(--ink-dim);
  opacity: 0;
  transition: opacity 1.8s ease;
}
.line-text .whisper-seg.visible { opacity: 1; }

.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 30px;
}
.choice-btn {
  width: 100%;
  text-align: left;
  padding: 14px 15px;
  background: rgba(13, 10, 14, .54);
  border: 1px solid rgba(239, 238, 234, .13);
  border-radius: 9px;
  color: var(--ink);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.65;
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease, opacity .2s ease;
}
.choice-btn:hover:not(:disabled) { border-color: var(--card-border-hover); background: rgba(156,49,69,.11); }
.choice-btn.selected { border-color: rgba(196,89,110,.65); background: rgba(156,49,69,.18); }
.choice-btn:disabled { cursor: default; opacity: .32; }
.choice-btn:disabled.selected { opacity: 1; }

.story-branch {
  margin: 34px 0 0;
  padding: 26px 0 0 14px;
  border-top: 1px solid rgba(239,238,234,.10);
  border-left: 1px solid rgba(196,89,110,.38);
}
.reaction-text {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.62;
  margin: 0;
  min-height: 1.62em;
}
.continue-button { margin-top: 28px; max-width: 190px; }

/* ---------- 결과 ---------- */
.result-reader {
  margin: auto 24px;
  padding: 48px 4px 56px;
  text-align: left;
}
.result-caption { margin: 12px 0 24px; color: var(--ink-dim); font-size: 12.5px; }
.result-title {
  font-size: 27px;
  line-height: 1.35;
  letter-spacing: .04em;
  color: var(--ink);
  margin: 0 0 18px;
}
.result-text { font-size: 15px; line-height: 2; white-space: pre-line; margin: 0 0 34px; color: var(--ink); }
.result-next { display: block; text-decoration: none; text-align: center; margin-bottom: 10px; }
.result-restart { display: block; color: var(--ink-dim); }

/* ---------- 시그니처 ---------- */
.signature-overlay {
  position: fixed;
  inset: 0;
  max-width: 480px;
  margin: 0 auto;
  background: rgba(8, 8, 11, .91);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1s ease;
}
.signature-overlay.visible { opacity: 1; pointer-events: auto; }
.signature-text { font-size: 26px; font-weight: 700; text-align: center; color: var(--ink); letter-spacing: .03em; line-height: 1.6; }
.typing-cursor { display: none; }

@media (max-width: 380px) {
  .room-phase { display: none; }
  #room-title { max-width: 180px; }
  .story-wrap { padding-left: 20px; padding-right: 20px; }
}

@media (min-width: 481px) {
  #app { box-shadow: 0 0 60px rgba(0,0,0,.5); }
}
