:root {
  color-scheme: dark;
  --bg: #151319;
  --panel: #211e26;
  --line: #3d3842;
  --muted: #b8b0ba;
  --gold: #ffcf70;
  --red: #ffad90;
  --blue: #cabaff;
  --ink: #f5eee8;
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font: 100%/1.45 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  align-content: center;
}
main {
  width: min(92%, 1200px);
  margin: auto;
  padding: clamp(1rem, 3vh, 2.25rem) 0;
}
header, nav, .brand, .fighter, .wind, footer, footer span, button, .dialogHead {
  display: flex;
  align-items: center;
}
header, footer, .dialogHead { justify-content: space-between; }
header { gap: 1rem; margin-bottom: 1.2rem; }
.brand { min-width: 0; }
.brand canvas { width: clamp(128px, 16vw, 188px); height: auto; }
canvas { image-rendering: pixelated; }
nav { gap: .35rem; }
button, input { font: inherit; }
button {
  justify-content: center;
  gap: .5rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled, input:disabled { cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}
button:enabled:hover { background-color: #322d36; }
button:enabled:active { background-color: #3c3540; }
.nav, footer button {
  min-height: 40px;
  padding: 0 .65rem;
  color: var(--muted);
  font-size: .875rem;
  font-weight: 550;
  border-color: transparent;
}
.nav:enabled:hover, footer button:enabled:hover { color: var(--ink); }
#lan { color: var(--ink); border-color: var(--line); }
i { display: inline-flex; align-items: center; justify-content: center; }
i svg { width: 17px; height: 17px; }
.cabinet { overflow: hidden; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); }
.scorebar {
  display: grid;
  align-items: center;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: .65rem;
  min-height: 66px;
  padding: .55rem clamp(.8rem, 2vw, 1.55rem);
  background: #1b191f;
}
.fighter { min-width: 0; }
.fighter.blue { flex-direction: row-reverse; text-align: right; }
.player-pick {
  color: inherit; border: 1px solid transparent; padding: .17rem .3rem;
  gap: .54rem; min-width: 0; min-height: 44px; text-align: start;
}
.blue .player-pick { flex-direction: row-reverse; text-align: end; }
.player-meta { min-width: 0; }
.player-pick > i { align-self: center; color: var(--muted); opacity: .75; }
.player-pick > i svg { width: 13px; height: 13px; }
.player-pick:enabled:hover > i, .player-pick:focus-visible > i { color: inherit; opacity: 1; }
.player-pick:disabled > i { display: none; }
.avatar { flex: none; width: 42px; height: auto; }
.playername { display: block; font-size: .94rem; font-weight: 650; line-height: 1.15; }
.red { color: var(--red); }
.blue { color: var(--blue); }
.pips { display: flex; gap: 3px; margin-top: 6px; }
.blue .pips { justify-content: end; }
.pips b { width: 11px; height: 3px; background: #514a53; }
.pips b.on { background: currentColor; }
.round { text-align: center; display: grid; gap: .12rem; }
.round strong, .wind, #precision { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.round strong { font-size: .8rem; letter-spacing: .08em; }
.round small { font-size: .78rem; color: var(--muted); }
.view { position: relative; overflow: hidden; aspect-ratio: 800 / 320; }
.view > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.view .scenery { pointer-events: none; }
#arena, #city3d, .wind-marker, #blastPreview { image-rendering: auto; }
.avatar, .swatch canvas { image-rendering: auto; }
@media (max-width: 900px) and (max-aspect-ratio: 1 / 1) {
  .view { aspect-ratio: 800 / 410; }
}
.wind {
  position: absolute; top: 1.1rem; left: .85rem; gap: .4rem;
  color: #f0e6f2; background: #2c233bc9; padding: .26rem .5rem;
  font-size: .77rem; line-height: 1.4; border-radius: 3px; pointer-events: none;
}
.wind svg { width: 15px; height: 15px; }
#arena { touch-action: none; user-select: none; }
#arena:focus-visible { outline: 1px solid #ddae7394; outline-offset: -2px; }
.shot-bar {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  min-height: 62px; padding: .4rem clamp(.65rem, 1.6vw, 1.25rem);
  border-top: 1px solid var(--line); background: #1b191f;
}
.shot-status { display: grid; gap: .08rem; min-width: 0; }
#turn { display: flex; align-items: center; gap: .48rem; font-size: .9rem; font-weight: 650; }
#turn b { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
#message { color: var(--muted); font-size: .79rem; }
#message:empty { display: none; }
.shot-tools, #precision, #precision label { display: flex; align-items: center; }
.shot-tools { flex: none; gap: .7rem; }
#precision { color: #e7dce8; font-size: .89rem; border: 1px solid var(--line); border-radius: 5px; }
#precision button { width: 33px; min-height: 38px; padding: 0; border: 0; color: var(--muted); touch-action: none; }
#precision button:enabled:hover { color: var(--ink); }
#precision button svg { width: 14px; height: 14px; }
#precision label { cursor: text; white-space: nowrap; min-height: 36px; padding: 0 .15rem; }
#precision label:hover, #precision label:focus-within { background: #302b34; }
#precision input {
  appearance: textfield; -moz-appearance: textfield; border: 0; border-radius: 2px;
  width: 4.8ch; padding: 0; text-align: right; color: inherit; background: transparent; font: inherit;
}
#precision input:focus-visible { outline-offset: 1px; }
#precision input::-webkit-inner-spin-button { appearance: none; }
#precision label span { color: var(--muted); }
.action {
  position: relative; min-height: 40px; min-width: 9.1rem; margin-left: auto; padding: .3rem .8rem; gap: .4rem; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  color: #362616; background: var(--gold); border: 1px solid #ffe0a3;
  font-size: .88rem; font-weight: 650; white-space: nowrap;
}
.action:enabled:hover, dialog .primary:enabled:hover { background: #ffdb8d; }
.action:enabled:active, dialog .primary:enabled:active { background: #f5bd59; }
.action:disabled { color: var(--muted); border-color: var(--line); background: #28242d; font-weight: 500; }
#precision:has(input:disabled) { opacity: .5; }
.action canvas { width: 19px; height: auto; }
.action.has-power { width: 9.1rem; padding-bottom: .6rem; }
#power-track { position: absolute; left: .65rem; right: .65rem; bottom: 5px; height: 3px; background: #63472e40; }
#power-track::after { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(to right, transparent 0 calc(25% - 1px), #ffe0a3 0 25%); }
#power-fill { display: block; height: 100%; background: #624026; transform-origin: left; transform: scaleX(0); }
#last-power { position: absolute; z-index: 1; top: -2px; width: 2px; height: 7px; background: #735138; transform: translateX(-1px); }
#power-value { font: 600 .78rem/1 var(--mono); min-width: 4ch; text-align: right; }
#power-value::before { content: "↑"; margin-right: .22rem; }
#power-value[data-direction="down"]::before { content: "↓"; }
#power-value:is([data-direction="full"], [data-direction="low"])::before { content: "–"; }
footer { padding: .4rem .15rem 0; color: var(--muted); font-size: .82rem; }
footer span, footer button { gap: .48rem; }
footer button:disabled { opacity: .55; }
dialog {
  width: min(92vw, 440px); max-height: 88vh; overflow: auto; padding: 1.4rem;
  color: var(--ink); background: var(--panel); border: 1px solid #514854;
  border-radius: 8px; box-shadow: 0 16px 64px #0006;
}
dialog::backdrop { background: #100e15cf; }
.dialogHead { gap: .8rem; margin-bottom: 1rem; }
.dialogHead h1 { margin: 0; font-size: 1.35rem; line-height: 1.2; font-weight: 650; }
.dialogHead button { width: 34px; height: 34px; font-size: 1.4rem; line-height: 1; }
#dialogBody { font-size: 1rem; line-height: 1.5; }
#dialogBody p { margin: .7rem 0 1rem; color: #d0c9d4; }
#dialogBody p:empty { display: none; }
dialog label { display: block; margin: .75rem 0; }
dialog input {
  width: 100%; margin-top: .2rem; padding: .55rem .65rem; font-size: 1rem;
  background: #17141a; color: var(--ink); border: 1px solid #584f5c; border-radius: 4px;
}
dialog button:not(#close), dialog a { min-height: 40px; padding: .42rem .78rem; font-weight: 600; }
dialog .primary, dialog a { background: var(--gold); color: #372817; border-radius: 4px; }
dialog a { display: inline-block; text-decoration: none; }
dialog hr { border: 0; border-top: 1px solid var(--line); margin: 1.2rem 0; }
.err { color: var(--red) !important; }
.row { display: flex; align-items: stretch; gap: .5rem; margin-top: .2rem; }
.row > * { min-width: 0; }
.row input { margin: 0; }

#swatches {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem;
}
#swatches .swatch {
  position: relative; display: grid; justify-items: center; gap: .25rem;
  padding: .7rem .25rem .5rem; background: #1b181f;
  border: 1px solid #443c47; color: #e3dbe4;
  font-size: .86rem; font-weight: 550;
}
.swatch canvas { width: 58px; height: 48px; }
#swatches .swatch:enabled:hover { border-color: #8b7d91; background: #29242d; }
#swatches .swatch[aria-pressed="true"] {
  color: var(--swatch, var(--ink)); border-color: currentColor;
  background-color: color-mix(in srgb, var(--swatch, var(--ink)) 8%, #1b181f);
}
.swatch[aria-pressed="true"]::after {
  content: ""; position: absolute; top: .45rem; right: .45rem;
  width: 7px; height: 3px; border-left: 2px solid; border-bottom: 2px solid;
  transform: rotate(-45deg);
}

@media (min-width: 900px) and (max-height: 760px) {
  main { width: min(94%, 1200px, max(760px, calc((100svh - 272px) * 2.75))); padding: .65rem 0; }
  header { margin-bottom: .65rem; }
  .scorebar { min-height: 52px; }
}
@media (max-width: 820px) { main { width: 94%; } }
@media (max-width: 620px) {
  main { width: 95%; }
  header { gap: .45rem; margin-bottom: .8rem; }
  nav { gap: .12rem; }
  .nav { min-height: 40px; padding: 0 .48rem; }
  #help span { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); }
  #help { width: 36px; }
  .scorebar { min-height: 54px; padding-inline: .6rem; gap: .35rem; }
  .avatar { width: 29px; }
  .player-pick { gap: .25rem; padding-inline: 0; }
  .player-pick > i svg { width: 11px; height: 11px; }
  .playername { font-size: .8rem; }
  .pips { gap: 2px; }
  .pips b { width: 7px; }
  .round strong { font-size: .72rem; }
  .round small { font-size: .72rem; }
  .wind { top: .55rem; left: .42rem; font-size: .69rem; padding: .1rem .28rem; }
  .wind svg { width: 12px; height: 12px; }
  footer { padding-top: .2rem; }
}
@media (max-width: 365px) {
  .avatar { display: none; }
  .brand canvas { width: 112px; }
}

#points { color: var(--ink); font-size: 1.22rem; line-height: 1.1; letter-spacing: .14em; }
.round small { white-space: nowrap; }
[hidden] { display: none !important; }
.sound-toggle { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.sound-toggle input { width: 1.25rem; height: 1.25rem; accent-color: var(--gold); }
.sound-toggle, .sound-toggle input, #testBlast { cursor: pointer; }
#testBlast { margin-top: 1rem; }
@media (max-width: 620px) {
  #sound span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #sound { width: 36px; }
}
#blastPreview { display: block; width: 100%; height: auto; border-radius: 4px; margin: .2rem 0 1rem; }

@media (max-width: 600px) {
  .shot-bar { flex-wrap: wrap; gap: .45rem; }
  .shot-status { flex: 1 0 100%; min-height: 2.4rem; justify-content: center; }
  .shot-tools { flex: 1; justify-content: space-between; }
  #turn { font-size: .8rem; }
  #message { font-size: .75rem; }
}
@media (pointer: coarse) {
  #precision button { width: 42px; }
  #precision button, .action, .nav { min-height: 44px; }
}

.movement { display: flex; align-items: center; gap: 1px; }
.movement button {
  width: 32px; min-height: 38px; padding: 0; border: 1px solid transparent;
  border-radius: 4px; color: var(--muted); font: 1.05rem var(--mono);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.movement button:enabled:hover, .movement button:active { color: var(--ink); background: #342e37; }
@media (max-width: 840px) {
  .shot-bar:has(.movement) { flex-wrap: wrap; row-gap: .45rem; }
  .shot-bar:has(.movement) .shot-status { flex: 1 0 100%; }
  .shot-bar:has(.movement) .shot-tools { flex: 1; }
  .movement { margin-right: auto; }
}
@media (pointer: coarse) {
  .movement button { width: 40px; min-height: 44px; }
}
@media (max-width: 480px) {
  .shot-tools:has(.movement) { gap: .28rem; }
  .movement { gap: 0; }
  .movement button { width: 29px; }
  .shot-tools:has(.movement) #precision button { width: 27px; }
  .shot-tools:has(.movement) .action { min-width: 0; flex: 1; padding-inline: .45rem; }
}

.opponent select {
  appearance: auto; background: var(--bg); color: var(--muted); font: inherit;
  border: 0; padding: .32rem .1rem; cursor: pointer;
}
.opponent select:hover, .opponent select:focus-visible { color: var(--ink); }
.opponent select option { background: #211c25; color: var(--ink); }

.movement button[data-held="true"] { color: var(--gold); background: #40382c; border-color: #766346; }
@media (any-pointer: coarse) {
  .shot-tools button { touch-action: none; -webkit-touch-callout: none; user-select: none; }
  .view, .shot-bar { -webkit-touch-callout: none; }
  #precision input { font-size: 16px; }
  main { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
}
@media (any-pointer: coarse) and (max-width: 620px) {
  main { width: calc(100% - 14px); padding-block: max(10px,env(safe-area-inset-top)) max(10px,env(safe-area-inset-bottom)); }
  .view { aspect-ratio: 800 / 520; }
  .nav, #sound, #help { min-width: 44px; min-height: 44px; }
  .shot-bar:has(.movement) {
    display: grid; grid-template-columns: minmax(0,1fr) auto; grid-template-areas: "status aim" "move fire";
    gap: .35rem .5rem; padding: .35rem .5rem .55rem;
  }
  .shot-tools:has(.movement) { display: contents; }
  .shot-status { grid-area: status; }
  .movement { grid-area: move; gap: 3px; }
  .movement button { width: 45px; min-height: 50px; border-color: var(--line); background: #29252d; }
  .shot-tools:has(.movement) #precision { grid-area: aim; justify-self: end; }
  .shot-tools:has(.movement) #precision button { width: 44px; min-height: 44px; }
  .shot-tools:has(.movement) .action { grid-area: fire; width: 100%; min-height: 50px; margin: 0; }
  .row input, dialog select, dialog input[type="text"] { font-size: 16px; }
}
@media (any-pointer: coarse) and (orientation: landscape) and (max-height: 560px) {
  main {
    display: grid; grid-template-columns: 1fr auto;
    width: min(calc(100% - 8px),calc((100svh - 147px - env(safe-area-inset-bottom)) * 2.75));
    min-width: min(100%,460px); padding-block: max(1px,env(safe-area-inset-top)) max(1px,env(safe-area-inset-bottom));
  }
  header { grid-column: 1; grid-row: 1; margin: 0; gap: .2rem; }
  .brand canvas { width: 92px; }
  nav { gap: 0; margin-left: auto; }
  .nav, #help, #sound { padding: .2rem .38rem; min-width: 44px; min-height: 44px; }
  #help span, #sound span { display: none; }
  footer { grid-column: 2; grid-row: 1; padding: 0; gap: 0; }
  footer button, footer select { font-size: .72rem; padding-inline: .3rem; }
  footer > span > i { display: none; }
  .cabinet { grid-column: 1/-1; }
  .scorebar { min-height: 43px; padding: 0 .5rem; }
  .avatar { width: 29px; }
  .view { aspect-ratio: 800 / 290; }
  .wind { left: .4rem; top: .33rem; font-size: .65rem; }
  .shot-bar:has(.movement) {
    display: grid; grid-template-columns: auto 1fr auto auto; grid-template-areas: "move status aim fire";
    padding: 2px 4px; gap: .27rem; min-height: 49px;
  }
  .shot-tools:has(.movement) { display: contents; }
  .movement { grid-area: move; gap: 1px; }
  .movement button, .shot-tools:has(.movement) #precision button { width: 44px; min-height: 44px; }
  .shot-status { grid-area: status; line-height: 1.15; }
  #turn { font-size: .72rem; }
  #message { font-size: .65rem; }
  #precision { grid-area: aim; }
  .shot-tools:has(.movement) .action { grid-area: fire; min-width: 98px; min-height: 44px; margin: 0; padding-inline: .3rem; }
}
