:root {
  color-scheme: dark;
  --page: #0b1011;
  --surface: #111718;
  --surface-raised: #192123;
  --line: #2b3738;
  --line-bright: #405052;
  --text: #f3f5ef;
  --muted: #95a2a3;
  --cyan: #6bdad6;
  --coral: #f06f61;
  --amber: #efbd52;
  --violet: #b69be8;
  --header-height: 64px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--page);
}

body,
button {
  color: var(--text);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

button svg,
a svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

[hidden] {
  display: none !important;
}

.game-app {
  display: grid;
  width: 100%;
  height: 100dvh;
  grid-template-rows: var(--header-height) minmax(0, 1fr);
  background: var(--page);
  user-select: none;
}

.topbar {
  position: relative;
  z-index: 20;
  display: grid;
  min-width: 0;
  grid-template-columns: 42px minmax(170px, 1fr) minmax(500px, 720px) minmax(98px, 1fr);
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: #111617;
}

.home-button,
.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: #c4cecc;
  background: var(--surface-raised);
  cursor: pointer;
  text-decoration: none;
}

.home-button:hover,
.icon-button:hover:not(:disabled) {
  border-color: var(--line-bright);
  color: #ffffff;
}

.icon-button:disabled {
  opacity: 0.42;
  cursor: default;
}

.icon-button .play-icon,
.icon-button.is-paused .pause-icon,
.mute-line {
  display: none;
}

.icon-button.is-paused .play-icon,
.icon-button.is-muted .mute-line {
  display: block;
}

.icon-button.is-muted .sound-wave {
  display: none;
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  position: relative;
  display: block;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 1px solid #415255;
  border-radius: 50%;
  background: #172022;
}

.brand-mark i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 12px;
  border-radius: 2px;
  background: var(--cyan);
  transform-origin: 2px 0;
}

.brand-mark i:nth-child(1) {
  transform: rotate(0deg) translate(-2px, -15px);
}

.brand-mark i:nth-child(2) {
  transform: rotate(90deg) translate(-2px, -15px);
}

.brand-mark i:nth-child(3) {
  transform: rotate(180deg) translate(-2px, -15px);
}

.brand-mark i:nth-child(4) {
  transform: rotate(270deg) translate(-2px, -15px);
}

