:root {
  color-scheme: dark;
  --ink: #08090d;
  --navy: #142d40;
  --panel: #1d3b53;
  --white: #fff8e7;
  --muted: #bed4dd;
  font-family: "Trebuchet MS", system-ui, sans-serif;
  background: #102435;
  color: var(--white);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(ellipse at 50% 0%, #274e5b 0%, #172f44 45%, #102435 90%);
}
button { font: inherit; touch-action: manipulation; cursor: pointer; }
button:focus-visible { outline: 3px solid #fff0a1; outline-offset: 3px; }
button:disabled { cursor: default; }

.game {
  width: min(100%, 540px);
  margin-inline: auto;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
.top {
  min-height: 62px;
  position: relative;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
}
h1 {
  margin: 0;
  text-align: center;
  font-size: clamp(13px, 4vw, 18px);
  line-height: .96;
  font-weight: 950;
  letter-spacing: .15em;
  filter: drop-shadow(0 3px 0 #08090d);
}
h1 span, h1 strong {
  display: block;
  paint-order: stroke fill;
  -webkit-text-stroke: 3px var(--ink);
}
h1 strong {
  margin-top: 3px;
  font-size: clamp(27px, 8.5vw, 43px);
  letter-spacing: .025em;
  color: #ffd073;
  -webkit-text-stroke-width: 5px;
}
.language {
  position: absolute;
  inset: auto 0 auto auto;
  min-width: 44px;
  min-height: 44px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  color: var(--white);
  font-weight: 900;
  background: var(--panel);
  box-shadow: inset 0 2px #ffffff26, 0 3px var(--ink);
}
.battlefield {
  position: relative;
  height: clamp(270px, calc(100dvh - 267px), 487px);
  border: 3px solid var(--ink);
  border-radius: 17px;
  overflow: hidden;
  background: #6cb476;
  box-shadow: 0 4px 0 var(--ink);
}
#arena { display: block; width: 100%; height: 100%; }
.stage, .hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 18px);
  margin: 0;
  padding: 5px 10px;
  border-radius: 8px;
  background: #142d40eb;
  border: 2px solid var(--ink);
  text-align: center;
  font-weight: 800;
}
.stage { top: 8px; font-size: clamp(.83rem, 4vw, 1rem); }
.hint { bottom: 8px; font-size: .84rem; }
.hud {
  position: absolute;
  top: 46px;
  left: 8px;
  right: 8px;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, .65fr) minmax(0, 1fr);
  gap: 5px;
  padding: 5px;
  border: 2px solid var(--ink);
  border-radius: 11px;
  background: #142d40f0;
  box-shadow: 0 2px #152c36;
}
.hud > div { display: grid; align-content: center; min-width: 0; gap: 3px; padding: 0 4px; text-align: center; }
.hud > div + div { border-left: 1px solid #577183; }
.hud span, .reserve { color: var(--muted); font-size: clamp(.73rem, 3vw, .85rem); font-weight: 800; }
.hud strong { font-size: .97rem; font-variant-numeric: tabular-nums; }
.mastery strong { color: #ffd073; }
.meter { display: grid; position: relative; overflow: hidden; border: 2px solid var(--ink); border-radius: 7px; background: var(--panel); }
.meter span { position: absolute; inset: 0 auto 0 0; background: #65c95c; box-shadow: inset 0 2px #e0f6ae; }
.meter strong { z-index: 1; paint-order: stroke fill; -webkit-text-stroke: 3px var(--ink); }

.controls {
  margin-top: 9px;
  padding: 8px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: #233f54;
  box-shadow: inset 0 2px #ffffff24, 0 3px var(--ink);
}
.draw { display: flex; align-items: center; min-height: 58px; gap: 9px; padding: 5px; background: #172f44; border: 2px solid var(--ink); border-radius: 10px; }
.portrait {
  flex: 0 0 53px;
  height: 47px;
  display: grid;
  place-items: center;
  background: repeating-linear-gradient(-45deg, #285363 0 5px, #2d5a69 5px 10px);
  border: 2px solid var(--ink);
  border-radius: 7px;
}
.portrait[data-rarity="common"] { background: #599c83; }
.portrait[data-rarity="rare"] { background: #a993d5; }
.portrait canvas { width: 49px; height: auto; }
.draw-copy { min-width: 0; display: grid; gap: 1px; line-height: 1.15; }
.draw-copy p { margin: 0; color: #ffd589; font-size: .74rem; font-weight: 800; }
.draw-copy strong { font-size: .98rem; overflow-wrap: anywhere; }
.draw-copy span { color: var(--muted); font-size: .82rem; }
.reserve { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 3px 6px; margin: 7px 0; }
.pips { display: flex; gap: 4px; }
.pips i { width: clamp(15px, 5vw, 25px); height: 11px; border: 1.5px solid var(--ink); border-radius: 4px; background: #142d40; }
.pips .full { background: #ffc961; box-shadow: inset 0 2px #ffe5aa; }
.actions { display: flex; gap: 7px; }
.actions > button { flex: 1; min-width: 0; }
.button {
  min-height: 46px;
  padding: 7px 8px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  color: var(--white);
  font-size: clamp(.83rem, 3.8vw, 1.04rem);
  font-weight: 900;
  line-height: 1.1;
  background: linear-gradient(var(--face) 0 78%, var(--edge) 78% 100%);
  box-shadow: inset 0 2px #ffffff70, 0 2px var(--ink);
}
.button { paint-order: stroke fill; -webkit-text-stroke: 3px var(--ink); }
.booster { --face: #e97d2f; --edge: #a94e28; }
.start { --face: #308fce; --edge: #1c5c9c; }
.button:active:not(:disabled) { transform: translateY(2px); box-shadow: inset 0 2px #ffffff50; }
.button:disabled { --face: #536675; --edge: #364b5b; color: #e1e7e4; }

dialog {
  width: min(355px, calc(100% - 28px));
  padding: 18px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  text-align: center;
  background: var(--panel);
  color: var(--white);
  box-shadow: 0 5px var(--ink);
}
dialog::backdrop { background: #0b1d2bca; }
dialog h2 { margin: 0; color: #ffd073; }
dialog .button { width: 100%; margin-top: 4px; }
dialog p { margin: 6px 0 10px; color: var(--muted); }
.error { text-align: center; }

@media (min-width: 600px) {
  .game { padding-top: 16px; }
}
@media (max-height: 590px) {
  .top { min-height: 51px; margin-bottom: 6px; }
  .battlefield { min-height: 235px; }
}
