/* =========================================================
   DARK SACHI: BLADE OF THE VOID
   Canvas void-runner · brand-matched UI
   ========================================================= */

:root {
  --void:        #050508;
  --void-2:      #0a0a14;
  --char:        #141421;
  --char-2:      #1b1a2b;
  --line:        #2a2540;
  --purple:      #4B0082;
  --magenta:     #FF1A4B;
  --magenta-2:   #ff3a6a;
  --gold:        #FFC83A;
  --green:       #7BFFA1;
  --ink:         #f6f3ff;
  --ink-2:       #cfc8ea;
  --ink-3:       #948cb5;

  --f-display: 'Cabinet Grotesk','Satoshi',ui-sans-serif,system-ui,sans-serif;
  --f-body:    'Satoshi',ui-sans-serif,system-ui,sans-serif;
  --f-mono:    'JetBrains Mono',ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;

  --r-sm: 8px;
  --r:    14px;
  --r-lg: 22px;
  --ease: cubic-bezier(.22,.61,.36,1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--void);
  color: var(--ink);
  font-family: var(--f-body);
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--magenta); color: #fff; }

/* ============ STAGE ============ */
.stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  background:
    radial-gradient(120% 90% at 50% -10%, #150d24 0%, var(--void) 60%);
  overflow: hidden;
  touch-action: none;
}
#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ============ HUD ============ */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 18px 0;
  pointer-events: none;
  z-index: 6;
  transition: opacity .35s var(--ease);
}
.hud--hidden { opacity: 0; }
.hud__left, .hud__right { display: flex; align-items: center; gap: 14px; }
.hud__brand {
  color: var(--ink);
  opacity: .85;
  pointer-events: auto;
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(10,10,20,.45);
  backdrop-filter: blur(8px);
  transition: opacity .2s var(--ease), border-color .2s var(--ease);
}
.hud__brand:hover { opacity: 1; border-color: var(--magenta); }
.hud__hearts { display: flex; gap: 6px; }
.heart {
  width: 22px; height: 22px;
  transition: transform .2s var(--ease), opacity .3s var(--ease);
}
.heart svg { width: 100%; height: 100%; display: block; }
.heart--lost { opacity: .22; transform: scale(.82); }
.heart--pulse { animation: heartpulse .5s var(--ease); }
@keyframes heartpulse { 0%,100%{transform:scale(1);} 40%{transform:scale(1.45);} }

.hud__score {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  background: rgba(10,10,20,.45);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 5px 12px;
  line-height: 1;
}
.hud__label {
  font-family: var(--f-mono);
  font-size: 9px;
  letter-spacing: .22em;
  color: var(--ink-3);
}
.hud__value {
  font-family: var(--f-mono);
  font-weight: 500;
  font-size: 22px;
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--gold);
  margin-top: 3px;
}

