:root {
  --night: #0b0f1c;
  --ink: #060811;
  --gold: #d9b36a;
  --gold-soft: rgba(217, 179, 106, .55);
  --cream: #f3e6c8;
  --muted: #b7ab93;
  --red: #c9463d;
  --panel: rgba(10, 13, 24, .78);
  --serif: "Shippori Mincho B1", "Hiragino Mincho ProN", serif;
  --sans: "Zen Kaku Gothic New", "Hiragino Sans", sans-serif;
  --sa-l: env(safe-area-inset-left, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--cream); font-family: var(--sans); overflow: hidden; overscroll-behavior: none; }
body { position: fixed; inset: 0; user-select: none; -webkit-user-select: none; touch-action: none; }
#app { position: absolute; inset: 0; overflow: hidden; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

.btn {
  font-family: var(--serif); font-weight: 700; font-size: 17px; letter-spacing: .12em;
  min-width: 200px; padding: 12px 26px; color: var(--cream);
  border: 1px solid var(--gold-soft); border-radius: 999px;
  background: linear-gradient(180deg, rgba(40, 32, 22, .85), rgba(14, 12, 20, .9));
  box-shadow: 0 0 0 3px rgba(217, 179, 106, .08), 0 6px 24px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 230, 180, .15);
  transition: transform .15s, box-shadow .2s;
}
.btn:active { transform: scale(.96); }
.btn.sub { font-size: 14px; min-width: 150px; padding: 9px 20px; opacity: .85; }
.ghost-btn { position: absolute; right: calc(16px + var(--sa-r)); top: calc(14px + var(--sa-t)); padding: 6px 14px; font-size: 13px; color: var(--muted); border: 1px solid rgba(255, 255, 255, .2); border-radius: 999px; background: rgba(0, 0, 0, .35); z-index: 5; }

