:root {
  --ink: #2b1a10;
  --ink-deep: #1a1420;
  --parchment: #e8d3a2;
  --parchment-deep: #d8bd85;
  --gold: #d7a533;
  --gold-bright: #ffe6a2;
  --gold-pale: #f6dda0;
  --vermilion: #b23a1e;
  --vermilion-bright: #e35a2a;
  --lapis: #1f3f8c;
  --violet: #5b2c6f;
  --teal: #2a7b78;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a1420;
  color: var(--ink);
  font-family: "Alegreya", Georgia, serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #1a1420;
}

#game, #game canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 3px;
}

/* ---------- parchment surfaces ---------- */

.parchment {
  position: relative;
  border-style: solid;
  border-width: clamp(12px, 3.6vw, 30px);
  border-image: url("assets/parchment_panel.webp") 14% fill stretch;
  background-color: var(--parchment);
  color: #3a2412;
  box-shadow: 0 10px 40px rgba(20, 8, 30, .55);
}

.parchment.thin {
  border-width: clamp(6px, 2.1vw, 11px);
  border-image: url("assets/parchment_panel.webp") 11% fill stretch;
  box-shadow: 0 3px 14px rgba(20, 8, 30, .45);
}

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

#hud {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  padding-top: var(--safe-t);
}
#hud button { pointer-events: auto; }

#heroRail {
  position: absolute;
  top: calc(8px + var(--safe-t));
  left: max(8px, env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: row;
  gap: clamp(4px, 1.2vw, 10px);
  pointer-events: none;
}

.heroMedal {
  position: relative;
  width: clamp(44px, 12vw, 70px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0;
  pointer-events: auto;
  transition: transform .18s ease, filter .18s ease;
}
.medalFrame {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #f7e3ae, #c99a3a 60%, #7c5416 100%);
  padding: clamp(2px, .7vw, 4px);
  box-shadow:
    0 0 0 1px #5d3c10,
    0 3px 10px rgba(20, 8, 30, .55),
    inset 0 0 8px rgba(255, 240, 190, .6);
}
.medalFrame::before {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 1px solid rgba(255, 224, 150, .45);
  opacity: 0;
  transition: opacity .2s ease;
}
.medalFrame img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid #4a2c0c;
}
.heroMedal.active { transform: translateY(-2px) scale(1.06); }
.heroMedal.active .medalFrame {
  box-shadow:
    0 0 0 2px #ffe6a2,
    0 0 18px 4px rgba(255, 216, 120, .75),
    0 0 34px 10px rgba(255, 190, 70, .28),
    inset 0 0 10px rgba(255, 247, 210, .9);
}
.heroMedal.active .medalFrame::before { opacity: 1; animation: haloPulse 2.4s ease-in-out infinite; }
.heroMedal.down { filter: grayscale(1) brightness(.55); }
.heroMedal.down .medalFrame { box-shadow: 0 0 0 1px #2c1c0c, 0 2px 6px rgba(20, 8, 30, .55); }
.medalName {
  margin-top: 5px;
  font-family: "Alegreya SC", Georgia, serif;
  font-size: clamp(7px, 2.1vw, 10px);
  letter-spacing: .02em;
  color: #f4dfad;
  text-shadow: 0 1px 3px #1c0e2a, 0 0 8px rgba(25, 12, 35, .8);
  line-height: 1;
  white-space: nowrap;
}
.hp {
  position: absolute;
  left: 12%;
  width: 76%;
  bottom: -5px;
  height: clamp(4px, .9vw, 6px);
  background: #2a0d0a;
  border: 1px solid #5a2a1c;
  border-radius: 3px;
  overflow: hidden;
}
.hp i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(180deg, #e96a37, #b23a1e 55%, #7c1d12);
  transition: width .2s ease;
}

#topRight {
  position: absolute;
  top: calc(8px + var(--safe-t));
  right: max(8px, env(safe-area-inset-right, 0px));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  width: clamp(122px, 33vw, 196px);
}

