@font-face {
  font-family: 'monogram';
  src: url('../assets/monogram.ttf') format('truetype');
  font-display: block;
}

:root {
  --bg: #0c0a12;
  --bar: #14111d;
  --ink: #e8dcc8;
  --dim: #8b8398;
  --ember: #ff9d5a;
  --line: #2b2438;
  --blood: #e05a54;
  --gold: #f3c14b;
  --shard: #9fd8ff;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'monogram', monospace;
  -webkit-font-smoothing: none;
  font-smooth: never;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
}

#game {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #07060c;
}

#ui { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#ui > * { pointer-events: auto; }
#ui button { font-family: 'monogram', monospace; cursor: pointer; }

/* ---------- HUD ---------- */
.hud {
  position: absolute; top: 0; left: 0; right: 0;
  padding: calc(var(--safe-t) + 6px) calc(var(--safe-r) + 8px) 6px calc(var(--safe-l) + 8px);
  background: linear-gradient(#0c0a12ee, #0c0a1200);
  pointer-events: none;
}
.hud.hidden { display: none; }
.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hpwrap { display: flex; align-items: center; gap: 6px; }
.hpbar { width: 120px; max-width: 40vw; height: 10px; background: #2b2438; border: 1px solid #4a4258; }
.hpfill { height: 100%; background: linear-gradient(#e05a54, #a83b3b); transition: width .18s; }
.hpnum { font-size: 16px; color: var(--ink); }
.hud-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.tag { font-size: 16px; color: var(--ink); display: inline-flex; align-items: center; gap: 3px; }
.floortag { color: var(--dim); }
.ic-gold, .ic-shard { width: 10px; height: 10px; display: inline-block; }
.ic-gold { background: var(--gold); border-radius: 50%; }
.ic-shard { background: var(--shard); clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); }
.mutebtn, .pausebtn { background: none; border: 1px solid var(--line); color: var(--ink); width: 28px; height: 28px; font-size: 16px; }
.mutebtn.off { color: var(--dim); }
.pausebtn { color: var(--ember); }
.buffs { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.buff { font-size: 12px; padding: 1px 4px; border: 1px solid var(--line); color: var(--ink); background: #14111d; }
.buff-poison { color: #8fd07a; } .buff-burn { color: var(--ember); } .buff-frozen { color: var(--shard); }
.buff-haste { color: var(--gold); } .buff-stun { color: var(--blood); } .buff-invis { color: var(--dim); }

/* ---------- bottom bar ---------- */
.bottombar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; gap: 6px; justify-content: center;
  padding: 6px calc(var(--safe-r) + 8px) calc(var(--safe-b) + 8px) calc(var(--safe-l) + 8px);
  background: linear-gradient(#0c0a1200, #0c0a12dd);
}
.bottombar.hidden { display: none; }
.bbtn {
  flex: 1; max-width: 120px; min-height: 48px;
  background: var(--bar); border: 1px solid var(--line); color: var(--ink);
  font-size: 18px;
}
.bbtn:active { border-color: var(--ember); box-shadow: 0 0 8px #ff9d5a55 inset; }

/* ---------- touch joystick (movement) ----------
   .joyzone is an INVISIBLE bounding box, bottom-left. Pressing down anywhere
   inside it spawns .joy-base centered on the touch (COD-Mobile / Unity
   floating-stick style) instead of demanding a precise grab at one fixed
   spot. Sizing is clamped hard so it can't balloon on a big-screen phone and
   start eating taps meant for the map or the attack/interact buttons. */
.joyzone {
  display: none;
  position: absolute;
  left: var(--safe-l);
  bottom: calc(var(--safe-b) + 74px); /* clear the bottom action bar */
  --joy-zone-size: clamp(148px, 40vmin, 210px);
  width: var(--joy-zone-size);
  height: var(--joy-zone-size);
  touch-action: none;
  z-index: 15;
}
@media (pointer: coarse) {
  .joyzone { display: block; }
}
body.in-title .joyzone,
body:has(.dialogue:not(.hidden)) .joyzone,
body:has(.scrim:not(.hidden)) .joyzone,
body:has(.howto:not(.hidden)) .joyzone {
  display: none;
}
.joy-base {
  position: absolute;
  width: clamp(82px, 23vmin, 118px);
  height: clamp(82px, 23vmin, 118px);
  border-radius: 50%;
  background: #14111d99;
  border: 1px solid var(--line);
  opacity: 0;
  visibility: hidden;
}
.joy-base.active { opacity: 1; visibility: visible; border-color: var(--ember); }
.joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: 44%; height: 44%;
  border-radius: 50%;
  background: #2b2438cc;
  border: 1px solid var(--dim);
  transform: translate(-50%, -50%);
}
.joy-base.active .joy-knob { background: #ff9d5a4d; border-color: var(--ember); }

/* landscape: shorter screen — keep the zone from creeping into the HUD */
@media (orientation: landscape) {
  .joyzone { --joy-zone-size: clamp(132px, 38vmin, 180px); bottom: calc(var(--safe-b) + 64px); }
}

/* ---------- touch action buttons (attack / interact) ---------- */
.touch-actions {
  display: none;
  position: absolute;
  right: calc(var(--safe-r) + 16px);
  bottom: calc(var(--safe-b) + 78px);
  width: clamp(84px, 24vmin, 128px);
  height: clamp(84px, 24vmin, 128px);
  z-index: 15;
}
@media (pointer: coarse) {
  .touch-actions { display: block; }
}
body.in-title .touch-actions,
body:has(.dialogue:not(.hidden)) .touch-actions,
body:has(.scrim:not(.hidden)) .touch-actions,
body:has(.howto:not(.hidden)) .touch-actions,
body.in-title .interact-hint,
body:has(.dialogue:not(.hidden)) .interact-hint,
body:has(.scrim:not(.hidden)) .interact-hint,
body:has(.howto:not(.hidden)) .interact-hint {
  display: none;
}
.tabtn {
  position: absolute;
  border-radius: 50%;
  background: #14111d99;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 22px;
  touch-action: none;
}
.tabtn:active { background: #2b2438cc; border-color: var(--ember); color: var(--ember); }
.tab-attack { right: 0; bottom: 0; width: 58%; height: 58%; }
.tab-interact { left: 0; top: 0; width: 38%; height: 38%; font-size: 18px; }
.tab-aim { right: 0; top: 0; width: 38%; height: 38%; font-size: 18px; color: var(--shard); }
@media (orientation: landscape) {
  .touch-actions { bottom: calc(var(--safe-b) + 64px); right: calc(var(--safe-r) + 20px); }
}

/* ---------- interact prompt ---------- */
.interact-hint {
  position: absolute;
  left: 50%; bottom: calc(var(--safe-b) + 62px);
  transform: translateX(-50%);
  background: #14111dee;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 15px;
  padding: 4px 10px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 14;
}
.interact-hint.hidden { display: none; }
.hint-touch { display: none; }
@media (pointer: coarse) {
  .hint-kb { display: none; }
  .hint-touch { display: inline; }
}

/* ---------- toasts ---------- */
.toasts { position: absolute; left: 50%; bottom: 84px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 4px; align-items: center; pointer-events: none; width: 92%; max-width: 460px; }
.toast { background: #14111dee; border: 1px solid var(--line); color: var(--ink); font-size: 16px; padding: 4px 10px; text-align: center; transition: opacity .5s; }
.toast.fade { opacity: 0; }
@media (pointer: coarse) {
  .interact-hint,
  .toasts {
    left: 12px; right: 148px; width: auto; max-width: none; transform: none;
    bottom: calc(var(--safe-b) + clamp(170px, 25vh, 220px));
  }
  .interact-hint { overflow-wrap: anywhere; white-space: normal; text-align: center; }
}

/* ---------- sheets ---------- */
.scrim { position: absolute; inset: 0; background: #05040999; }
.scrim.hidden, .sheet.hidden, .inspect.hidden, .title-screen.hidden, .dialogue.hidden, .howto.hidden { display: none; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 70vh; background: var(--bar); border-top: 3px double var(--line);
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-b);
  animation: slideup .16s ease-out;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.sheet-title { font-size: 20px; color: var(--ember); }
.sheet-close { background: none; border: 1px solid var(--line); color: var(--ink); width: 32px; height: 32px; font-size: 16px; }
.sheet-body { overflow-y: auto; padding: 8px 12px 14px; }

.item-row, .up-row { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px solid #1e1a2a; flex-wrap: wrap; }
.item-icon { width: 32px; height: 32px; image-rendering: pixelated; flex: 0 0 auto; }
.item-info { flex: 1; min-width: 120px; }
.item-name { font-size: 17px; color: var(--ink); }
.item-tags { font-size: 13px; color: var(--dim); }
.action-row { display: flex; gap: 6px; width: 100%; margin-top: 4px; flex-wrap: wrap; }
.abtn { min-height: 44px; padding: 0 12px; background: #1c1828; border: 1px solid var(--line); color: var(--ink); font-size: 16px; }
.abtn.buy { color: var(--gold); }
.abtn:active { border-color: var(--ember); }
.owned { color: var(--dim); font-size: 15px; padding: 0 10px; }
.empty { color: var(--dim); font-size: 16px; padding: 16px 4px; text-align: center; }
.sub-head { color: var(--ember); font-size: 16px; margin: 10px 0 4px; }
.shop-note, .shard-count { color: var(--dim); font-size: 15px; padding: 4px 0 8px; font-style: italic; }
.shard-count { color: var(--shard); font-style: normal; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; margin-bottom: 8px; }
.stat { display: flex; justify-content: space-between; border-bottom: 1px solid #1e1a2a; padding: 2px 0; }
.stat-k { color: var(--dim); font-size: 15px; }
.stat-v { color: var(--ink); font-size: 16px; }

.journal .jpage { border: 1px solid var(--line); padding: 8px; margin-bottom: 8px; background: #100d18; }
.jtitle { color: var(--ember); font-size: 17px; margin-bottom: 4px; }
.jtext { color: var(--ink); font-size: 16px; line-height: 1.3; }

/* side card on wide screens */
@media (min-width: 900px) {
  .sheet { left: auto; right: 0; top: 0; bottom: 0; width: 380px; max-height: 100vh; border-top: none; border-left: 3px double var(--line); }
}

/* ---------- inspect ---------- */
.inspect {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
  background: #14111df2; border: 1px solid var(--ember); color: var(--ink);
  font-size: 17px; padding: 10px 14px; max-width: 80%; text-align: center; white-space: pre-line;
}

/* ---------- dialogue ---------- */
.dialogue {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 30;
  /* clear the bottom action bar so the box never slides under the buttons */
  padding: 10px calc(var(--safe-r) + 10px) calc(var(--safe-b) + 86px) calc(var(--safe-l) + 10px);
}
.dlg-inner {
  display: flex; gap: 10px; align-items: stretch;
  background: #100d18f5; border: 3px double var(--line); padding: 10px;
  max-width: 760px; margin: 0 auto;
}
.dlg-portrait { width: 72px; height: 72px; image-rendering: pixelated; border: 1px solid var(--line); background: #07060c; flex: 0 0 auto; }
.dlg-body { flex: 1; display: flex; flex-direction: column; }
.dlg-name { color: var(--ember); font-size: 18px; margin-bottom: 2px; }
.dlg-text { color: var(--ink); font-size: 19px; line-height: 1.3; flex: 1; }
.dlg-hint { color: var(--dim); font-size: 13px; text-align: right; margin-top: 4px; }
.dlg-choices { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.dlg-choices.hidden { display: none; }
.dlg-choice {
  min-height: 44px; padding: 0 14px; text-align: left;
  background: #1c1828; border: 1px solid var(--line); color: var(--ink); font-size: 18px;
}
.dlg-choice:active { border-color: var(--ember); }

/* ---------- title ---------- */
.title-screen {
  position: absolute; inset: 0; z-index: 20; overflow: hidden;
  background: #07060c; color: var(--ink);
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}
.title-atmosphere { position: absolute; inset: 0; overflow: hidden; pointer-events: none; background:
  radial-gradient(circle at 50% 92%, #c8643030 0 8%, transparent 38%),
  radial-gradient(circle at 50% 35%, #35233a 0, #100c18 42%, #050409 85%); }
.title-atmosphere::before { content: ''; position: absolute; inset: 0; opacity: .22; background:
  repeating-linear-gradient(0deg, transparent 0 31px, #9d876d18 32px 33px),
  repeating-linear-gradient(90deg, transparent 0 63px, #9d876d10 64px 65px); }
.title-keep { position: absolute; left: 50%; bottom: -4vh; width: min(920px, 105vw); height: 48vh; transform: translateX(-50%); opacity: .42; background: #030207; clip-path: polygon(0 100%,0 53%,8% 53%,8% 35%,15% 35%,15% 57%,25% 57%,25% 22%,32% 22%,32% 54%,40% 54%,40% 10%,46% 10%,46% 49%,54% 49%,54% 0,61% 0,61% 54%,70% 54%,70% 30%,78% 30%,78% 58%,88% 58%,88% 39%,95% 39%,95% 61%,100% 61%,100% 100%); }
.title-gate { position: absolute; left: 50%; bottom: 0; width: min(310px, 60vw); height: 38vh; transform: translateX(-50%); border: clamp(18px,4vw,42px) solid #0b0810; border-bottom: 0; border-radius: 48% 48% 0 0; box-shadow: 0 0 80px #ff9d5a18 inset, 0 0 40px #000; }
.ember-field i { position: absolute; left: calc(7% + var(--i) * 7.7%); bottom: -10px; width: 3px; height: 3px; background: var(--ember); box-shadow: 0 0 8px var(--ember); opacity: 0; animation: titleEmber calc(5s + var(--i) * .22s) linear calc(var(--i) * -.7s) infinite; }
@keyframes titleEmber { 0% { transform: translate(0,0); opacity: 0; } 15% { opacity: .75; } 70% { opacity: .25; } 100% { transform: translate(calc((var(--i) - 6) * 3px),-92vh); opacity: 0; } }
.title-scroll { position: relative; z-index: 2; width: 100%; height: 100%; overflow-y: auto; overscroll-behavior: contain; display: flex; justify-content: center; align-items: center; padding: clamp(16px,3vh,34px) clamp(14px,3vw,30px); }
.title-card { width: min(860px,100%); display: flex; flex-direction: column; align-items: center; gap: clamp(10px,1.7vh,18px); text-align: center; padding: clamp(18px,3vw,34px); background: linear-gradient(180deg,#100c18e8,#09070ed9); border: 1px solid #57445b; box-shadow: 0 24px 80px #000b,0 0 0 4px #08060cbf,0 0 60px #ff9d5a0d inset; }
.title-header { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.title-kicker,.section-label { color: var(--ember); letter-spacing: 3px; font-size: 14px; }
.title-logo { font-size: clamp(48px,8vw,76px); line-height: .9; color: var(--ink); text-shadow: 3px 3px 0 #8a3f31,0 0 22px #ff9d5a33; letter-spacing: clamp(3px,1vw,9px); font-weight: normal; }
.title-tag { font-size: clamp(18px,2.6vw,24px); color: #b7a9bb; }
.title-premise { width: min(680px,100%); display: flex; align-items: center; gap: 12px; text-align: left; color: #d0c4b6; border-top: 1px solid #392f40; border-bottom: 1px solid #392f40; padding: 10px 14px; background: #08070cb3; font-size: clamp(16px,2vw,19px); line-height: 1.25; }
.premise-mark { color: var(--gold); font-size: 22px; }
.hero-section { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.hero-pick { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 9px; width: 100%; }
.hero-cell { position: relative; border: 1px solid var(--line); padding: 8px 7px; background: #100d18e8; color: var(--ink); display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; min-height: 112px; }
.hero-cell:hover { background: #1a1422; border-color: #71556f; }
.hero-cell canvas { image-rendering: pixelated; width: 56px; height: 56px; }
.hero-cell.sel { border-color: var(--ember); box-shadow: 0 0 16px #ff9d5a44 inset,0 0 12px #ff9d5a33; }
.hero-copy { display: flex; flex-direction: column; gap: 1px; }
.hero-name { font-size: 16px; color: var(--ink); }
.hero-role { font-size: 12px; color: var(--dim); line-height: 1.1; }
.hero-selected { display: none; position: absolute; right: 5px; top: 4px; color: var(--ember); font-size: 10px; letter-spacing: 1px; }
.hero-cell.sel .hero-selected { display: block; }
.title-save { width: min(560px,100%); min-height: 48px; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 7px 12px; border: 1px solid #3a3042; background: #08070caa; text-align: left; }
.title-save span:last-child { display: flex; flex-direction: column; } .title-save strong { color: var(--gold); font-size: 16px; font-weight: normal; } .title-save small { color: var(--dim); font-size: 13px; } .save-flame { color: var(--ember); text-shadow: 0 0 8px var(--ember); }
.title-btns { display: flex; gap: 9px; flex-wrap: wrap; justify-content: center; }
.tbtn { min-height: 48px; padding: 0 20px; background: #17121f; border: 1px solid #4c3c51; color: var(--ink); font-size: 19px; }
.tbtn.primary { border-color: var(--ember); color: #ffe0c5; background: linear-gradient(#3a201d,#231318); box-shadow: 0 0 16px #ff9d5a22 inset; }
.tbtn.quiet { color: var(--dim); }
.tbtn:hover { border-color: var(--ember); } .tbtn:active { box-shadow: 0 0 10px #ff9d5a55 inset; }
#ui button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.title-note { max-width: 650px; color: #756d7d; font-size: 13px; line-height: 1.2; }
body.in-title .hud, body.in-title .bottombar { display: none; }
.title-foot { font-size: 12px; letter-spacing: 2px; color: #625a6a; }
@media (max-width: 620px) { .hero-pick { grid-template-columns: repeat(2,minmax(0,1fr)); } .hero-cell { min-height: 90px; flex-direction: row; justify-content: center; } .hero-cell canvas { width: 48px; height: 48px; } .title-card { padding: 18px 14px; } .title-premise { font-size: 15px; } }
@media (max-height: 700px) and (orientation: landscape) { .title-scroll { align-items: flex-start; } .title-card { display: grid; grid-template-columns: .85fr 1.15fr; gap: 8px 18px; text-align: center; } .title-header,.title-premise,.title-note,.title-foot { grid-column: 1; } .hero-section,.title-save,.title-btns { grid-column: 2; } .hero-section { grid-row: 1 / span 2; align-self: end; } .title-save { grid-row: 3; } .title-btns { grid-row: 4; } .title-note { grid-row: 3; } .title-foot { grid-row: 4; } .hero-pick { grid-template-columns: repeat(2,1fr); } .hero-cell { min-height: 82px; flex-direction: row; } .title-logo { font-size: 46px; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .ember-field i { animation: none; }
}

/* ---------- pause menu ---------- */
.pause-menu { display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.pausebtn-row { width: 100%; min-height: 48px; justify-content: center; display: flex; align-items: center; font-size: 18px; }
.pausebtn-row.quit { color: var(--blood); }
.pause-vol { display: flex; flex-direction: column; gap: 4px; padding: 4px 2px; }
.pause-vol-lab { color: var(--ink-dim, #8b8398); font-size: 13px; letter-spacing: 1px; }
.pause-vol input[type=range] { width: 100%; accent-color: var(--accent, #9df5c2); }

/* ---------- How to Play ---------- */
.howto {
  position: absolute; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: #05040bdd; padding: 16px;
}
.howto-box {
  background: var(--bar); border: 3px double var(--line);
  padding: 16px; max-width: 720px; width: 100%; max-height: 90vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px; align-items: center;
}
.howto-title { font-size: 26px; color: var(--ember); }
.howto-panels { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; width: 100%; }
.howto-panel { flex: 1; min-width: 220px; background: #100d18; border: 1px solid var(--line); padding: 12px; }
.howto-h { color: var(--ember); font-size: 19px; margin-bottom: 6px; }
.howto-panel ul { list-style: none; }
.howto-panel li { font-size: 17px; color: var(--ink); line-height: 1.5; }
.howto-demo { display: flex; justify-content: center; margin-bottom: 8px; }
.howto-knight { image-rendering: pixelated; width: 96px; height: 96px; border: 1px solid var(--line); background: #07060c; }
.howto-tip { margin-top: 10px; color: var(--gold); font-size: 15px; font-style: italic; }
.howto-close { min-height: 48px; padding: 0 24px; }
