:root {
  font:
    13px Tahoma,
    Arial,
    sans-serif;
  color: #293333;
  background: #e4e3d8;
  --line: #98a4a1;
  --paper: #f4f3e9;
  --blue: #d5e3e8;
  --sage: #dce5d6;
  --cream: #ece6cf;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  overflow: hidden;
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
button,
select,
input {
  border: 1px solid #8b9998;
  border-radius: 3px;
  background: #faf9f1;
  padding: 7px 9px;
}
button {
  cursor: pointer;
}
button:hover {
  background: #e5ece8;
}
button:disabled {
  cursor: wait;
  opacity: 0.6;
}
button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 2px solid #315d78;
  outline-offset: 2px;
}
a {
  color: #275c7b;
}
label {
  display: flex;
  gap: 8px;
  align-items: center;
}
input[type='checkbox'] {
  accent-color: #4d7163;
}
p {
  margin: 9px 0;
  line-height: 1.5;
}
[hidden] {
  display: none !important;
}
#game {
  position: fixed;
  inset: 0;
  background-color: #e1e1d4;
  background-image:
    linear-gradient(#858d7912 1px, transparent 1px),
    linear-gradient(90deg, #858d7912 1px, transparent 1px);
  background-size: 80px 80px;
  touch-action: none;
}
canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#overlay {
  pointer-events: none;
}
#top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 5px max(9px, env(safe-area-inset-right)) 5px max(9px, env(safe-area-inset-left));
  background: #edf0e8eb;
  border-bottom: 1px solid var(--line);
  height: 38px;
  z-index: 3;
}
#top strong {
  font-size: 13px;
}
#top button {
  margin-left: auto;
  padding: 3px 9px;
}
#performance {
  font-size: 11px;
  color: #596660;
}
.panel {
  position: fixed;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 12px;
  z-index: 5;
  max-height: calc(100dvh - 70px);
  overflow: auto;
}
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--blue);
  border-bottom: 1px solid var(--line);
  font-weight: bold;
  margin: -12px -12px 12px;
  padding: 8px 12px;
  gap: 8px;
}
.bar button {
  padding: 3px 8px;
  font-weight: normal;
}
.join-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.muted,
.controls {
  color: #59645f;
  font-size: 12px;
}
#menu {
  width: min(760px, calc(100% - 24px));
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
#name {
  width: 180px;
}
#classes {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  margin-top: 14px;
}
#classes button {
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  background: #e9eade;
}
#classes button[aria-checked='true'] {
  border: 2px solid #4d7163;
  padding: 3px;
  background: var(--sage);
}
#classes canvas {
  position: static;
  width: 72px;
  height: 88px;
  image-rendering: pixelated;
}
#classes span {
  font-size: 11px;
}
#class-description {
  min-height: 32px;
  padding: 8px;
  border: 1px solid #c6cdc3;
  background: #edf0e6;
}
#join {
  background: var(--sage);
  min-width: 100px;
  font-weight: bold;
}
#account {
  font-size: 12px;
}
#best {
  margin-bottom: 0;
}
#hud {
  position: fixed;
  z-index: 3;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(330px, calc(100% - 28px));
  pointer-events: none;
  background: #f2f3e9e8;
  padding: 7px;
  border: 1px solid #a6b0a4;
  border-radius: 3px;
}
#hud button {
  pointer-events: auto;
  padding: 2px 6px;
  font-size: 11px;
}
.health {
  height: 21px;
  background: #ddd6cf;
  position: relative;
  border: 1px solid #80937a;
}
.health > div {
  height: 100%;
  background: #8da97b;
}
.health span {
  position: absolute;
  inset: 0;
  text-align: center;
  font-size: 12px;
  line-height: 19px;
}
.hud-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  margin: 5px 0;
}
.xp {
  height: 4px;
  background: #d3d9d8;
}
.xp > div {
  height: 100%;
  background: #6e99ab;
}
#charge {
  position: relative;
  height: 15px;
  margin-top: 5px;
  background: #dbd6c5;
  border: 1px solid #9c967d;
  overflow: hidden;
}
#charge-fill {
  background: #b9a770;
  height: 100%;
}
#charge-window {
  position: absolute;
  left: 65%;
  width: 17%;
  height: 100%;
  border-left: 2px solid #426c42;
  border-right: 2px solid #426c42;
  background: #8aab6d55;
}
#charge span {
  position: absolute;
  inset: 0;
  text-align: center;
  font-size: 10px;
}
#protection {
  font-size: 11px;
  color: #355f78;
  text-align: center;
}
#upgrades {
  right: 12px;
  top: 49px;
  width: min(310px, calc(100% - 24px));
  padding: 9px;
}
#upgrades .bar {
  margin: -9px -9px 8px;
  padding: 6px 9px;
  background: var(--cream);
}
#upgrade-choices {
  display: grid;
  gap: 6px;
}
#upgrade-choices button {
  text-align: left;
  padding: 8px;
}
#upgrade-choices small {
  display: block;
  margin-top: 4px;
  line-height: 1.3;
  color: #536059;
}
#results {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  min-width: 270px;
}
#result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 24px;
}
#save-status {
  font-size: 12px;
}
#options {
  width: min(430px, calc(100% - 24px));
  right: 12px;
  top: 48px;
}
.option-grid {
  display: grid;
  gap: 12px;
}
.option-grid label:first-child,
.option-grid label:nth-child(5) {
  justify-content: space-between;
}
details {
  margin-top: 15px;
}
summary {
  cursor: pointer;
}
#bindings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin: 10px 0;
}
#bindings label {
  justify-content: space-between;
  font-size: 11px;
}
#bindings input {
  width: 65px;
  padding: 4px;
}
#status {
  position: fixed;
  left: 50%;
  top: 45px;
  transform: translateX(-50%);
  z-index: 8;
  background: #f6ecd8;
  border: 1px solid #ac9f7d;
  padding: 7px 12px;
  border-radius: 3px;
  max-width: calc(100% - 24px);
  text-align: center;
}
#status:empty {
  display: none;
}
#touch-hints {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  color: #56665c7a;
  font-size: 12px;
}
#move-hint,
#attack-hint {
  position: absolute;
  bottom: 22%;
  width: 50%;
  text-align: center;
}
#move-hint {
  left: 0;
}
#attack-hint {
  right: 0;
}
@media (max-width: 640px) {
  #classes {
    grid-template-columns: repeat(4, 1fr);
  }
  #classes canvas {
    width: 58px;
    height: 70px;
  }
  #menu {
    top: 48%;
    padding: 10px;
  }
  #menu .bar {
    margin: -10px -10px 10px;
  }
  #name {
    width: 140px;
  }
  .join-line {
    gap: 7px;
  }
  #top {
    gap: 8px;
  }
  #population {
    font-size: 11px;
  }
  #performance {
    font-size: 10px;
  }
  #upgrades {
    width: calc(100% - 24px);
  }
  #upgrade-choices {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }
  #upgrade-choices button {
    padding: 6px;
    font-size: 11px;
  }
  #upgrade-choices small {
    font-size: 10px;
  }
  #hud {
    bottom: max(8px, env(safe-area-inset-bottom));
    width: 260px;
  }
}
@media (max-height: 520px) {
  #menu {
    top: 48px;
    transform: translateX(-50%);
    max-height: calc(100dvh - 60px);
  }
  #classes {
    margin-top: 8px;
    grid-template-columns: repeat(7, 1fr);
  }
  #classes canvas {
    height: 56px;
    width: 50px;
  }
  #class-description {
    margin: 5px 0;
    min-height: 0;
    padding: 4px;
  }
  .controls {
    margin: 5px 0;
  }
  #hud {
    width: 260px;
  }
  #upgrades {
    width: 280px;
  }
  #upgrade-choices {
    grid-template-columns: 1fr;
  }
  #upgrade-choices small {
    display: inline;
    margin-left: 5px;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto;
  }
}
@media (pointer: coarse) {
  input,
  select {
    font-size: 16px;
  }
}
#leaders {
  position: fixed;
  top: 46px;
  left: 10px;
  z-index: 2;
  font-size: 11px;
  pointer-events: none;
  color: #425348;
  max-width: 190px;
  background: #f2f3e9b8;
  border: 1px solid #a6b0a480;
  padding: 6px;
}
#leaders > div {
  font-weight: bold;
}
#leader-list {
  padding-left: 20px;
  margin: 5px 0 0;
}
#leader-list li {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.5;
}
@media (max-width: 640px) {
  #leaders {
    font-size: 10px;
    max-width: 150px;
  }
  #leader-list li:nth-child(n + 4) {
    display: none;
  }
}
.arena-title { margin: 0; font-size: inherit; }
