/* style.css — 「말포이가 나보고 책임지래」 화면.
 * 미연시 화면 문법을 따른다: 왼쪽 위 로고 + 왼쪽 아래 글자 메뉴, 아래 전체 폭 대사창, 대사창 안 작은 글자 메뉴,
 * 바닥에 선 스탠딩 인물, 화면 전체를 덮는 창.
 * 쓰지 않는 것: 반투명 유리판·blur, 알약 버튼, 둥근 카드 격자, 그라데이션 글자, 큰 그림자, 둥근 모서리.
 * 효과는 페이드 하나(.25s). 외부 폰트를 불러오지 않는다(바이블 8-1). */
:root {
  --bg: #0f0d0b;
  --panel: rgba(15, 13, 11, .92);
  --text: #ece3d0;
  --text-dim: rgba(236, 227, 208, .5);
  --line: rgba(236, 227, 208, .1);
  --gold: #c9a45c;
  --gold-dim: rgba(201, 164, 92, .45);
  --think: #a9bad3;
  --boxh: 25vh;
  --boxh: 25dvh;
  --padx: clamp(22px, 8vw, 150px);
  --sans: Pretendard, "Pretendard Variable", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  --serif: "Nanum Myeongjo", "AppleMyungjo", "Noto Serif KR", serif;
  font-family: var(--sans);
  color: var(--text);
  background: #000;
}
@media (orientation: portrait) { :root { --boxh: 32vh; --boxh: 32dvh; } }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; }
img { height: auto; -webkit-user-drag: none; user-select: none; -webkit-user-select: none; pointer-events: none; -webkit-touch-callout: none; }
button, input, textarea { font: inherit; color: inherit; }
button { border-radius: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 1px solid var(--gold); outline-offset: 3px; }

#app { position: relative; width: 100vw; height: 100vh; height: 100dvh; overflow: hidden; }
.screen { position: absolute; inset: 0; }

.fade { animation: fade .25s ease-out both; }
@keyframes fade { from { opacity: 0; } }

/* 글자만 있는 버튼 — 버튼 모양 없음 */
.menu button, .menu a, #quick button, .end-nav button, .set-links button, .ask-row button, .x {
  appearance: none; background: none; border: 0; padding: 0; margin: 0;
  color: inherit; text-decoration: none; cursor: pointer;
}

/* ---------- 타이틀 ---------- */
#title { background: var(--bg); }
.title-bg { position: absolute; inset: 0; background: var(--bg) center / cover no-repeat; }
.title-bg.img::after { content: ""; position: absolute; inset: 0; background: rgba(8, 7, 6, .62); }
.logo {
  position: absolute; z-index: 1;
  left: clamp(24px, 6vw, 96px); top: calc(env(safe-area-inset-top, 0px) + clamp(28px, 9vh, 100px));
  right: 24px;
}
#gameTitle {
  margin: 0; font-family: var(--serif); font-weight: 800;
  font-size: clamp(34px, 6.2vw, 78px); line-height: 1.16; letter-spacing: -.02em;
  color: #f3ead6; word-break: keep-all;
}
#gameTitle span { display: block; }
#gameTitle span + span { padding-left: .6em; }
.subtitle {
  margin: 1.1em 0 0; font-family: var(--serif); font-size: clamp(13px, 1.5vw, 16px);
  letter-spacing: .22em; color: var(--gold);
}
.badge { margin: .8em 0 0; font-size: 11px; letter-spacing: .3em; color: var(--gold); }
.menu {
  position: absolute; z-index: 1;
  left: clamp(24px, 6vw, 96px); bottom: calc(env(safe-area-inset-bottom, 0px) + clamp(32px, 10vh, 110px));
  display: flex; flex-direction: column; align-items: flex-start;
}
.menu button, .menu a {
  position: relative; display: block; padding: 7px 0 7px 22px;
  font-family: var(--serif); font-size: clamp(16px, 1.6vw, 19px); letter-spacing: .1em;
  color: rgba(236, 227, 208, .78);
}
.menu button::before, .menu a::before {
  content: "◆"; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  font-size: 9px; color: var(--gold); opacity: 0;
}
.menu button:hover:not(:disabled), .menu a:hover, .menu button:focus-visible, .menu a:focus-visible { color: var(--gold); outline: none; }
.menu button:hover:not(:disabled)::before, .menu a:hover::before,
.menu button:focus-visible::before, .menu a:focus-visible::before { opacity: 1; }
.menu button:disabled, .menu button.off { color: rgba(236, 227, 208, .3); }
.menu button:disabled { cursor: default; }
.boot-err {
  position: absolute; z-index: 1; right: 16px; bottom: 12px; left: 45%; margin: 0;
  font-size: 12px; line-height: 1.5; color: #e39a88; text-align: right; overflow-wrap: anywhere;
}

