* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: #14121c;
  color: #eee;
  font-family: "Trebuchet MS", system-ui, sans-serif;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 16px;
}
#game {
  position: relative;
  width: min(960px, 100%, calc((100vh - 80px) * 16 / 9));
  aspect-ratio: 16 / 9;
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
canvas { display: block; width: 100%; height: 100%; image-rendering: auto; }

#hud {
  position: absolute; inset: 0 0 auto 0;
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 16px;
  pointer-events: none;
}
.side { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.p2 { align-items: flex-end; }
.name { font-weight: 800; letter-spacing: 1px; font-size: clamp(10px, 1.6vw, 15px); text-shadow: 0 2px 0 #000; }
.who { opacity: .6; font-weight: 400; }
.bar {
  width: 100%; height: clamp(10px, 2.2vw, 20px);
  background: #3a0d0d; border: 2px solid #111; border-radius: 4px; overflow: hidden;
  display: flex;
}
.p2 .bar { justify-content: flex-end; }
.fill { height: 100%; width: 100%; background: linear-gradient(#ffe35a, #e8a913); transition: width .15s; }
.fill.low { background: linear-gradient(#8fe36b, #3c9a22); animation: pulse .6s infinite alternate; }
@keyframes pulse { to { filter: brightness(1.4); } }
.tag { font-size: clamp(10px, 1.4vw, 13px); font-weight: 700; color: #9cf27a; visibility: hidden; text-shadow: 0 1px 0 #000; }
.tag.on { visibility: visible; animation: wobble .4s infinite alternate; }
@keyframes wobble { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
#timer {
  min-width: 2.4em; text-align: center;
  font-size: clamp(18px, 3.6vw, 34px); font-weight: 900;
  background: #111a; border: 2px solid #000; border-radius: 6px; padding: 0 6px;
  text-shadow: 0 2px 0 #000;
}

#banner {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; pointer-events: none;
  font-weight: 900; text-shadow: 0 4px 0 #000, 0 0 20px #000a;
}
#banner.top { justify-content: flex-start; padding-top: 7.5%; }
#banner.top .big { font-size: clamp(20px, 4.6vw, 44px); }
#banner.top .mid { font-size: clamp(12px, 2.1vw, 20px); margin-top: 2px; }
#banner.top .small { font-size: clamp(10px, 1.5vw, 14px); margin-top: 6px; }
#banner .big { font-size: clamp(28px, 7vw, 72px); color: #ffe35a; letter-spacing: 2px; }
#banner .mid { font-size: clamp(16px, 3vw, 30px); color: #fff; margin-top: 6px; }
#banner .small { font-size: clamp(11px, 1.8vw, 18px); color: #ccc; margin-top: 14px; font-weight: 600; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .35; } }

#help {
  font-size: 14px; color: #aaa; text-align: center;
  display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; align-items: center;
}
.langbox select {
  background: #2a2733; color: #fff; border: 1px solid #555; border-radius: 4px;
  font: inherit; padding: 2px 6px;
}
#draft { color: #e8c86a; font-size: 12px; }
#draft:empty { display: none; }

/* character select */
.cards { display: flex; gap: 14px; margin-top: 14px; flex-wrap: wrap; justify-content: center; }
.card {
  width: clamp(120px, 22vw, 200px); padding: 12px 14px; border-radius: 10px;
  background: #1c1a26e6; border: 3px solid #444; text-shadow: none;
}
.card.on { border-color: #ffe35a; box-shadow: 0 0 0 3px #ffe35a55; }
.card.soon { opacity: .55; border-style: dashed; }
.cname { font-size: clamp(16px, 2.4vw, 24px); color: #ffe35a; }
.ctag { font-size: clamp(11px, 1.5vw, 14px); color: #ddd; font-weight: 600; margin-top: 6px; }
kbd {
  background: #2a2733; border: 1px solid #555; border-bottom-width: 3px; border-radius: 4px;
  padding: 1px 6px; font-family: inherit; color: #fff;
}

/* special-move meter under the player's health bar */
.meter { display: none; position: relative; width: 55%; height: clamp(5px, 1vw, 9px); background: #15202b; border: 2px solid #111; border-radius: 4px; }
.meter.on { display: block; }
.mfill { height: 100%; width: 0; background: linear-gradient(#9fdcff, #2f8fd8); }
.mfill.full { background: linear-gradient(#fff7a8, #ffb300); animation: pulse .4s infinite alternate; }
.mlabel { position: absolute; left: calc(100% + 8px); top: 50%; transform: translateY(-50%); white-space: nowrap;
  font-size: clamp(10px, 1.4vw, 13px); font-weight: 800; color: #ffe35a; text-shadow: 0 1px 0 #000; }

/* tap a card to pick it */
.card { pointer-events: auto; cursor: pointer; }

/* ---------- touch screens (phones / tablets) ---------- */
#touch, #rotate { display: none; }
body.touch {
  padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  gap: 8px;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
  min-height: 100dvh; height: auto;
}
body.touch #controls { display: none; }
body.touch #touch {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; max-width: 960px; gap: 10px;
  touch-action: none;
}
.tbtn {
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .12); border: 2px solid rgba(255, 255, 255, .35);
  border-radius: 14px; color: #fff; font-weight: 800;
  text-shadow: 0 1px 0 #000; touch-action: none;
}
.tbtn.on { background: rgba(255, 227, 90, .55); border-color: #ffe35a; transform: scale(.94); }

.dpad {
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); gap: 4px;
  width: min(42vw, 180px); aspect-ratio: 1;
}
.arrow { font-size: clamp(18px, 5vw, 26px); border-radius: 12px; }
.arrow.up { grid-area: 1 / 2; } .arrow.left { grid-area: 2 / 1; }
.arrow.right { grid-area: 2 / 3; } .arrow.down { grid-area: 3 / 2; }

.actions {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  width: min(46vw, 220px);
}
.act { flex-direction: column; aspect-ratio: 1; border-radius: 50%; gap: 1px; }
.act .ic { font-size: clamp(18px, 5vw, 24px); line-height: 1; }
.act .lb { font-size: clamp(8px, 2.3vw, 11px); text-transform: uppercase; letter-spacing: .5px; }
.act.slap { background: rgba(255, 122, 26, .3); border-color: #ff7a1a; }
.act.block { background: rgba(80, 150, 255, .25); border-color: #6aa2ff; grid-column: 1 / 2; }
.act.special {
  grid-column: 2 / 4; aspect-ratio: auto; border-radius: 30px;
  background: rgba(255, 210, 31, .28); border-color: #ffd21f; flex-direction: row; gap: 6px;
}
.act.special .ic { color: #ffd21f; }

.menu { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.tbtn.small { padding: 8px 12px; font-size: 13px; border-radius: 10px; min-width: 64px; }
.tbtn.start { background: rgba(255, 227, 90, .3); border-color: #ffe35a; }

body.touch #rotate { color: #888; font-size: 12px; text-align: center; }
body.touch { overflow-x: hidden; }
@media (orientation: portrait) {
  body.touch #rotate { display: block; }
  body.touch { justify-content: flex-start; padding-top: max(16px, env(safe-area-inset-top)); }
  body.touch #game { width: 100%; }
  body.touch #touch { gap: 6px; margin-top: 6px; }
  body.touch .dpad { width: 34vw; }
  body.touch .actions { width: 40vw; gap: 5px; }
  body.touch .tbtn.small { min-width: 0; padding: 8px 6px; font-size: 11px; }
}

/* sideways phone: the game fills the height, the controls float over its lower corners */
@media (orientation: landscape) {
  body.touch { padding-top: 4px; padding-bottom: 4px; justify-content: center; }
  body.touch #game { width: min(100%, calc((100dvh - 8px) * 16 / 9)); border-radius: 0; }
  body.touch #help { display: none; }
  body.touch #touch {
    position: fixed; left: 0; right: 0; bottom: 0; max-width: none;
    padding: 0 max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    pointer-events: none; align-items: flex-end;
  }
  body.touch #touch > * { pointer-events: auto; }
  body.touch .tbtn { background: rgba(20, 18, 28, .35); }
  body.touch .tbtn.on { background: rgba(255, 227, 90, .55); }
  body.touch .dpad { width: min(30vh, 150px); opacity: .85; }
  body.touch .actions { width: min(38vh, 190px); opacity: .9; }
  body.touch .menu { flex-direction: row; align-self: flex-end; }
  body.touch .menu .tbtn.small { padding: 3px 8px; font-size: 10px; min-width: 0; opacity: .7; }
}
