:root {
  --bg: #14110f;
  --ink: #f3eee3;
  --ink-dim: #b8ae9d;
  --accent: #9fd27f;
  --accent-ink: #14210f;
  --panel: rgba(20, 17, 15, 0.82);
  --line: rgba(243, 238, 227, 0.18);
}

* { box-sizing: border-box; }
/* display 를 따로 준 요소도 hidden 속성이면 확실히 숨긴다 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
}

/* 사진과 임시 그림은 화면을 꽉 채우고 가운데를 기준으로 잘린다 (세로 화면 = 가로 사진의 중앙) */
.shots, .shot, .cure-video, .placeholder, .shade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.shots { isolation: isolate; overflow: hidden; }
/* 사진 두 장을 겹쳐 두고, 새 사진을 위에 올려 서서히 나타나게 한다. 넘기는 시간은 app.js 가 정한다. */
.shot {
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.8s linear;
  animation: drift 44s ease-in-out infinite alternate;
}
.shot.on { opacity: 1; }
.cure-video { object-fit: cover; z-index: 2; }
.cure-video[hidden] { display: none; }
body.has-shot .placeholder { display: none; }
/* 사진이 멈춰 보이지 않게 아주 느리게 확대하고 움직인다 */
@keyframes drift {
  from { transform: scale(1.0) translate(0, 0); }
  to { transform: scale(1.06) translate(-0.8%, -0.6%); }
}

.shade {
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), transparent 30%, transparent 60%, rgba(0, 0, 0, 0.7));
  pointer-events: none;
}

.hud, .card, .controls { position: relative; z-index: 1; text-align: center; }

.partner { margin: 0 0 6px; font-size: 0.9rem; font-weight: 600; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.7); min-height: 1.3em; }

.phase {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
}
.time {
  margin: 4px 0 0;
  font-size: clamp(3.2rem, 14vw, 6rem);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.6);
}

/* 가로 화면에서는 타이머가 가운데 있는 얼굴을 가리므로 왼쪽 위로 옮기고 조금 줄인다 */
@media (min-aspect-ratio: 4/3) {
  .hud { align-self: flex-start; text-align: left; padding-left: 12px; }
  .hud .time { font-size: clamp(2.6rem, 5vw, 4.2rem); }
  .hud .bar { margin-left: 0; }
  .hud .combo { justify-content: flex-start; }
}

