/* ASHEN SOULS — HUD styling. Dark Souls register: thin bevelled bars, bronze frames,
   wide-spaced serif capitals, slow fades, the "YOU DIED" moment. */

:root {
  --serif: "Cinzel", "Trajan Pro", "Optima", "Times New Roman", Georgia, serif;
  --hp: #a01616;
  --hp-bright: #c02020;
  --chip: #d9c9a3;
  --stam: #4d7a26;
  --stam-bright: #66a032;
  --frame: #6d6551;
  --frame-dark: #26241f;
  --ink: #ded6c4;
  --gold: #d9c69a;
  --hud-scale: 1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: #07070a; color: var(--ink);
  font-family: var(--serif);
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
}

#app { position: fixed; inset: 0; overflow: hidden; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; background: #0a0b0e; }

/* ---------------------------------------------------------------- HUD frame */

#hud { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.hidden { display: none !important; }

#hud-left {
  position: absolute; top: calc(18px + env(safe-area-inset-top)); left: calc(22px + env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 7px;
  transform: scale(var(--hud-scale)); transform-origin: top left;
}

.bar {
  position: relative; height: 15px; width: clamp(210px, 24vw, 360px);
  background: linear-gradient(#161412, #0d0c0b);
  border: 1px solid #0a0908;
  box-shadow: 0 0 0 1px rgba(120, 108, 84, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 2px 6px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
.bar-stam { width: clamp(160px, 18vw, 268px); height: 12px; }
.bar-fp { width: clamp(120px, 13vw, 200px); height: 9px; }
.bar-fp .bar-label { position: absolute; left: 6px; top: -2px; font-size: 8px; letter-spacing: 0.3em; color: rgba(200, 214, 232, 0.5); }
.bar-fp .bar-fill { background: linear-gradient(#3c5f86, #23364d); }

.bar-fill, .bar-chip {
  position: absolute; left: 0; top: 0; bottom: 0; width: 100%;
  transform-origin: left center;
  transition: none;
}
.bar-chip {
  background: linear-gradient(rgba(226, 210, 174, 0.85), rgba(180, 160, 120, 0.5));
  opacity: 0; z-index: 1;
}
.bar-fill { z-index: 2; }
.bar-hp .bar-fill { background: linear-gradient(#c62222, #8d1010 65%, #6d0c0c); box-shadow: inset 0 1px 0 rgba(255, 190, 190, 0.28); }
.bar-stam .bar-fill { background: linear-gradient(#73b23a, #3f6a1f 70%, #33571a); box-shadow: inset 0 1px 0 rgba(220, 255, 190, 0.28); }
.bar-boss .bar-fill { background: linear-gradient(#b31f1f, #7c1212 60%, #5c0c0c); }
.bar-frame {
  position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background: repeating-linear-gradient(90deg, rgba(0,0,0,0.16) 0 12px, rgba(255,255,255,0.02) 12px 24px);
}

/* ---------------------------------------------------------------- souls */

#hud-souls {
  position: absolute; top: calc(20px + env(safe-area-inset-top)); right: calc(24px + env(safe-area-inset-right));
  display: flex; align-items: center; gap: 10px;
  font-size: 25px; letter-spacing: 0.06em; color: #e8e2d2;
  text-shadow: 0 2px 6px #000, 0 0 18px rgba(180, 200, 255, 0.25);
}
.icon-souls { width: 22px; height: 22px; color: #cfe1ff; filter: drop-shadow(0 0 6px rgba(150, 190, 255, 0.6)); }

/* ---------------------------------------------------------------- equipment */

#hud-equip {
  position: absolute; left: calc(22px + env(safe-area-inset-left)); bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex; gap: 10px; align-items: flex-end;
  transform: scale(var(--hud-scale)); transform-origin: bottom left;
}
.slot {
  position: relative; width: 62px; height: 62px;
  background: linear-gradient(160deg, rgba(28, 26, 22, 0.82), rgba(12, 11, 10, 0.86));
  border: 1px solid rgba(130, 118, 92, 0.5);
  box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.7), 0 2px 8px rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
}
.slot svg { width: 68%; height: 68%; opacity: 0.95; }
.slot-key { position: absolute; right: 3px; bottom: 1px; font-size: 9px; letter-spacing: 0.08em; color: rgba(210, 198, 166, 0.55); }
.slot-estus .estus-count {
  position: absolute; right: 5px; top: 1px; font-size: 22px; color: #f1e6c8;
  text-shadow: 0 0 10px rgba(255, 190, 90, 0.6), 0 2px 4px #000;
}
.slot-estus.depleted { filter: grayscale(0.85) brightness(0.7); }
.slot-estus.depleted .estus-count { color: #9d9481; text-shadow: none; }
.slot.active { border-color: rgba(230, 205, 140, 0.9); box-shadow: 0 0 14px rgba(220, 190, 120, 0.35), inset 0 0 14px rgba(0, 0, 0, 0.7); }

/* ---------------------------------------------------------------- boss bar */

#boss-wrap {
  position: absolute; left: 50%; bottom: calc(34px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(58vw, 720px);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  opacity: 0; transition: opacity 0.6s ease;
}
#boss-wrap.show { opacity: 1; }
#boss-name {
  font-size: clamp(13px, 1.5vw, 19px); letter-spacing: 0.36em; color: #ded4bd;
  text-shadow: 0 2px 8px #000; padding-left: 0.36em;
}
.bar-boss { width: 100%; height: 13px; }

/* ---------------------------------------------------------------- title cards */

#banner-wrap {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; pointer-events: none;
}
#banner {
  font-size: clamp(40px, 9.5vw, 140px); letter-spacing: 0.16em; text-align: center;
  opacity: 0; color: #8f1010; padding-left: 0.16em;
  text-shadow: 0 0 40px rgba(0, 0, 0, 0.9), 0 6px 22px #000;
  transition: opacity 2.2s ease;
}
#banner.show { opacity: 1; }
#banner.death { color: #7e0d0d; }
#banner.victory { color: #d6c79c; font-size: clamp(26px, 5.2vw, 76px); letter-spacing: 0.22em; }
#banner.zone { color: #cfc3a4; font-size: clamp(22px, 3.6vw, 52px); letter-spacing: 0.34em; }
#banner-sub {
  font-size: clamp(12px, 1.4vw, 18px); letter-spacing: 0.28em; color: rgba(214, 204, 178, 0.72);
  opacity: 0; transition: opacity 2.4s ease; text-align: center;
}
#banner-sub.show { opacity: 1; }

#zone-title {
  position: absolute; left: 50%; bottom: 22%; transform: translateX(-50%);
  font-size: clamp(16px, 2.4vw, 30px); letter-spacing: 0.4em; color: #d8cdb0;
  opacity: 0; transition: opacity 1.6s ease; text-shadow: 0 3px 12px #000;
  white-space: nowrap;
}
#zone-title.show { opacity: 0.92; }

/* ---------------------------------------------------------------- prompts & toasts */

#prompt {
  position: absolute; left: 50%; bottom: 21%; transform: translateX(-50%);
  padding: 8px 20px; font-size: 16px; letter-spacing: 0.16em; color: #e6dcc4;
  background: linear-gradient(rgba(12, 11, 10, 0.78), rgba(6, 6, 6, 0.72));
  border-top: 1px solid rgba(150, 136, 106, 0.5);
  border-bottom: 1px solid rgba(150, 136, 106, 0.5);
  opacity: 0; transition: opacity 0.25s ease; white-space: nowrap;
}
#prompt.show { opacity: 1; }
#prompt b { color: #f4e7c4; }

#toasts {
  position: absolute; right: calc(26px + env(safe-area-inset-right)); top: 30%;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
.toast {
  padding: 7px 14px; font-size: 14px; letter-spacing: 0.12em; color: #e3d9c0;
  background: linear-gradient(rgba(14, 13, 11, 0.8), rgba(8, 7, 7, 0.8));
  border-left: 2px solid rgba(180, 156, 108, 0.8);
  opacity: 0; transform: translateX(12px); transition: opacity 0.4s ease, transform 0.4s ease;
}
.toast.show { opacity: 1; transform: translateX(0); }

#stance-break {
  position: absolute; left: 50%; top: 26%; transform: translateX(-50%);
  font-size: clamp(18px, 2.6vw, 34px); letter-spacing: 0.3em; color: #f0e2b8;
  opacity: 0; transition: opacity 0.3s ease; text-shadow: 0 0 22px rgba(255, 210, 120, 0.5), 0 3px 10px #000;
}
#stance-break.show { opacity: 1; }

/* ---------------------------------------------------------------- screen effects */

#vignette {
  position: absolute; inset: 0; pointer-events: none; z-index: 6;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 42%, rgba(0,0,0,0.42) 84%, rgba(0,0,0,0.72) 100%);
  mix-blend-mode: multiply;
}
#grain {
  position: absolute; inset: -50%; pointer-events: none; z-index: 7; opacity: 0.055;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/></filter><rect width='180' height='180' filter='url(%23n)' opacity='0.7'/></svg>");
  animation: grainShift 0.7s steps(3) infinite;
}
@keyframes grainShift {
  0% { transform: translate(0, 0); }
  33% { transform: translate(-3%, 2%); }
  66% { transform: translate(2%, -3%); }
  100% { transform: translate(0, 0); }
}
#damage-flash {
  position: absolute; inset: 0; pointer-events: none; z-index: 8; opacity: 0;
  background: radial-gradient(ellipse at center, rgba(120, 0, 0, 0) 38%, rgba(140, 8, 8, 0.55) 100%);
  transition: opacity 0.28s ease;
}
#lowhp {
  position: absolute; inset: 0; pointer-events: none; z-index: 8; opacity: 0;
  background: radial-gradient(ellipse at center, rgba(90, 0, 0, 0) 45%, rgba(110, 4, 4, 0.5) 100%);
  animation: lowhpPulse 1.5s ease-in-out infinite;
}
#lowhp.show { opacity: 1; }
@keyframes lowhpPulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.85; } }
#fade {
  position: absolute; inset: 0; pointer-events: none; z-index: 20; background: #000; opacity: 0;
  transition: opacity 0.8s ease;
}
#fade.white { background: #eef2f7; }
#fade.instant { transition: opacity 0.05s linear; }
#fade.show { opacity: 1; }

