:root {
  --ink: #f4ead8;
  --muted: #b7aa98;
  --gold: #e2b657;
  --blood: #9d2f3c;
  --panel: rgba(18, 12, 16, 0.92);
  --line: rgba(226, 182, 87, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #100c10;
  color: var(--ink);
  font-family: "Avenir Next", "Hiragino Sans", "Yu Gothic", sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#mute, #pausebtn, #focusbtn, #bombbtn {
  border: 1px solid var(--line);
  background: rgba(12, 8, 10, 0.72);
  color: var(--gold);
  border-radius: 999px;
  font: inherit;
  letter-spacing: 0.08em;
  cursor: pointer;
}

#mute {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  right: 14px;
  z-index: 6;
  min-width: 72px;
  height: 32px;
  font-size: 12px;
}

#hud {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

#hud[hidden] { display: none !important; }

#top, #meters, #bossbar, #controls, #banner {
  pointer-events: none;
}

#top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: calc(12px + env(safe-area-inset-top)) 96px 0 16px;
}

#scoreline {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#scoreline span, #meters span, #bossname {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.16em;
}

#scoreline b {
  font-family: "Iowan Old Style", Palatino, "Hiragino Mincho ProN", serif;
  font-size: 28px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--gold);
  line-height: 1;
}

#pausebtn {
  pointer-events: auto;
  min-width: 64px;
  height: 32px;
  font-size: 12px;
}

#meters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 8px 16px 0;
}

#meters b {
  color: var(--ink);
  font-weight: 700;
}

#meters #stage {
  font-family: "Iowan Old Style", Palatino, "Hiragino Mincho ProN", serif;
  color: var(--gold);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.16em;
}

#lifeblock {
  position: absolute;
  z-index: 3;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(226, 182, 87, 0.7);
  background: rgba(12, 8, 10, 0.9);
}

#lifeblock > span {
  color: var(--gold);
  font-size: 13px;
  letter-spacing: 0.2em;
}

#lifeicons {
  display: flex;
  gap: 5px;
  min-height: 18px;
}

#lifecount {
  font-family: "Iowan Old Style", Palatino, "Hiragino Mincho ProN", serif;
  font-size: 26px;
  font-weight: 500;
  line-height: 1;
  color: #fff6e8;
}

#lifeblock.last #lifecount { color: #ffb4a8; }

#bombblock {
  position: absolute;
  z-index: 3;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(226, 182, 87, 0.7);
  background: rgba(12, 8, 10, 0.9);
}

#bombblock > span {
  color: var(--gold);
  font-size: 13px;
  letter-spacing: 0.2em;
}

#bombcount {
  font-family: "Iowan Old Style", Palatino, "Hiragino Mincho ProN", serif;
  font-size: 26px;
  font-weight: 500;
  line-height: 1;
  color: #fff6e8;
}

#bombicons {
  display: flex;
  gap: 4px;
  min-height: 16px;
}

#bombicons i {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: #9d2f3c;
  box-shadow: inset 0 0 0 1.5px #e2b657;
}

#bombnote {
  color: #ffb4a8;
  font-style: normal;
  font-size: 13px;
  letter-spacing: 0.12em;
}

#bombnote[hidden] { display: none !important; }

#bombblock.empty #bombcount { color: #ffb4a8; }

#lifeicons i {
  width: 18px;
  height: 24px;
  background: linear-gradient(180deg, #fff6e8 0 4px, #e15b6a 4px);
  clip-path: polygon(50% 0, 100% 100%, 50% 72%, 0 100%);
  filter: drop-shadow(0 0 1px #e2b657);
}

#lifeblock.last #lifeicons i {
  background: linear-gradient(180deg, #fff 0 4px, #ff8d9a 4px);
  animation: life-pulse 0.7s ease-in-out infinite;
}

#lifenote {
  color: #ffb4a8;
  font-style: normal;
  font-size: 13px;
  letter-spacing: 0.12em;
}

#lifenote[hidden] { display: none !important; }

@keyframes life-pulse {
  50% { opacity: 0.45; }
}

