:root {
  --black: #0B0708;
  --soot: #1C1210;
  --red: #C4141E;
  --ember: #FF4B1F;
  --bone: #E9E2D4;
  --steel: #4A4148;
  --hud-h: clamp(64px, 11vh, 104px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--black);
  overflow: hidden;
  overscroll-behavior: none;
  font-family: "Archivo", "Arial Narrow", Arial, sans-serif;
  color: var(--bone);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--black);
}

#stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  transition: filter 700ms ease;
}

#stage.decolour canvas {
  filter: saturate(0.25) contrast(1.08) brightness(0.9);
}

#grain {
  position: absolute;
  inset: 0;
  background-image: url("assets/grain.png");
  background-size: 256px 256px;
  opacity: 0.085;
  mix-blend-mode: overlay;
  pointer-events: none;
  z-index: 3;
}

#vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 48%, rgba(0,0,0,0) 38%, rgba(0,0,0,0.42) 72%, rgba(0,0,0,0.82) 100%);
  pointer-events: none;
  z-index: 4;
}

#flash {
  position: absolute;
  inset: 0;
  background: var(--bone);
  opacity: 0;
  pointer-events: none;
  z-index: 22;
}

#flash.on {
  animation: flashHit 200ms steps(3, end);
}

@keyframes flashHit {
  0% { opacity: 0.32; }
  45% { opacity: 0.1; }
  100% { opacity: 0; }
}

#blazeGlow {
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 0 rgba(255, 75, 31, 0);
  pointer-events: none;
  z-index: 6;
  transition: box-shadow 300ms ease;
}

#blazeGlow.on {
  box-shadow: inset 0 0 150px 14px rgba(255, 75, 31, 0.22), inset 0 0 38px 3px rgba(196, 20, 30, 0.38);
  animation: blazePulse 900ms ease-in-out infinite alternate;
}

@keyframes blazePulse {
  from { box-shadow: inset 0 0 110px 8px rgba(255, 75, 31, 0.16), inset 0 0 26px 2px rgba(196, 20, 30, 0.3); }
  to { box-shadow: inset 0 0 170px 20px rgba(255, 75, 31, 0.28), inset 0 0 46px 5px rgba(196, 20, 30, 0.46); }
}

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

#hud {
  opacity: 0;
  transition: opacity 420ms ease;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--hud-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: clamp(10px, 1.6vw, 26px);
  padding: 10px clamp(12px, 2vw, 30px) 8px;
  background: linear-gradient(180deg, rgba(11,7,8,0.97) 0%, rgba(11,7,8,0.9) 76%, rgba(11,7,8,0.0) 100%);
  border-bottom: 1px solid rgba(196,20,30,0.55);
  z-index: 12;
  pointer-events: none;
}

body.playing #hud { opacity: 1; }

.side {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  padding-top: 2px;
}

.fighter-id {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.side.right .fighter-id { justify-content: flex-end; }

.emblem {
  flex: 0 0 auto;
  width: clamp(18px, 2.2vh, 24px);
  height: clamp(18px, 2.2vh, 24px);
  display: grid;
  place-items: center;
  background: var(--red);
  color: var(--bone);
  font-weight: 700;
  font-size: clamp(8px, 1vh, 11px);
  letter-spacing: 0.06em;
  clip-path: polygon(0 0, 100% 0, 100% 72%, 72% 100%, 0 100%);
}

.emblem.rival { background: var(--bone); color: var(--red); }

.fname {
  font-weight: 700;
  font-size: clamp(9px, 1.55vh, 16px);
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--bone);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trough {
  position: relative;
  height: clamp(13px, 2.1vh, 21px);
  background: #070405;
  border: 1.5px solid var(--bone);
  overflow: hidden;
}

.trough .residue {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(78,9,13,0.55), rgba(120,14,20,0.28));
}

.side.right .trough .residue {
  background: linear-gradient(270deg, rgba(78,9,13,0.55), rgba(120,14,20,0.28));
}

.trough .fill {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  background: var(--red);
  box-shadow: inset 0 0 14px rgba(0,0,0,0.45);
  transition: width 110ms linear;
}

.side.left .trough .fill { left: 0; }
.side.right .trough .fill { right: 0; }

.trough .notches {
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(to right, transparent 0 calc(10% - 1px), rgba(233,226,212,0.26) calc(10% - 1px) 10%);
  pointer-events: none;
}

.blaze-meter {
  display: flex;
  align-items: center;
  gap: 6px;
  height: clamp(7px, 1.1vh, 10px);
}

.side.right .blaze-meter { flex-direction: row-reverse; }

.blaze-tag {
  font-size: clamp(6px, 0.8vh, 8px);
  font-weight: 700;
  letter-spacing: 0.22em;
  color: rgba(233,226,212,0.6);
}