/* ---------- 본편 무대 ---------- */
#game { background: #000; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#stage { position: absolute; inset: 0; cursor: pointer; }
.bg-layer, .bg-layer img, .bg-fall { position: absolute; inset: 0; width: 100%; height: 100%; }
.bg-layer img { object-fit: cover; object-position: 50% 50%; }
.bg-fall { background-color: #14110e; }

/* 장소 이름 — 왼쪽 위. 그림 없는 장소는 계속(.stay), 그림 있는 장소는 바뀔 때 2초 */
.place {
  position: absolute; z-index: 4; margin: 0;
  top: calc(env(safe-area-inset-top, 0px) + 18px); left: clamp(16px, 3vw, 36px);
  max-width: 70vw; padding: 2px 0 2px 10px; border-left: 2px solid var(--gold);
  font-family: var(--serif); font-size: 14px; letter-spacing: .12em; color: rgba(236, 227, 208, .85);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transition: opacity .25s;
}
.place.on { opacity: 1; }

/* 인물 — 투명 배경 스탠딩, 바닥 정렬. 위치는 화면 25% / 50% / 75% */
#chars { position: absolute; inset: 0; pointer-events: none; }
.sprite {
  position: absolute; bottom: 0; left: 50%;
  height: 85vh; height: 85dvh; width: auto; max-width: none;
  transform: translateX(-50%); transition: filter .25s;
}
.sprite[data-pos="left"] { left: 25%; }
.sprite[data-pos="right"] { left: 75%; }
.sprite.dim { filter: brightness(.55); }
@media (orientation: portrait) { .sprite { height: 62vh; height: 62dvh; } }

#cgLayer { position: absolute; inset: 0; z-index: 3; background: #000; }
#cgLayer img { width: 100%; height: 100%; object-fit: contain; }

/* ---------- 대사창 ---------- */
.box {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  height: var(--boxh); min-height: 150px;
  padding: 30px var(--padx) calc(env(safe-area-inset-bottom, 0px) + 40px);
  background: var(--panel);
  border-top: 4px double var(--gold-dim);
  cursor: pointer; outline: none;
}
.box:focus-visible { border-top-color: var(--gold); }
.name-tag {
  position: absolute; top: 0; left: calc(var(--padx) - 18px); transform: translateY(-62%);
  padding: 5px 20px 5px 12px; min-width: 7em;
  background: var(--bg); border: 1px solid var(--gold-dim); border-left: 6px solid var(--c, var(--gold));
  font-family: var(--serif); font-weight: 700; font-size: 16px; letter-spacing: .08em; color: var(--text);
}
#text {
  margin: 0; max-width: 1000px;
  font-family: var(--serif); font-size: 19px; line-height: 1.8; color: var(--text);
  word-break: keep-all; overflow-wrap: anywhere;
}
.box.t-think #text { color: var(--think); }
.cursor {
  position: absolute; right: var(--padx); bottom: calc(env(safe-area-inset-bottom, 0px) + 38px);
  font-size: 10px; color: var(--gold); animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }
.modes { position: absolute; top: 9px; right: 18px; margin: 0; font-size: 11px; font-weight: 700; letter-spacing: .22em; color: var(--gold); }
.modes span + span { margin-left: 10px; }
#quick {
  position: absolute; right: 18px; left: 18px; bottom: calc(env(safe-area-inset-bottom, 0px) + 9px);
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 15px;
}
#quick button { font-size: 12.5px; letter-spacing: .04em; color: var(--text-dim); padding: 3px 0; }
#quick button:hover { color: rgba(236, 227, 208, .9); }
#quick button[aria-pressed="true"] { color: var(--gold); }