.counterCard {
  width: 100%;
  padding: 4px 9px 5px;
  text-align: center;
  background-color: #e7d0a0;
}
.counterLabel {
  font-family: "Alegreya SC", Georgia, serif;
  font-size: clamp(7.5px, 2.1vw, 11px);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #6a4420;
  line-height: 1.1;
}
.counterValue {
  font-family: "Alegreya SC", Georgia, serif;
  font-weight: 700;
  font-size: clamp(23px, 6.4vw, 40px);
  line-height: .95;
  color: #9a6a16;
  text-shadow: 0 0 1px #ffe9ae, 0 1px 0 #fff2c6, 0 2px 2px rgba(85, 50, 10, .35);
}

.invasionCard {
  width: 100%;
  padding: 4px 8px 6px;
  background-color: #e7d0a0;
}
.invasionTop {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  font-family: "Alegreya SC", Georgia, serif;
  color: #5b3a1a;
  line-height: 1;
}
.invasionLabel {
  font-size: clamp(7px, 1.9vw, 10px);
  letter-spacing: .08em;
  text-transform: uppercase;
}
.roundLabel {
  font-size: clamp(8px, 2.2vw, 12px);
  color: #7d1f12;
  white-space: nowrap;
}
.invasionStrip {
  position: relative;
  margin-top: 4px;
  height: clamp(8px, 2.4vw, 13px);
  border-radius: 7px;
  background:
    linear-gradient(180deg, rgba(255, 246, 212, .9), rgba(214, 183, 122, .85)),
    #e8d3a2;
  border: 1px solid #8b6428;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(90, 55, 15, .45);
}
.inkBlob {
  position: absolute;
  top: -60%;
  left: -4%;
  width: 88%;
  height: 220%;
  border-radius: 48% 52% 46% 54% / 55% 44% 56% 45%;
  background:
    radial-gradient(ellipse at 35% 50%, #3a1d4e 0 28%, #5b2c6f 46%, rgba(34, 18, 44, .85) 68%, rgba(24, 12, 30, 0) 72%);
  transform-origin: left center;
  transition: transform .9s cubic-bezier(.3, .8, .3, 1), opacity .9s ease;
  opacity: .92;
}
.inkBlob.b2 {
  left: auto;
  right: -6%;
  width: 52%;
  transform-origin: right center;
  opacity: .7;
  border-radius: 58% 42% 60% 40% / 45% 58% 42% 55%;
}

.livesCard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 3px 8px 4px;
  background-color: #e7d0a0;
}
.livesLabel {
  font-family: "Alegreya SC", Georgia, serif;
  font-size: clamp(7px, 1.8vw, 10px);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #5b3a1a;
}
.livesDots { display: flex; align-items: center; gap: 3px; min-height: 38%; }
.lifeDot {
  width: clamp(7px, 2vw, 11px);
  height: clamp(7px, 2vw, 11px);
  border-radius: 50%;
  border: 1px solid #7a5214;
  background: radial-gradient(circle at 35% 30%, #fff2c2, #e1b447 55%, #9a6a16);
  box-shadow: 0 0 5px rgba(255, 220, 130, .8);
}
.lifeNone {
  font-family: "Alegreya SC", Georgia, serif;
  font-size: clamp(8px, 2.1vw, 11px);
  color: #88612c;
}

#helpBtn {
  position: absolute;
  right: max(10px, env(safe-area-inset-right, 0px));
  bottom: calc(84px + var(--safe-b));
  width: clamp(26px, 7vw, 34px);
  height: clamp(26px, 7vw, 34px);
  border-radius: 50%;
  border: 1.5px solid #e6c577;
  background: radial-gradient(circle at 40% 30%, #4a2c56, #241527 70%);
  color: #f4dfa6;
  font-family: "Uncial Antiqua", Georgia, serif;
  font-size: clamp(14px, 4vw, 20px);
  line-height: 1;
  box-shadow: 0 2px 10px rgba(15, 6, 20, .6), inset 0 0 8px rgba(255, 220, 140, .22);
  z-index: 4;
}

#statusChips {
  position: absolute;
  top: calc(168px + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  width: min(90vw, 560px);
  pointer-events: none;
}
.chip {
  font-family: "Alegreya SC", Georgia, serif;
  font-size: clamp(8px, 2.2vw, 12px);
  line-height: 1;
  padding: 4px 8px;
  border-radius: 99px;
  color: #f8ecc9;
  background: rgba(38, 22, 44, .82);
  border: 1px solid rgba(232, 195, 110, .65);
  box-shadow: 0 2px 8px rgba(15, 6, 20, .5);
  white-space: nowrap;
}
.chip.good { color: #ffe9a9; border-color: #d9a83a; background: rgba(66, 44, 12, .85); }
.chip.bad { color: #f3c9e9; border-color: #b06aa8; background: rgba(52, 18, 48, .88); }
.chip.angel { color: #fff4d2; border-color: #ffe6a2; background: rgba(94, 66, 18, .9); }

#offLeft, #offRight {
  position: absolute;
  top: 46%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 7px;
  border-radius: 99px;
  background: rgba(40, 22, 46, .72);
  border: 1px solid rgba(255, 224, 150, .55);
  box-shadow: 0 0 14px rgba(255, 205, 90, .2);
  pointer-events: none;
  z-index: 4;
  opacity: .9;
}
#offLeft { left: max(5px, env(safe-area-inset-left, 0px)); }
#offRight { right: max(5px, env(safe-area-inset-right, 0px)); }
.offArrow {
  font-family: "Uncial Antiqua", Georgia, serif;
  font-size: clamp(17px, 5vw, 28px);
  line-height: .8;
  color: #ffe6a2;
  text-shadow: 0 0 8px rgba(255, 205, 90, .6);
}
.offLabel {
  font-family: "Alegreya SC", Georgia, serif;
  font-size: clamp(7px, 2vw, 10px);
  letter-spacing: .04em;
  color: #f5e4b6;
  text-transform: uppercase;
  white-space: nowrap;
}
#offLeft .offArrow, #offRight .offArrow { animation: nudgeArrow 1.8s ease-in-out infinite; }
@keyframes nudgeArrow {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(2px); }
}
#offLeft .offArrow { animation-name: nudgeArrowLeft; }
@media (max-aspect-ratio: 1/1) {
  #offLeft, #offRight { top: 24%; padding: 3px 6px; }
  .offLabel { font-size: 7px; }
  .offArrow { font-size: 17px; }
}

@keyframes nudgeArrowLeft {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(-2px); }
}

#waveBanner {
  position: absolute;
  top: 27%;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .45s ease, transform .45s ease;
  z-index: 5;
}
#waveBanner.show { opacity: 1; transform: translateY(0); }
.wbMain {
  font-family: "Uncial Antiqua", Georgia, serif;
  font-size: clamp(26px, 8.5vw, 62px);
  line-height: 1;
  color: #ffe9a9;
  text-shadow: 0 2px 0 #7c4c10, 0 4px 18px rgba(20, 6, 28, .9), 0 0 32px rgba(255, 205, 90, .55);
  letter-spacing: .02em;
}
.wbSub {
  margin-top: 4px;
  font-family: "Alegreya", Georgia, serif;
  font-style: italic;
  font-size: clamp(11px, 3vw, 19px);
  color: #f0d79d;
  text-shadow: 0 2px 8px rgba(20, 6, 28, .95);
}