/* ---------------------------------------------------------------- title screen */

#title {
  position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4vh;
  background: linear-gradient(rgba(6, 6, 9, 0.55), rgba(4, 4, 6, 0.88) 70%, #040406);
  transition: opacity 1.4s ease;
}
#title.hide { opacity: 0; pointer-events: none; }
.title-inner { display: flex; flex-direction: column; align-items: center; gap: 1.1rem; padding: 0 6vw; text-align: center; }
.title-emblem { width: clamp(70px, 9vw, 120px); color: #b9ab84; opacity: 0.9; animation: emblemPulse 7s ease-in-out infinite; }
@keyframes emblemPulse { 0%, 100% { opacity: 0.62; } 50% { opacity: 0.95; } }
.title-emblem svg { width: 100%; height: auto; display: block; }
#title h1 {
  margin: 0; font-size: clamp(38px, 8vw, 116px); font-weight: 400; letter-spacing: 0.22em;
  color: #ded2b4; text-shadow: 0 0 60px rgba(210, 180, 120, 0.28), 0 6px 26px #000; padding-left: 0.22em;
}
#title h2 {
  margin: 0; font-size: clamp(13px, 1.7vw, 22px); font-weight: 400; letter-spacing: 0.46em;
  color: rgba(206, 194, 164, 0.72); padding-left: 0.46em;
}
.title-flavor { max-width: 46ch; font-size: clamp(12px, 1.2vw, 16px); line-height: 1.9; color: rgba(196, 186, 162, 0.62); font-style: italic; letter-spacing: 0.06em; }
.title-keys { margin-top: 2vh; }
.press { font-size: clamp(13px, 1.5vw, 19px); letter-spacing: 0.3em; color: #efe4c6; animation: pressPulse 2.6s ease-in-out infinite; }
@keyframes pressPulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }
.subkeys { max-width: 78ch; font-size: clamp(10px, 1vw, 12.5px); line-height: 2; letter-spacing: 0.1em; color: rgba(178, 168, 146, 0.6); }
.title-foot {
  position: absolute; bottom: calc(20px + env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center;
  font-size: clamp(9px, 0.9vw, 12px); letter-spacing: 0.16em; color: rgba(150, 142, 124, 0.5); padding: 0 6vw;
}

/* ---------------------------------------------------------------- controls overlay */

#controls, #pause {
  position: absolute; inset: 0; z-index: 22; display: flex; align-items: center; justify-content: center;
  background: rgba(4, 4, 6, 0.82);
}
.controls-panel, .pause-panel {
  width: min(760px, 90vw); max-height: 86vh; overflow: auto; padding: clamp(18px, 3vw, 34px);
  background: linear-gradient(rgba(20, 19, 17, 0.96), rgba(11, 11, 12, 0.97));
  border: 1px solid rgba(140, 126, 98, 0.45);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), inset 0 0 40px rgba(0, 0, 0, 0.5);
}
.controls-panel h3, .pause-panel h3 {
  margin: 0 0 18px; font-weight: 400; letter-spacing: 0.34em; font-size: clamp(15px, 1.8vw, 22px);
  color: #ded1af; text-align: center;
}
.controls-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px 22px; }
.controls-grid > div { display: flex; align-items: baseline; gap: 12px; font-size: 13.5px; letter-spacing: 0.05em; }
.controls-grid b { min-width: 8.6em; color: #e9dcb6; font-weight: 400; letter-spacing: 0.12em; }
.controls-grid span { color: rgba(198, 189, 168, 0.78); }
.controls-note { margin-top: 20px; font-size: 12.5px; line-height: 1.9; color: rgba(186, 176, 152, 0.66); border-top: 1px solid rgba(120, 108, 84, 0.3); padding-top: 14px; }
.controls-close, .pause-hint { margin-top: 14px; text-align: center; font-size: 12px; letter-spacing: 0.2em; color: rgba(170, 160, 138, 0.6); }
#pause-stats { text-align: center; font-size: 13.5px; line-height: 2; color: rgba(206, 196, 172, 0.85); }

/* ---------------------------------------------------------------- touch */

#touch { position: absolute; inset: 0; z-index: 12; pointer-events: none; }
#touch-stick {
  position: absolute; left: calc(18px + env(safe-area-inset-left)); bottom: calc(24px + env(safe-area-inset-bottom));
  width: min(30vw, 150px); height: min(30vw, 150px); border-radius: 50%;
  background: radial-gradient(circle, rgba(30, 30, 32, 0.5), rgba(12, 12, 14, 0.28));
  border: 1px solid rgba(160, 148, 118, 0.35); pointer-events: auto; touch-action: none;
}
#touch-stick-knob {
  position: absolute; left: 50%; top: 50%; width: 42%; height: 42%; margin: -21% 0 0 -21%;
  border-radius: 50%; background: radial-gradient(circle at 40% 35%, rgba(206, 196, 168, 0.6), rgba(70, 66, 56, 0.5));
  border: 1px solid rgba(210, 196, 160, 0.4);
}
#touch-look { position: absolute; right: 0; top: 0; width: 55%; height: 68%; pointer-events: auto; touch-action: none; }
.touch-buttons {
  position: absolute; right: calc(14px + env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom));
  width: 46vw; max-width: 260px; height: 40vh; max-height: 240px; pointer-events: none;
}
.tb {
  position: absolute; pointer-events: auto; font-family: var(--serif); letter-spacing: 0.12em;
  color: #e5dabb; background: radial-gradient(circle at 40% 35%, rgba(46, 44, 40, 0.72), rgba(14, 14, 15, 0.68));
  border: 1px solid rgba(160, 146, 116, 0.5); border-radius: 50%;
  font-size: 11px; touch-action: none;
}
.tb.is-down { background: radial-gradient(circle at 40% 35%, rgba(120, 100, 60, 0.8), rgba(40, 34, 24, 0.75)); }
.tb-big { right: 2%; bottom: 4%; width: 34%; aspect-ratio: 1; font-size: 12px; }
.tb-mid { right: 40%; bottom: 26%; width: 27%; aspect-ratio: 1; }
.tb-small { width: 22%; aspect-ratio: 1; font-size: 9px; }
.tb-small:nth-of-type(1) { right: 4%; bottom: 70%; }
.tb-small:nth-of-type(2) { right: 40%; bottom: 74%; }
.tb-small:nth-of-type(3) { right: 74%; bottom: 60%; }

