/* Fight Foundry — HUD & page chrome */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --hud-yellow: #ffd23d;
  --hud-orange: #ff8a2a;
  --hud-red: #e83b3b;
  --hud-blue: #2ea6ff;
  --hud-dark: rgba(8, 10, 16, .82);
  --px-font: "Lucida Console", Consolas, monospace;
  --game-display-width: min(100vw, calc(100vh * 1.7142857));
  --game-display-height: min(100vh, calc(100vw * .5833333));
}

html, body {
  height: 100%;
  background: #05060a;
  overflow: hidden;
  font-family: var(--px-font);
  color: #eee;
  user-select: none;
}

#game {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#screen {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  width: var(--game-display-width);
  height: var(--game-display-height);
  max-width: 100vw;
  max-height: 100vh;
}

#nativeHud {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: var(--game-display-width);
  height: var(--game-display-height);
  max-width: 100vw;
  max-height: 100vh;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
  display: none;
  z-index: 4;
}

#game.native-hud-ready #nativeHud { display: block; }
#game.native-hud-ready #topbar,
#game.native-hud-ready #bottombar { display: none; }
#game.native-screen-presentation-active #nativeHud,
#game.native-screen-presentation-active #hud { visibility: hidden; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: var(--game-display-width);
  height: var(--game-display-height);
  pointer-events: none;
  font-size: clamp(9px, 1.4vh, 14px);
  z-index: 5;
}