/* ---------- 선택지 — 대사창 위 영역 가운데, 넓은 띠 ---------- */
.choices {
  position: absolute; z-index: 6; left: 50%; top: calc((100% - var(--boxh)) / 2);
  transform: translate(-50%, -50%);
  width: min(640px, 88vw);
  display: flex; flex-direction: column; gap: 10px; outline: none;
}
.opt {
  display: flex; align-items: baseline; gap: 14px; width: 100%;
  padding: 14px 20px 14px 18px; text-align: left; cursor: pointer;
  background: rgba(15, 13, 11, .94); color: var(--text);
  border: 1px solid var(--gold-dim); border-left: 3px solid rgba(15, 13, 11, .94);
  font-family: var(--serif); font-size: 17px; line-height: 1.5;
  transition: border-color .15s;
}
.opt:hover, .opt:focus-visible { border-left-color: var(--gold); outline: none; }
.opt .n { flex: none; font-family: var(--sans); font-size: 11px; color: var(--gold); }
.opt .tx { overflow-wrap: anywhere; word-break: keep-all; }
.opt.picked .tx { color: rgba(236, 227, 208, .62); }

/* ---------- 장 시작·엔딩 — 검은 화면 ---------- */
.card-screen {
  position: absolute; inset: 0; z-index: 15; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center; cursor: pointer;
}
.card-screen small { font-family: var(--serif); font-size: 15px; letter-spacing: .3em; color: var(--gold); }
.card-screen p { margin: .7em 0 0; font-family: var(--serif); font-size: clamp(22px, 3.4vw, 32px); letter-spacing: .06em; color: var(--text); word-break: keep-all; }
.card-screen.end { cursor: default; }
.end-nav { display: flex; gap: 30px; margin-top: 2.6em; }
.end-nav button { font-family: var(--serif); font-size: 16px; letter-spacing: .1em; color: var(--text-dim); }
.end-nav button:hover, .end-nav button:focus-visible { color: var(--gold); outline: none; }