#bossbar {
  position: absolute;
  z-index: 3;
  margin: 0;
  padding: 4px 10px 5px;
  border-radius: 10px;
  border: 1px solid rgba(226, 182, 87, 0.28);
  background: rgba(8, 4, 8, 0.38);
  box-shadow: none;
  backdrop-filter: blur(3px);
}

#bosshead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}

#bossleft {
  font-family: "Iowan Old Style", Palatino, "Hiragino Mincho ProN", serif;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.08em;
  color: rgba(255, 246, 232, 0.78);
  white-space: nowrap;
}

#bossbar[hidden] { display: none !important; }

#bossbar #bossname {
  display: block;
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
  font-family: "Iowan Old Style", Palatino, "Hiragino Mincho ProN", serif;
  font-size: 13px;
  line-height: 1.2;
  letter-spacing: 0.14em;
  color: rgba(244, 228, 190, 0.9);
}

#bossbar #bossname.rainbow {
  background-image: linear-gradient(
    90deg,
    #ff3b3b 0%,
    #ffe14a 16%,
    #5dff7a 33%,
    #3ecbff 50%,
    #7a7bff 66%,
    #e15bff 83%,
    #ff3b3b 100%
  );
  background-size: 140px 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: rainbow 1.1s linear infinite;
}

#bossbar.rainbow .track i {
  background: linear-gradient(
    90deg,
    #ff3b3b,
    #ff8a00,
    #ffe14a,
    #5dff7a,
    #3ecbff,
    #7a7bff,
    #e15bff,
    #ff3b6a
  );
  background-size: 220% 100%;
  animation: rainbow 1.1s linear infinite;
}

.track {
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  border: none;
}

.track i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, rgba(180, 70, 82, 0.72), rgba(255, 186, 176, 0.88));
}

#bossbar.spell .track i {
  background: linear-gradient(90deg, #8a6a28, #f0d78c);
}

#bossbar.low {
  border-color: rgba(255, 170, 176, 0.4);
}

#bossbar.low #bossleft {
  color: rgba(255, 196, 188, 0.92);
}

#bossbar.low .track i {
  background: linear-gradient(90deg, rgba(196, 64, 78, 0.8), rgba(255, 150, 158, 0.95));
}

#banner {
  position: absolute;
  top: 28%;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 0 8px;
  color: #fff6e4;
  font-family: "Iowan Old Style", Palatino, "Hiragino Mincho ProN", serif;
  letter-spacing: 0.34em;
  font-size: 20px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  text-shadow:
    0 0 16px rgba(226, 182, 87, 0.55),
    0 2px 8px rgba(0, 0, 0, 0.85);
}

#banner::before,
#banner::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(226, 182, 87, 0.85), transparent);
}

#banner::before { top: 0; }
#banner::after { bottom: 0; }

#banner.on {
  opacity: 1;
  animation: banner-in 0.55s ease-out both;
}

@keyframes banner-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

#hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  white-space: nowrap;
  opacity: 0;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.7);
}

#hint.on { opacity: 1; }

#controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  padding: 0 14px;
}

#focusbtn, #bombbtn {
  pointer-events: auto;
  min-width: 88px;
  height: 52px;
  font-size: 15px;
}

#focusbtn.held {
  background: #6e2430;
  color: #fff6e8;
}

#overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 24px 18px;
  background: rgba(8, 5, 8, 0.5);
  overflow: auto;
}

#overlay[hidden] { display: none !important; }

.panel {
  width: min(720px, 100%);
  padding: 28px 24px 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    radial-gradient(520px 160px at 50% 0%, rgba(226, 182, 87, 0.16), transparent 60%),
    var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.seal {
  width: 64px;
  height: 64px;
  margin: 0 auto 8px;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold);
  border-radius: 50%;
  color: var(--gold);
  font-family: "Iowan Old Style", Palatino, "Hiragino Mincho ProN", serif;
  font-size: 28px;
}

h1, h2, .kicker, .lead {
  font-family: "Iowan Old Style", Palatino, "Hiragino Mincho ProN", serif;
}

h1 {
  margin: 0;
  font-size: clamp(32px, 7vw, 52px);
  font-weight: 500;
  letter-spacing: 0.1em;
}

h2 {
  margin: 6px 0 8px;
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 500;
  letter-spacing: 0.14em;
}

