:root {
  --ink: #3a2030;
  --cream: #fff6e2;
  --red: #e4553b;
  --gold: #ffc94a;
  --sky: #3f9fe8;
  --font: "Baloo 2", "Nunito", "Trebuchet MS", "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #4aa3f0;
  font-family: var(--font); color: var(--ink);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: none; overscroll-behavior: none;
}
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: none; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .3s; }
#hud.on { opacity: 1; }
#vignette {
  position: absolute; inset: 0; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(214, 40, 60, .75) 100%);
}
#bars {
  position: absolute; left: calc(14px + env(safe-area-inset-left)); top: calc(12px + env(safe-area-inset-top));
  display: grid; gap: 6px; width: min(260px, 42vw);
}
.bar span {
  display: block; font-size: 12px; font-weight: 800; letter-spacing: .04em; color: #fff;
  text-shadow: 0 1px 0 var(--ink), 0 0 4px rgba(58, 32, 48, .7);
}
.track {
  height: 14px; border-radius: 9px; background: rgba(58, 32, 48, .55);
  border: 2px solid var(--ink); overflow: hidden;
}
#stBar .track { height: 9px; }
.fill { height: 100%; transform-origin: left center; border-radius: 6px; }
#hpFill { background: linear-gradient(#ff8a6a, var(--red)); }
#stFill { background: linear-gradient(#ffe38a, var(--gold)); }
#stBar.empty .fill { background: #b9aeb4; }

#topRight {
  position: absolute; right: calc(14px + env(safe-area-inset-right)); top: calc(12px + env(safe-area-inset-top));
  display: flex; gap: 10px; align-items: center;
}
#riders {
  font-weight: 800; font-size: 16px; color: #fff; font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 0 var(--ink), 0 0 4px rgba(58, 32, 48, .7);
}
.chip {
  pointer-events: auto; border: 2px solid var(--ink); background: var(--cream); border-radius: 999px;
  padding: 5px 14px; font-weight: 800; font-size: 13px; min-height: 36px;
}

#reticle, #lock, .marker { position: absolute; left: 0; top: 0; will-change: transform; }
#reticle::before {
  content: ""; position: absolute; left: -15px; top: -15px; width: 30px; height: 30px; border-radius: 50%;
  border: 2.5px solid #fff; box-shadow: 0 0 0 1.5px rgba(58, 32, 48, .6), inset 0 0 0 1.5px rgba(58, 32, 48, .6);
}
#reticle::after {
  content: ""; position: absolute; left: -2.5px; top: -2.5px; width: 5px; height: 5px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 1.5px rgba(58, 32, 48, .6);
}
#reticle.firing::before { border-color: var(--gold); }
#chargeRing {
  --c: 0; position: absolute; left: -27px; top: -27px; width: 54px; height: 54px; border-radius: 50%; opacity: 0;
  background: conic-gradient(var(--gold) calc(var(--c) * 360deg), rgba(58, 32, 48, .35) 0);
  -webkit-mask: radial-gradient(circle, transparent 19px, #000 20px); mask: radial-gradient(circle, transparent 19px, #000 20px);
}
#chargeRing.on { opacity: 1; }
#chargeRing.full { background: conic-gradient(#fff 360deg, #fff 0); box-shadow: 0 0 14px var(--gold); }
#reticle.locked::before { border-color: var(--gold); scale: 1.15; }
#hitMark { position: absolute; left: 0; top: 0; opacity: 0; rotate: 45deg; scale: 1.5; transition: opacity .12s, scale .12s; }
#hitMark::before, #hitMark::after {
  content: ""; position: absolute; background: #fff; border-radius: 2px; box-shadow: 0 0 0 1.5px var(--ink);
}
#hitMark::before { left: -19px; top: -2px; width: 38px; height: 4px; }
#hitMark::after { left: -2px; top: -19px; width: 4px; height: 38px; }
#hitMark.on { opacity: 1; scale: 1; transition: none; }
#hitMark.kill { scale: 1.7; }
#hitMark.kill::before, #hitMark.kill::after { background: #ff4a5a; }
#dmg { position: absolute; inset: 0; overflow: hidden; }
.dmgNum {
  position: absolute; left: 0; top: 0; opacity: 0; will-change: transform, opacity; white-space: nowrap;
  font-weight: 800; font-size: 20px; font-variant-numeric: tabular-nums;
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill;
}
.dmgNum.heavy { font-size: 30px; }
#flashFx { position: absolute; inset: 0; background: #fff; opacity: 0; }
#lvBar span { display: flex; align-items: center; gap: 6px; }
#lvBar em { font-style: normal; }
#lvBar .track { height: 7px; }
#flameSwatch { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink); background: #ff7a2a; }
#xpFill { background: #ff7a2a; }
#boltChip { display: none; }
#boltChip.on { display: block; }
#boltChip span {
  display: block; font-size: 12px; font-weight: 800; letter-spacing: .04em; color: #fff;
  text-shadow: 0 1px 0 var(--ink), 0 0 4px rgba(58, 32, 48, .7);
}
#boltChip .track { height: 7px; width: 60%; }
#boltFill { background: #9fdcff; }
#boltChip.ready #boltFill { background: #fff; box-shadow: 0 0 8px #9fdcff; }
#boltChip.ready span::after { content: " " attr(data-ready); color: #bfe9ff; }
#lock::before {
  content: ""; position: absolute; left: -24px; top: -24px; width: 48px; height: 48px;
  border: 3px solid var(--gold); border-radius: 10px; transform: rotate(45deg);
  box-shadow: 0 0 0 1.5px rgba(58, 32, 48, .5);
}
#lock { opacity: 0; transition: opacity .1s; }

