:root {
  color-scheme: light;
  font-family: "Microsoft YaHei UI", "PingFang SC", "Segoe UI", sans-serif;
  color: #1b2030;
  background: #fff;
  --ink: #1b2030;
}

*, *::before, *::after { box-sizing: border-box; }

html, body, .stage {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #fff;
}

.stage { position: relative; isolation: isolate; }

#battlefield {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  cursor: crosshair;
  background: #fff;
}

#battlefield:focus { outline: none; }
#battlefield:focus-visible { outline: 2px solid #737983; outline-offset: -2px; }

.battle-actions {
  position: absolute;
  z-index: 1;
  top: max(12px, env(safe-area-inset-top, 0px));
  right: max(12px, env(safe-area-inset-right, 0px));
  display: flex;
  gap: 6px;
  pointer-events: none;
}

.battle-action {
  min-height: 44px;
  pointer-events: auto;
  padding: 7px 10px;
  border: 1px solid #d7d9e0;
  border-radius: 9px;
  background: #fffffff5;
  color: var(--ink);
  box-shadow: 0 3px 12px #1b203016;
  font: inherit;
  font-size: .875rem;
  font-weight: 700;
  cursor: pointer;
}

.audio-toggle { min-width: 84px; }
.clear-button { min-width: 54px; }
.audio-toggle[aria-pressed="true"] { background: #fff1b8; border-color: #d3bb63; }
.battle-action:hover:not(:disabled) { border-color: #737983; }
.battle-action:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.battle-action:disabled { color: #686b73; cursor: default; }

.unit-dock {
  position: absolute;
  z-index: 1;
  bottom: max(17px, env(safe-area-inset-bottom, 0px));
  left: 50%;
  display: flex;
  align-items: center;
  gap: 7px;
  width: max-content;
  max-width: calc(100% - 20px);
  flex-wrap: wrap;
  justify-content: center;
  padding: 5px;
  border: 1px solid #d7d9e0;
  border-radius: 13px;
  background: #fffffff5;
  box-shadow: 0 3px 12px #1b203020;
  transform: translateX(-50%);
  pointer-events: none;
}

.unit {
  position: relative;
  display: grid;
  width: 51px;
  height: 51px;
  padding: 4px;
  place-items: center;
  overflow: visible;
  border: 1px solid #dedfe3;
  border-radius: 8px;
  background: #f8f9fa;
  cursor: pointer;
  pointer-events: auto;
}

.unit:hover { border-color: #9fa0ab; }
.unit[aria-pressed="true"] { border: 2px solid var(--ink); padding: 3px; background: #fff1b8; }
.unit:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.unit canvas { display: block; width: 100%; height: 100%; pointer-events: none; }

.unit-name {
  position: absolute;
  bottom: calc(100% + 11px);
  left: 50%;
  display: none;
  padding: 5px 9px;
  border-radius: 5px;
  color: #fff;
  background: var(--ink);
  transform: translateX(-50%);
  font: 700 .86rem/1.25 "Microsoft YaHei UI", "PingFang SC", sans-serif;
  white-space: nowrap;
  pointer-events: none;
}

.unit-name::after {
  content: "";
  position: absolute;
  top: calc(100% - 1px);
  left: calc(50% - 4px);
  border: 4px solid transparent;
  border-bottom: 0;
  border-top-color: var(--ink);
}

.unit:hover .unit-name, .unit:focus-visible .unit-name { display: block; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.notice { position: relative; margin: 24px; text-align: center; }

@media (max-width: 660px) {
  .unit-dock { gap: 5px; }
  .unit { width: 42px; height: 42px; }
}
