@font-face {
  font-family: 'DotGothic16';
  src: url('../assets/fonts/dotgothic16-latin.woff2') format('woff2');
  font-display: swap;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: #0b0d14; color: #fff; overflow: hidden;
  font-family: 'DotGothic16', ui-monospace, monospace; -webkit-font-smoothing: none;
  user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none;
}
#game { position: fixed; inset: 0; overflow: hidden; background: #000; }
#game > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#sprites { image-rendering: auto; }
#light { mix-blend-mode: multiply; pointer-events: none; }
#glow { mix-blend-mode: screen; pointer-events: none; }

/* HD-2D diorama depth of field: blur bands top & bottom */
.tilt { position: absolute; left: 0; right: 0; pointer-events: none; }
#tilt-top {
  top: 0; height: 26%;
  backdrop-filter: blur(2.6px) saturate(1.06); -webkit-backdrop-filter: blur(2.6px) saturate(1.06);
  mask-image: linear-gradient(to bottom, #000 0%, rgba(0,0,0,.55) 45%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, rgba(0,0,0,.55) 45%, transparent 100%);
}
#tilt-bottom {
  bottom: 0; height: 22%;
  backdrop-filter: blur(2.2px); -webkit-backdrop-filter: blur(2.2px);
  mask-image: linear-gradient(to top, #000 0%, rgba(0,0,0,.5) 45%, transparent 100%);
  -webkit-mask-image: linear-gradient(to top, #000 0%, rgba(0,0,0,.5) 45%, transparent 100%);
}
body.no-tilt .tilt { display: none; }
#vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse 75% 70% at 50% 48%, transparent 55%, rgba(5,4,12,.55) 100%);
}
#fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .45s ease; }
#fade.on { opacity: 1; }
#fade.white { background: #fff6dc; }

/* ---------------------------------------------------- windows (DQ style) */
.win {
  position: absolute; color: #fff;
  background: linear-gradient(180deg, rgba(18,22,64,.94), rgba(8,10,34,.94));
  border: 3px solid #f4f1e6; border-radius: 10px;
  box-shadow: 0 0 0 2px #0a0b1c, inset 0 0 0 2px rgba(0,0,0,.6), 0 10px 30px rgba(0,0,0,.45);
  text-shadow: 2px 2px 0 #000;
}
#dialog {
  left: 50%; bottom: max(3.5%, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(880px, 94vw); min-height: 7.4em; padding: 1em 1.4em 1.2em;
  font-size: clamp(16px, 2.3vw, 24px); line-height: 1.55; letter-spacing: .02em;
}
#dialog-name {
  position: absolute; top: -1.05em; left: 1em; padding: .1em .7em; font-size: .78em;
  background: #f4f1e6; color: #12163c; border-radius: 6px; text-shadow: none;
}
#dialog-name:empty { display: none; }
#dialog-text { white-space: pre-wrap; min-height: 3.1em; }
#dialog-text .hl { color: #ffd257; }
#dialog-next { position: absolute; right: .8em; bottom: .3em; font-size: .7em; animation: bob .7s steps(2) infinite; visibility: hidden; }
#dialog.done #dialog-next { visibility: visible; }
@keyframes bob { 50% { transform: translateY(4px); } }

#choice {
  right: max(4vw, calc(50% - 440px)); bottom: calc(max(3.5%, env(safe-area-inset-bottom)) + 9em);
  padding: .6em 1.2em .6em 1.8em; font-size: clamp(15px, 2.1vw, 22px); line-height: 1.7;
}
#choice div { position: relative; cursor: pointer; }
#choice div.sel::before { content: '▶'; position: absolute; left: -1.2em; animation: blink .8s steps(2) infinite; }
@keyframes blink { 50% { opacity: .2; } }

#menu {
  left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, 92vw);
  padding: 1em 1.6em; font-size: clamp(15px, 2vw, 21px); line-height: 1.6;
}
#menu h2 { margin: 0 0 .4em; font-size: 1.1em; letter-spacing: .2em; color: #ffd257; font-weight: normal; }
#menu .row { display: flex; justify-content: space-between; gap: 1em; }
#menu .items { margin-top: .6em; display: grid; grid-template-columns: 1fr 1fr; gap: .2em 1em; }
#menu .items span { display: flex; align-items: center; gap: .4em; }
#menu .items canvas { width: 1.6em; height: 1.6em; image-rendering: pixelated; }
#menu .quest { margin-top: .7em; padding-top: .6em; border-top: 2px solid rgba(244,241,230,.3); color: #d8dcff; }
#menu .hint { margin: .8em 0 0; font-size: .75em; opacity: .6; }

/* ---------------------------------------------------- HUD */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hearts {
  position: absolute; left: max(18px, env(safe-area-inset-left)); top: max(14px, env(safe-area-inset-top));
  display: flex; gap: 2px; filter: drop-shadow(2px 2px 0 rgba(0,0,0,.7));
}
#hearts canvas { width: 34px; height: 34px; image-rendering: pixelated; }
#hearts canvas.pop { animation: pop .3s ease; }
@keyframes pop { 40% { transform: scale(1.35); } }
#counters {
  position: absolute; right: max(18px, env(safe-area-inset-right)); top: max(14px, env(safe-area-inset-top));
  display: flex; gap: 16px; font-size: 22px; text-shadow: 2px 2px 0 #000;
}
.ctr { display: flex; align-items: center; gap: 4px; }
.ctr canvas { width: 28px; height: 28px; image-rendering: pixelated; filter: drop-shadow(2px 2px 0 rgba(0,0,0,.7)); }
#area-name {
  position: absolute; left: 50%; top: 13%; transform: translateX(-50%);
  font-size: clamp(20px, 3.4vw, 38px); letter-spacing: .25em; white-space: nowrap;
  text-shadow: 0 0 18px rgba(0,0,0,.8), 3px 3px 0 #000; opacity: 0; transition: opacity 1s;
}
#area-name.show { opacity: 1; }
#area-name small { display: block; text-align: center; font-size: .45em; letter-spacing: .4em; color: #ffd257; }
#bossbar {
  position: absolute; left: 50%; bottom: 5%; transform: translateX(-50%); width: min(520px, 80vw);
  font-size: 16px; letter-spacing: .3em; text-shadow: 2px 2px 0 #000; text-align: center;
}
#bossbar i { display: block; height: 12px; margin-top: 4px; border: 2px solid #f4f1e6; border-radius: 4px; background: rgba(0,0,0,.6); overflow: hidden; }
#bossbar em { display: block; height: 100%; width: 100%; background: linear-gradient(#9be36b, #3e8f2a); transition: width .25s; }