.brand-copy {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.brand-copy strong {
  overflow: hidden;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy small,
.metrics span,
.direction-readout span,
.screen-kicker,
.wave-banner small,
.fire-button small {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 9px;
  font-weight: 700;
}

.metrics {
  display: grid;
  height: 100%;
  grid-template-columns: repeat(4, minmax(70px, 1fr)) minmax(106px, 1.2fr);
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.metrics > div {
  display: grid;
  min-width: 0;
  align-content: center;
  gap: 3px;
  padding: 0 14px;
  border-right: 1px solid var(--line);
}

.metrics > div:last-child {
  border-right: 0;
}

.metrics strong {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.health-cells {
  display: grid;
  width: 82px;
  height: 12px;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
}

.health-cells i {
  border: 1px solid #507074;
  background: var(--cyan);
}

.health-cells i.is-empty {
  background: #222b2d;
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.battlefield {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #315f38;
  isolation: isolate;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.direction-readout {
  position: absolute;
  top: 16px;
  left: 18px;
  z-index: 5;
  display: flex;
  min-width: 82px;
  height: 31px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 10px;
  border: 1px solid rgba(83, 105, 108, 0.72);
  border-radius: 5px;
  background: rgba(17, 23, 24, 0.88);
}

.direction-readout strong {
  color: var(--cyan);
  font-size: 13px;
}

.wave-banner {
  position: absolute;
  top: 17%;
  left: 50%;
  z-index: 8;
  display: grid;
  width: 122px;
  height: 74px;
  place-content: center;
  border-top: 1px solid var(--amber);
  border-bottom: 1px solid var(--amber);
  background: rgba(14, 19, 20, 0.88);
  text-align: center;
  transform: translateX(-50%);
}

.wave-banner strong {
  color: var(--amber);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 31px;
}

.screen-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(8, 12, 13, 0.76);
}

.screen-layer.is-hidden {
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms ease;
}

.screen-content {
  display: grid;
  width: min(430px, calc(100% - 36px));
  justify-items: center;
  text-align: center;
}

.screen-kicker {
  margin: 0 0 14px;
  color: var(--amber);
  font-size: 10px;
}

.screen-content h1 {
  margin: 0;
  color: var(--text);
  font-size: clamp(36px, 6vh, 62px);
  line-height: 1;
}

.screen-copy {
  margin: 13px 0 24px;
  color: #b6c0bd;
  font-size: 14px;
}

.screen-result {
  display: grid;
  width: min(290px, 100%);
  margin: 0 0 20px;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--line-bright);
  border-bottom: 1px solid var(--line-bright);
}

.screen-result div {
  display: grid;
  gap: 4px;
  padding: 13px;
}

.screen-result div + div {
  border-left: 1px solid var(--line);
}

.screen-result span {
  color: var(--muted);
  font-size: 10px;
}

.screen-result strong {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 20px;
}

.primary-button {
  display: flex;
  height: 46px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 22px;
  border: 1px solid #b88b35;
  border-radius: 5px;
  color: #18130a;
  background: var(--amber);
  font-weight: 800;
  cursor: pointer;
}

.primary-button:hover {
  background: #ffd16f;
}

.mobile-controls {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(15px, env(safe-area-inset-bottom));
  left: max(16px, env(safe-area-inset-left));
  z-index: 7;
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  pointer-events: none;
}

.dpad {
  display: grid;
  width: 150px;
  height: 100px;
  grid-template: repeat(2, 50px) / repeat(3, 50px);
  pointer-events: auto;
}

.control-button,
.fire-button {
  border: 1px solid #516062;
  color: #e3e9e5;
  background: rgba(24, 32, 34, 0.94);
  cursor: pointer;
  touch-action: none;
}

.control-button {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
}

.control-button.is-active {
  border-color: var(--cyan);
  color: #10201f;
  background: var(--cyan);
}

.up-button {
  grid-area: 1 / 2;
  border-radius: 6px 6px 0 0;
}

.left-button {
  grid-area: 2 / 1;
  border-radius: 6px 0 0 6px;
}

.dpad-center {
  grid-area: 2 / 2;
  border: 1px solid #354345;
  background: rgba(15, 21, 22, 0.9);
}

.right-button {
  grid-area: 2 / 3;
  border-radius: 0 6px 6px 0;
}

.fire-button {
  display: grid;
  width: 84px;
  height: 84px;
  place-content: center;
  border-color: #a57b34;
  border-radius: 50%;
  color: #18130a;
  background: var(--amber);
}

.fire-button span {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
}

.fire-button small {
  margin-top: 3px;
  color: #604819;
}

.fire-button.is-active {
  background: #ffe09a;
  transform: scale(0.96);
}

@media (max-width: 920px) {
  :root {
    --header-height: 104px;
  }

  .topbar {
    grid-template-columns: 38px minmax(0, 1fr) auto;
    grid-template-rows: 54px 50px;
    gap: 0 9px;
    padding: 0 12px;
  }

  .home-button {
    width: 34px;
    height: 34px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  .brand-copy strong {
    font-size: 14px;
  }

  .brand-copy small {
    font-size: 8px;
  }

  .top-actions {
    gap: 6px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
  }

  .metrics {
    grid-area: 2 / 1 / 3 / 4;
    width: calc(100% + 24px);
    height: 50px;
    margin-left: -12px;
    grid-template-columns: repeat(4, minmax(52px, 1fr)) minmax(88px, 1.25fr);
  }

  .metrics > div {
    gap: 2px;
    padding: 0 8px;
  }

  .metrics strong {
    font-size: 14px;
  }

  .health-cells {
    width: min(76px, 100%);
    gap: 2px;
  }

  .mobile-controls {
    display: flex;
  }
}

@media (max-width: 520px) {
  .brand-mark {
    display: none;
  }

  .brand-copy small {
    display: none;
  }

  .metrics > div {
    padding: 0 6px;
  }

  .metrics span {
    font-size: 8px;
  }

  .metrics strong {
    font-size: 13px;
  }

  .health-cells {
    height: 10px;
  }

  .direction-readout {
    top: 10px;
    left: 10px;
  }

  .screen-content {
    transform: translateY(-28px);
  }

  .screen-content h1 {
    font-size: 38px;
  }

  .dpad {
    width: 132px;
    height: 88px;
    grid-template: repeat(2, 44px) / repeat(3, 44px);
  }

  .control-button {
    width: 44px;
    height: 44px;
  }

  .fire-button {
    width: 76px;
    height: 76px;
  }
}

@media (max-height: 660px) and (max-width: 920px) {
  .mobile-controls {
    transform: scale(0.82);
    transform-origin: bottom left;
  }

  .fire-button {
    position: absolute;
    right: 0;
    bottom: 0;
    transform-origin: bottom right;
  }

  .screen-copy {
    margin-bottom: 15px;
  }
}

@media (pointer: coarse) {
  .mobile-controls {
    display: flex;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