/* ---------- Title ---------- */
.screen { position: absolute; inset: 0; z-index: 30; }
#title { background: var(--ink); overflow: hidden; }
#title .art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; animation: kenburns 30s ease-in-out infinite alternate; }
#title video.art { animation: none; opacity: 0; transition: opacity 1.2s; }
#title video.art.on { opacity: 1; }
@keyframes kenburns { from { transform: scale(1.04) translate(0, 0); } to { transform: scale(1.12) translate(-1.5%, -1%); } }
#title .shade { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(6, 8, 17, .85) 0%, rgba(6, 8, 17, .35) 45%, transparent 70%), linear-gradient(0deg, rgba(6, 8, 17, .7), transparent 40%); }
.title-block { position: absolute; left: calc(5vw + var(--sa-l)); top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; align-items: flex-start; gap: 6px; max-width: min(560px, 60vw); }
.genre { font-family: var(--serif); letter-spacing: .3em; color: var(--muted); font-size: 13px; }
#logo { margin: 0; line-height: 1; }
#logoImg { width: min(520px, 55vw); filter: drop-shadow(0 0 18px rgba(255, 220, 160, .35)); }
#logo .fallback { display: none; font-family: var(--serif); font-weight: 800; font-size: clamp(34px, 6vw, 64px); letter-spacing: .04em; text-shadow: 0 0 20px rgba(255, 220, 160, .5); }
#logo.noimg img { display: none; } #logo.noimg .fallback { display: inline; }
#logo .fallback em { font-style: normal; font-size: 1.25em; }
.catch { font-family: var(--serif); font-size: clamp(15px, 2.2vw, 20px); letter-spacing: .25em; margin: 6px 0 20px; text-shadow: 0 2px 10px #000; }
.title-block nav { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.endings { font-size: 12px; color: var(--muted); letter-spacing: .1em; margin-top: 10px; }
#title .hint { position: absolute; bottom: calc(12px + var(--sa-b)); right: calc(18px + var(--sa-r)); font-size: 12px; color: var(--muted); opacity: .8; margin: 0; }
@media (orientation: portrait) {
  #title .shade { background: linear-gradient(0deg, rgba(6, 8, 17, .95) 0%, rgba(6, 8, 17, .5) 40%, transparent 65%), linear-gradient(180deg, rgba(6, 8, 17, .6), transparent 25%); }
  .title-block { left: 50%; top: auto; bottom: calc(40px + var(--sa-b)); transform: translateX(-50%); align-items: center; text-align: center; max-width: 92vw; width: 92vw; }
  .title-block nav { align-items: center; }
  #logoImg { width: 86vw; }
  #title .hint { left: 0; right: 0; text-align: center; }
}

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
#hud > * { pointer-events: auto; }
.objective {
  position: absolute; left: calc(14px + var(--sa-l)); top: calc(12px + var(--sa-t));
  display: flex; align-items: center; gap: 10px; padding: 8px 18px 8px 12px; max-width: 46vw;
  font-family: var(--serif); font-weight: 700; font-size: 15px; letter-spacing: .06em;
  background: linear-gradient(90deg, rgba(8, 10, 20, .85), rgba(8, 10, 20, .35)); border-top: 1px solid var(--gold-soft); border-bottom: 1px solid rgba(217, 179, 106, .2);
  pointer-events: none !important; transition: opacity .4s;
}
.objective.flash { animation: objflash 1.2s; }
@keyframes objflash { 0%, 100% { box-shadow: none; } 30% { box-shadow: 0 0 22px rgba(255, 210, 140, .6); } }
.diamond { width: 12px; height: 12px; flex: none; transform: rotate(45deg); border: 2px solid #9fd0ff; background: rgba(159, 208, 255, .35); box-shadow: 0 0 8px #9fd0ff; }
.memcount { position: absolute; left: calc(16px + var(--sa-l)); top: calc(52px + var(--sa-t)); font-size: 12px; color: var(--gold); letter-spacing: .12em; pointer-events: none !important; }
#minimap { position: absolute; right: calc(12px + var(--sa-r)); top: calc(10px + var(--sa-t)); width: 150px; height: 116px; border: 1px solid var(--gold-soft); border-radius: 6px; background: rgba(8, 10, 18, .7); pointer-events: none !important; }
#menuBtn { position: absolute; right: calc(172px + var(--sa-r)); top: calc(12px + var(--sa-t)); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; font-size: 18px; background: rgba(8, 10, 18, .6); border: 1px solid rgba(217, 179, 106, .35); }
#inventory { position: absolute; left: 50%; bottom: calc(10px + var(--sa-b)); transform: translateX(-50%); display: flex; gap: 8px; }
#inventory button { width: 52px; height: 52px; border-radius: 8px; padding: 4px; border: 1px solid var(--gold-soft); background: rgba(12, 12, 20, .7); box-shadow: inset 0 0 12px rgba(217, 179, 106, .12); }
#inventory button img { width: 100%; height: 100%; object-fit: contain; }
#inventory button.new { animation: newitem 1.6s 2; }
@keyframes newitem { 50% { box-shadow: 0 0 18px rgba(255, 220, 150, .9); transform: translateY(-4px); } }

#stick { position: absolute; left: calc(40px + var(--sa-l)); bottom: calc(34px + var(--sa-b)); width: 130px; height: 130px; border-radius: 50%; border: 1.5px solid rgba(255, 255, 255, .28); background: radial-gradient(circle, rgba(255, 255, 255, .06), rgba(255, 255, 255, .02)); pointer-events: none !important; transition: opacity .3s; opacity: .75; }
#stick i { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, rgba(255, 255, 255, .6), rgba(200, 200, 210, .25)); box-shadow: 0 0 12px rgba(255, 255, 255, .2); }
#stick.active { opacity: 1; }

.act {
  position: absolute; right: calc(120px + var(--sa-r)); bottom: calc(40px + var(--sa-b)); width: 98px; height: 98px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: radial-gradient(circle at 50% 40%, rgba(40, 36, 30, .85), rgba(10, 10, 16, .85)); border: 2px solid rgba(255, 240, 210, .75);
  box-shadow: 0 0 0 4px rgba(217, 179, 106, .15), 0 0 24px rgba(255, 220, 150, .35); animation: actpulse 1.8s infinite;
}
.act .ico { font-size: 30px; line-height: 1; filter: grayscale(1) brightness(2); }
.act b { font-size: 13px; letter-spacing: .1em; }
.act:active { transform: scale(.94); }
@keyframes actpulse { 50% { box-shadow: 0 0 0 7px rgba(217, 179, 106, .08), 0 0 34px rgba(255, 220, 150, .55); } }
.round { position: absolute; right: calc(24px + var(--sa-r)); bottom: calc(60px + var(--sa-b)); width: 66px; height: 66px; border-radius: 50%; background: rgba(10, 10, 16, .7); border: 1.5px solid rgba(255, 255, 255, .4); display: grid; place-items: center; }
.round svg { width: 34px; fill: #e8e2d6; }
.round.on { background: rgba(80, 110, 160, .6); border-color: #9fd0ff; box-shadow: 0 0 16px rgba(159, 208, 255, .5); }
#prompt { position: absolute; right: calc(110px + var(--sa-r)); bottom: calc(146px + var(--sa-b)); font-size: 13px; color: var(--cream); text-shadow: 0 1px 4px #000; pointer-events: none !important; letter-spacing: .08em; }
#toast { position: absolute; left: 50%; top: 22%; transform: translate(-50%, 0); padding: 10px 22px; border-radius: 8px; background: var(--panel); border: 1px solid var(--gold-soft); font-size: 15px; letter-spacing: .06em; opacity: 0; transition: opacity .35s, transform .35s; pointer-events: none !important; display: flex; align-items: center; gap: 12px; max-width: 80vw; }
#toast.on { opacity: 1; transform: translate(-50%, 8px); }
#toast img { width: 44px; height: 44px; object-fit: contain; }

#danger { position: absolute; inset: 0; z-index: 9; pointer-events: none; opacity: 0; background: radial-gradient(ellipse at center, transparent 45%, rgba(120, 0, 10, .55) 100%); transition: opacity .3s; }
#vignette { position: absolute; inset: 0; z-index: 8; pointer-events: none; background: radial-gradient(ellipse at 50% 55%, transparent 55%, rgba(0, 0, 0, .55) 100%); }
#hideView { position: absolute; inset: 0; z-index: 9; pointer-events: none; opacity: 0; transition: opacity .4s; background: linear-gradient(90deg, #1a0406 0%, #3a0a10 30%, transparent 43%, transparent 57%, #3a0a10 70%, #1a0406 100%); }
#hideView.on { opacity: 1; }

/* ---------- Dialogue ---------- */
#dialogue { position: absolute; left: 0; right: 0; bottom: 0; z-index: 20; height: 42%; min-height: 180px; pointer-events: auto; }
#dlgFace { position: absolute; left: calc(3vw + var(--sa-l)); bottom: 0; height: 125%; max-width: 32vw; object-fit: contain; object-position: bottom; -webkit-mask-image: linear-gradient(0deg, transparent 0, #000 22%); mask-image: linear-gradient(0deg, transparent 0, #000 22%); filter: drop-shadow(0 0 20px rgba(0, 0, 0, .6)); transition: opacity .2s; }
#dlgFace.boxed { border-radius: 10px; -webkit-mask-image: radial-gradient(ellipse 70% 75% at 50% 45%, #000 55%, transparent 100%); mask-image: radial-gradient(ellipse 70% 75% at 50% 45%, #000 55%, transparent 100%); height: 110%; }
#dialogue .box { position: absolute; left: calc(max(24vw, 180px) + var(--sa-l)); right: calc(4vw + var(--sa-r)); bottom: calc(18px + var(--sa-b)); min-height: 110px; padding: 16px 26px 18px; border-radius: 10px; background: linear-gradient(180deg, rgba(12, 14, 26, .88), rgba(6, 8, 16, .94)); border: 1px solid var(--gold-soft); box-shadow: 0 0 0 4px rgba(217, 179, 106, .06), 0 10px 40px rgba(0, 0, 0, .6); }
#dialogue.noface .box { left: calc(4vw + var(--sa-l)); }
#dlgName { position: absolute; top: -15px; left: 20px; padding: 3px 16px; font-family: var(--serif); font-size: 15px; letter-spacing: .15em; background: linear-gradient(90deg, #3a2a15, #1d160c); border: 1px solid var(--gold-soft); border-radius: 4px; }
#dlgName:empty { display: none; }
#dlgText { margin: 6px 0 0; font-family: var(--serif); font-size: clamp(16px, 2.3vw, 21px); line-height: 1.7; letter-spacing: .05em; white-space: pre-wrap; }
#dialogue .next { position: absolute; right: 18px; bottom: 10px; font-style: normal; font-size: 12px; color: var(--gold); animation: bob 1s infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }
#choices { position: absolute; inset: 0; z-index: 21; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; background: rgba(0, 0, 0, .35); }
#choices .btn { min-width: min(420px, 80vw); font-size: 18px; padding: 16px 28px; }

/* ---------- Cutscene ---------- */
#cutscene { position: absolute; inset: 0; z-index: 18; background: #000; }
#cutscene .cg { position: absolute; inset: 0; overflow: hidden; }
#cutscene img, #cutscene video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#cutscene img.kb { animation: cgkb 14s ease-out forwards; }
@keyframes cgkb { from { transform: scale(1.02); } to { transform: scale(1.12) translate(-1%, -1.5%); } }
#cutscene video { opacity: 0; }
#cutscene video.on { opacity: 1; }
#cutscene::before, #cutscene::after { content: ""; position: absolute; left: 0; right: 0; height: 6vh; background: #000; z-index: 2; }
#cutscene::before { top: 0; } #cutscene::after { bottom: 0; }

#chapter { position: absolute; inset: 0; z-index: 25; display: flex; flex-direction: column; align-items: center; justify-content: center; background: radial-gradient(ellipse, rgba(10, 12, 24, .7), rgba(0, 0, 0, .95)); animation: chin 3.6s forwards; pointer-events: none; }
#chapter small { font-family: var(--serif); letter-spacing: .5em; color: var(--gold); font-size: 14px; }
#chapter h2 { font-family: var(--serif); font-size: clamp(30px, 5vw, 48px); letter-spacing: .25em; margin: 10px 0 0; text-shadow: 0 0 24px rgba(255, 220, 160, .45); }
#chapter h2::after { content: ""; display: block; height: 1px; margin: 14px auto 0; width: 60%; background: linear-gradient(90deg, transparent, var(--gold), transparent); }
@keyframes chin { 0% { opacity: 0; } 15%, 80% { opacity: 1; } 100% { opacity: 0; } }

#memory { position: absolute; inset: 0; z-index: 26; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(4, 5, 10, .82); backdrop-filter: blur(3px); animation: fadein .6s; }
#memory .card { display: flex; gap: 22px; align-items: center; max-width: min(860px, 92vw); padding: 18px; border: 1px solid var(--gold-soft); border-radius: 10px; background: linear-gradient(180deg, rgba(30, 24, 16, .9), rgba(10, 10, 16, .95)); box-shadow: 0 0 60px rgba(255, 210, 140, .2); }
#memImg { width: min(300px, 38vw); aspect-ratio: 1; object-fit: cover; border-radius: 4px; box-shadow: 0 6px 24px #000; transform: rotate(-2deg); animation: memin 1s cubic-bezier(.2, .8, .2, 1.2); }
@keyframes memin { from { transform: rotate(-12deg) scale(.6); opacity: 0; } }
#memory small { color: var(--gold); letter-spacing: .3em; font-family: var(--serif); }
#memory h3 { font-family: var(--serif); font-size: 26px; margin: 6px 0 10px; letter-spacing: .12em; }
#memory p { font-family: var(--serif); line-height: 1.8; margin: 0; font-size: 15px; }
#memory .tap { color: var(--muted); font-size: 12px; margin-top: 14px; animation: bob 1.4s infinite; }
@keyframes fadein { from { opacity: 0; } }
@media (orientation: portrait) { #memory .card { flex-direction: column; text-align: center; } #memImg { width: 60vw; } }

/* ---------- Overlays ---------- */
#menu { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(0, 0, 0, .6); }
.panel { width: min(420px, 90vw); padding: 22px 26px; border-radius: 12px; background: linear-gradient(180deg, #17151f, #0b0b12); border: 1px solid var(--gold-soft); display: flex; flex-direction: column; gap: 14px; }
.panel h3 { margin: 0 0 4px; font-family: var(--serif); letter-spacing: .3em; text-align: center; }
.panel label { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px; }
.panel input[type=range] { width: 60%; accent-color: var(--gold); }
.panel select { background: #1d1a24; color: var(--cream); border: 1px solid var(--gold-soft); border-radius: 6px; padding: 5px 8px; font: inherit; }
.panel .row { display: flex; gap: 10px; justify-content: center; margin-top: 6px; }
.panel .row .btn { min-width: 0; flex: 1; font-size: 15px; }

#gameover, #ending { position: absolute; inset: 0; z-index: 35; background: #000; animation: fadein 1.2s; }
#gameover img, #ending img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .75; }
#ending img { opacity: .9; animation: kenburns 25s ease-out forwards; }
.go-text, .end-text { position: absolute; left: 0; right: 0; bottom: 0; padding: 30px 6vw calc(30px + var(--sa-b)); text-align: center; background: linear-gradient(0deg, rgba(0, 0, 0, .92), rgba(0, 0, 0, .5) 70%, transparent); }
.go-text h2 { font-family: var(--serif); font-size: clamp(26px, 4vw, 40px); letter-spacing: .2em; color: #e7d6d0; margin: 0; }
.go-text p { font-family: var(--serif); color: #b88; letter-spacing: .2em; }
.end-text small { color: var(--gold); letter-spacing: .4em; font-family: var(--serif); }
.end-text h2 { font-family: var(--serif); font-size: clamp(28px, 4.5vw, 44px); letter-spacing: .2em; margin: 6px 0 8px; text-shadow: 0 0 20px rgba(255, 220, 160, .5); }
.end-text p { font-family: var(--serif); line-height: 1.9; white-space: pre-line; max-width: 720px; margin: 0 auto 18px; }

#loading { position: absolute; inset: 0; z-index: 60; background: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; transition: opacity .6s; }
#loading.done { opacity: 0; pointer-events: none; }
#loading .moon { width: 46px; height: 46px; border-radius: 50%; box-shadow: 12px -6px 0 0 var(--gold); animation: spin 2.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#loading p { font-family: var(--serif); letter-spacing: .3em; color: var(--muted); font-size: 14px; }
#fade { position: absolute; inset: 0; z-index: 50; background: #000; opacity: 0; pointer-events: none; transition: opacity .7s; }
#fade.on { opacity: 1; pointer-events: auto; }
#rotate { display: none; }
@media (orientation: portrait) and (max-width: 700px) {
  #app.playing #rotate { display: block; position: absolute; top: calc(60px + var(--sa-t)); left: 50%; transform: translateX(-50%); z-index: 12; font-size: 12px; padding: 6px 12px; border-radius: 999px; background: rgba(0, 0, 0, .55); color: var(--muted); white-space: nowrap; animation: fadeout 6s forwards; pointer-events: none; }
  @keyframes fadeout { 80% { opacity: 1; } 100% { opacity: 0; } }
  .objective { max-width: 60vw; font-size: 13px; }
  #minimap { width: 110px; height: 85px; }
  #menuBtn { right: calc(130px + var(--sa-r)); }
  #stick { width: 116px; height: 116px; left: 22px; bottom: calc(90px + var(--sa-b)); }
  .act { right: 96px; bottom: calc(96px + var(--sa-b)); width: 86px; height: 86px; }
  .round { right: 16px; bottom: calc(110px + var(--sa-b)); width: 58px; height: 58px; }
  #prompt { bottom: calc(190px + var(--sa-b)); right: 80px; }
  #dialogue { height: 36%; }
  #dlgFace { max-width: 42vw; height: 95%; bottom: 150px; left: 0; }
  #dialogue .box { left: 3vw !important; right: 3vw; }
}

#a2hs { position: absolute; top: calc(14px + var(--sa-t)); right: calc(14px + var(--sa-r)); max-width: min(330px, 80vw); padding: 12px 34px 12px 14px; border-radius: 10px; font-size: 13px; line-height: 1.6; background: rgba(8, 10, 20, .88); border: 1px solid var(--gold-soft); box-shadow: 0 6px 24px rgba(0,0,0,.5); z-index: 3; }
#a2hs b { color: var(--gold); }
#a2hs .share { display: inline-flex; align-items: center; gap: 2px; color: #9fd0ff; }
#a2hs svg { width: 15px; height: 15px; }
#a2hs button { position: absolute; top: 4px; right: 8px; font-size: 18px; color: var(--muted); }
@media (orientation: portrait) { #a2hs { left: 50%; right: auto; transform: translateX(-50%); } }

.panel { max-height: 92vh; overflow-y: auto; }
.dev { border-top: 1px solid rgba(217,179,106,.3); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.dev h4 { margin: 4px 0 0; font-family: var(--serif); font-size: 15px; letter-spacing: .2em; color: var(--gold); }
.dev summary { cursor: pointer; color: var(--gold); font-size: 13px; letter-spacing: .15em; margin-bottom: 8px; }
.dev[open] { display: flex; }
.dev .check { justify-content: flex-start; gap: 8px; }
.dev .check input { width: 18px; height: 18px; accent-color: var(--gold); }
.dev .note { color: var(--muted); font-size: 11.5px; line-height: 1.5; }
.dev select { max-width: 60%; }
#autoBadge { position: absolute; left: 50%; top: calc(8px + var(--sa-t)); transform: translateX(-50%); z-index: 45; padding: 3px 14px; border-radius: 999px; font-size: 12px; letter-spacing: .2em; color: #1a1208; background: #ffd98a; box-shadow: 0 0 12px rgba(255,217,138,.6); animation: bob 1.6s infinite; }
#app:not(.playing) #autoBadge { display: none; }

#ending.over { background: transparent; }
#ending.over .end-text { background: linear-gradient(0deg, rgba(0,0,0,.94), rgba(0,0,0,.55) 65%, transparent); }
