/* ============================================================
   Nightfall — UI shell
   Canvas draws the world; everything here is chrome on top.
   ============================================================ */

:root {
  --bg: #07050c;
  --ink: #f2ecff;
  --dim: #a99cc4;
  --line: rgba(180, 150, 255, .18);
  --panel: rgba(18, 11, 30, .92);
  --blood: #e0345a;
  --blood-dark: #7d0f2b;
  --xp: #57d8ff;
  --gold: #ffd166;
  --violet: #a06bff;
  --radius: 14px;
  --font: "Trebuchet MS", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
}

#app {
  position: fixed;
  inset: 0;
  display: block;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #07050c;
  touch-action: none;
}

.hidden { display: none !important; }

#vignette, #hurt {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

#vignette {
  background: radial-gradient(ellipse at center,
    rgba(0, 0, 0, 0) 34%, rgba(0, 0, 0, .55) 78%, rgba(0, 0, 0, .88) 100%);
}

#hurt {
  background: var(--blood);
  opacity: 0;
  mix-blend-mode: screen;
  will-change: opacity;
}

/* ============================================================
   HUD
   ============================================================ */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px calc(env(safe-area-inset-bottom, 0px) + 10px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-variant-numeric: tabular-nums;
  z-index: 2;
}

.hud-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.hud-left { display: flex; align-items: center; gap: 8px; flex: 1 1 0; min-width: 0; max-width: 340px; }
.hud-center { text-align: center; flex: 0 0 auto; }
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: 1 1 0; min-width: 0; }

.bar {
  position: relative;
  height: 16px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .55);
  border: 1px solid var(--line);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .6);
}

.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  border-radius: 999px;
  transition: width .12s linear;
}

.hp-bar { flex: 1 1 auto; min-width: 90px; }
.hp-bar .bar-fill { background: linear-gradient(180deg, #ff5c7a, var(--blood) 55%, var(--blood-dark)); }

.bar-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-shadow: 0 1px 2px #000, 0 0 6px #000;
}

.lvl-chip {
  display: flex;
  align-items: baseline;
  gap: 3px;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(87, 216, 255, .14);
  border: 1px solid rgba(87, 216, 255, .45);
  color: var(--xp);
  font-weight: 800;
  font-size: 14px;
  line-height: 1.3;
  white-space: nowrap;
}
.lvl-word { font-size: 9px; opacity: .8; letter-spacing: .1em; }

.timer {
  font-size: clamp(22px, 5vw, 34px);
  font-weight: 800;
  letter-spacing: .06em;
  line-height: 1;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .9);
}

.wave {
  font-size: 10px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--dim);
  margin-top: 3px;
}

.stat { display: flex; align-items: baseline; gap: 6px; line-height: 1.15; }
.stat-k { font-size: 9px; letter-spacing: .16em; color: var(--dim); }
.stat-v { font-size: clamp(13px, 2.6vw, 17px); font-weight: 800; }