/* ---------- bottom controls ---------- */

#bottomBar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(8px + var(--safe-b));
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 4px;
  padding-left: max(6px, env(safe-area-inset-left, 0px));
  padding-right: max(6px, env(safe-area-inset-right, 0px));
  pointer-events: none;
  z-index: 3;
}
#bottomBar > * { pointer-events: auto; }

.moveBtn {
  width: clamp(36px, 11vw, 58px);
  height: clamp(42px, 13vw, 66px);
  flex: 0 0 auto;
  border-radius: 12px;
  color: #ffe9ae;
  background: linear-gradient(180deg, rgba(62, 39, 70, .92), rgba(30, 18, 36, .95));
  border: 1.5px solid rgba(226, 187, 98, .8);
  box-shadow: 0 4px 14px rgba(15, 6, 20, .55), inset 0 1px 0 rgba(255, 236, 180, .25);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  transition: transform .08s ease, background .08s ease;
}
.moveBtn svg { width: 60%; height: 60%; }
.moveBtn:active, .moveBtn.pressed {
  transform: scale(.94);
  background: linear-gradient(180deg, rgba(120, 82, 30, .95), rgba(56, 34, 14, .96));
}

#powerBar {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(3px, 1.1vw, 7px);
  flex: 0 1 auto;
}