#banner {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); pointer-events: none;
  font-size: clamp(22px, 4vw, 44px); letter-spacing: .12em; color: #ffe9a8; text-align: center;
  text-shadow: 0 0 24px rgba(255,170,60,.8), 3px 3px 0 #000; opacity: 0; transition: opacity .6s;
}
#banner.show { opacity: 1; }

/* ---------------------------------------------------- title */
#title { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; }
#title-bg, #ending-bg {
  position: absolute; inset: -4%; background: #111 center/cover no-repeat;
  animation: kenburns 40s ease-in-out infinite alternate; filter: saturate(1.1) contrast(1.05);
}
#title-bg::after, #ending-bg::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 40%, rgba(0,0,0,.05), rgba(0,0,0,.65)), linear-gradient(transparent 55%, rgba(5,6,16,.85));
}
@keyframes kenburns { from { transform: scale(1) translate(0,0); } to { transform: scale(1.08) translate(-1.5%, 1%); } }
#title-inner { position: relative; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4vh; padding: 0 4vw; }
#logo h1 {
  margin: 0; font-weight: normal; font-size: clamp(44px, 10vw, 120px); letter-spacing: .12em; line-height: 1;
  color: #ffe6a3; text-shadow: 0 0 30px rgba(255,150,40,.75), 0 0 80px rgba(255,90,20,.45), 5px 5px 0 #2a0f05;
  animation: flicker 4s infinite;
}
#logo .sub { display: block; font-size: clamp(13px, 1.8vw, 20px); letter-spacing: .6em; opacity: .85; margin-bottom: .6em; text-shadow: 2px 2px 0 #000; }
@keyframes flicker { 0%,100% { filter: brightness(1); } 47% { filter: brightness(1.08); } 50% { filter: brightness(.92); } 53% { filter: brightness(1.05); } }
#title-menu { position: relative; padding: .7em 1.8em; display: flex; flex-direction: column; gap: .2em; min-width: 260px; }
#title-menu button, #ending button {
  font: inherit; font-size: clamp(18px, 2.3vw, 24px); color: #fff; background: none; border: 0; cursor: pointer;
  text-shadow: 2px 2px 0 #000; padding: .2em .8em; position: relative;
}
#title-menu button.sel::before, #title-menu button:hover::before { content: '▶'; position: absolute; left: -.6em; animation: blink .8s steps(2) infinite; }
#title-menu button:disabled { opacity: .35; cursor: default; }
#title-controls { margin: 0; font-size: clamp(11px, 1.3vw, 15px); opacity: .8; text-shadow: 2px 2px 0 #000; line-height: 1.6; }
#loading { margin: 0; font-size: 14px; opacity: .7; }
.touch #title-controls { display: none; }

#ending { position: absolute; inset: 0; z-index: 9; display: grid; place-items: center; }
#ending-inner { position: relative; padding: 1.4em 2em; text-align: center; width: min(640px, 92vw); font-size: clamp(14px, 1.8vw, 19px); line-height: 1.6; }
#ending-inner h2 { margin: 0 0 .4em; font-weight: normal; color: #ffd257; font-size: 1.5em; }
#ending .credits { margin: 1em 0; font-size: .78em; opacity: .85; }
#ending .credits p { margin: .2em 0; }
#ending a { color: #9fd0ff; }

/* ---------------------------------------------------- touch controls */
#touch { position: absolute; inset: 0; pointer-events: none; }
#stick {
  position: absolute; left: max(4vw, env(safe-area-inset-left)); bottom: max(5vh, env(safe-area-inset-bottom));
  width: 140px; height: 140px; border-radius: 50%; pointer-events: auto;
  background: radial-gradient(circle, rgba(255,255,255,.08), rgba(255,255,255,.16)); border: 2px solid rgba(255,255,255,.35);
}
#nub { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px; border-radius: 50%; background: rgba(255,255,255,.4); border: 2px solid rgba(255,255,255,.7); }
#tbtns { position: absolute; right: max(4vw, env(safe-area-inset-right)); bottom: max(5vh, env(safe-area-inset-bottom)); width: 170px; height: 150px; }
#tbtns button {
  position: absolute; pointer-events: auto; border-radius: 50%; font: inherit; font-size: 22px; color: #fff;
  background: rgba(20,24,70,.55); border: 3px solid rgba(244,241,230,.8); text-shadow: 2px 2px 0 #000;
}
#tb-a { right: 0; top: 20px; width: 78px; height: 78px; }
#tb-b { right: 92px; top: 66px; width: 64px; height: 64px; }
#tb-m { right: 8px; top: -44px; width: 46px; height: 46px; font-size: 18px !important; }
#tbtns button:active, #tbtns button.on { background: rgba(255,210,87,.5); }

[hidden] { display: none !important; }