/* boss */
.boss-wrap {
  position: absolute;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 74px);
  transform: translateX(-50%);
  width: min(560px, 82vw);
  text-align: center;
}
.boss-name {
  font-size: 11px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: #ffb3c2;
  margin-bottom: 4px;
  text-shadow: 0 1px 6px #000;
}
.boss-bar { height: 11px; }
.boss-bar .bar-fill { background: linear-gradient(180deg, #ff8fa3, #c31437 60%, #4a0616); }

/* bottom */
.hud-bottom { display: flex; flex-direction: column; gap: 7px; }

.loadout { display: flex; flex-wrap: wrap; gap: 5px; }

.chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(24, 14, 38, .8);
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
}
.chip .ic { font-style: normal; font-size: 11px; line-height: 1; }
.chip b { font-weight: 700; }
.chip .lv { color: var(--gold); font-size: 10px; }
.chip.max .lv { color: #7dffa8; }
.chip.pass { opacity: .78; }

.xp-bar { height: 9px; }
.xp-bar .bar-fill {
  background: linear-gradient(180deg, #a5edff, var(--xp) 60%, #1b7fa8);
  box-shadow: 0 0 12px rgba(87, 216, 255, .55);
}

.hud-buttons {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  right: 12px;
  display: flex;
  gap: 6px;
  pointer-events: auto;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(18, 11, 30, .8);
  color: var(--ink);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s, transform .1s;
}
.icon-btn:hover { background: rgba(50, 30, 80, .9); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.off { color: #6b5f85; }

/* Give the right-hand stats room to clear the pause/mute buttons. */
.hud-right { padding-right: 82px; }

/* ============================================================
   Overlay screens
   ============================================================ */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: block;
  pointer-events: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(10, 5, 20, .82), rgba(4, 2, 8, .96));
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  pointer-events: auto;
  overflow-y: auto;
  animation: fade .18s ease-out;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: min(520px, 100%);
  max-height: 100%;
  padding: clamp(18px, 4vw, 30px);
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .75), inset 0 1px 0 rgba(255, 255, 255, .05);
  text-align: center;
}
.panel-wide { width: min(760px, 100%); }
.panel-sm { width: min(420px, 100%); }

.title {
  font-size: clamp(40px, 11vw, 76px);
  font-weight: 900;
  letter-spacing: .04em;
  line-height: .95;
  background: linear-gradient(180deg, #fff 10%, #ff87a3 55%, var(--blood) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 18px rgba(224, 52, 90, .45));
}
.title span { display: inline; opacity: .92; }

.tagline {
  color: var(--dim);
  font-size: clamp(12px, 2.6vw, 15px);
  margin: 8px 0 20px;
  letter-spacing: .04em;
}

.h1 { font-size: clamp(24px, 6vw, 34px); font-weight: 800; letter-spacing: .04em; margin-bottom: 12px; }
.h1.dead { color: var(--blood); text-shadow: 0 0 26px rgba(224, 52, 90, .5); }
.h2 { font-size: 11px; letter-spacing: .2em; text-transform: uppercase; color: var(--dim); margin-bottom: 10px; }

.cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  margin-top: 24px;
  text-align: left;
  border-top: 1px solid var(--line);
  padding-top: 20px;
}
.col { min-width: 0; }

.keys { list-style: none; font-size: 12px; color: var(--dim); line-height: 2.1; }
.keys em { font-style: normal; color: var(--ink); opacity: .85; }

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, .07);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
}

.note { font-size: 11px; color: var(--dim); margin-top: 10px; line-height: 1.5; opacity: .8; }

.scores { list-style: none; counter-reset: s; font-size: 12.5px; }
.scores li {
  counter-increment: s;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px dashed rgba(180, 150, 255, .12);
}
.scores li::before {
  content: counter(s);
  flex: none;
  width: 17px;
  color: var(--gold);
  font-weight: 800;
  font-size: 11px;
}
.scores li.empty { color: var(--dim); font-style: italic; }
.scores li.empty::before { content: "—"; color: var(--dim); }
.scores .sc { font-weight: 800; }
.scores .meta { margin-left: auto; color: var(--dim); font-size: 11px; white-space: nowrap; }
.scores li.fresh .sc { color: var(--gold); }

/* buttons */
.btn {
  display: block;
  width: 100%;
  margin: 8px 0 0;
  padding: 13px 18px;
  border: none;
  border-radius: 11px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .06em;
  cursor: pointer;
  transition: transform .1s, filter .15s, background .15s;
}
.btn:active { transform: translateY(1px) scale(.99); }

.btn-primary {
  background: linear-gradient(180deg, #ff5c7a, var(--blood) 55%, #a81238);
  color: #fff;
  box-shadow: 0 8px 24px rgba(224, 52, 90, .35);
}
.btn-primary:hover { filter: brightness(1.12); }

.btn-ghost {
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--line);
  color: var(--dim);
}
.btn-ghost:hover { background: rgba(255, 255, 255, .11); color: var(--ink); }

.btn-sm { padding: 8px 14px; font-size: 12px; width: auto; margin: 12px auto 0; }
.hint { opacity: .6; font-size: 11px; font-weight: 600; }

/* ============================================================
   Level-up cards
   ============================================================ */

.level-title {
  font-size: clamp(22px, 5vw, 30px);
  font-weight: 900;
  letter-spacing: .1em;
  color: var(--xp);
  text-shadow: 0 0 26px rgba(87, 216, 255, .45);
}
.level-sub { font-size: 11px; letter-spacing: .2em; text-transform: uppercase; color: var(--dim); margin: 5px 0 18px; }

.cards { display: grid; gap: 10px; }

.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .045);
  border: 1px solid var(--line);
  text-align: left;
  cursor: pointer;
  font-family: var(--font);
  color: var(--ink);
  transition: transform .12s, background .15s, border-color .15s;
}
.card:hover, .card:focus-visible {
  background: rgba(160, 107, 255, .16);
  border-color: rgba(160, 107, 255, .6);
  transform: translateX(3px);
  outline: none;
}