/* level tag */
.hud__level {
  font-family: var(--f-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .16em;
  color: var(--ink-2);
  background: rgba(10,10,20,.45);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 7px 11px;
  backdrop-filter: blur(8px);
}
.hud__level--boss {
  color: #fff;
  border-color: var(--magenta);
  background: rgba(255,26,75,.18);
  box-shadow: 0 0 18px -4px var(--magenta);
  animation: bosspulse 1.1s infinite;
}
@keyframes bosspulse { 0%,100%{opacity:1;} 50%{opacity:.6;} }

/* ============ BOSS HP BAR ============ */
.bossbar {
  position: absolute;
  top: max(64px, calc(env(safe-area-inset-top) + 56px));
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  width: min(560px, 84vw);
  z-index: 6;
  opacity: 0;
  pointer-events: none;
  transition: opacity .4s var(--ease), transform .4s var(--ease);
}
.bossbar--show { opacity: 1; transform: translateX(-50%) translateY(0); }
.bossbar__label {
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: .26em;
  color: var(--magenta-2);
  text-align: center;
  margin-bottom: 5px;
  text-shadow: 0 0 10px rgba(255,26,75,.6);
}
.bossbar__track {
  height: 12px;
  border-radius: 100px;
  background: rgba(8,6,18,.7);
  border: 1px solid var(--magenta);
  box-shadow: 0 0 20px -6px var(--magenta), inset 0 0 8px rgba(0,0,0,.6);
  overflow: hidden;
}
.bossbar__fill {
  height: 100%;
  width: 100%;
  border-radius: 100px;
  background: linear-gradient(90deg, var(--purple), var(--magenta) 60%, var(--gold));
  box-shadow: 0 0 12px rgba(255,26,75,.7);
  transition: width .25s var(--ease);
}

/* ============ LEVEL BANNER ============ */
.banner {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s var(--ease);
  padding: 24px;
}
.banner--show { opacity: 1; }
.banner__title {
  font-family: var(--f-display);
  font-weight: 800;
  font-size: clamp(1.6rem, 7vw, 3rem);
  letter-spacing: -.01em;
  color: var(--ink);
  text-shadow: 0 0 30px rgba(75,0,130,.8), 0 2px 12px rgba(0,0,0,.8);
  transform: translateY(8px);
  transition: transform .5s var(--ease);
}
.banner--show .banner__title { transform: translateY(0); }
.banner__sub {
  margin-top: 12px;
  font-family: var(--f-mono);
  font-size: clamp(.78rem, 2.6vw, .95rem);
  letter-spacing: .04em;
  color: var(--magenta-2);
  text-shadow: 0 0 14px rgba(255,26,75,.5);
  max-width: 34ch;
}

/* ============ OVERLAYS ============ */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(110% 90% at 50% 30%, rgba(8,6,18,.55) 0%, rgba(5,5,8,.86) 70%);
  backdrop-filter: blur(3px);
  animation: fadein .4s var(--ease);
}
.overlay[hidden] { display: none; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: min(560px, 100%);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.panel__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 100px;
  padding: 6px 14px;
  margin-bottom: 22px;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--magenta);
  box-shadow: 0 0 12px var(--magenta);
  animation: blink 2s infinite;
}
@keyframes blink { 0%,100%{opacity:1;} 50%{opacity:.35;} }

