@font-face {
  font-family: Oswald;
  src: url("../assets/schron/fonts/Oswald.ttf") format("truetype");
  font-style: normal;
  font-weight: 200 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
  --display: Oswald, "Arial Narrow", sans-serif;
  --night: #101511;
  --panel: #262a20;
  --ink: #f5edd7;
  --muted: #c5c3ab;
  --rule: #50513b;
  --amber: #f1b64d;
  --acid: #a9c95a;
  --red: #ee5448;
  --hud-height: 47px;
  --height: var(--tg-viewport-stable-height, 100dvh);
  --stage-width: min(100vw, calc(var(--height) * 9 / 16));
  --battle-inset: max(0px, calc((var(--height) - var(--stage-width) * 16 / 9) / 2));
  --safe-top: max(env(safe-area-inset-top, 0px), var(--schron-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--schron-bottom, 0px));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--schron-left, 0px));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--schron-right, 0px));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #090d0a;
  color: var(--ink);
}

body {
  display: grid;
  place-items: center;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:disabled { cursor: default; }

button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

::selection { background: var(--amber); color: var(--night); }

#app {
  position: relative;
  inline-size: var(--stage-width);
  block-size: var(--height);
  overflow: hidden;
  isolation: isolate;
  container-type: inline-size;
  background: var(--night);
}

#raidSurface { position: absolute; inset: 0; overflow: hidden; overflow: clip; background: #0a0e0b; }

#raidSurface::before {
  position: absolute;
  content: "";
  inset: -12px;
  z-index: 0;
  pointer-events: none;
  background: url("../assets/schron/arena.png") center / cover;
  filter: blur(18px) brightness(.62) saturate(.85);
  transform: scale(1.08);
}

#raidSurface::after {
  position: absolute;
  content: "";
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 42%, #080c0980 100%);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

#game {
  position: absolute;
  top: var(--battle-inset);
  inset-inline: 0;
  z-index: 1;
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  touch-action: none;
  box-shadow: 0 0 0 1px #000000b0;
}
#game:focus-visible { outline: 1px solid #dbc491; outline-offset: -1px; }

#damageFlash {
  position: absolute;
  z-index: 2;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  background: radial-gradient(ellipse, transparent 35%, #a6201a91);
  transition: opacity 140ms ease-out;
}

#damageFlash.active { opacity: 1; transition-duration: 35ms; }

#hud {
  position: absolute;
  z-index: 4;
  top: max(0px, var(--safe-top));
  inset-inline: var(--safe-left) var(--safe-right);
  min-height: var(--hud-height);
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content 44px;
  align-items: center;
  gap: clamp(4px, 2.1cqw, 11px);
  padding-inline: clamp(7px, 2.5cqw, 12px) 0;
  background: #191d16f5;
  border-bottom: 1px solid #81704d;
  pointer-events: none;
}

#app:has(#startScreen:not(.hidden)) #hud { visibility: hidden; }

.hud-wave,
.hud-score {
  display: flex;
  align-items: baseline;
  gap: 4px;
  white-space: nowrap;
  font: 650 clamp(11px, 3.1cqw, 15px)/1.1 var(--display);
  color: #daceb0;
  font-variant-numeric: tabular-nums;
}

.hud-score {
  justify-content: center;
  border-inline: 1px solid #66604a;
  padding-inline: 4px;
}

.hud-wave b, .hud-score b { font-size: clamp(15px, 4.5cqw, 24px); color: #faedd0; }
.hud-wave b { color: #ffca6c; }

.hearts { display: flex; gap: 3px; }

.hearts i {
  width: clamp(11px, 4cqw, 19px);
  aspect-ratio: 1;
  background: var(--red);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M10 18 2 10C-2 5 4 0 10 5c6-5 12 0 8 5Z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.hearts i.off { background: #666353; }
.hearts i.spare { display: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--ink);
  pointer-events: auto;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn.muted { color: var(--muted); }
.icon-btn.muted svg path:last-child { opacity: .2; }
#hud .icon-btn:focus-visible { outline-offset: -4px; }

#waveBanner,
#bossBar,
#toast,
#touchHint {
  position: absolute;
  z-index: 3;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}

#waveBanner {
  top: calc(var(--battle-inset) + 24cqw);
  width: min(74%, 305px);
  padding: 6px 10px 10px;
  border-block: 1px solid #a88443;
  background: #141810ed;
  text-align: center;
  font: 650 clamp(22px, 8cqw, 36px)/1.1 var(--display);
}

.banner-wave b { color: var(--amber); }

#bossBar {
  top: calc(max(0px, var(--safe-top)) + var(--hud-height) + 6px);
  left: auto;
  right: max(8px, var(--safe-right));
  transform: none;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  width: min(61%, 305px);
  padding: 4px 5px;
  background: #141810df;
}

.boss-label {
  color: #ff987e;
  font: 650 12px/1.1 var(--display);
  letter-spacing: .06em;
}

.boss-track {
  height: 7px;
  padding: 1px;
  border: 1px solid #8e493a;
  background: #170e0b;
}

.boss-track i {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--red);
  transition: width 120ms linear;
}