.card-icon {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 21px;
  background: rgba(0, 0, 0, .4);
  border: 1px solid var(--line);
}
.card-body { flex: 1 1 auto; min-width: 0; }
.card-name { font-size: 14.5px; font-weight: 800; letter-spacing: .02em; display: flex; align-items: center; gap: 7px; }
.card-desc { font-size: 11.5px; color: var(--dim); line-height: 1.45; margin-top: 3px; }
.card-key {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  color: var(--dim);
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--line);
}
.tag {
  font-size: 9px;
  letter-spacing: .12em;
  padding: 2px 6px;
  border-radius: 5px;
  text-transform: uppercase;
  font-weight: 800;
}
.tag.new { background: rgba(255, 209, 102, .18); color: var(--gold); border: 1px solid rgba(255, 209, 102, .4); }
.tag.lv { background: rgba(87, 216, 255, .15); color: var(--xp); border: 1px solid rgba(87, 216, 255, .38); }
.tag.max { background: rgba(125, 255, 168, .15); color: #7dffa8; border: 1px solid rgba(125, 255, 168, .38); }

/* ============================================================
   Pause / game over stats
   ============================================================ */

.pause-stats, .over-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 6px 0 18px;
}
.ovs {
  padding: 9px 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--line);
}
.ovs .k { display: block; font-size: 9px; letter-spacing: .16em; text-transform: uppercase; color: var(--dim); }
.ovs .v { display: block; font-size: clamp(17px, 4.4vw, 22px); font-weight: 800; margin-top: 2px; }
.ovs.big { grid-column: 1 / -1; }
.ovs.big .v { color: var(--gold); font-size: clamp(28px, 8vw, 40px); }

.rank {
  display: inline-block;
  margin-bottom: 12px;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(255, 209, 102, .14);
  border: 1px solid rgba(255, 209, 102, .45);
  color: var(--gold);
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  animation: pop .35s cubic-bezier(.2, 1.6, .4, 1);
}
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ============================================================
   Touch stick
   ============================================================ */

.stick { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.stick-base, .stick-knob {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity .12s;
}
.stick-base {
  width: 116px; height: 116px;
  border: 2px solid rgba(200, 180, 255, .3);
  background: rgba(20, 10, 35, .3);
}
.stick-knob {
  width: 52px; height: 52px;
  background: rgba(224, 52, 90, .55);
  border: 2px solid rgba(255, 190, 205, .7);
  box-shadow: 0 0 20px rgba(224, 52, 90, .5);
}
.stick.on .stick-base, .stick.on .stick-knob { opacity: 1; }

.touch-only { display: none; }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 620px) {
  .cols { grid-template-columns: 1fr; gap: 18px; }
  .hud-right { padding-right: 78px; }
  .hud-left { max-width: 46%; }
  .stat-k { display: none; }
  .stat { gap: 0; }
  .stat::after { content: ""; }
  .hud-right .stat:nth-child(1) .stat-v::before { content: "★ "; color: var(--gold); font-size: 11px; }
  .hud-right .stat:nth-child(2) .stat-v::before { content: "☠ "; color: var(--blood); font-size: 11px; }
  .hud-right .stat:nth-child(3) .stat-v::before { content: "♛ "; color: var(--dim); font-size: 11px; }
  .card-desc { font-size: 11px; }
  /* Collapse the loadout to icon + level so it can't eat the play area. */
  .chip { font-size: 10px; padding: 2px 6px; gap: 3px; }
  .chip b { display: none; }
  .chip .ic { font-size: 12px; }
}

@media (max-width: 380px) {
  .card-icon { width: 34px; height: 34px; font-size: 17px; }
  .panel { padding: 16px 13px; }
}

/* Short/landscape phones: the level-up list must not overflow the viewport. */
@media (max-height: 520px) {
  .cards { gap: 7px; }
  .card { padding: 8px 11px; }
  .card-icon { width: 32px; height: 32px; font-size: 16px; }
  .card-desc { font-size: 10.5px; }
  .level-sub { margin-bottom: 11px; }
  .tagline { margin-bottom: 12px; }
}

@media (hover: none) and (pointer: coarse) {
  .touch-only { display: list-item; }
  .icon-btn { width: 40px; height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