.panel__title {
  font-family: var(--f-display);
  font-weight: 800;
  font-size: clamp(2.1rem, 8vw, 3.6rem);
  line-height: .98;
  letter-spacing: -.02em;
  margin: 0 0 16px;
  color: var(--ink);
  text-shadow: 0 4px 40px rgba(75,0,130,.6);
}
.panel__title em {
  font-style: normal;
  color: var(--magenta);
  text-shadow: 0 0 28px rgba(255,26,75,.55);
}
.panel__title--over em { color: var(--gold); text-shadow: 0 0 28px rgba(255,200,58,.45); }
.panel__title--win em { color: var(--green); text-shadow: 0 0 28px rgba(123,255,161,.5); }
.panel__eyebrow--win { border-color: rgba(255,200,58,.4); color: var(--gold); }
.dot--gold { background: var(--gold); box-shadow: 0 0 12px var(--gold); }
.panel__lede {
  color: var(--ink-2);
  font-size: clamp(1rem, 3.5vw, 1.18rem);
  line-height: 1.5;
  max-width: 30ch;
  margin: 0 0 28px;
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-family: var(--f-body);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .01em;
  border-radius: 100px;
  padding: 13px 26px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform .15s var(--ease), box-shadow .2s var(--ease), background .2s var(--ease), border-color .2s var(--ease);
  text-decoration: none;
  color: var(--ink);
  user-select: none;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn--lg { font-size: 17px; padding: 16px 34px; }
.btn--primary {
  background: linear-gradient(135deg, var(--magenta), var(--purple));
  color: #fff;
  box-shadow: 0 8px 30px -8px rgba(255,26,75,.6), inset 0 1px 0 rgba(255,255,255,.16);
}
.btn--primary:hover { box-shadow: 0 12px 40px -8px rgba(255,26,75,.8), inset 0 1px 0 rgba(255,255,255,.2); transform: translateY(-1px); }
.btn--ghost {
  background: rgba(255,255,255,.03);
  border-color: var(--line);
  color: var(--ink-2);
}
.btn--ghost:hover { border-color: var(--magenta); color: var(--ink); }
.btn--gold {
  background: rgba(255,200,58,.1);
  border-color: rgba(255,200,58,.45);
  color: var(--gold);
}
.btn--gold:hover { background: rgba(255,200,58,.18); border-color: var(--gold); }
.btn--x {
  background: rgba(255,255,255,.04);
  border-color: var(--line);
  color: var(--ink);
}
.btn--x:hover { background: #fff; color: #000; border-color: #fff; }

/* ============ HOW TO PLAY ============ */
.howto {
  display: flex;
  gap: 10px;
  margin-top: 30px;
  flex-wrap: wrap;
  justify-content: center;
}
.howto__row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-3);
}
kbd {
  font-family: var(--f-mono);
  font-size: 12px;
  color: var(--ink);
  background: var(--char-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 4px 9px;
  min-width: 22px;
  text-align: center;
}
.howto__mobile {
  display: none;
  margin-top: 26px;
  font-size: 13px;
  color: var(--ink-3);
}

/* ============ FINAL SCORE ============ */
.finalscore {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 8px 0 30px;
}
.finalscore__label {
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: .24em;
  color: var(--ink-3);
}
.finalscore__value {
  font-family: var(--f-display);
  font-weight: 800;
  font-size: clamp(3rem, 14vw, 5rem);
  line-height: 1;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 40px rgba(255,200,58,.4);
}
.finalscore__best {
  font-family: var(--f-mono);
  font-size: 12px;
  letter-spacing: .12em;
  color: var(--ink-3);
}
.overactions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: min(420px, 100%);
}
.overactions .btn { width: 100%; }
.overactions .btn--primary { grid-column: 1 / -1; }
.overactions .btn--gold { grid-column: 1 / -1; }

/* ============ MOBILE TOUCH CONTROLS ============ */
.touchpad {
  position: absolute;
  left: 0; right: 0;
  bottom: max(18px, env(safe-area-inset-bottom));
  padding: 0 20px;
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  z-index: 7;
  pointer-events: none;
}
.touchpad__right { display: flex; gap: 14px; pointer-events: none; }
.tbtn {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 74px; height: 74px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(20,16,33,.6);
  backdrop-filter: blur(8px);
  color: var(--ink-2);
  font-family: var(--f-mono);
  font-size: 9px;
  letter-spacing: .12em;
  transition: transform .1s var(--ease), background .15s var(--ease), border-color .15s var(--ease);
}
.tbtn svg { width: 28px; height: 28px; }
.tbtn:active, .tbtn--active { transform: scale(.9); }
.tbtn--jump:active, .tbtn--jump.tbtn--active { background: rgba(123,255,161,.22); border-color: var(--green); color: var(--green); }
.tbtn--slash:active, .tbtn--slash.tbtn--active { background: rgba(255,26,75,.22); border-color: var(--magenta); color: var(--magenta-2); }
.tbtn--dash:active, .tbtn--dash.tbtn--active { background: rgba(255,200,58,.2); border-color: var(--gold); color: var(--gold); }

/* show touch controls on coarse pointers / narrow screens */
body.is-touch .touchpad { display: flex; }
body.is-touch .howto { display: none; }
body.is-touch .howto__mobile { display: block; }

@media (max-width: 540px) {
  .overactions { grid-template-columns: 1fr 1fr; }
  .tbtn { width: 66px; height: 66px; }
  .tbtn svg { width: 24px; height: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .dot, .heart--pulse { animation: none; }
  .overlay { animation: none; }
}