.kicker {
  margin: 0 0 8px;
  color: var(--gold);
  letter-spacing: 0.28em;
  font-size: 13px;
}

.lead {
  margin: 8px 0 0;
  color: var(--ink);
  letter-spacing: 0.08em;
  font-size: 18px;
}

.help {
  margin: 16px auto 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.85;
}

.keys {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.08em;
}

.ships {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.ship {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 108px;
  padding: 10px 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(244, 234, 216, 0.18);
  background: rgba(255, 255, 255, 0.03);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.ship.on {
  border-color: var(--gold);
  background: rgba(226, 182, 87, 0.1);
}

.ship .tag {
  color: var(--gold);
  font-size: 11px;
  letter-spacing: 0.14em;
}

.ship .portrait {
  align-self: center;
  width: 84px;
  height: 78px;
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
}

.ship strong {
  font-family: "Iowan Old Style", Palatino, "Hiragino Mincho ProN", serif;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.06em;
}

.ship strong em {
  display: block;
  margin-bottom: 1px;
  color: var(--gold);
  font-style: normal;
  font-size: 11px;
  letter-spacing: 0.12em;
}

.ship .desc {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

button.primary, button.ghost {
  pointer-events: auto;
  margin-top: 18px;
  min-width: 168px;
  height: 46px;
  padding: 0 18px;
  border-radius: 999px;
  font: inherit;
  letter-spacing: 0.14em;
  cursor: pointer;
}

button.primary {
  border: 1px solid var(--gold);
  background: #6e2430;
  color: #fff6e8;
}

button.primary:hover { background: #8a3140; }

button.ghost {
  margin-left: 8px;
  border: 1px solid rgba(244, 234, 216, 0.25);
  background: transparent;
  color: var(--ink);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0 4px;
}

.stats div {
  padding: 10px 6px;
  border-top: 1px solid rgba(226, 182, 87, 0.35);
}

.stats b {
  display: block;
  margin-top: 4px;
  font-size: 22px;
  font-family: "Iowan Old Style", Palatino, "Hiragino Mincho ProN", serif;
  font-weight: 500;
}

.stats span {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.12em;
}

.fail h2 { color: #ffb4a8; }
.clear h2 { color: #f3e2b0; }

a.hub {
  display: inline-block;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.14em;
  text-decoration: none;
}

a.hub:hover { color: var(--gold); }

.best {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.12em;
}

#overlay.curtain {
  background: rgba(6, 3, 6, 0.55);
  pointer-events: none;
}

#overlay.curtain.holy {
  background:
    radial-gradient(circle at 50% 46%, rgba(255, 236, 190, 0.42), rgba(18, 10, 6, 0.28) 58%);
}

.panel.interlude {
  position: relative;
  width: min(1100px, 100%);
  border: none;
  background: transparent;
  box-shadow: none;
  pointer-events: none;
  overflow: visible;
}

.inferno {
  position: absolute;
  left: 50%;
  bottom: 18%;
  width: min(920px, 92vw);
  height: 180px;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 0;
}

.inferno i {
  position: absolute;
  bottom: 0;
  width: 70px;
  height: 140px;
  border-radius: 50% 50% 45% 45%;
  background: radial-gradient(circle at 50% 70%, #fff6c8 0%, #ffd15a 18%, #ff7a18 46%, #e02312 72%, transparent 78%);
  filter: blur(1px);
  transform-origin: 50% 100%;
  animation: lick 0.28s ease-in-out infinite alternate;
  opacity: 0.92;
}

.inferno i:nth-child(1) { left: 4%; height: 110px; animation-duration: 0.22s; }
.inferno i:nth-child(2) { left: 18%; height: 160px; animation-duration: 0.31s; }
.inferno i:nth-child(3) { left: 34%; height: 190px; animation-duration: 0.24s; }
.inferno i:nth-child(4) { left: 48%; height: 210px; animation-duration: 0.27s; }
.inferno i:nth-child(5) { left: 62%; height: 170px; animation-duration: 0.21s; }
.inferno i:nth-child(6) { left: 76%; height: 150px; animation-duration: 0.33s; }
.inferno i:nth-child(7) { left: 88%; height: 120px; animation-duration: 0.25s; }

.boom {
  position: relative;
  z-index: 1;
  margin: 8px 0 0;
  font-size: clamp(28px, 6.4vw, 84px);
  line-height: 1.15;
  letter-spacing: 0.14em;
  font-weight: 500;
  white-space: nowrap;
  animation: slam 0.5s ease-out both;
}

.boom.advent {
  font-size: clamp(36px, 8vw, 108px);
  white-space: nowrap;
}

.boom span {
  background-image: linear-gradient(
    100deg,
    #ff3b3b 0%,
    #ff8a00 14%,
    #ffe14a 28%,
    #5dff7a 42%,
    #3ecbff 56%,
    #7a7bff 70%,
    #e15bff 84%,
    #ff3b6a 100%
  );
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: rainbow 1.1s linear infinite;
  filter:
    drop-shadow(0 0 10px rgba(255, 220, 150, 0.55))
    drop-shadow(0 0 22px rgba(255, 90, 40, 0.35));
}

.boom span.goldline {
  background-image: none;
  color: #fff6e4;
  -webkit-text-fill-color: #fff6e4;
  animation: none;
  filter:
    drop-shadow(0 0 12px rgba(226, 182, 87, 0.6))
    drop-shadow(0 0 26px rgba(180, 40, 40, 0.35));
}

.fire-lead {
  position: relative;
  z-index: 1;
  margin-top: 10px;
  font-family: "Iowan Old Style", Palatino, "Hiragino Mincho ProN", serif;
  font-size: 16px;
  letter-spacing: 0.32em;
  color: rgba(255, 242, 220, 0.92);
  text-shadow: 0 0 16px rgba(226, 182, 87, 0.4);
}

.divine {
  position: absolute;
  left: 50%;
  top: 42%;
  width: min(780px, 92vw);
  height: min(780px, 92vw);
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 0;
}

.divine .core {
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 252, 240, 0.96) 0%, rgba(255, 226, 150, 0.62) 26%, rgba(255, 196, 90, 0.2) 50%, transparent 70%);
  animation: divine-pulse 1.5s ease-in-out infinite alternate;
}

.divine .halo {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58%;
  height: 58%;
  border-radius: 50%;
  border: 3px solid rgba(255, 244, 214, 0.95);
  box-shadow:
    0 0 18px rgba(255, 236, 190, 0.95),
    0 0 48px rgba(255, 210, 120, 0.75),
    inset 0 0 28px rgba(255, 250, 230, 0.65);
  transform: translate(-50%, -50%);
}

.divine .rays {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: repeating-conic-gradient(
    from 0deg,
    rgba(255, 244, 210, 0) 0deg 7deg,
    rgba(255, 248, 220, 0.72) 7deg 10deg,
    rgba(255, 244, 210, 0) 10deg 18deg
  );
  -webkit-mask-image: radial-gradient(circle, transparent 16%, #000 34%, transparent 74%);
  mask-image: radial-gradient(circle, transparent 16%, #000 34%, transparent 74%);
  animation: spin-rays 16s linear infinite;
}

@keyframes slam {
  from { transform: scale(1.4); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes rainbow {
  from { background-position: 0% 50%; }
  to { background-position: 220% 50%; }
}

@keyframes lick {
  from { transform: scaleY(0.82) scaleX(0.9) translateY(8px); }
  to { transform: scaleY(1.12) scaleX(1.08) translateY(-6px); }
}

@keyframes divine-pulse {
  from { transform: scale(0.9); opacity: 0.72; }
  to { transform: scale(1.08); opacity: 1; }
}

@keyframes spin-rays {
  to { transform: rotate(360deg); }
}

@media (max-width: 640px) {
  .stats, .ships { grid-template-columns: 1fr; }
  .ship { min-height: 0; }
  button.ghost { margin-left: 0; }
  .panel { padding: 22px 16px 16px; }
  #banner { font-size: 16px; letter-spacing: 0.22em; }
  #hint {
    max-width: 92vw;
    white-space: normal;
    text-align: center;
    line-height: 1.45;
  }
  .boom.advent { white-space: normal; }
}
