:root {
  --paper: #FBF4E4; --paper-2: #F3E7CC; --ink: #3B2A1E; --ink-soft: #6E5A47;
  --accent: #E8792B; --accent-dark: #B9561A; --pen: #2E6BD9; --danger: #B83A2B;
  --radius: 14px; --edge: clamp(14px, 2vw, 28px);
  --font-title: "Jua", "Gowun Dodum", system-ui, sans-serif;
  --font-body: "Gowun Dodum", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; color: var(--ink); font-family: var(--font-body); }
body { background: #2A1A10; transition: background .6s; }
body[data-bg="title"] { background: radial-gradient(ellipse at 50% 30%, #9A6A3E, #3A2416 70%); }
body[data-bg="hatch"] { background: radial-gradient(ellipse at 55% 25%, #FFD9A0, #5A3A26 65%); }
body[data-bg="observe"], body[data-bg="inspect"] { background: radial-gradient(ellipse at 45% 45%, #FFF6E2, #E9CFA2 75%); }
body[data-bg="ending1"] { background: linear-gradient(#BFE3F2, #FCEFD2); }
body[data-bg="fryer"] { background: radial-gradient(ellipse at 50% 40%, #4A3424, #140C07 70%); }
#gl { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; touch-action: none; }

/* 장면 전환: 동그랗게 닫혔다가 열림 */
#iris { position: fixed; inset: 0; background: #1E140D; pointer-events: none; z-index: 50; clip-path: circle(0% at 50% 50%); }
#iris.closing { animation: irisIn .32s ease-in forwards; }
#iris.opening { animation: irisOut .55s cubic-bezier(.2,.8,.2,1) forwards; }
@keyframes irisIn { from { clip-path: circle(0% at var(--ix,50%) var(--iy,50%)); } to { clip-path: circle(150% at var(--ix,50%) var(--iy,50%)); } }
@keyframes irisOut { from { clip-path: polygon(0 0,100% 0,100% 100%,0 100%); opacity: 1; } to { clip-path: polygon(0 0,100% 0,100% 100%,0 100%); opacity: 0; } }

.scene { position: fixed; inset: 0; display: none; pointer-events: none; z-index: 10; }
.scene.on { display: block; }
.scene a, .scene button, .scene .card, .scene .confirm, .scene .hud, .scene .modal-dim { pointer-events: auto; }
.scene.entering a, .scene.entering button { pointer-events: none !important; }

/* 랜딩: 장면에 들어올 때마다 아래에서 내려앉듯 */
.scene.on .land { animation: land .7s cubic-bezier(.2,1.4,.4,1) both; animation-delay: calc(var(--i, 0) * 110ms + 380ms); }
@keyframes land { 0% { opacity: 0; transform: translateY(28px) scale(.96); } 100% { opacity: 1; transform: none; } }
.title-wrap .land, .confirm.land { transform-origin: 50% 100%; }
@media (prefers-reduced-motion: reduce) { .scene.on .land { animation: fadeOnly .3s both; } @keyframes fadeOnly { from { opacity: 0; } } }

.btn { display: inline-block; text-decoration: none; font-family: var(--font-title); font-size: 18px; border: 0; border-radius: var(--radius); padding: 12px 22px; cursor: pointer;
  background: var(--accent); color: #fff; box-shadow: 0 4px 0 var(--accent-dark); transition: transform .08s, box-shadow .08s; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dark); }
.btn:focus-visible, .chip:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--pen); outline-offset: 3px; }
.btn.ghost { background: var(--paper); color: var(--ink); box-shadow: 0 4px 0 #CDB993; }
.btn.danger { background: #fff; color: var(--danger); box-shadow: 0 4px 0 #DCC4B8; }
.btn.sm { font-size: 15px; padding: 9px 14px; }
.btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: rgba(255,248,230,.94); color: var(--ink); cursor: pointer; display: grid; place-items: center; box-shadow: 0 3px 0 rgba(0,0,0,.18); text-decoration: none; font-size: 18px; }
.icon-btn svg { width: 22px; height: 22px; }

/* 타이틀 */
.title-wrap { position: absolute; left: 50%; bottom: clamp(40px, 12vh, 140px); transform: translateX(-50%); text-align: center; width: min(92vw, 760px); }
.title-wrap h1 { font-family: var(--font-title); font-weight: 400; font-size: clamp(48px, 7.4vw, 120px); margin: 0; color: #FFF3D6; text-shadow: 0 5px 0 #8A5A2B, 0 12px 34px rgba(0,0,0,.4); letter-spacing: -1px; }
.title-wrap p { color: #F7E4BE; font-size: clamp(16px, 1.5vw, 21px); margin: 10px 0 26px; text-shadow: 0 2px 6px rgba(0,0,0,.4); }
.title-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.sound { position: absolute; right: var(--edge); top: var(--edge); }

/* 인트로 */
.skip { position: absolute; left: var(--edge); top: var(--edge); color: #FFF3D6; font-family: var(--font-title); text-decoration: none; background: rgba(0,0,0,.25); padding: 8px 14px; border-radius: 999px; }
.dots { position: absolute; right: var(--edge); top: calc(var(--edge) + 8px); display: flex; gap: 6px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: rgba(255,243,214,.35); }
.dots i.on { background: #FFF3D6; }
.dialog { position: absolute; left: 50%; bottom: max(var(--edge), env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(94vw, 1040px);
  background: rgba(251,244,228,.97); border-radius: 18px; padding: 18px 56px 18px 22px; font-size: clamp(16px, 1.35vw, 20px); line-height: 1.6; color: var(--ink); text-decoration: none;
  box-shadow: 0 8px 0 rgba(0,0,0,.12), 0 16px 40px rgba(0,0,0,.25); }
.scene.on .dialog.land { animation-name: landX; }
@keyframes landX { 0% { opacity: 0; transform: translate(-50%, 28px); } 100% { opacity: 1; transform: translate(-50%, 0); } }
.dialog b { font-family: var(--font-title); font-weight: 400; color: var(--accent-dark); margin-right: 8px; }
.dialog .next { position: absolute; right: 18px; bottom: 18px; width: 0; height: 0; border-left: 10px solid transparent; border-right: 10px solid transparent; border-top: 12px solid var(--accent); animation: bob 1s infinite; }
@keyframes bob { 50% { transform: translateY(4px); } }

/* 관찰 · 확인 공통 */
.observe-head { position: absolute; left: var(--edge); top: var(--edge); max-width: 520px; }
.observe-head h2, .inspect-head h2 { font-family: var(--font-title); font-weight: 400; font-size: clamp(22px, 2.2vw, 32px); margin: 0; }
.observe-head p { margin: 6px 0 0; color: var(--ink-soft); }
.inspect-head { position: absolute; left: var(--edge); right: calc(var(--edge) + 360px); top: var(--edge); display: flex; justify-content: space-between; align-items: center; pointer-events: auto; }
.views { position: absolute; left: var(--edge); right: calc(var(--edge) + 360px); bottom: calc(var(--edge) + 4px); display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; pointer-events: none; }
#inspect .views { bottom: calc(var(--edge) + 76px); }
.chip { pointer-events: auto; font-family: var(--font-title); font-size: 16px; border: 2px solid #E5D3AE; background: rgba(255,250,238,.95); color: var(--ink); border-radius: 999px; padding: 10px 18px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: #FFF4DC; border-color: var(--ink); }
.actions { position: absolute; left: var(--edge); right: calc(var(--edge) + 360px); bottom: var(--edge); display: flex; gap: 14px; justify-content: center; pointer-events: none; }
.card { position: absolute; right: var(--edge); top: var(--edge); bottom: var(--edge); width: 340px; background: rgba(251,244,228,.92); backdrop-filter: blur(8px); border-radius: 20px; padding: 22px 20px;
  display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 40px rgba(80,50,20,.18); overflow: auto; }
.card h2 { font-family: var(--font-title); font-weight: 400; font-size: 24px; margin: 0; }
.note-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.note-list li { display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: start; background: rgba(255,255,255,.6); border: 1.5px dashed #D8C49C; border-radius: 12px; padding: 12px; }
.note-list .mark { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #D8C49C; display: grid; place-items: center; font-weight: 700; color: #fff; }
.note-list li.seen { border-style: solid; border-color: #E9C98C; background: #FFFBF0; }
.note-list li.seen .mark { background: var(--accent); border-color: var(--accent); }
.note-list strong { font-family: var(--font-title); font-weight: 400; font-size: 17px; display: block; }
.note-list span { font-size: 14px; color: var(--ink-soft); line-height: 1.45; }
.card .btn { margin-top: auto; text-align: center; }
.foot-labels span { position: absolute; display: none; transform: translate(-50%, 0); font-family: var(--font-title); font-size: 15px; color: var(--ink-soft); background: rgba(255,250,238,.85); padding: 2px 10px; border-radius: 999px; }
.foot-labels.show span { display: block; }

/* 사육장 HUD */
.hud { position: absolute; left: var(--edge); right: var(--edge); top: var(--edge); display: flex; align-items: center; gap: 18px; padding: 8px 10px 8px 20px;
  background: rgba(40,25,15,.62); backdrop-filter: blur(6px); border-radius: 18px; color: #FFF1D2; }
.hud .stat { font-family: var(--font-title); font-size: 18px; white-space: nowrap; }
.hud .stat b { font-weight: 400; font-size: 22px; }
.hud .stat small { font-family: var(--font-body); font-size: 13px; opacity: .8; margin-right: 6px; }
.hud .spacer { flex: 1; }
.hud .tools { display: flex; gap: 8px; align-items: center; }
.farm-hint { position: absolute; left: 50%; bottom: var(--edge); transform: translateX(-50%); margin: 0; color: #FFF6DE; font-family: var(--font-title); font-size: 18px; background: rgba(40,25,15,.5); padding: 8px 18px; border-radius: 999px; white-space: nowrap; }
.scene.on .farm-hint.land { animation-name: landX; }
.bubble { position: absolute; background: #FFFBF0; border-radius: 14px; padding: 8px 14px; font-family: var(--font-title); box-shadow: 0 6px 20px rgba(0,0,0,.25); transform: translate(-50%, -130%); pointer-events: none; }

/* 포기 확인 */
.modal-dim { position: absolute; inset: 0; background: rgba(30,18,10,.55); }
.confirm { position: absolute; left: 50%; top: 50%; width: min(90vw, 460px); margin-left: max(-45vw, -230px); margin-top: -120px; background: var(--paper); border-radius: 22px; padding: 28px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.45); pointer-events: auto; }
.confirm h2 { font-family: var(--font-title); font-weight: 400; font-size: 28px; margin: 0 0 8px; }
.confirm p { margin: 0 0 22px; color: var(--ink-soft); line-height: 1.6; }
.confirm .row { display: flex; gap: 12px; justify-content: center; }

/* 엔딩 */
.caption { position: absolute; left: 50%; bottom: clamp(30px, 7vh, 70px); transform: translateX(-50%); color: #FFF7E4; font-size: clamp(17px, 1.6vw, 24px); text-align: center; text-shadow: 0 2px 10px rgba(0,0,0,.55); width: min(92vw, 900px); line-height: 1.6; }
.scene.on .caption.land { animation-name: landX; }
.caption em { display: block; font-style: normal; font-family: var(--font-title); font-size: .85em; opacity: .9; margin-bottom: 4px; }
#ending1 .caption { color: #3B2A1E; text-shadow: 0 1px 0 rgba(255,255,255,.7); }
.end-actions { position: absolute; right: var(--edge); bottom: var(--edge); }
.next-link { position: absolute; right: var(--edge); bottom: var(--edge); color: #FFF3D6; font-size: 26px; text-decoration: none; width: 52px; height: 52px; display: grid; place-items: center; border-radius: 50%; background: rgba(255,255,255,.12); }
.tag { position: absolute; background: #FFF8E8; border: 2px solid var(--ink); border-radius: 10px; padding: 4px 10px; font-family: var(--font-title); font-size: 15px; white-space: nowrap; transform: translate(-50%, -50%); opacity: 0; transition: opacity .6s; }
.tags.show .tag { opacity: 1; }

@media (max-width: 900px) {
  .card { left: var(--edge); right: var(--edge); top: auto; bottom: var(--edge); width: auto; max-height: 34dvh; padding: 14px; gap: 8px; }
  .card h2 { font-size: 18px; }
  .note-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .note-list li { padding: 8px; grid-template-columns: 22px 1fr; gap: 6px; }
  .note-list .mark { width: 20px; height: 20px; font-size: 12px; }
  .note-list span { display: none; }
  .note-list strong { font-size: 14px; }
  .views { right: var(--edge); bottom: calc(34dvh + var(--edge) + 10px); }
  .views .chip { padding: 8px 12px; font-size: 14px; }
  .inspect-head { right: var(--edge); }
  #inspect .card { max-height: 22dvh; }
  #inspect .views { bottom: calc(22dvh + var(--edge) + 70px); }
  #inspect .actions { right: var(--edge); bottom: calc(22dvh + var(--edge) + 12px); }
  .observe-head p { display: none; }
  .hud { flex-wrap: wrap; gap: 4px 14px; padding: 8px 10px 8px 14px; }
  .hud .stat { font-size: 14px; } .hud .stat b { font-size: 17px; }
  .hud .spacer { display: none; }
  .hud .tools { width: 100%; }
  .hud .tools .danger { margin-left: auto; }
  .title-wrap { bottom: 9vh; }
}

/* ---------------- 앱 추가 ---------------- */
[hidden] { display: none !important; }
body[data-bg="mart"] { background: linear-gradient(#F4EEE2, #D9D4C8); }
body[data-bg="farewell"] { background: linear-gradient(#CFE3EE, #E9E2D6); }
.noscript { position: fixed; inset: auto 0 40% 0; text-align: center; color: #FFF3D6; font-size: 18px; padding: 0 20px; z-index: 60; }
button.skip { border: 0; cursor: pointer; font-size: 15px; }
button.skip:focus-visible, .dialog:focus-visible, .token:focus-visible, .next-link:focus-visible { outline: 3px solid var(--pen); outline-offset: 3px; }

/* 대사 상자: 버튼이라 키보드로도 넘긴다 */
button.dialog { border: 0; text-align: left; cursor: pointer; font-family: var(--font-body); }
.dialog .line { display: inline; }
.dialog.waiting { cursor: default; }
.dialog.waiting .next { display: none; }
.dialog.waiting .line { color: var(--accent-dark); font-family: var(--font-title); }
.dialog.pop .line { animation: lineIn .35s ease-out both; }
@keyframes lineIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.intro .dialog { z-index: 2; }

/* 교정기: 끌어서 발가락에 놓는 도구 */
.token { position: absolute; left: clamp(20px, 14vw, 260px); top: 46%; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: rgba(255,250,238,.96); border: 2px dashed var(--accent); border-radius: 16px; padding: 10px 18px 8px; cursor: grab; touch-action: none; font-family: var(--font-title); color: var(--ink); font-size: 15px;
  box-shadow: 0 8px 24px rgba(80,50,20,.25); animation: nudge 1.6s ease-in-out infinite; }
.token svg { width: 110px; height: 36px; }
.token.dragging { cursor: grabbing; animation: none; box-shadow: 0 14px 30px rgba(80,50,20,.35); }
.scene.on .token { pointer-events: auto; }
@keyframes nudge { 50% { translate: 0 -5px; } }
.action-float { position: absolute; left: clamp(20px, 14vw, 260px); top: 46%; }

/* 사육장 노트(떠 있는 카드)와 아이의 한마디 */
.card.floating { top: calc(var(--edge) + 76px); bottom: auto; max-height: calc(100dvh - var(--edge) * 2 - 90px); z-index: 3; }
.card-head { display: flex; justify-content: space-between; align-items: center; }
.icon-btn.sm { width: 36px; height: 36px; font-size: 15px; }
.remark { position: absolute; left: 50%; bottom: calc(var(--edge) + 56px); transform: translateX(-50%); width: min(92vw, 640px); background: rgba(251,244,228,.97); border-radius: 16px; padding: 14px 18px;
  font-size: clamp(16px, 1.3vw, 19px); line-height: 1.55; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.remark b { font-family: var(--font-title); font-weight: 400; color: var(--accent-dark); margin-right: 8px; }
.remark.pop { animation: landX .5s cubic-bezier(.2,1.4,.4,1) both; }

/* 소리 버튼 상태 */
.icon-btn .mute { display: none; }
.icon-btn.muted .wave { display: none; }
.icon-btn.muted .mute { display: inline; }
.icon-btn.muted { color: var(--ink-soft); }

/* 엔딩의 "처음부터": 끝에 내려앉음 */
.end-actions { opacity: 0; transform: translateY(24px); transition: opacity .6s, transform .7s cubic-bezier(.2,1.4,.4,1); pointer-events: none; }
.end-actions.show { opacity: 1; transform: none; }
.end-actions.show .btn { pointer-events: auto; }
button.next-link { border: 0; cursor: pointer; }

/* 넓은 화면: 노트 카드와 대사 상자를 조금 키운다 */
@media (min-width: 1700px) {
  .card { width: 380px; }
  .inspect-head, .views, .actions { right: calc(var(--edge) + 400px); }
}

@media (max-width: 900px) {
  .card.floating { top: auto; bottom: var(--edge); max-height: 46dvh; }
  .card.floating .note-list span { display: inline; font-size: 13px; }
  .card.floating .note-list { grid-template-columns: 1fr; }
  .action-float { left: var(--edge); top: auto; bottom: calc(var(--edge) + 150px); }
  .token { left: var(--edge); top: auto; bottom: calc(var(--edge) + 150px); }
  .remark { bottom: calc(var(--edge) + 52px); }
  .end-actions { left: var(--edge); right: var(--edge); text-align: center; }
}
@media (max-width: 420px) {
  .dialog { padding: 14px 40px 14px 16px; }
  .hud .tools .btn.sm { padding: 8px 10px; font-size: 14px; }
}
h2[tabindex="-1"]:focus { outline: none; }