#toast, #touchHint {
  max-width: calc(100% - 24px);
  padding: 6px 10px;
  background: #101511e8;
  font-size: 12px;
  text-align: center;
}

#toast {
  bottom: calc(max(var(--battle-inset), var(--safe-bottom)) + 25cqw);
  border: 1px solid var(--rule);
  opacity: 0;
  transition: opacity 150ms ease;
}

#toast.show { opacity: 1; }
#touchHint { bottom: calc(max(var(--battle-inset), var(--safe-bottom)) + 8px); }

#raidBuffs,
#awardToast {
  position: absolute;
  z-index: 3;
  pointer-events: none;
}

#raidBuffs {
  top: calc(max(0px, var(--safe-top)) + var(--hud-height) + 8px);
  left: max(8px, var(--safe-left));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

#raidBuffs span {
  padding: 3px 7px;
  border: 1px solid currentColor;
  background: #152019ef;
  font: 650 12px/1.2 var(--display);
  text-transform: uppercase;
}

#shieldBuff { color: #b4dbea; }
#rapidBuff { color: #f9cb73; font-variant-numeric: tabular-nums; }

#awardToast {
  top: calc(max(0px, var(--safe-top)) + var(--hud-height) + 50px);
  right: max(8px, var(--safe-right));
  max-width: 57%;
  padding: 6px 9px;
  border: 1px solid #94753e;
  background: #28251af5;
  color: #ffdc91;
  font-weight: 650;
  font-size: 12px;
  opacity: 0;
  transition: opacity 150ms ease;
}

#awardToast.show { opacity: 1; }
.hidden, [hidden] { display: none !important; }

#app:has(#startScreen:not(.hidden)) #abilityBtn { visibility: hidden; }

.ability-btn {
  position: absolute;
  z-index: 5;
  right: max(10px, var(--safe-right));
  bottom: calc(max(var(--battle-inset), var(--safe-bottom)) + 10px);
  width: clamp(48px, 15cqw, 60px);
  height: clamp(48px, 15cqw, 60px);
  padding: 0;
  border: 2px solid #6d6448;
  border-radius: 50%;
  background: #141810ee;
  box-shadow: 0 0 0 1px #050805cc, 0 2px 10px #00000080;
  overflow: hidden;
  isolation: isolate;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.ability-btn img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: .92;
  transition: filter 160ms ease, opacity 160ms ease;
  pointer-events: none;
}

.ability-cd {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #0a0d0bc9;
  color: #f5edd7;
  font: 650 clamp(15px, 4.4cqw, 20px)/1 var(--display);
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
  pointer-events: none;
}

.ability-btn.cooling img { opacity: .4; filter: grayscale(.8) brightness(.7); }
.ability-btn.cooling { border-color: #4f4a38; }

.ability-btn.ready {
  border-color: var(--amber);
  box-shadow: 0 0 0 1px #050805cc, 0 0 12px #f1b64d59;
}

.ability-btn.ready::before {
  position: absolute;
  content: "";
  inset: -2px;
  z-index: -1;
  border: 1px solid #ffd88a;
  border-radius: 50%;
  animation: ability-ready 2.2s ease-in-out infinite;
  pointer-events: none;
}

.ability-btn.active {
  border-color: #ffd88a;
  box-shadow: 0 0 0 1px #050805cc, 0 0 16px #ffd88a8c;
}

.ability-btn:focus-visible { outline-offset: 2px; }
.ability-btn:disabled { cursor: default; }

#touchHint { max-width: calc(100% - 2 * clamp(48px, 15cqw, 60px) - 30px); }

@keyframes ability-ready {
  0%, 100% { transform: scale(1); opacity: .5; }
  50% { transform: scale(1.1); opacity: .12; }
}

@media (prefers-reduced-motion: reduce) {
  .ability-btn img, .ability-cd { transition: none; }
  .ability-btn.ready::before { animation: none; opacity: .35; }
}

@media (hover: hover) {
  button:not(:disabled):hover { filter: brightness(1.10); }
}

@media (prefers-reduced-motion: reduce) {
  #damageFlash, .boss-track i, #toast, #awardToast { transition: none; }
}