.powerBtn {
  position: relative;
  width: clamp(34px, 11.2vw, 58px);
  height: clamp(38px, 12.6vw, 64px);
  flex: 0 0 auto;
  padding: 2px;
  border-radius: 9px;
  background:
    linear-gradient(180deg, #f1dcab, #cba75f 60%, #9a742c);
  border: 1.5px solid #5c3a0c;
  box-shadow: 0 4px 14px rgba(15, 6, 20, .55), inset 0 0 0 1px rgba(255, 241, 196, .5);
  overflow: hidden;
  touch-action: none;
  transition: transform .1s ease, filter .15s ease;
}
.powerBtn .iconWrap {
  position: absolute;
  inset: 2px;
  border-radius: 6px;
  background:
    radial-gradient(circle at 50% 40%, #f3dfb0, #d8b66c 62%, #a88137);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.powerBtn img, .powerBtn svg.angelIcon {
  width: 92%;
  height: 92%;
  object-fit: contain;
  display: block;
}
.powerBtn .cdShade {
  position: absolute;
  inset: 0;
  background: rgba(22, 12, 30, .68);
  pointer-events: none;
  transition: opacity .15s linear;
}
.powerBtn .cdFill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  background: linear-gradient(180deg, rgba(255, 211, 92, .05), rgba(255, 196, 54, .55));
  pointer-events: none;
  mix-blend-mode: screen;
}
.powerBtn .keyHint {
  position: absolute;
  top: 2px;
  left: 3px;
  font-family: "Alegreya SC", Georgia, serif;
  font-size: clamp(6px, 1.7vw, 9px);
  line-height: 1;
  color: #3b2408;
  background: rgba(255, 240, 194, .85);
  border-radius: 3px;
  padding: 1px 2px;
  pointer-events: none;
  z-index: 3;
}
.powerBtn.ready {
  box-shadow: 0 0 0 1px #ffe6a2, 0 0 14px 2px rgba(255, 205, 90, .5), 0 4px 14px rgba(15, 6, 20, .55), inset 0 0 0 1px rgba(255, 241, 196, .6);
}
.powerBtn.ready::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 10px;
  border: 1px solid rgba(255, 230, 160, .65);
  animation: softGlow 2.2s ease-in-out infinite;
  pointer-events: none;
}
.powerBtn.cooling { filter: saturate(.7) brightness(.82); }
.powerBtn:active { transform: translateY(2px) scale(.97); }
.powerBtn.denied { animation: nudge .22s ease; }