/* ---------------------------------------------------------------- boot */

#boot {
  position: absolute; inset: 0; z-index: 40; background: #050506; display: flex;
  align-items: center; justify-content: center; transition: opacity 1s ease;
}
#boot.hide { opacity: 0; pointer-events: none; }
.boot-text { font-size: 13px; letter-spacing: 0.4em; color: rgba(200, 188, 158, 0.75); animation: pressPulse 2.4s ease-in-out infinite; }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 900px), (max-height: 560px) {
  :root { --hud-scale: 0.86; }
  #boss-wrap { width: min(78vw, 560px); bottom: calc(96px + env(safe-area-inset-bottom)); }
  #prompt { bottom: 30%; font-size: 13px; }
  #hud-souls { font-size: 19px; }
  #hud-souls .icon-souls { width: 18px; height: 18px; }
  .slot { width: 52px; height: 52px; }
  .slot-estus .estus-count { font-size: 18px; }
}
@media (max-width: 560px) {
  :root { --hud-scale: 0.78; }
  #hud-left { top: calc(12px + env(safe-area-inset-top)); left: calc(12px + env(safe-area-inset-left)); }
  #hud-souls { top: calc(14px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); }
  #hud-equip { left: calc(12px + env(safe-area-inset-left)); bottom: calc(12px + env(safe-area-inset-bottom)); }
  #boss-wrap { bottom: calc(120px + env(safe-area-inset-bottom)); }
  #zone-title { white-space: normal; width: 90vw; text-align: center; }
}
@media (max-aspect-ratio: 3/4) {
  #boss-wrap { width: 88vw; }
}


