:root {
  --sand-bg: #f5efe6;
  --sand-dot: rgba(168, 152, 130, 0.24);
  --ink: #1e1b18;
  --surface: rgba(255, 255, 255, 0.94);
  --surface-solid: #ffffff;
  --border: rgba(30, 27, 24, 0.12);
  --muted: #6b635b;
  --blue-team: #2563eb;
  --red-team: #dc2626;
  --accent: #f59e0b;
  --shadow-sm: 0 2px 6px rgba(30, 27, 24, 0.08);
  --shadow-md: 0 6px 20px rgba(30, 27, 24, 0.12);
  --shadow-lg: 0 12px 32px rgba(30, 27, 24, 0.16);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--sand-bg);
  color: var(--ink);
}

/* Full-Viewport Battlefield Canvas */
#battleCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
  cursor: crosshair;
  background-color: var(--sand-bg);
  background-image: radial-gradient(var(--sand-dot) 1.25px, transparent 1.25px);
  background-size: 22px 22px;
}

#battleCanvas.move-mode {
  cursor: pointer;
}

#battleCanvas.move-mode.moving {
  cursor: pointer;
}

/* HUD Overlay Container */
.hud-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.hud-overlay button,
.hud-overlay a,
.hud-overlay label,
.hud-overlay .dock-container {
  pointer-events: auto;
}

/* Top Bar: Responsive Flex Row preventing logo/icon overlap */
.hud-top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 20;
  pointer-events: none;
}

.hud-top-left {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 6px;
}

.hud-top-left .game-language { pointer-events: auto; }
.comic-localized { white-space: normal; text-align: center; }

/* Top-Center: Comic-Book BATTLE DRAW Logo */
.hud-top-center {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  pointer-events: none;
}

.comic-logo {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transform: rotate(-1.5deg);
  filter: drop-shadow(0 3px 0 rgba(30, 27, 24, 0.18));
}

.comic-word {
  font-family: "Arial Black", "Impact", system-ui, sans-serif;
  font-weight: 900;
  font-size: 1.45rem;
  letter-spacing: 0.8px;
  line-height: 1;
  padding: 4px 10px;
  border-radius: 8px;
  border: 2.5px solid var(--ink);
  box-shadow: 2.5px 2.5px 0 var(--ink);
}

.comic-battle {
  background: #fbbf24;
  color: var(--ink);
  transform: rotate(-1.5deg);
}

.comic-draw {
  background: #ef4444;
  color: #ffffff;
  transform: rotate(1.5deg);
  text-shadow: 1.5px 1.5px 0 var(--ink);
}

/* Unified Wonderworld / Duh! Games! Brand Pill */
.ww-home-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: -0.2px;
  padding: 5px 12px 5px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(30, 27, 24, 0.14);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: all 0.18s ease;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1;
}
.ww-home-pill:hover {
  background: #ffffff;
  border-color: rgba(30, 27, 24, 0.28);
  transform: translateY(-1px);
  color: var(--ink);
}
.ww-home-pill .ww-logo-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  flex-shrink: 0;
  display: block;
}
.ww-home-pill .ww-text-short {
  display: none;
}

/* Top-Right: Circular Action Buttons */
.hud-top-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.circle-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.14s ease, background 0.14s ease, box-shadow 0.14s ease;
}

.circle-btn:active {
  transform: translateY(0) scale(0.95);
}

.circle-btn-play {
  background: #10b981;
  color: #ffffff;
  border-color: rgba(0, 0, 0, 0.12);
}

.circle-btn-play.paused {
  background: #f59e0b;
  color: #ffffff;
}

@media (hover: hover) and (pointer: fine) {
  .circle-btn:hover {
    background: var(--surface-solid);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }
  .circle-btn-play:hover {
    background: #059669;
  }
  .circle-btn-play.paused:hover {
    background: #d97706;
  }
}

.circle-btn.muted {
  color: var(--muted);
}

/* Bottom-Left: Active Unit Count Pill */
.hud-bottom-left {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 20;
  pointer-events: none;
}

.unit-count-pill {
  background: var(--surface);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  font-variant-numeric: tabular-nums;
}

/* Bottom-Center: Floating 4-Tab Dock */
.hud-bottom-center {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  max-width: calc(100vw - 260px);
}

/* Anchor the team switcher to the dock itself, not the crowded bottom controls.
   The dock height can change across screen sizes and item categories, so an
   absolute offset based on its own box keeps both team buttons unobstructed. */
.hud-bottom-center > .team-selector-pills {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
  z-index: 1;
  white-space: nowrap;
  pointer-events: auto;
}

.dock-container {
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 6px 8px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  overflow: hidden;
}

.dock-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(30, 27, 24, 0.05);
  padding: 3px;
  border-radius: 12px;
}