.jesusBtn {
  position: relative;
  width: clamp(46px, 15vw, 76px);
  height: clamp(46px, 15vw, 76px);
  flex: 0 0 auto;
  border-radius: 50%;
  margin-left: clamp(4px, 1.5vw, 10px);
  background:
    radial-gradient(circle at 50% 42%, #fff7d8 0 8%, #f4d071 26%, #c8922a 55%, #7a4b0d 82%, #4a2a06);
  border: 2px solid #ffe6a2;
  box-shadow:
    0 0 0 2px #5b3608,
    0 0 18px 3px rgba(255, 206, 90, .38),
    0 4px 16px rgba(15, 6, 20, .6),
    inset 0 0 12px rgba(255, 250, 220, .7);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
  z-index: 2;
}
.jesusBtn .jesusText {
  position: relative;
  font-family: "Uncial Antiqua", Georgia, serif;
  font-size: clamp(7px, 2.2vw, 11px);
  letter-spacing: .04em;
  color: #3a1f05;
  text-shadow: 0 1px 0 rgba(255, 249, 215, .9);
  z-index: 2;
  line-height: 1;
}
.jesusBtn .cdShade {
  position: absolute;
  inset: 0;
  background: rgba(24, 12, 30, .62);
  pointer-events: none;
}
.jesusBtn .cdFill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  background: linear-gradient(180deg, rgba(255, 220, 120, .08), rgba(255, 190, 50, .5));
  mix-blend-mode: screen;
  pointer-events: none;
}
.jesusBtn.ready {
  animation: jesusPulse 2.6s ease-in-out infinite;
}
.jesusBtn.ready .cdShade { opacity: 0; }
.jesusBtn.cooling { filter: saturate(.72) brightness(.8); }
.jesusBtn:active { transform: scale(.95); }
.jesusBtn.denied { animation: nudge .22s ease; }

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(84px + var(--safe-b));
  transform: translate(-50%, 8px);
  max-width: min(88vw, 520px);
  padding: 6px 14px;
  border-radius: 99px;
  font-family: "Alegreya SC", Georgia, serif;
  font-size: clamp(9px, 2.6vw, 14px);
  line-height: 1.2;
  text-align: center;
  color: #f7e7bd;
  background: rgba(34, 19, 40, .88);
  border: 1px solid rgba(230, 195, 115, .55);
  box-shadow: 0 4px 18px rgba(10, 4, 16, .6);
  opacity: 0;
  transition: opacity .3s ease, transform .3s ease;
  pointer-events: none;
  z-index: 6;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.good { color: #ffe9a9; border-color: #d9a83a; background: rgba(58, 40, 12, .9); }
#toast.bad { color: #f4cdeb; border-color: #b56aad; background: rgba(52, 18, 48, .92); }

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

#titleScreen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: block;
  pointer-events: none;
}
.titleArtWrap {
  position: absolute;
  left: 50%;
  top: calc(10px + var(--safe-t));
  transform: translateX(-50%);
  width: min(78vw, 470px);
  pointer-events: none;
  filter: drop-shadow(0 10px 26px rgba(20, 6, 28, .55));
}
.titleArt { width: 100%; height: auto; display: block; }
.titleRule {
  position: absolute;
  left: 50%;
  top: calc(10px + min(69vw, 417px) + var(--safe-t));
  transform: translateX(-50%);
  width: min(80vw, 460px);
  text-align: center;
  pointer-events: none;
}
.titleRule::before, .titleRule::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 18%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(240, 208, 140, .8));
}
.titleRule::before { left: 0; }
.titleRule::after { right: 0; transform: scaleX(-1); }
.titleRule span {
  font-family: "Uncial Antiqua", Georgia, serif;
  font-size: clamp(12px, 3.4vw, 20px);
  color: #f6dfa8;
  letter-spacing: .06em;
  text-shadow: 0 2px 8px rgba(20, 6, 28, .95), 0 0 18px rgba(255, 205, 90, .3);
}