.blaze-ch {
  position: relative;
  flex: 1;
  height: 100%;
  background: #060304;
  border: 1px solid rgba(233,226,212,0.35);
  overflow: hidden;
}

.blaze-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0%;
  background: var(--ember);
  transition: width 100ms linear;
}

.side.right .blaze-fill { right: 0; }
.side.left .blaze-fill { left: 0; }

.blaze-fill.ready { animation: blazeReady 620ms steps(2, end) infinite; }

@keyframes blazeReady {
  0% { background: var(--ember); }
  100% { background: #ffb08a; }
}

.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding-top: 0;
}

#timer {
  font-weight: 700;
  font-size: clamp(30px, 6.4vh, 64px);
  line-height: 0.86;
  letter-spacing: 0.02em;
  color: var(--bone);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(0,0,0,0.7);
  transition: color 160ms linear;
}

#timer.warn { color: var(--ember); }
#timer.danger {
  color: var(--red);
  animation: timerPulse 460ms steps(2, end) infinite;
}

@keyframes timerPulse {
  0% { opacity: 1; }
  100% { opacity: 0.42; }
}

.pips {
  display: flex;
  gap: 6px;
  height: 8px;
}

.round-line {
  font-size: 9px;
  letter-spacing: 0.15em;
  font-weight: 700;
  color: rgba(233, 226, 212, 0.82);
  white-space: nowrap;
  margin-top: 2px;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.8);
}

.pips i {
  display: block;
  width: 18px;
  height: 6px;
  background: transparent;
  border: 1px solid rgba(233,226,212,0.55);
}

.pips i.p { background: var(--red); border-color: var(--red); box-shadow: 0 0 8px rgba(196, 20, 30, 0.9); }
.pips i.s { background: var(--bone); border-color: var(--bone); box-shadow: 0 0 7px rgba(233, 226, 212, 0.6); }

/* ---------------- sound + legend ---------------- */

#soundBtn {
  display: block;
  position: absolute;
  top: calc(var(--hud-h) + 8px);
  right: 10px;
  z-index: 30;
  background: rgba(11,7,8,0.72);
  color: rgba(233,226,212,0.78);
  border: 1px solid rgba(233,226,212,0.28);
  padding: 5px 8px;
  font-family: "Archivo", Arial, sans-serif;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  cursor: pointer;
}

#soundBtn:hover { color: var(--bone); border-color: var(--bone); }

#legend {
  opacity: 0;
  transition: opacity 420ms ease;
  position: absolute;
  left: 50%;
  bottom: calc(8px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 12;
  display: flex;
  gap: clamp(10px, 2.2vw, 30px);
  white-space: nowrap;
  padding: 6px 14px;
  background: rgba(11,7,8,0.74);
  border-top: 1px solid rgba(196,20,30,0.5);
  font-size: clamp(8px, 1.05vw, 11px);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(233,226,212,0.66);
  pointer-events: none;
}

body.playing #legend { opacity: 1; }

#legend b {
  color: var(--bone);
  font-weight: 700;
  margin-left: 4px;
}

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

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 260ms ease, visibility 260ms;
}

.overlay.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

#title {
  background:
    radial-gradient(120% 66% at 50% 96%, rgba(196,20,30,0.24) 0%, rgba(196,20,30,0.07) 48%, rgba(196,20,30,0) 72%),
    linear-gradient(180deg, rgba(11,7,8,0.86) 0%, rgba(11,7,8,0.18) 38%, rgba(11,7,8,0.1) 62%, rgba(11,7,8,0.86) 100%);
  z-index: 25;
}

.title-inner {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0 4vw;
  transform: translateY(-1.5vh);
}

.credit {
  font-weight: 700;
  font-size: clamp(9px, 1.5vw, 15px);
  letter-spacing: 0.46em;
  color: rgba(233,226,212,0.86);
  margin-bottom: clamp(8px, 1.4vh, 18px);
  text-transform: none;
  padding-left: 0.46em;
}

.credit span { color: var(--red); margin: 0 0.3em; }

.ygb-logo {
  display: block;
  width: clamp(38px, 6vh, 72px);
  height: auto;
  margin: 0 auto clamp(6px, 1.2vh, 14px);
  filter: drop-shadow(-2px 2px 0 rgba(196, 20, 30, 0.85));
}

.wordmark {
  margin: 0;
  font-family: "Alfa Slab One", Georgia, serif;
  font-weight: 400;
  font-size: clamp(1.9rem, 9.2vw, 15rem);
  line-height: 0.84;
  letter-spacing: -0.005em;
  text-transform: uppercase;
  color: var(--bone);
  text-shadow: -0.045em 0.05em 0 var(--red);
  white-space: nowrap;
}

.wordmark span { display: inline; }