#topbar {
  position: absolute;
  top: 3%; left: 2%; right: 2%;
  display: flex;
  gap: 1.5%;
  align-items: flex-start;
  filter: drop-shadow(0 3px 5px rgba(0,0,0,.55));
}
#topbar .side { flex: 1; position: relative; }
#topbar .center { position: relative; width: 12%; text-align: center; }
#timer {
  position: relative; z-index: 0; display: inline-block; min-width: 2.4em;
  font-size: 2.2em; color: var(--hud-yellow); text-shadow: 2px 2px 0 #000; font-weight: bold;
}
#timer::before {
  content: ""; position: absolute; z-index: -1; inset: -.14em -.22em -.2em;
  background: linear-gradient(145deg, #53c6ff, #174b9e 52%, #081c55);
  border: 2px solid #071333; outline: 1px solid #9fe5ff;
  clip-path: polygon(18% 0, 82% 0, 100% 50%, 82% 100%, 18% 100%, 0 50%);
}
#timer.urgent { color: #ff6a58; animation: timer-urgent .5s steps(2) infinite; }
@keyframes timer-urgent { 50% { transform: scale(1.12); text-shadow: 2px 2px 0 #000, 0 0 14px rgba(255,70,50,.72); } }
/* The timer plate overhangs its box by .2em at the bottom, and #timer's z-index makes it
   paint over this static sibling, so the label needs both the clearance and the layer. */
#mode  {
  position: relative; z-index: 1; margin-top: .75em; white-space: nowrap;
  font-size: .8em; color: #9ab; letter-spacing: .2em; text-shadow: 1px 1px 0 #000;
}

.side .name {
  font-size: 1.1em; font-weight: bold; letter-spacing: .15em;
  color: #72ff78; text-shadow: 2px 2px 0 #000;
  margin-bottom: 2px;
}
.side.p2 { text-align: right; }
.team-member { position: relative; transition: opacity .1s linear, filter .1s linear; }
.team-member.active::before {
  content: "▶"; position: absolute; left: -1.25em; top: 1.55em;
  color: var(--hud-yellow); font-size: .72em; text-shadow: 1px 1px 0 #000;
}
.p2 .team-member.active::before { content: "◀"; left: auto; right: -1.25em; }
.team-member.reserve { margin-top: 3px; opacity: .66; filter: saturate(.72); }
.team-member.reserve.onscreen-partner { opacity: 1; filter: saturate(1) brightness(1.12); }
.team-member.reserve.onscreen-partner::after {
  content: "DUO"; position: absolute; top: 0; font-size: .62em; font-weight: 900;
  color: #84d8ff; text-shadow: 1px 1px 0 #000;
}
.p1 .team-member.reserve.onscreen-partner::after { right: 0; }
.p2 .team-member.reserve.onscreen-partner::after { left: 0; }
.team-member.reserve.knocked-out { opacity: .28; filter: grayscale(1); }
.team-member.reserve .name { font-size: .72em; color: #aab6c8; margin-bottom: 1px; }
.special-partner {
  margin-top: 4px; color: #fff7a3; font-size: .68em; font-weight: 900; letter-spacing: .08em;
  text-shadow: 1px 1px 0 #000, 0 0 5px rgba(255,210,61,.58);
}
.special-partner.active { color: #fff; animation: helper-active .18s steps(2) infinite; }
@keyframes helper-active { 50% { color: var(--hud-yellow); transform: translateX(2px); } }

/* Modern HUD: plain straight bars (no skew) with crisp vector rendering. */
.healthbar {
  position: relative;
  height: 14px;
  background: #26060a;
  border: 2px solid #000;
  outline: 1px solid #5a6472;
  border-radius: 2px;
  overflow: hidden;
}
.healthbar .fill {
  position: absolute; inset: 0;
  background: linear-gradient(#fff9c9 0 30%, var(--hud-yellow) 30% 65%, var(--hud-orange) 65%);
  transform-origin: left;
  transition: filter .08s linear;
}
.p2 .healthbar .fill { transform-origin: right; }
.healthbar .fill.red { background: #c22; }
.healthbar::after {
  content: ""; position: absolute; inset: 1px 0 auto; height: 2px; z-index: 3;
  background: rgba(255,255,255,.42); pointer-events: none;
}
.partner-healthbar { height: 9px; border-width: 1px; outline-color: #3e4654; }
.partner-healthbar::after { height: 1px; }
.side.low-health .healthbar { animation: health-danger .46s steps(2) infinite; }
@keyframes health-danger { 50% { outline-color: #ff4a3d; box-shadow: 0 0 10px rgba(255,45,35,.6); } }

#bottombar {
  position: absolute; left: 2%; right: 2%; bottom: 2.5%;
  display: flex; justify-content: space-between; align-items: end;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.72));
}
.meterwrap { display: flex; align-items: center; gap: 5px; width: 46%; }
.p2-meter { flex-direction: row-reverse; }
.level-label { color: #fff; font-size: .72em; font-weight: 900; letter-spacing: .08em; text-shadow: 2px 2px 0 #000; }
.meter {
  position: relative; flex: 1; height: 13px;
  background: #111827; border: 2px solid #000; outline: 1px solid #f1f4f8;
  overflow: hidden;
}
.meter .fill {
  position: absolute; inset: 0;
  background: linear-gradient(#fffbd4 0 34%, var(--hud-yellow) 34% 70%, var(--hud-orange) 70%);
  transform-origin: left;
}
.p2-meter .meter .fill { transform-origin: right; }
.meter .fill.max { background: linear-gradient(#fff 0 40%, #ffd23d 40%); animation: meter-max .4s steps(2) infinite; }
.variable-cross .meter .fill { background: linear-gradient(#fff 0 35%, #83eeff 35% 70%, #3c8cff 70%); animation: meter-max .24s steps(2) infinite; }
@keyframes meter-max { 50% { filter: brightness(1.65); } }
.stocks { min-width: 1ch; color: var(--hud-yellow); font-weight: 900; font-size: 1.65em; line-height: 1; text-shadow: 2px 2px 0 #000; }
.dmginfo { margin-top: 4px; color: #9ab; font-size: .85em; text-shadow: 1px 1px 0 #000; min-height: 1.2em; opacity: 0; transform: translateY(-2px); transition: opacity .12s, transform .12s; }
.dmginfo.active { opacity: 1; transform: translateY(0); color: #d9e6f3; }

/* combo counter */
#combo {
  position: absolute; left: 4%; top: 22%;
  font-size: 2.4em; font-weight: bold; font-style: italic;
  color: var(--hud-yellow);
  text-shadow: 3px 3px 0 #a02, -1px -1px 0 #a02, 1px -1px 0 #a02, -1px 1px 0 #a02;
  animation: combo-enter .18s cubic-bezier(.2,1.8,.3,1) both;
}
@keyframes combo-enter { from { opacity: 0; transform: translateX(-18px) scale(1.45) rotate(-5deg); } to { opacity: 1; transform: none; } }
#combo #comboNum { font-size: 1.5em; color: #fff; }
#combo.hidden { display: none; }

#announce {
  position: absolute; left: 50%; top: 34%;
  transform: translateX(-50%);
  font-size: 2.6em; font-weight: bold; font-style: italic; white-space: nowrap;
  color: #fff;
  text-shadow: -3px -3px 0 #08101d, 3px -3px 0 #08101d, -3px 3px 0 #08101d, 3px 3px 0 #08101d, 0 0 18px var(--hud-blue);
  z-index: 8;
  filter: drop-shadow(0 8px 4px rgba(0,0,0,.5));
}
#announce.hidden { display: none; animation: none; }
#announce[data-kind="round_call"] { color: #fff; font-size: 3.6em; letter-spacing: .06em; animation: announce-round 1.08s ease-out both; }
#announce[data-kind="fight_call"] { color: var(--hud-yellow); font-size: 7em; letter-spacing: .03em; animation: announce-fight .75s cubic-bezier(.15,.9,.24,1) both; }
#announce[data-kind="ko_call"] { color: #ff5a46; font-size: 8em; letter-spacing: .03em; animation: announce-ko 1.16s cubic-bezier(.1,.82,.25,1) both; }
#announce[data-kind="match_result"] { color: #fff; font-size: 4.5em; animation: announce-result 3s ease-out both; }
#announce[data-kind="team_switch"] { color: #84d8ff; font-size: 3.2em; animation: announce-switch .7s ease-out both; }
#game[data-visual-ready="true"] #announce { animation: none !important; opacity: 1; }
@keyframes announce-round {
  0% { opacity: 0; transform: translateX(-50%) scale(2.2); }
  20% { opacity: 1; transform: translateX(-50%) scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes announce-fight { 0% { opacity: 0; transform: translateX(-50%) scale(3.6) skewX(-12deg); } 24% { opacity: 1; transform: translateX(-50%) scale(1) skewX(-12deg); } 70% { opacity: 1; } 100% { opacity: 0; transform: translateX(-50%) scale(.8) skewX(-12deg); } }
@keyframes announce-ko { 0% { opacity: 0; transform: translateX(-50%) scale(4) rotate(-8deg); } 18% { opacity: 1; transform: translateX(-50%) scale(1.05) rotate(-8deg); } 72% { opacity: 1; } 100% { opacity: 0; transform: translateX(-50%) scale(.82) rotate(-8deg); } }
@keyframes announce-result { 0% { opacity: 0; transform: translateX(-50%) translateY(15px) scale(1.4); } 12%, 80% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); } 100% { opacity: 0; } }
@keyframes announce-switch { 0% { opacity: 0; transform: translateX(-50%) scale(1.8) skewX(-12deg); } 18%, 68% { opacity: 1; transform: translateX(-50%) scale(1) skewX(-12deg); } 100% { opacity: 0; } }

/* input history */
#inputHistory {
  position: absolute; left: 2%; bottom: 16%;
  display: flex; flex-direction: column-reverse; gap: 2px;
  min-height: 30%;
}
#inputHistory .row {
  display: flex; align-items: center; gap: 3px;
  background: rgba(0,0,0,.45);
  padding: 1px 5px; border-radius: 3px;
  width: max-content;
}
#inputHistory .dir { color: #fff; font-size: 1.25em; text-shadow: 1px 1px 0 #000; }
#inputHistory .btn {
  display: inline-block; width: 1.6em; height: 1.6em; line-height: 1.6em;
  border-radius: 50%; text-align: center; font-weight: bold; font-size: .8em;
  color: #fff; text-shadow: 1px 1px 0 rgba(0,0,0,.6);
}
#inputHistory .btn.P { background: radial-gradient(circle at 35% 30%, #ff9a56, #c92f00); }
#inputHistory .btn.K { background: radial-gradient(circle at 35% 30%, #6fc0ff, #0b4f9e); }

#menuButton,
#debugButton {
  position: absolute; left: 2%; bottom: 8.5%;
  pointer-events: auto;
  min-width: 72px;
  padding: .55em 1em;
  border: 2px solid #0a0d14;
  outline: 1px solid #76849a;
  border-radius: 4px;
  background: linear-gradient(#354258, #141b28);
  color: #fff;
  font: bold .95em var(--px-font);
  letter-spacing: .14em;
  text-shadow: 1px 1px 0 #000;
  box-shadow: 0 3px 0 #07090e, 0 0 12px rgba(46, 166, 255, .22);
  cursor: pointer;
}
#debugButton { left: calc(2% + 84px); }
#menuButton:hover,
#debugButton:hover { color: var(--hud-yellow); background: linear-gradient(#465872, #1b2535); opacity: 1; }
#menuButton:active,
#debugButton:active { transform: translateY(2px); box-shadow: 0 1px 0 #07090e; }
#menuButton:focus-visible,
#debugButton:focus-visible { outline: 2px solid var(--hud-yellow); outline-offset: 2px; }

#metadataLegend {
  position: absolute; left: 1.5%; top: 21%;
  display: grid; grid-template-columns: repeat(2, max-content); gap: 3px 12px;
  padding: 7px 9px;
  border: 1px solid rgba(150, 180, 215, .45); border-radius: 4px;
  background: rgba(4, 7, 12, .78);
  color: #b9c5d3; font: bold .68em/1.25 var(--px-font);
  letter-spacing: .08em; text-shadow: 1px 1px 0 #000;
  pointer-events: none;
}
#metadataLegend.hidden { display: none; }
.metadata-legend-item { display: flex; align-items: center; gap: 5px; }
.metadata-legend-swatch { width: 8px; height: 8px; border: 1px solid rgba(255,255,255,.65); }

/* ---------- move list panel ---------- */
#movelist {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 1050px); max-height: 88vh;
  background: var(--hud-dark);
  border: 1px solid #3a4656; border-radius: 10px;
  backdrop-filter: blur(6px);
  padding: 18px 22px;
  overflow: auto;
  z-index: 20;
}
#movelist.hidden { display: none; }
.ml-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.ml-head h1 { font-size: 18px; color: var(--hud-yellow); letter-spacing: .06em; }
.ml-head .src { color: #8aa; font-size: 12px; font-weight: normal; margin-left: 10px; }
#mlClose {
  background: none; border: 1px solid #556; color: #cde;
  border-radius: 5px; padding: 3px 10px; cursor: pointer; font-family: inherit;
}
#mlClose:hover { background: #334; }
.ml-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 4px 26px; }
.ml-cat { grid-column: 1 / -1; margin-top: 10px; color: var(--hud-orange); font-size: 12px; letter-spacing: .2em; border-bottom: 1px solid #333c48; padding-bottom: 3px; }
.ml-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 3px 2px; }
.ml-row:hover { background: rgba(255,255,255,.05); }
.ml-row .mv { color: #dfe7f0; }
.ml-row .cmd { color: var(--hud-yellow); white-space: nowrap; font-weight: bold; }
.ml-row .cmd .k { color: #9fd1ff; }
.ml-note { font-size: 11px; color: #8aa; margin-top: 12px; line-height: 1.6; }

/* ---------- arcade menu ---------- */
#menu {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: var(--game-display-width);
  height: var(--game-display-height);
  display: flex; align-items: center; justify-content: center;
  background: rgba(3, 4, 10, .45);
  z-index: 15;
}
#menu.hidden { display: none; }
.menu-box {
  text-align: center;
  background: rgba(8, 10, 18, .88);
  border: 2px solid #3a4656; outline: 4px solid rgba(0,0,0,.6);
  border-radius: 6px;
  padding: 3vh 4vw;
  backdrop-filter: blur(3px);
}
.menu-title {
  font-size: clamp(28px, 7vh, 56px); font-weight: bold; font-style: italic;
  color: var(--hud-red); letter-spacing: .04em;
  text-shadow: 3px 3px 0 #000, 0 0 24px rgba(232,59,59,.55);
}
.menu-title span { color: #fff; text-shadow: 3px 3px 0 #000; }
.menu-sub {
  color: #8aa; font-size: clamp(9px, 1.6vh, 13px); letter-spacing: .3em;
  margin: 6px 0 3vh;
}
#menuOpts { list-style: none; display: flex; flex-direction: column; gap: 1.6vh; }
#menuOpts li {
  font-size: clamp(14px, 3.2vh, 26px); font-weight: bold; letter-spacing: .12em;
  color: #9ab; text-shadow: 2px 2px 0 #000;
}
#menuOpts li.sel { color: var(--hud-yellow); animation: menublink 1s steps(2) infinite; }
#menuOpts li.sel::before { content: "▶ "; color: #fff; }
#menuOpts li.sel::after { content: " ◀"; color: #fff; }
@keyframes menublink { 50% { opacity: .55; } }
/* ---------- spatial debug overlay ---------- */
#metadataMenu {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 4vh 4vw;
  background: rgba(2, 4, 9, .64);
  backdrop-filter: blur(3px);
  z-index: 30;
}
#metadataMenu.hidden { display: none; }
.metadata-panel {
  width: min(720px, 92vw); max-height: 88vh;
  padding: clamp(16px, 3vh, 28px);
  overflow: auto;
  background: rgba(8, 12, 20, .96);
  border: 2px solid #47627c; outline: 4px solid rgba(0,0,0,.62);
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(0,0,0,.55), 0 0 24px rgba(46, 166, 255, .18);
}
.metadata-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 2.2vh; }
#metadataMenuTitle {
  color: #9fdcff; font-size: clamp(18px, 3.8vh, 30px); font-weight: bold;
  letter-spacing: .18em; text-shadow: 2px 2px 0 #000;
}
.metadata-sub { margin-top: 5px; color: #71869c; font-size: clamp(9px, 1.5vh, 12px); letter-spacing: .22em; }
#metadataClose {
  flex: none; width: 36px; height: 36px;
  border: 1px solid #526a82; border-radius: 5px;
  background: #151e2b; color: #d7e5f2;
  font: bold 22px/1 var(--px-font); cursor: pointer;
}
#metadataClose:hover { border-color: var(--hud-yellow); color: var(--hud-yellow); background: #263244; }
#metadataClose:focus-visible { outline: 2px solid var(--hud-yellow); outline-offset: 2px; }
#metadataOpts {
  list-style: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}
#metadataOpts li { min-width: 0; }
#metadataOpts .metadata-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 1.2em;
  width: 100%; min-height: 40px; padding: .55em .7em; border: 1px solid #263241; border-radius: 4px;
  background: rgba(14, 20, 30, .8); color: #91a2b5;
  font-size: clamp(10px, 1.7vh, 13px); font-weight: bold; letter-spacing: .1em;
  font-family: var(--px-font); text-shadow: 1px 1px 0 #000; cursor: pointer;
}
#metadataOpts .metadata-toggle:hover { border-color: #6d8299; color: #d7e2ee; }
#metadataOpts .metadata-toggle:focus-visible { outline: 2px solid var(--hud-yellow); outline-offset: 1px; }
#metadataOpts .metadata-toggle.enabled { border-color: #3aa768; background: rgba(26, 72, 46, .62); color: #e7fff0; }
#metadataOpts .toggle-value { min-width: 2.4em; color: #66788c; text-align: right; }
#metadataOpts .metadata-toggle.enabled .toggle-value { color: #6cff9d; }
.metadata-hint {
  margin-top: 2vh; color: #718296; font-size: clamp(8px, 1.45vh, 11px);
  text-align: center; letter-spacing: .14em;
}
@media (max-width: 600px) {
  #metadataOpts { grid-template-columns: 1fr; }
  .metadata-panel { max-height: 92vh; }
}
.menu-hint {
  margin-top: 2vh; color: #789; font-size: clamp(8px, 1.5vh, 12px); letter-spacing: .18em;
}

/* ---------- loading ---------- */
#loading {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center;
  background: #05060a; color: #9ab;
  z-index: 40; font-size: 14px; letter-spacing: .2em;
}
#loading .load-logo { font-size: 84px; color: #e83b3b; text-shadow: 0 0 40px rgba(232,59,59,.5); }
#loading.hidden { display: none; }

/* Embedded in the site the game is watched, not operated, so the menu and debug controls are
   hidden there. Opened on its own at /play they are still available. */
#game[data-embedded="true"] #menuButton,
#game[data-embedded="true"] #debugButton,
#game[data-embedded="true"] #metadataLegend { display: none; }