.titlePanel {
  position: absolute;
  left: 50%;
  bottom: calc(10px + var(--safe-b));
  transform: translateX(-50%);
  width: min(92vw, 600px);
  padding: 12px 14px 11px;
  text-align: center;
  pointer-events: auto;
  background-color: #e9d4a4;
}
.titleLead {
  margin: 0 0 6px;
  font-size: clamp(12px, 3.4vw, 19px);
  line-height: 1.25;
  color: #3c2410;
}
.titleHint {
  margin: 0 0 10px;
  font-size: clamp(10px, 2.8vw, 14px);
  font-style: italic;
  line-height: 1.25;
  color: #6b431d;
}
.titleButtons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.goldBtn {
  font-family: "Uncial Antiqua", Georgia, serif;
  font-size: clamp(12px, 3.4vw, 19px);
  line-height: 1;
  padding: 10px 18px 9px;
  color: #331c05;
  background:
    linear-gradient(180deg, #fff0bc 0%, #efd073 34%, #d7a533 64%, #a9791c 100%);
  border: 1.5px solid #6b440e;
  border-radius: 8px;
  box-shadow:
    inset 0 1px 0 #fff9dd,
    inset 0 -2px 0 rgba(90, 52, 8, .35),
    0 3px 12px rgba(30, 12, 40, .45);
  text-shadow: 0 1px 0 rgba(255, 248, 214, .8);
}
.goldBtn:active { transform: translateY(1px); box-shadow: inset 0 2px 4px rgba(90, 52, 8, .35); }
.quietBtn {
  font-family: "Alegreya", Georgia, serif;
  font-size: clamp(11px, 3vw, 15px);
  padding: 8px 12px;
  border-radius: 7px;
  color: #4d2f12;
  border: 1px solid rgba(110, 72, 24, .55);
  background: rgba(255, 246, 218, .28);
}
.quietBtn:active { background: rgba(255, 246, 218, .5); }
.titleBest {
  margin-top: 7px;
  font-family: "Alegreya SC", Georgia, serif;
  font-size: clamp(8px, 2.2vw, 11px);
  color: #7c5726;
  min-height: 0;
}

/* ---------- modals ---------- */

#helpModal, #endScreen {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, 3vh) 12px;
  background: rgba(14, 7, 20, .58);
  backdrop-filter: blur(2px);
  pointer-events: auto;
}
.helpPanel, .endPanel {
  width: min(94vw, 660px);
  max-height: 90vh;
  overflow-y: auto;
  padding: clamp(14px, 4vw, 26px);
  background-color: #ead5a6;
}
.panelTitle {
  margin: 0 0 8px;
  font-family: "Uncial Antiqua", Georgia, serif;
  font-weight: 400;
  font-size: clamp(22px, 6vw, 38px);
  line-height: 1.05;
  text-align: center;
  color: #6f2a14;
  text-shadow: 0 1px 0 #ffeec2;
}
.helpGrid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  font-size: clamp(12px, 3.2vw, 16px);
  line-height: 1.28;
  color: #3f2610;
}
.helpGrid div {
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(122, 82, 30, .22);
}
.helpGrid b {
  display: block;
  font-family: "Alegreya SC", Georgia, serif;
  font-size: .92em;
  letter-spacing: .04em;
  color: #7c4a12;
}
.helpGrid span { display: block; }
.helpFoot { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

.endLead {
  margin: 0 auto 10px;
  max-width: 46em;
  text-align: center;
  font-size: clamp(12px, 3.2vw, 17px);
  line-height: 1.3;
  color: #4a2d12;
}
.endStats {
  display: flex;
  justify-content: center;
  gap: clamp(10px, 4vw, 28px);
  flex-wrap: wrap;
  margin: 6px 0 12px;
  font-family: "Alegreya SC", Georgia, serif;
  color: #6b4215;
}
.endStats .stat { text-align: center; }
.endStats .stat b {
  display: block;
  font-size: clamp(20px, 6vw, 34px);
  line-height: 1;
  color: #9a6a16;
  font-weight: 700;
}
.endStats .stat span {
  font-size: clamp(8px, 2.3vw, 11px);
  letter-spacing: .06em;
  text-transform: uppercase;
}
.endBoard {
  margin: 4px 0 12px;
  text-align: center;
  font-family: "Alegreya SC", Georgia, serif;
  font-size: clamp(10px, 2.8vw, 14px);
  color: #5d3b14;
}
.endBoard .boardTitle {
  font-size: .82em;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #7c4a12;
  margin-bottom: 4px;
}
.endBoard .boardRow { display: flex; justify-content: center; gap: 10px; line-height: 1.5; }
.endBoard .boardRow a { color: #7d1f12; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- overlays ---------- */

#miracleWord {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%) scale(.7);
  z-index: 45;
  font-family: "Uncial Antiqua", Georgia, serif;
  font-size: clamp(54px, 17vw, 210px);
  line-height: 1;
  letter-spacing: .02em;
  color: #fff1bb;
  text-shadow:
    0 0 18px rgba(255, 236, 170, .95),
    0 0 52px rgba(255, 196, 60, .85),
    0 0 120px rgba(255, 160, 20, .55),
    0 6px 0 rgba(122, 70, 8, .5);
  opacity: 0;
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
}
#miracleWord.show { animation: miracle 2.1s cubic-bezier(.2, .8, .2, 1) forwards; }

#flash {
  position: absolute;
  inset: 0;
  z-index: 18;
  pointer-events: none;
  background: radial-gradient(circle at 50% 45%, #fff8d8 0%, #ffe08a 38%, rgba(255, 190, 60, .45) 65%, rgba(255, 170, 40, 0) 82%);
  opacity: 0;
}
#flash.show { animation: flash 1.3s ease-out forwards; }
#flash.hurt { background: radial-gradient(circle at 50% 55%, rgba(180, 60, 40, .55), rgba(60, 10, 20, 0) 70%); }
#flash.hurt.show { animation: hurtflash .5s ease-out forwards; }

#loading {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 40%, #3b2248, #1a1420 70%);
  padding: 20px;
  transition: opacity .5s ease;
}
#loading.done { opacity: 0; pointer-events: none; }
.loadingPanel {
  width: min(78vw, 380px);
  padding: 18px 20px;
  text-align: center;
  background-color: #e8d3a2;
}
.loadingTitle {
  font-family: "Uncial Antiqua", Georgia, serif;
  font-size: clamp(20px, 5.4vw, 30px);
  color: #6f2a14;
  line-height: 1.1;
}
.loadingSub {
  margin: 5px 0 12px;
  font-family: "Alegreya", Georgia, serif;
  font-style: italic;
  font-size: clamp(11px, 3vw, 15px);
  color: #6b431d;
}
.loadingTrack {
  height: 8px;
  border-radius: 5px;
  background: #b8975c;
  border: 1px solid #7a5214;
  overflow: hidden;
}
.loadingTrack i {
  display: block;
  width: 4%;
  height: 100%;
  background: linear-gradient(90deg, #b23a1e, #eaa63a 45%, #ffe6a2);
  transition: width .2s ease;
}

/* ---------- wide screens: two-column title ---------- */

@media (min-aspect-ratio: 1/1) {
  .titleArtWrap {
    left: max(4vw, 24px);
    top: 45%;
    transform: translateY(-55%);
    width: min(34vw, 440px);
  }
  .titleRule {
    left: max(4vw, 24px);
    top: calc(16px + var(--safe-t));
    transform: none;
    width: min(34vw, 440px);
  }
  .titlePanel {
    left: max(4vw, 24px);
    bottom: max(2.2vh, 10px);
    transform: none;
    width: min(46vw, 560px);
    padding: 9px 13px 8px;
    text-align: left;
  }
  .titlePanel .titleButtons { justify-content: flex-start; }
  .titleBest { text-align: left; }
  .helpGrid { grid-template-columns: 1fr 1fr; gap: 8px 18px; }
  #topRight { width: clamp(150px, 22vw, 230px); }
}

@media (max-height: 560px) and (min-aspect-ratio: 1/1) {
  .titleArtWrap {
    left: max(3vw, 16px);
    top: calc(10px + var(--safe-t));
    transform: none;
    width: min(30vw, 280px);
  }
  .titleRule {
    left: max(3vw, 16px);
    top: calc(44px + min(26.7vw, 249px) + var(--safe-t));
    transform: none;
    width: min(30vw, 280px);
    text-align: left;
  }
  .titleRule::before, .titleRule::after { display: none; }
  .titleRule span { font-size: 12px; }
  .titlePanel {
    left: max(3vw, 16px);
    bottom: max(2vh, 8px);
    transform: none;
    width: min(30vw, 280px);
    padding: 6px 10px 5px;
    text-align: left;
    border-width: 12px;
    border-image-slice: 14% fill;
  }
  .titleButtons { flex-wrap: nowrap; }
  .titleLead { display: none; }
  .titleHint { margin-bottom: 5px; font-size: 10px; line-height: 1.2; }
  .titleButtons { gap: 5px; }
  .goldBtn { font-size: 12px; padding: 6px 10px 5px; }
  .quietBtn { font-size: 10px; padding: 5px 8px; }
  .titleBest { display: none; }

  #heroRail { top: calc(6px + var(--safe-t)); gap: 4px; }
  .heroMedal { width: clamp(38px, 8vw, 52px); }
  .medalName { font-size: 7px; }
  #topRight {
    top: calc(6px + var(--safe-t));
    right: max(6px, env(safe-area-inset-right, 0px));
    flex-direction: row;
    align-items: stretch;
    width: auto;
    gap: 4px;
  }
  #topRight > * { width: auto; }
  .counterCard { min-width: 96px; padding: 2px 7px 3px; }
  .counterLabel { font-size: 7px; }
  .counterValue { font-size: clamp(18px, 4vw, 28px); }
  .invasionCard { min-width: 150px; padding: 2px 6px 3px; }
  .invasionLabel, .roundLabel { font-size: 7px; }
  .invasionStrip { height: 6px; margin-top: 2px; }
  .livesCard { min-width: 108px; padding: 2px 6px; }
  .livesLabel { font-size: 7px; }
  .lifeDot { width: 7px; height: 7px; }
  #statusChips { top: calc(60px + var(--safe-t)); }
  .chip { font-size: 9px; padding: 2px 6px; }
  #waveBanner { top: 21%; }
  .wbMain { font-size: clamp(24px, 5vw, 48px); }
  .wbSub { font-size: 11px; }
  #bottomBar { bottom: calc(5px + var(--safe-b)); }
  .moveBtn { width: clamp(34px, 7vw, 46px); height: clamp(36px, 8vw, 52px); }
  .powerBtn { width: clamp(34px, 7vw, 46px); height: clamp(38px, 8vw, 52px); }
  .powerBtn .keyHint { font-size: 6px; }
  .jesusBtn { width: clamp(46px, 9vw, 58px); height: clamp(46px, 9vw, 58px); }
  .jesusBtn .jesusText { font-size: 8px; }
  #toast { bottom: calc(64px + var(--safe-b)); font-size: 10px; }
  #helpBtn { bottom: calc(70px + var(--safe-b)); width: 26px; height: 26px; }
  #offLeft, #offRight { top: 40%; }
  .offLabel { font-size: 8px; }
  .offArrow { font-size: 20px; }
}