/* ---------- 진행 막대 ---------- */
.bar {
  width: min(72vw, 300px);
  height: 6px;
  margin: 12px auto 0;
  border-radius: 3px;
  background: rgba(243, 238, 227, 0.22);
  overflow: hidden;
}
.bar-fill {
  width: 0;
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.25s linear;
}
body[data-state="break"] .bar-fill { background: #f0c35a; }

/* 세션 콤보: 점 4개 */
.combo { margin: 10px 0 0; display: flex; gap: 6px; justify-content: center; align-items: center; font-size: 0.8rem; color: var(--ink-dim); }
.combo[hidden] { display: none; }
.combo i { width: 8px; height: 8px; border-radius: 50%; background: rgba(243, 238, 227, 0.25); }
.combo i.on { background: #f0c35a; }
.combo span { margin-left: 4px; }

/* 좀비의 말, 개그 자막, 기억 조각, 쪽지 */
.card {
  margin: auto 0 14px;
  max-width: min(92vw, 440px);
  padding: 10px 16px;
  border-radius: 16px;
  background: var(--panel);
  opacity: 0;
  transition: opacity 0.3s;
}
.card.show { opacity: 1; }
.card p { margin: 0; }
.card-label { font-size: 0.75rem; letter-spacing: 0.06em; color: var(--accent); }
.card-label:empty, .card-sub:empty { display: none; }
.card-text { font-size: 1rem; line-height: 1.5; white-space: pre-line; }
.card-sub { margin-top: 6px !important; font-size: 0.85rem; color: var(--ink-dim); }

.notice {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center;
  padding: 8px 10px; border-radius: 14px; background: var(--panel); font-size: 0.85rem;
}
.notice[hidden] { display: none; }

.controls { width: 100%; max-width: 360px; display: grid; gap: 10px; }
.row { display: flex; gap: 10px; justify-content: center; }
.row .btn { flex: 1; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 18px;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-size: 1.1rem; }
.btn.ghost { font-weight: 500; font-size: 0.9rem; padding: 10px 14px; }
.btn.small { padding: 6px 10px; flex: none; }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
body[data-state="focus"] .btn.primary,
body[data-state="nudge"] .btn.primary { background: var(--panel); color: var(--ink); border-color: var(--line); }

.total { margin: 0; font-size: 0.85rem; color: var(--ink-dim); }
/* 오늘 아직 출석을 못 채웠으면 연속 일수를 흐리게 */
.total .streak { color: #f0c35a; }
.total .streak.pending { opacity: 0.5; }

/* 집중 중에는 버튼을 흐리게 해서 화면을 조용하게 둔다 */
body[data-state="focus"] .controls { opacity: 0.55; transition: opacity 0.4s; }
body[data-state="focus"] .controls:hover,
body[data-state="focus"] .controls:focus-within { opacity: 1; }

/* ---------- 설정 ---------- */
dialog {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #1f1b18;
  color: var(--ink);
  padding: 20px;
  width: min(92vw, 340px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin: 0 0 14px; font-size: 1.1rem; }
dialog h3 { margin: 20px 0 10px; font-size: 0.95rem; }
dialog label { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
dialog input[type="number"] {
  width: 84px;
  padding: 10px;
  font: inherit;
  color: var(--ink);
  background: #14110f;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: right;
}
dialog .unit, .hint { color: var(--ink-dim); }
.hint { font-size: 0.8rem; margin: 12px 0 16px; }
dialog input[type="text"] {
  flex: 1; min-width: 0; padding: 10px; font: inherit; color: var(--ink);
  background: #14110f; border: 1px solid var(--line); border-radius: 10px;
}
dialog select {
  padding: 10px; font: inherit; color: var(--ink);
  background: #14110f; border: 1px solid var(--line); border-radius: 10px;
}
dialog.wide { width: min(94vw, 720px); max-height: 92dvh; overflow: auto; }
dialog .row { margin-top: 16px; }

/* ---------- 타이틀 ---------- */
#intro { width: min(92vw, 420px); }
.intro-kicker { margin: 0 0 6px; font-size: 0.8rem; letter-spacing: 0.1em; color: var(--accent); }
dialog .intro-title { margin: 0 0 16px; font-size: 1.45rem; line-height: 1.35; }
.intro-list { margin: 0; padding-left: 1.2em; font-size: 0.92rem; line-height: 1.6; color: var(--ink-dim); }
.intro-list li { margin: 8px 0; }
.intro-list strong { color: var(--ink); }

/* ---------- 좀비 선택 ---------- */
.pick-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.pick-card, .frame {
  appearance: none; padding: 0; overflow: hidden; text-align: left; font: inherit; color: var(--ink);
  background: #14110f; border: 2px solid var(--line); border-radius: 14px; cursor: pointer;
}
.pick-card.chosen { border-color: var(--accent); }
.pick-card:focus-visible, .frame:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.thumb { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #2a2420; }
/* 사진이 아직 없는 좀비는 단계 색으로 칠한 얼굴을 대신 보여 준다 */
.thumb.blank { display: grid; place-items: center; font-size: 2.4rem; color: rgba(20, 17, 15, 0.55); background: var(--skin, #8fbf7a); }
.thumb.empty { display: grid; place-items: center; font-size: 2rem; color: var(--ink-dim); background: #1a1613; }
.pick-card strong, .frame strong { display: block; padding: 8px 10px 0; font-size: 0.95rem; }
.pick-card span, .frame span { display: block; padding: 2px 10px 10px; font-size: 0.8rem; color: var(--ink-dim); }

/* ---------- 액자 벽 ---------- */
.frames { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.frame { border-width: 5px; border-color: #6b5545; border-radius: 6px; }
.frame.cured { border-color: #c9a45c; }
.frame.unmet { cursor: default; border-style: dashed; border-width: 2px; }
.frame.current strong::after { content: " · 공부 중"; color: var(--accent); font-weight: 500; font-size: 0.8rem; }

/* ---------- 친구 화면 ---------- */
.prof-img { display: block; width: 100%; max-height: 42dvh; object-fit: cover; border-radius: 12px; background: #2a2420; }
.prof-img[hidden] { display: none; }
.prof-reveal { margin: 10px 0 0; font-size: 0.95rem; }
.prof-reveal:empty { display: none; }
.memories { margin: 0; padding-left: 1.4em; font-size: 0.9rem; line-height: 1.55; }
.memories li { margin: 6px 0; }
.memories li.locked { color: var(--ink-dim); opacity: 0.6; }
.gag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.gag-grid figure { margin: 0; }
.gag-grid .thumb { aspect-ratio: 16 / 9; border-radius: 10px; }
.gag-grid figcaption { margin-top: 4px; font-size: 0.8rem; color: var(--ink-dim); }
.ending-text { white-space: pre-line; line-height: 1.7; font-size: 0.95rem; }

/* ---------- 진단 패널 ---------- */
#debug {
  position: fixed;
  z-index: 5;
  left: 8px;
  right: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  max-height: 60dvh;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(15, 13, 11, 0.96);
  font-size: 0.8rem;
}
.debug-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
#debugFacts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 10px; }
#debugFacts dt { color: var(--ink-dim); }
#debugFacts dd { margin: 0; overflow-wrap: anywhere; }
#debugLog { margin: 0; padding-left: 0; list-style: none; font-family: ui-monospace, Consolas, monospace; font-size: 0.75rem; color: var(--ink-dim); }
#debugLog li { padding: 2px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }

/* ---------- 임시 그림: 치료 단계에 따라 피부색이 사람에 가까워진다 ---------- */
body[data-look="s1"], .look-s1 { --skin: #8fbf7a; --skin-dark: #4d7a3f; }
body[data-look="s2"], .look-s2 { --skin: #a6c48b; --skin-dark: #5f8050; }
body[data-look="s3"], .look-s3 { --skin: #c6c79c; --skin-dark: #86805a; }
body[data-look="s4"], .look-s4 { --skin: #e0c5a6; --skin-dark: #9a7a5c; }
body[data-look="human"], .look-human { --skin: #f2caa8; --skin-dark: #a8785a; }
.skin { fill: var(--skin); transition: fill 2s; }
.skin-stroke { stroke: var(--skin); fill: none; transition: stroke 2s; }
.skin-line { stroke: var(--skin-dark); fill: none; }
body[data-look="human"] .scar { display: none; }

/* ---------- 임시 그림의 상태별 움직임 ---------- */
.placeholder * { transform-box: fill-box; }
.head { transform-origin: 50% 100%; transition: transform 0.4s; }
.arm { transform-origin: 0% 0%; }
.zombie { transform-origin: 50% 100%; }
.lids, .zzz { opacity: 0; transition: opacity 0.3s; }
.rain { animation: rain 0.7s linear infinite; }
.glow { transition: opacity 0.6s; }

body[data-state="idle"] .head { transform: rotate(14deg) translateY(26px); }
body[data-state="idle"] .eyes { opacity: 0; }
body[data-state="idle"] .lids { opacity: 1; }
body[data-state="idle"] .zzz { opacity: 1; animation: float 2.4s ease-in-out infinite; }
body[data-state="idle"] .glow { opacity: 0.04; }

body[data-state="focus"] .head { transform: rotate(5deg) translateY(8px); animation: nod 5s ease-in-out infinite; }
body[data-state="focus"] .arm { animation: write 0.9s ease-in-out infinite; }

body[data-state="break"] .zombie { animation: bounce 0.6s ease-in-out infinite; }
body[data-state="break"] .head { transform: rotate(-8deg); }
body[data-state="break"] .arm { transform: rotate(-110deg); }

body[data-state="nudge"] .head { transform: scale(1.35) translateY(-10px); }
body[data-state="nudge"] .pupil { transform: scale(1.5); }
body[data-state="nudge"] .glow { opacity: 0.03; }

@keyframes write { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(7deg); } }
@keyframes nod { 0%, 100% { transform: rotate(5deg) translateY(8px); } 50% { transform: rotate(8deg) translateY(12px); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-18px); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }
@keyframes rain { from { transform: translate(0, 0); } to { transform: translate(-14px, 40px); } }

@media (prefers-reduced-motion: reduce) {
  .placeholder *, .shot { animation: none !important; }
}

/* 서담 마을 집계 */
.town-count { margin: 0 0 10px; font-size: 1rem; line-height: 1.5; }
.town-bar { width: 100%; margin: 0 0 4px; }
.town-rank, .town-sub { margin: 0; padding-left: 1.6em; font-size: 0.9rem; line-height: 1.5; }
.town-rank > li { margin: 6px 0; }
.town-rank li > span { margin-right: 10px; }
.town-rank li > b { color: var(--accent); font-weight: 600; }
.town-rank li.mine > span { text-decoration: underline; text-underline-offset: 3px; }
.town-sub { margin-top: 4px; color: var(--ink-dim); }
.pick-card .again { display: block; font-style: normal; font-size: 0.75rem; color: var(--accent); }
.town-rank li.locked { list-style: none; margin-left: -1.6em; }
