* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }
body {
  background: #0ea5e9;
  color: #fff;
  font-family: "Trebuchet MS", system-ui, -apple-system, sans-serif;
  overflow: hidden;
}
#top-bar {
  position: absolute; top: 10px; left: 12px; right: 12px;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.90), rgba(30, 41, 59, 0.94));
  backdrop-filter: blur(8px);
  padding: 9px 16px; border-radius: 16px;
  border: 2px solid rgba(251, 191, 36, 0.65);
  z-index: 10; box-shadow: 0 10px 25px rgba(0,0,0,0.35);
}
.hud-side { display: flex; align-items: center; gap: 12px; }
.king-box {
  background: #0f172a; padding: 6px 12px; border-radius: 12px;
  border: 2px solid #475569; min-width: 175px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.6);
}
.king-title {
  font-size: 11px; font-weight: 900; color: #fde047;
  text-transform: uppercase; display: flex; justify-content: space-between;
  letter-spacing: 0.5px;
}
.hp-bar-bg {
  width: 100%; height: 10px; background: #1e293b;
  border-radius: 6px; margin-top: 4px; overflow: hidden;
  border: 1px solid #334155;
}
.hp-bar-fill {
  height: 100%; background: linear-gradient(90deg, #16a34a, #4ade80);
  width: 100%; transition: width 0.2s;
}
.hp-bar-fill.enemy { background: linear-gradient(90deg, #dc2626, #fb7185); }

.controls-group { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
button {
  background: linear-gradient(180deg, #334155, #1e293b);
  color: #f8fafc; border: 2px solid #64748b;
  padding: 7px 11px; border-radius: 10px; cursor: pointer;
  font-weight: 800; font-size: 12px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
  box-shadow: 0 3px 0 #0f172a;
  transition: transform 0.1s, filter 0.15s;
}
button:hover { filter: brightness(1.15); }
button:active { transform: translateY(2px); box-shadow: 0 1px 0 #0f172a; }
button.active {
  background: linear-gradient(180deg, #f59e0b, #d97706);
  border-color: #fef08a; color: #fff;
}
button.mode-btn {
  background: linear-gradient(180deg, #8b5cf6, #6d28d9);
  border-color: #ddd6fe;
}
button.stage-btn {
  background: linear-gradient(180deg, #ea580c, #c2410c);
  border-color: #fed7aa;
}
button.diff-btn {
  background: linear-gradient(180deg, #475569, #334155);
  border-color: #cbd5e1;
}
.ammo-btn .count { color: #fde047; }
.ammo-btn.empty { opacity: 0.45; filter: grayscale(1); cursor: not-allowed; }
.banner-stats { font-size: 13px !important; color: #fde68a !important; }
.banner-stats:empty { display: none; }
#hint {
  position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  display: flex; align-items: center; gap: 12px;
  background: rgba(15, 23, 42, 0.92); border: 2px solid #fde047; border-radius: 14px;
  padding: 10px 14px; color: #f8fafc; font-size: 13px; font-weight: 700; line-height: 1.4;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); z-index: 5;
}
#hint[hidden] { display: none; }
#hint span { flex: 1; }
#hintOk { flex-shrink: 0; }
#moveLeftBtn, #moveRightBtn { touch-action: none; -webkit-touch-callout: none; }
button.obs-btn {
  background: linear-gradient(180deg, #059669, #047857);
  border-color: #6ee7b7;
}

#bottom-bar {
  position: absolute; bottom: 10px; left: 12px; right: 12px;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.88), rgba(30, 41, 59, 0.94));
  backdrop-filter: blur(8px);
  padding: 9px 16px; border-radius: 16px;
  border: 2px solid rgba(255,255,255,0.2);
  z-index: 10; box-shadow: 0 10px 25px rgba(0,0,0,0.4);
}
.ammo-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.badge {
  padding: 6px 14px; border-radius: 10px; font-weight: 900; font-size: 12px;
  background: linear-gradient(90deg, #0284c7, #38bdf8); color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  box-shadow: 0 3px 10px rgba(56,189,248,0.4);
}
.badge.cpu { background: linear-gradient(90deg, #dc2626, #f97316); }

#banner {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: linear-gradient(180deg, #1e293b, #0f172a);
  border: 4px solid #fbbf24;
  padding: 28px 46px; border-radius: 22px; text-align: center;
  z-index: 20; display: none; box-shadow: 0 25px 60px rgba(0,0,0,0.8);
}
#banner h1 { font-size: 36px; margin-bottom: 8px; color: #fde047; text-shadow: 0 3px 0 #713f12; }
#banner p { font-size: 16px; color: #e2e8f0; margin-bottom: 18px; }
canvas { display: block; width: 100vw; height: 100vh; cursor: crosshair; }

/* Compact HUD for small or short screens: icons and short names, so the bars stay one or
   two slim rows and leave the height to the battlefield */
@media (max-width: 1180px), (max-height: 620px) {
  #top-bar, #bottom-bar { left: 6px; right: 6px; padding: 5px 8px; gap: 6px; border-radius: 12px; }
  #top-bar { top: 6px; }
  #bottom-bar { bottom: 6px; }
  .hud-side { gap: 8px; }
  .controls-group, .ammo-bar { gap: 5px; }
  .king-box { min-width: 0; padding: 4px 8px; }
  .king-title { font-size: 10px; gap: 8px; }
  .hp-bar-bg { height: 7px; margin-top: 3px; }
  button { padding: 5px 9px; font-size: 11px; }
  #scoreText { font-size: 14px !important; }
  #windText { font-size: 12px !important; }
  .lbl, .desc, .cap { display: none; }
  .badge {
    display: inline-block; max-width: 100%; padding: 4px 10px; font-size: 11px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle;
  }
  #bottom-bar > div:last-child { min-width: 0; flex: 1 1 200px; text-align: right; }
}

/* Players lobby: vs computer, two on one device, or online with a room code */
#lobby, #campaignMap {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(2, 6, 23, 0.55); backdrop-filter: blur(3px);
}
#lobby[hidden], #campaignMap[hidden] { display: none; }
.campaign-stages { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 2px; }
button.campaign-stage {
  display: grid; grid-template-columns: 44px 1fr auto; grid-template-rows: auto auto;
  align-items: center; text-align: left; column-gap: 10px; padding: 10px 12px;
}
button.campaign-stage:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(0.6); }
.cs-icon { grid-row: 1 / 3; font-size: 30px; text-align: center; }
.cs-name { font-size: 15px; color: #fde047; }
.cs-meta { grid-column: 2; font-size: 11px; color: #94a3b8; }
.cs-stars { grid-row: 1 / 3; grid-column: 3; font-size: 18px; color: #fbbf24; letter-spacing: 2px; }
button.campaign-stage:disabled .cs-stars { font-size: 11px; letter-spacing: 0; color: #94a3b8; }
.banner-stars { font-size: 40px; color: #fbbf24; letter-spacing: 6px; text-shadow: 0 3px 0 #713f12; margin-bottom: 6px; }
.banner-stars:empty { display: none; }
.lobby-card {
  position: relative; width: min(440px, 100%); max-height: 100%; overflow: auto;
  background: linear-gradient(180deg, #1e293b, #0f172a);
  border: 3px solid #fbbf24; border-radius: 20px; padding: 20px 22px;
  box-shadow: 0 25px 60px rgba(0,0,0,0.7); text-align: center;
}
.lobby-card h2 { font-size: 20px; color: #fde047; margin-bottom: 12px; }
.lobby-card h3 { font-size: 15px; color: #e2e8f0; margin: 16px 0 4px; }
.lobby-modes { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.lobby-hint { font-size: 12px; color: #94a3b8; margin-bottom: 10px; }
.lobby-row { display: flex; gap: 6px; justify-content: center; align-items: center; flex-wrap: wrap; }
.lobby-or { font-size: 12px; color: #94a3b8; font-weight: 800; }
#joinCode {
  width: 84px; padding: 7px 8px; border-radius: 10px; border: 2px solid #64748b;
  background: #0f172a; color: #fde047; font: 900 15px "Trebuchet MS", sans-serif;
  text-align: center; letter-spacing: 3px; text-transform: uppercase; user-select: text;
}
.room-info { margin-top: 12px; font-size: 14px; color: #e2e8f0; }
.room-info strong { font-size: 22px; color: #fde047; letter-spacing: 4px; margin: 0 6px; }
.lobby-status { min-height: 18px; margin-top: 10px; font-size: 13px; color: #bae6fd; }
.lobby-close { position: absolute; top: 8px; right: 8px; padding: 3px 8px; }

/* Upright phones see the whole battlefield shrunk to fit; suggest turning sideways */
#rotateHint {
  display: none;
  position: absolute; left: 50%; transform: translateX(-50%);
  z-index: 9; pointer-events: none;
  background: rgba(15, 23, 42, 0.86); color: #fde047;
  border: 2px solid rgba(251, 191, 36, 0.7); border-radius: 14px;
  padding: 8px 14px; font-size: 13px; font-weight: 900; text-align: center;
  white-space: nowrap; box-shadow: 0 8px 20px rgba(0,0,0,0.35);
}
@media (orientation: portrait) and (pointer: coarse) {
  #rotateHint { display: block; }
}