@media (max-width: 380px) {
  .medalName { display: none; }
  #topRight { width: 118px; }
  .livesCard { width: 92%; }
}

/* ---------- animations ---------- */

@keyframes haloPulse {
  0%, 100% { opacity: .35; transform: scale(1); }
  50% { opacity: .9; transform: scale(1.06); }
}
@keyframes softGlow {
  0%, 100% { opacity: .2; }
  50% { opacity: .85; }
}
@keyframes jesusPulse {
  0%, 100% { box-shadow: 0 0 0 2px #5b3608, 0 0 16px 2px rgba(255, 206, 90, .35), 0 4px 16px rgba(15, 6, 20, .6), inset 0 0 12px rgba(255, 250, 220, .65); }
  50% { box-shadow: 0 0 0 2px #ffe6a2, 0 0 28px 8px rgba(255, 216, 120, .7), 0 4px 16px rgba(15, 6, 20, .6), inset 0 0 18px rgba(255, 252, 230, .95); }
}
@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-3px); }
  65% { transform: translateX(3px); }
}
@keyframes miracle {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.55); filter: blur(8px); }
  14% { opacity: 1; transform: translate(-50%, -50%) scale(1.04); filter: blur(0); }
  24% { transform: translate(-50%, -50%) scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.15); filter: blur(2px); }
}
@keyframes flash {
  0% { opacity: 0; }
  12% { opacity: .72; }
  38% { opacity: .32; }
  100% { opacity: 0; }
}
@keyframes hurtflash {
  0% { opacity: 0; }
  20% { opacity: .85; }
  100% { opacity: 0; }
}