.marker { display: none; }
.marker i {
  position: absolute; left: -7px; top: -7px; width: 14px; height: 14px; background: #c59bff;
  border: 2px solid var(--ink); transform: rotate(45deg); border-radius: 3px;
}
.marker b {
  position: absolute; left: -17px; top: 12px; width: 34px; height: 6px; border-radius: 4px;
  background: rgba(58, 32, 48, .6); border: 1.5px solid var(--ink); overflow: hidden;
}
.marker u { display: block; height: 100%; background: #c59bff; transform-origin: left center; }
.marker.danger i { background: #ff4a5a; animation: pulse .35s infinite alternate; }
.marker.danger u { background: #ff4a5a; }
.marker.off b { display: none; }
.marker.off i {
  width: 0; height: 0; left: -10px; top: -12px; background: none; border-radius: 0; transform: none;
  border: 10px solid transparent; border-bottom: 18px solid #c59bff; border-top: 0;
  filter: drop-shadow(0 0 1.5px var(--ink)) drop-shadow(0 0 1.5px var(--ink));
}
.marker.off.danger i { border-bottom-color: #ff4a5a; background: none; }
@keyframes pulse { to { scale: 1.35; } }

#bannerWrap {
  position: absolute; left: 0; right: 0; top: 20%; text-align: center; opacity: 0;
  transform: translateY(8px); transition: opacity .35s, transform .35s;
}
#bannerWrap.on { opacity: 1; transform: none; }
#banner {
  font-size: clamp(26px, 5.2vw, 52px); font-weight: 800; color: #fff; text-wrap: balance;
  text-shadow: 0 3px 0 var(--ink), 0 0 12px rgba(58, 32, 48, .55); -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill;
}
#bannerSub {
  font-size: clamp(14px, 2.2vw, 20px); font-weight: 700; color: #fff;
  text-shadow: 0 1px 0 var(--ink), 0 0 6px rgba(58, 32, 48, .8);
}
#hint, #warn {
  position: absolute; left: 50%; transform: translateX(-50%); padding: 7px 16px; border-radius: 999px;
  font-weight: 700; font-size: 14px; opacity: 0; transition: opacity .3s; text-align: center; max-width: 92vw;
}
#hint { bottom: calc(22px + env(safe-area-inset-bottom)); background: rgba(255, 246, 226, .92); border: 2px solid var(--ink); }
body.touch #hint { bottom: auto; top: calc(74px + env(safe-area-inset-top)); }
#warn { bottom: calc(76px + env(safe-area-inset-bottom)); background: var(--red); color: #fff; border: 2px solid var(--ink); }
#hint.on, #warn.on { opacity: 1; }
#fps {
  position: absolute; left: 14px; bottom: 10px; font: 12px/1.2 ui-monospace, Consolas, monospace; color: #fff;
  text-shadow: 0 0 3px #000; display: none;
}