.tagline {
  margin-top: clamp(8px, 2.2vh, 26px);
  font-family: "Alfa Slab One", Georgia, serif;
  font-size: clamp(0.95rem, 3.2vw, 3.1rem);
  letter-spacing: 0.06em;
  color: var(--bone);
  text-shadow: -0.03em 0.04em 0 rgba(196,20,30,0.9);
  text-transform: uppercase;
}

.start-prompt {
  margin-top: clamp(18px, 4vh, 54px);
  padding: 10px 18px;
  background: transparent;
  border: 0;
  color: var(--bone);
  font-family: "Archivo", Arial, sans-serif;
  font-weight: 700;
  font-size: clamp(9px, 1.4vw, 15px);
  letter-spacing: 0.34em;
  text-transform: uppercase;
  cursor: pointer;
  animation: promptBlink 1200ms steps(2, end) infinite;
}

.start-prompt:hover,
.start-prompt:focus-visible { color: var(--red); outline: 0; }

@keyframes promptBlink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0.22; }
}

.title-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 3px 16px;
  margin-top: clamp(12px, 2.4vh, 26px);
  max-width: 92vw;
  font-family: "Archivo", Arial, sans-serif;
  font-weight: 700;
  font-size: clamp(7px, 1vw, 11px);
  letter-spacing: 0.16em;
  color: rgba(233,226,212,0.85);
  text-transform: uppercase;
  text-align: center;
  background: rgba(11, 7, 8, 0.62);
  border: 1px solid rgba(196, 20, 30, 0.38);
  padding: 7px 14px;
}

.title-controls b { color: var(--red); font-weight: 700; }

#loadingNote {
  margin-top: 10px;
  font-size: 8px;
  letter-spacing: 0.3em;
  color: rgba(233,226,212,0.4);
}

/* round card */

#card {
  background: transparent;
  z-index: 24;
  transition: none;
  align-items: flex-start;
  padding-top: calc(var(--hud-h) + 12px);
}

.card-band {
  width: auto;
  max-width: 92%;
  height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.05em 0.55em 0.11em;
  background: linear-gradient(90deg, rgba(11,7,8,0) 0%, rgba(11,7,8,0.72) 14%, rgba(11,7,8,0.72) 86%, rgba(11,7,8,0) 100%);
  border-top: 2px solid rgba(196,20,30,0.9);
  border-bottom: 2px solid rgba(196,20,30,0.9);
  color: var(--bone);
  font-family: "Alfa Slab One", Georgia, serif;
  font-size: clamp(1.35rem, 4vw, 3.2rem);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-shadow: 0 2px 0 rgba(0,0,0,0.7);
  transform-origin: center;
}

#card.show .card-band { animation: bandIn 320ms cubic-bezier(0.18, 1.2, 0.3, 1) both; }

@keyframes bandIn {
  0% { transform: scaleY(0.08) scaleX(0.82); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

#card.fight {
  background: transparent;
}

#card.fight .card-band {
  background: transparent;
  border-color: transparent;
  color: var(--bone);
  font-size: clamp(2.2rem, 8vw, 7.5rem);
  text-shadow: -0.05em 0.055em 0 var(--red);
  height: auto;
  padding: 0.02em 0.4em 0.08em;
}

#card.fight.show .card-band { animation: fightIn 260ms cubic-bezier(0.2, 1.8, 0.35, 1) both; }

@keyframes fightIn {
  0% { transform: scale(1.7); opacity: 0; }
  62% { transform: scale(0.94); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* KO stamp */

#stamp {
  background: transparent;
  z-index: 26;
}

#stamp span {
  display: inline-block;
  padding: 0.02em 0.1em 0.06em;
  border: clamp(4px, 0.7vw, 9px) solid var(--bone);
  color: var(--red);
  font-family: "Alfa Slab One", Georgia, serif;
  font-size: clamp(4rem, 17vw, 15rem);
  line-height: 0.9;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  background: rgba(11,7,8,0.2);
  box-shadow: 0.06em 0.07em 0 rgba(196,20,30,0.55);
}

#stamp.left { justify-content: flex-start; padding-left: 7vw; }
#stamp.right { justify-content: flex-end; padding-right: 7vw; }
#stamp.left span { transform: rotate(-6deg); }
#stamp.right span { transform: rotate(6deg); }

@media (max-aspect-ratio: 1/1) {
  #stamp.left { padding-left: 2vw; }
  #stamp.right { padding-right: 2vw; }
  #stamp span { font-size: clamp(3rem, 30vw, 9rem); }
}

#stamp.show span { animation: stampDrop 420ms cubic-bezier(0.2, 1.35, 0.35, 1) both; }

@keyframes stampDrop {
  0% { opacity: 0; transform: translateY(-42vh) scale(1.5) rotate(-6deg); }
  70% { opacity: 1; transform: translateY(2vh) scale(0.96) rotate(-6deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(-6deg); }
}

/* match end */

#matchEnd {
  background:
    radial-gradient(90% 70% at 50% 55%, rgba(196,20,30,0.18), rgba(11,7,8,0.9) 70%),
    rgba(11,7,8,0.78);
  z-index: 28;
}