.dock-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 5px 13px;
  border-radius: 9px;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s ease;
}

.dock-tab.active {
  background: var(--surface-solid);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(30, 27, 24, 0.12);
}

.dock-items {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  overflow-x: auto;
  max-width: 100%;
  width: fit-content;
  padding: 2px 6px;
  scrollbar-width: none;
  touch-action: pan-x;
  -webkit-overflow-scrolling: touch;
}

.dock-items::-webkit-scrollbar {
  display: none;
}

.dock-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 62px;
  padding: 6px 8px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  flex-shrink: 0;
}

.dock-item.active {
  background: #ffffff;
  border-color: var(--ink);
  box-shadow: 0 3px 10px rgba(30, 27, 24, 0.14);
  transform: translateY(-2px);
}

@media (hover: hover) and (pointer: fine) {
  .dock-tab:hover {
    color: var(--ink);
    background: rgba(255, 255, 255, 0.5);
  }
  .dock-item:hover {
    background: #ffffff;
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
  }
}

.dock-item-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.45rem;
  line-height: 1;
  pointer-events: none;
}

.dock-item-icon svg {
  width: 32px;
  height: 32px;
  display: block;
  pointer-events: none;
}

.dock-item-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  pointer-events: none;
}

/* Bottom-Right: Team Battle Toggle & Team Color Selector */
.hud-bottom-right {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.team-selector-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  box-shadow: var(--shadow-sm);
}

.team-color-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.team-color-btn.active[data-team="blue"] {
  background: var(--blue-team);
  color: #ffffff;
}

.team-color-btn.active[data-team="red"] {
  background: var(--red-team);
  color: #ffffff;
}

.team-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.8);
}

.team-dot.blue { background: var(--blue-team); }
.team-dot.red { background: var(--red-team); }

.team-toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px 6px 14px;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s ease;
}

.team-toggle-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink);
}

.team-toggle-pill input {
  display: none;
}

.toggle-track {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: rgba(30, 27, 24, 0.18);
  position: relative;
  transition: background 0.2s ease;
}

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.team-toggle-pill input:checked + .toggle-track {
  background: var(--blue-team);
}

.team-toggle-pill input:checked + .toggle-track .toggle-thumb {
  transform: translateX(16px);
}

.hud-bottom-right-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.move-units-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

@media (hover: hover) and (pointer: fine) {
  .team-toggle-pill:hover {
    background: var(--surface-solid);
  }
  .move-units-pill:hover {
    background: var(--surface-solid);
    transform: translateY(-1px);
  }
}

.move-units-pill.active {
  background: var(--ink);
  color: #ffffff;
  border-color: var(--ink);
}

.move-units-pill.active.team-blue {
  background: var(--blue-team);
  border-color: var(--blue-team);
}

.move-units-pill.active.team-red {
  background: var(--red-team);
  border-color: var(--red-team);
}

/* Responsive Adjustments */
@media (max-width: 900px) {
  .hud-bottom-center {
    width: calc(100vw - 20px);
    max-width: 680px;
    bottom: 62px;
  }
  .hud-bottom-left {
    bottom: 12px;
    left: 12px;
  }
  .hud-bottom-right {
    bottom: 12px;
    right: 12px;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: calc(100vw - 105px);
  }
  .hud-bottom-right-controls {
    flex-direction: row;
    align-items: center;
    gap: 6px;
  }
}

@media (max-width: 720px) {
  .hud-top-bar {
    padding: 10px 10px;
    gap: 6px;
  }
  .hud-top-center {
    position: static;
    transform: none;
    flex: 1 1 auto;
    display: flex;
    justify-content: center;
    min-width: 0;
  }
  .comic-logo {
    gap: 4px;
  }
  .comic-word {
    font-size: 0.92rem;
    padding: 3px 6px;
    border-width: 2px;
    box-shadow: 2px 2px 0 var(--ink);
  }
  .ww-home-pill {
    padding: 5px 9px 5px 5px;
    gap: 5px;
    font-size: 12px;
  }
  .ww-home-pill .ww-text-full {
    display: none;
  }
  .ww-home-pill .ww-text-short {
    display: none;
  }
  .ww-home-pill { padding: 5px; }
  .hud-top-left .game-language summary { width: 34px; height: 34px; }
  .comic-localized { font-size: clamp(.67rem, 2.7vw, .9rem); }
  .hud-top-right {
    gap: 5px;
  }
  .circle-btn {
    width: 34px;
    height: 34px;
  }
  .circle-btn svg {
    width: 17px;
    height: 17px;
  }
  .dock-item {
    min-width: 54px;
    padding: 5px 6px;
  }
  .dock-item-icon,
  .dock-item-icon svg {
    width: 28px;
    height: 28px;
  }
  .dock-item-label {
    font-size: 0.64rem;
  }
}