/* ---------- boss ---------- */
#bossBar {
  position: absolute; left: 50%; top: calc(54px + env(safe-area-inset-top)); width: min(460px, 60vw);
  transform: translateX(-50%); text-align: center; display: none;
}
#bossBar.on { display: block; }
#bossBar span, #bossBar em {
  display: block; font-style: normal; font-weight: 800; font-size: 14px; letter-spacing: .06em; color: #fff;
  text-shadow: 0 1px 0 var(--ink), 0 0 4px rgba(58, 32, 48, .7);
}
#bossBar em { font-size: 13px; min-height: 18px; margin-top: 2px; }
#bossBar .track { height: 16px; }
#bossFill { background: linear-gradient(#8fa8e8, #5a6fc8); transition: background .15s; }
#bossBar.exposed #bossFill { background: linear-gradient(#fff3b0, var(--gold)); }
#bossBar.exposed .track { box-shadow: 0 0 14px var(--gold); }
#bossBar.exposed em { color: var(--gold); }
.marker.boss i { background: #8fd0ff; width: 20px; height: 20px; left: -10px; top: -10px; }
.marker.boss b { display: none; }
.marker.boss.off i { border-bottom-color: #8fd0ff; width: 0; height: 0; }
.marker.boss.exposed i { background: var(--gold); animation: pulse .25s infinite alternate; }
.marker.boss.off.exposed i { background: none; border-bottom-color: var(--gold); }
.dmgNum.crit { font-size: 26px; }
.dmgNum.heavy.crit { font-size: 40px; }
.dmgNum.armor { font-size: 15px; }
.dmgNum.heavy.armor { font-size: 20px; }

/* ---------- touch controls ---------- */
#touch { position: fixed; inset: 0; pointer-events: none; display: none; }
#touch.on { display: block; }
#lookZone { position: absolute; right: 0; top: 60px; bottom: 0; width: 54%; pointer-events: auto; touch-action: none; }
#joyZone { position: absolute; left: 0; bottom: 0; width: 46%; height: 72%; pointer-events: auto; touch-action: none; }
#joyBase {
  position: absolute; left: calc(92px + env(safe-area-inset-left)); top: calc(100% - 96px - env(safe-area-inset-bottom));
  width: 124px; height: 124px; margin: -62px 0 0 -62px; border-radius: 50%;
  background: rgba(255, 246, 226, .28); border: 2.5px solid rgba(58, 32, 48, .65);
}
#joyBase.held { background: rgba(255, 246, 226, .4); }
#joyKnob {
  position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; border-radius: 50%;
  transform: translate(-50%, -50%); background: var(--cream); border: 2.5px solid var(--ink);
}
.tbtn {
  position: absolute; pointer-events: auto; border-radius: 50%; border: 2.5px solid var(--ink);
  background: rgba(255, 246, 226, .82); font-weight: 800; font-size: 13px; padding: 0;
  display: grid; place-items: center;
}
.tbtn.held { background: var(--gold); scale: .94; }
#tFire { width: 92px; height: 92px; right: calc(22px + env(safe-area-inset-right)); bottom: calc(26px + env(safe-area-inset-bottom)); background: rgba(255, 138, 106, .9); font-size: 16px; }
#tBall { width: 70px; height: 70px; right: calc(124px + env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom)); }
#tBoost { width: 66px; height: 66px; right: calc(126px + env(safe-area-inset-right)); bottom: calc(98px + env(safe-area-inset-bottom)); }
#tDodge { width: 66px; height: 66px; right: calc(22px + env(safe-area-inset-right)); bottom: calc(130px + env(safe-area-inset-bottom)); }
#tFire.held { background: var(--gold); }
#tBolt { display: none; width: 62px; height: 62px; right: calc(104px + env(safe-area-inset-right)); bottom: calc(176px + env(safe-area-inset-bottom)); background: rgba(159, 220, 255, .5); }
#tBolt.on { display: grid; }
#tBolt.ready { background: #bfe9ff; box-shadow: 0 0 12px #9fdcff; }

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0; display: none; place-items: center; padding: 16px;
  background: rgba(30, 60, 120, .35); overflow: auto;
}
.screen.on { display: grid; }
#title { background: url(keyart.png) center / cover no-repeat #4aa3f0; }
.panel {
  width: min(760px, 100%); background: rgba(255, 246, 226, .93); border: 3px solid var(--ink);
  border-radius: 22px; padding: clamp(16px, 3vw, 30px); text-align: center;
  box-shadow: 0 8px 0 rgba(58, 32, 48, .35);
}
.panel.small { width: min(400px, 100%); }
h1 {
  margin: 0 0 4px; font-size: clamp(34px, 7vw, 62px); line-height: 1.05; font-weight: 800; color: var(--red);
  -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; letter-spacing: .01em; text-wrap: balance;
}
#end:not(.won) h1 { color: #8d72bd; }
.tag { margin: 0 0 16px; font-size: clamp(15px, 2.2vw, 19px); font-weight: 700; text-wrap: pretty; }
button.big {
  border: 3px solid var(--ink); background: var(--gold); border-radius: 999px; padding: 12px 34px;
  font-size: clamp(18px, 2.6vw, 24px); font-weight: 800; box-shadow: 0 5px 0 var(--ink); min-height: 48px;
  transition: translate .08s, box-shadow .08s;
}
button.big:hover { background: #ffd66e; }
button.big:active { translate: 0 4px; box-shadow: 0 1px 0 var(--ink); }
button.plain {
  display: block; margin: 16px auto 0; border: 2px solid var(--ink); background: var(--cream); border-radius: 999px;
  padding: 7px 18px; font-weight: 700; min-height: 40px;
}
button:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; }
.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; text-align: left; }
.col { background: rgba(255, 255, 255, .6); border: 2px solid rgba(58, 32, 48, .35); border-radius: 14px; padding: 10px 12px; }
.col h2 { margin: 0 0 6px; font-size: 14px; font-weight: 800; color: var(--red); }
dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 13px; line-height: 1.35; }
dt { font-weight: 800; white-space: nowrap; }
dd { margin: 0; }
.note { margin: 12px 0 0; font-size: 12px; opacity: .75; min-height: 1em; }
.settings { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 14px; font-weight: 800; font-size: 14px; }
.seg { display: inline-flex; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; background: var(--cream); }
.seg button { border: 0; background: none; padding: 6px 16px; font-weight: 700; min-height: 36px; }
.seg button + button { border-left: 2px solid var(--ink); }
.seg button[aria-pressed="true"] { background: var(--gold); font-weight: 800; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode { background: rgba(255, 255, 255, .6); border: 2px solid rgba(58, 32, 48, .35); border-radius: 14px; padding: 14px 12px 10px; }
.mode p { margin: 10px 0 0; font-size: 13px; line-height: 1.35; font-weight: 600; text-wrap: pretty; }
.mode .best { font-weight: 800; color: var(--red); min-height: 1.35em; margin-top: 6px; }
button.big.alt { background: #c9b4f2; }
button.big.alt:hover { background: #d9c8fa; }
#rankBox { display: grid; justify-items: center; margin: 6px 0 10px; }
#rankBox span { font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; opacity: .7; }
#rankLetter {
  font-size: 84px; line-height: 1; font-weight: 800; color: var(--gold);
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--ink);
}
#rankBox[data-rank="S"] #rankLetter { color: #8ff5ea; }
#rankBox[data-rank="A"] #rankLetter { color: var(--gold); }
#rankBox[data-rank="B"] #rankLetter { color: #9fd06a; }
#rankBox[data-rank="C"] #rankLetter { color: #c9b4f2; }
#rankBox[data-rank="D"] #rankLetter { color: #b9aeb4; }
#rankBox em { font-style: normal; font-size: 13px; font-weight: 800; color: var(--red); min-height: 1.2em; margin-top: 6px; }
#endStats { margin: 0 0 18px; grid-template-columns: 1fr auto; text-align: left; font-size: 14px; gap: 3px 16px; }
#endStats dd { font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
#endStats dt { font-weight: 600; }
#end .tag { font-size: 15px; margin-bottom: 12px; }
#end h1 { font-size: clamp(28px, 5vw, 44px); }
#end button.plain { margin-top: 12px; }
@media (max-height: 640px) {
  #rankLetter { font-size: 56px; }
  #rankBox { margin: 2px 0 6px; }
  #endStats { margin-bottom: 12px; font-size: 13px; gap: 1px 16px; }
  #end .panel { padding-top: 12px; padding-bottom: 12px; }
}
@media (max-width: 720px) {
  .controls { grid-template-columns: 1fr; }
  body:not(.touch) .col.tc, body.touch .col.kb, body.touch .col.gp { display: none; }
}
@media (max-width: 460px) { .modes { grid-template-columns: 1fr; } }
@media (max-height: 520px) {
  .controls { margin-top: 12px; }
  #rankLetter { font-size: 52px; }
  #endStats { margin-bottom: 10px; font-size: 13px; }
  .mode p:not(.best) { display: none; }
  .tag { margin-bottom: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .marker.danger i { animation: none; }
  #bannerWrap, #hud { transition: none; }
}
:lang(ko) body { word-break: keep-all; }
:lang(ko) h1 { letter-spacing: 0; }