/* ---------- 전체 화면 창 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column;
  background: #0c0a09;
  padding-top: env(safe-area-inset-top, 0px);
}
.overlay > header {
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 var(--padx); padding: 26px 0 12px; border-bottom: 1px solid var(--gold-dim);
}
.overlay h2 { margin: 0; font-family: var(--serif); font-weight: 700; font-size: 22px; letter-spacing: .24em; }
.x { width: 40px; height: 40px; margin-right: -10px; font-size: 18px; color: var(--text-dim); }
.x:hover, .x:focus-visible { color: var(--gold); outline: none; }
.ov-body {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 14px var(--padx) calc(env(safe-area-inset-bottom, 0px) + 40px);
  user-select: text; -webkit-user-select: text;
}
.ov-body > * { max-width: 1000px; }
.muted { color: var(--text-dim); font-size: 14px; }

/* 세이브 — 줄 목록: 번호 · 날짜 · 장 · 대사 첫 줄 */
.slots { list-style: none; margin: 0; padding: 0; }
.slots li { border-bottom: 1px solid var(--line); }
.slot {
  display: grid; grid-template-columns: 52px 150px minmax(0, 220px) minmax(0, 1fr); gap: 18px; align-items: baseline;
  width: 100%; padding: 15px 10px; text-align: left; cursor: pointer;
  background: none; border: 0; border-left: 3px solid transparent; color: var(--text);
}
.slot:hover:not(:disabled), .slot:focus-visible { border-left-color: var(--gold); background: rgba(201, 164, 92, .06); outline: none; }
.slot:disabled { cursor: default; opacity: .4; }
.slot .no { font-size: 12px; font-weight: 700; letter-spacing: .12em; color: var(--gold); }
.slot .at { font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.slot .ch { font-family: var(--serif); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .ln { font-family: var(--serif); font-size: 14px; color: rgba(236, 227, 208, .62); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot.empty .ch { color: var(--text-dim); }
@media (max-width: 700px) {
  .slot { grid-template-columns: 40px minmax(0, 1fr); gap: 2px 12px; }
  .slot .no { grid-row: span 3; }
  .slot .at, .slot .ch, .slot .ln { grid-column: 2; }
}

/* 로그 */
.log { list-style: none; margin: 0; padding: 0; max-height: calc(100dvh - 150px); overflow-y: auto; outline: none; }
.log li { padding: 10px 0 10px 14px; border-left: 2px solid var(--c, transparent); }
.log b { display: block; font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--c, var(--text-dim)); margin-bottom: 2px; }
.log span { font-family: var(--serif); font-size: 16px; line-height: 1.75; overflow-wrap: anywhere; word-break: keep-all; }
.log .k-think span { color: var(--think); }
.log .k-choice b { color: var(--gold); }
.log .k-narr span { color: rgba(236, 227, 208, .78); }

/* 수첩 */
.note .day { font-family: var(--serif); color: var(--gold); letter-spacing: .06em; }
.note h3, .settings h3 { margin: 1.6em 0 .5em; font-family: var(--serif); font-size: 15px; font-weight: 700; letter-spacing: .1em; color: var(--text-dim); }
.hearts { margin: 0; font-size: 20px; letter-spacing: .2em; color: rgba(236, 227, 208, .3); }
.hearts .on { color: #c86a5c; }
.stages { margin: 0; padding-left: 1.6em; font-family: var(--serif); line-height: 2; color: var(--text-dim); }
.stages .done { color: var(--text); }

/* 설정 */
.set-row {
  display: grid; grid-template-columns: minmax(7.5em, 200px) minmax(0, 320px) 6em; gap: 16px; align-items: center;
  min-height: 56px; border-bottom: 1px solid var(--line);
}
.set-row label { font-family: var(--serif); font-size: 16px; }
.set-row output { font-size: 13px; color: var(--text-dim); }
.set-row input[type="range"] { width: 100%; accent-color: var(--gold); }
.set-row input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--gold); }
.settings textarea {
  display: block; width: 100%; max-width: 640px; padding: 8px; resize: vertical;
  background: #000; border: 1px solid var(--line); color: var(--text); font: 12px/1.5 ui-monospace, Menlo, monospace;
}
.set-links { display: flex; gap: 24px; margin-top: 12px; }
.set-links button { font-size: 14px; color: var(--text-dim); }
.set-links button:hover, .set-links button:focus-visible { color: var(--gold); outline: none; }
.set-links .danger { color: #d98a7a; }
@media (max-width: 520px) { .set-row { grid-template-columns: 7.5em minmax(0, 1fr) 4.5em; gap: 10px; } }

/* 갤러리 — 엔딩 이름 목록 */
.count { margin: 0 0 10px; font-size: 13px; letter-spacing: .1em; color: var(--text-dim); }
.gallery { list-style: none; margin: 0; padding: 0; }
.gallery li { display: flex; align-items: baseline; gap: 18px; padding: 14px 4px; border-bottom: 1px solid var(--line); }
.gallery .kind { flex: none; width: 3em; font-size: 12px; color: var(--gold); }
.gallery b { font-family: var(--serif); font-weight: 400; font-size: 17px; }
.gallery .locked b { color: rgba(236, 227, 208, .3); }

/* 확인창 — 한 줄 */
.ask { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(0, 0, 0, .6); }
.ask-box {
  min-width: min(320px, 86vw); padding: 24px 30px 18px;
  background: var(--bg); border: 1px solid var(--gold-dim); border-top: 3px double var(--gold);
}
.ask-box p { margin: 0 0 22px; font-family: var(--serif); font-size: 18px; letter-spacing: .06em; }
.ask-row { display: flex; justify-content: flex-end; gap: 26px; }
.ask-row button { font-size: 15px; color: var(--text-dim); padding: 4px 0; }
.ask-row button:hover, .ask-row button:focus-visible { color: var(--gold); outline: none; }

/* 토스트 */
.toast {
  position: fixed; z-index: 40; top: calc(env(safe-area-inset-top, 0px) + 16px); left: 50%; transform: translateX(-50%);
  max-width: 88vw; padding: 7px 18px;
  background: var(--bg); border: 1px solid var(--gold-dim);
  font-size: 14px; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transition: opacity .25s; pointer-events: none;
}
.toast.on { opacity: 1; }

/* 세로 모바일 */
@media (max-width: 600px) {
  :root { --padx: 22px; }
  .box { padding-top: 26px; }
  #text { font-size: 17.5px; line-height: 1.75; }
  .name-tag { left: 14px; font-size: 15px; }
  #quick { gap: 4px 12px; }
  #quick button { font-size: 12px; }
  .opt { font-size: 16px; padding: 12px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* 해리 얼굴 — 대사창 왼쪽 (미연시 관례: 주인공은 서 있지 않고 대사창 안 얼굴로) */
.box-face { position: absolute; left: 16px; bottom: 0; width: clamp(130px, 13vw, 200px); height: auto; max-height: 125%;
  object-fit: contain; object-position: bottom; pointer-events: none; user-select: none; -webkit-user-drag: none;
  filter: drop-shadow(0 0 6px rgba(0,0,0,.6)); }
.box.has-face #text { padding-left: calc(clamp(130px, 13vw, 200px) + 24px); }
.box.has-face .name-tag { left: calc(clamp(130px, 13vw, 200px) + 32px); }
@media (max-width: 600px) {
  .box-face { width: 27vw; left: 4px; }
  .box.has-face #text { padding-left: calc(27vw + 6px); }
  .box.has-face .name-tag { left: calc(27vw + 10px); }
}