/* ---------------------------------------------------------------- touch layouts */
@media (pointer: coarse) {
  /* equipment moves under the bars so the virtual stick owns the lower left */
  #hud-equip {
    top: calc(84px + env(safe-area-inset-top));
    bottom: auto;
    left: calc(14px + env(safe-area-inset-left));
    transform: scale(0.82);
    transform-origin: top left;
  }
  .slot { width: 48px; height: 48px; }
  .slot-key { display: none; }
  #toasts {
    top: calc(84px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    align-items: flex-end;
    max-width: 46vw;
  }
  .toast { font-size: 12px; padding: 6px 10px; text-align: right; }
  #zone-title { bottom: 52%; font-size: 15px; letter-spacing: 0.28em; }
  #prompt { bottom: 40%; font-size: 12.5px; padding: 6px 12px; white-space: normal; max-width: 84vw; text-align: center; }
  #boss-wrap { bottom: calc(27vh + env(safe-area-inset-bottom)); }
  #touch-stick { bottom: calc(18px + env(safe-area-inset-bottom)); }
  .touch-buttons { bottom: calc(14px + env(safe-area-inset-bottom)); }
}
@media (max-height: 500px) and (pointer: coarse) {
  /* landscape phone: keep the middle of the screen clear */
  #hud-equip { top: calc(66px + env(safe-area-inset-top)); transform: scale(0.72); }
  #boss-wrap { bottom: calc(20px + env(safe-area-inset-bottom)); width: 62vw; }
  #zone-title { bottom: 58%; }
  .touch-buttons { width: 40vw; height: 52vh; }
}