.end-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0 5vw;
}

.end-kicker {
  font-weight: 700;
  font-size: clamp(8px, 1.2vw, 12px);
  letter-spacing: 0.5em;
  color: var(--red);
  margin-bottom: 12px;
  padding-left: 0.5em;
}

.end-title {
  font-family: "Alfa Slab One", Georgia, serif;
  font-size: clamp(1.7rem, 6.4vw, 6rem);
  line-height: 0.92;
  text-transform: uppercase;
  color: var(--bone);
  text-shadow: -0.04em 0.045em 0 var(--red);
}

.end-score {
  margin-top: 14px;
  font-weight: 700;
  font-size: clamp(1.5rem, 4vw, 3.4rem);
  letter-spacing: 0.2em;
  color: var(--bone);
  font-variant-numeric: tabular-nums;
}

/* ---------------- touch ---------------- */

#touch {
  position: absolute;
  inset: auto 0 0 0;
  z-index: 18;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 10px clamp(10px, 2.6vw, 26px) calc(12px + var(--safe-b));
  pointer-events: none;
}

#touch .pad,
#touch .actions { pointer-events: auto; }

.pad {
  display: grid;
  grid-template-columns: repeat(3, var(--tbtn));
  grid-template-rows: repeat(3, var(--tbtn));
  gap: 4px;
  --tbtn: clamp(38px, 9.4vmin, 58px);
}

.tbtn {
  -webkit-appearance: none;
  appearance: none;
  border: 1.5px solid rgba(233,226,212,0.55);
  background: rgba(11,7,8,0.62);
  color: rgba(233,226,212,0.9);
  font-family: "Archivo", Arial, sans-serif;
  font-weight: 700;
  font-size: clamp(8px, 1.7vmin, 11px);
  letter-spacing: 0.1em;
  cursor: pointer;
  touch-action: none;
  padding: 0;
}

.tbtn:active,
.tbtn.pressed {
  background: var(--red);
  border-color: var(--bone);
  color: var(--bone);
}

.pad .up { grid-column: 2; grid-row: 1; }
.pad .left { grid-column: 1; grid-row: 2; }
.pad .right { grid-column: 3; grid-row: 2; }
.pad .down { grid-column: 2; grid-row: 3; }

.pad::after {
  content: "MOVE";
  grid-column: 2;
  grid-row: 2;
  display: grid;
  place-items: center;
  font-size: 7px;
  letter-spacing: 0.22em;
  color: rgba(233,226,212,0.4);
  pointer-events: none;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, var(--abtn));
  grid-template-rows: repeat(2, var(--abtn));
  gap: 6px;
  --abtn: clamp(48px, 12vmin, 76px);
}

.actions .act {
  font-size: clamp(8px, 1.8vmin, 11px);
  letter-spacing: 0.08em;
}

.actions .act:nth-child(1) { grid-column: 1; grid-row: 2; border-color: rgba(196,20,30,0.8); }
.actions .act:nth-child(2) { grid-column: 2; grid-row: 2; border-color: rgba(196,20,30,0.8); }
.actions .act.blaze {
  grid-column: 2;
  grid-row: 1;
  border-color: rgba(255,75,31,0.8);
  color: var(--ember);
}

.actions .act.blaze.ready {
  background: rgba(196,20,30,0.72);
  color: var(--bone);
  animation: blazeReady 620ms steps(2, end) infinite;
}

@media (pointer: coarse), (max-width: 820px) {
  body.playing #touch { display: flex; }
  #legend { display: none; }
}

@media (max-aspect-ratio: 1/1) {
  .wordmark { white-space: normal; font-size: clamp(2.2rem, 13.4vw, 7.4rem); }
  .wordmark span { display: block; }
  .wordmark span + span { margin-top: 0.02em; }
  #hud { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .fname { font-size: 7px; letter-spacing: 0.07em; }
  #timer { font-size: clamp(26px, 5.2vh, 50px); }
  .pips i { width: 14px; }
  .round-line { font-size: 7px; letter-spacing: 0.12em; }
  #soundBtn { top: calc(var(--hud-h) + 4px); }
  .credit { letter-spacing: 0.3em; }
}

@media (max-height: 520px) and (orientation: landscape) {
  :root { --hud-h: 62px; }
  .title-inner { transform: translateY(-3vh); }
  .wordmark { font-size: clamp(2rem, 9vw, 7rem); }
  .tagline { margin-top: 6px; font-size: clamp(0.8rem, 2.6vw, 2rem); }
  .start-prompt { margin-top: 14px; }
  .credit { margin-bottom: 4px; }
}
