/* Sandbox: the setup screen (#sandboxSetup) and the in-battle tool rail and panels (#sandboxHud). */
#sandboxSetup,
#sandboxHud {
  --gold: #c3ab02;
  --gold-hi: #f0d64a;
  --ink: #fdf8d4;
  --dim: #a99f78;
  --faint: rgba(253, 248, 212, 0.08);
  --panel: rgba(5, 9, 14, 0.9);
  --line: rgba(195, 171, 2, 0.4);
  --soft-line: rgba(195, 171, 2, 0.18);
  --bad: #ff6a55;
  color: var(--ink);
  font-family: 'EmpireAtWar-Medium', 'Eurostile', 'Segoe UI', Arial, sans-serif;
  font-size: 13px;
  user-select: none;
}
#sandboxSetup *,
#sandboxHud * {
  box-sizing: border-box;
}
#sandboxSetup button,
#sandboxHud button,
#sandboxSetup input,
#sandboxHud input,
#sandboxSetup select,
#sandboxHud select {
  font: inherit;
  color: inherit;
}

/* Shared controls */
.sb-btn {
  height: 28px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(60, 54, 20, 0.85), rgba(20, 18, 8, 0.9));
  font-size: 12px !important;
  letter-spacing: 1px;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
}
.sb-btn:hover {
  border-color: var(--gold-hi);
  color: #fff !important;
}
.sb-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.sb-btn.sb-on {
  border-color: var(--gold-hi);
  background: linear-gradient(180deg, rgba(150, 128, 30, 0.95), rgba(60, 52, 14, 0.95));
  color: #fff !important;
}
.sb-btn.sb-danger:hover {
  border-color: var(--bad);
  color: var(--bad) !important;
}
.sb-wide {
  height: 38px;
  min-width: 200px;
  padding: 0 32px;
  font-size: 14px !important;
  letter-spacing: 2px;
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(90, 78, 22, 0.9), rgba(28, 24, 8, 0.95));
  clip-path: polygon(12px 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 12px 100%, 0 50%);
}
.sb-seg {
  display: inline-flex;
}
.sb-seg .sb-btn + .sb-btn {
  border-left-width: 0;
}
.sb-input,
.sb-select {
  height: 28px;
  min-width: 0;
  padding: 0 8px;
  border: 1px solid var(--soft-line);
  background: rgba(0, 0, 0, 0.55);
  outline: none;
  user-select: text;
}
.sb-input:focus,
.sb-select:focus {
  border-color: var(--gold);
}
.sb-select option {
  background: #0b0f14;
}
.sb-label {
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.sb-h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold-hi);
}
.sb-scroll {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--gold) rgba(0, 0, 0, 0.35);
}
.sb-swatch {
  width: 14px;
  height: 14px;
  flex: none;
  border: 1px solid rgba(0, 0, 0, 0.8);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25);
}
.sb-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 26px;
  cursor: pointer;
}
.sb-toggle input {
  accent-color: var(--gold);
  width: 15px;
  height: 15px;
  margin: 0;
}

/* Setup screen */
#sandboxSetup {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.25), rgba(0, 0, 0, 0.8));
  animation: sb-in 0.3s ease-out;
}
@keyframes sb-in {
  from {
    opacity: 0;
  }
}
#sandboxSetup .sb-panel {
  position: relative;
  width: min(1100px, 100%);
  height: min(720px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 20px 16px;
  background: linear-gradient(180deg, rgba(195, 171, 2, 0.08), transparent 120px), var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), inset 0 0 80px rgba(0, 0, 0, 0.6);
  clip-path: polygon(18px 0, calc(100% - 18px) 0, 100% 18px, 100% calc(100% - 18px), calc(100% - 18px) 100%, 18px 100%, 0 calc(100% - 18px), 0 18px);
}
#sandboxSetup .sb-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
#sandboxSetup h1 {
  margin: 0;
  font-family: 'EmpireAtWar-Bold', 'EmpireAtWar-Medium', 'Eurostile', 'Segoe UI', Arial, sans-serif;
  font-size: 30px;
  font-weight: 400;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--gold-hi);
  text-shadow: 0 0 18px rgba(240, 214, 74, 0.35), 0 2px 0 #000;
}
#sandboxSetup .sb-head p {
  margin: 2px 0 0;
  color: var(--dim);
  font-size: 12px;
}
#sandboxSetup .sb-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 14px;
}
#sandboxSetup .sb-col {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--soft-line);
}
#sandboxSetup .sb-maps {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#sandboxSetup .sb-map {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid transparent;
  background: var(--faint);
  text-align: left;
  cursor: pointer;
}
#sandboxSetup .sb-map:hover {
  border-color: var(--soft-line);
}
#sandboxSetup .sb-map.sb-on {
  border-color: var(--gold);
  background: rgba(195, 171, 2, 0.16);
}
#sandboxSetup .sb-map small {
  color: var(--dim);
  font-size: 11px;
}
#sandboxSetup .sb-preview {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
#sandboxSetup .sb-preview-box {
  width: 170px;
  height: 170px;
  flex: none;
  border: 1px solid var(--soft-line);
  background: #000 center / contain no-repeat;
}
#sandboxSetup .sb-preview-text {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
#sandboxSetup .sb-map-title {
  font-size: 18px;
  color: var(--gold-hi);
  letter-spacing: 1px;
}
#sandboxSetup .sb-preview-large {
  flex-direction: column;
}
#sandboxSetup .sb-preview-large .sb-preview-box {
  width: min(100%, 300px);
  height: auto;
  aspect-ratio: 1;
}
#sandboxSetup .sb-about p {
  margin: 0 0 6px;
  color: var(--dim);
  font-size: 12px;
  line-height: 1.45;
}
#sandboxSetup .sb-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
#sandboxSetup .sb-note {
  color: var(--dim);
  font-size: 12px;
  text-align: center;
  flex: 1;
}

/* In-battle rail and panels */
#sandboxHud {
  position: fixed;
  left: 8px;
  top: 12px;
  z-index: 40;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}
#sandboxHud .sb-rail {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  pointer-events: auto;
}
#sandboxHud .sb-rail-team {
  height: 6px;
  margin: 0 2px 4px;
  background: var(--team, var(--gold));
  box-shadow: 0 0 8px var(--team, var(--gold));
}
#sandboxHud .sb-tool {
  position: relative;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  background: var(--faint);
  cursor: pointer;
}
#sandboxHud .sb-tool svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#sandboxHud .sb-tool:hover {
  border-color: var(--line);
}
#sandboxHud .sb-tool.sb-on {
  border-color: var(--gold-hi);
  background: rgba(195, 171, 2, 0.22);
}
#sandboxHud .sb-tool.sb-on svg {
  stroke: var(--gold-hi);
}
#sandboxHud .sb-tool::after {
  content: attr(data-tip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.9);
  border: 1px solid var(--line);
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}
#sandboxHud .sb-tool:hover::after {
  opacity: 1;
}
#sandboxHud .sb-tool.sb-on::after,
#sandboxHud.sb-open .sb-tool::after {
  display: none;
}
#sandboxHud .sb-rail hr {
  width: 100%;
  margin: 2px 0;
  border: 0;
  border-top: 1px solid var(--soft-line);
}
#sandboxHud .sb-pane {
  width: 372px;
  max-height: min(640px, calc(57vh - 24px));
  overflow-y: auto;
  scrollbar-width: thin;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: linear-gradient(180deg, rgba(195, 171, 2, 0.07), transparent 80px), var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  pointer-events: auto;
  animation: sb-in 0.15s ease-out;
}
#sandboxHud .sb-pane[hidden] {
  display: none;
}
#sandboxHud .sb-pane.sb-wide-pane {
  width: 440px;
}
#sandboxHud .sb-pane-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--soft-line);
}
#sandboxHud .sb-close {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--dim);
  font-size: 18px !important;
  line-height: 1;
  cursor: pointer;
}
#sandboxHud .sb-close:hover {
  color: #fff;
}
#sandboxHud .sb-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
#sandboxHud .sb-row > .sb-input,
#sandboxHud .sb-row > .sb-select {
  flex: 1;
}
#sandboxHud .sb-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
#sandboxHud .sb-chips .sb-btn {
  height: 24px;
  padding: 0 8px;
  font-size: 11px !important;
}
#sandboxHud .sb-list {
  flex: 1;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
#sandboxHud .sb-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 3px 6px;
  border: 1px solid transparent;
  background: var(--faint);
  text-align: left;
  cursor: pointer;
}
#sandboxHud .sb-item:hover {
  border-color: var(--soft-line);
}
#sandboxHud .sb-item.sb-on {
  border-color: var(--gold-hi);
  background: rgba(195, 171, 2, 0.2);
}
#sandboxHud .sb-icon {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5) center / cover no-repeat;
  border: 1px solid var(--soft-line);
  color: var(--dim);
  font-size: 11px;
}
#sandboxHud .sb-item-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
#sandboxHud .sb-item-text b,
#sandboxHud .sb-item-text small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#sandboxHud .sb-item-text b {
  font-weight: 400;
}
#sandboxHud .sb-item-text small {
  color: var(--dim);
  font-size: 10px;
}
#sandboxHud .sb-empty {
  padding: 16px 4px;
  color: var(--dim);
  text-align: center;
}
#sandboxHud .sb-team-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  background: var(--faint);
  border-left: 3px solid var(--team, var(--gold));
}
#sandboxHud .sb-team-card.sb-on {
  background: rgba(195, 171, 2, 0.12);
}
#sandboxHud .sb-team-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
#sandboxHud .sb-team-name small {
  color: var(--dim);
  font-size: 11px;
}
#sandboxHud .sb-grid2 {
  display: flex;
  flex-wrap: wrap;
  gap: 0 16px;
}
#sandboxHud .sb-stat {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px 22px;
  align-items: center;
  gap: 6px;
  min-height: 28px;
}
#sandboxHud .sb-stat span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#sandboxHud .sb-stat.sb-changed span {
  color: var(--gold-hi);
}
#sandboxHud .sb-wide-pane .sb-stat {
  grid-template-columns: minmax(0, 1fr) 170px 22px;
}
#sandboxHud .sb-stat .sb-input {
  height: 24px;
  text-align: right;
}
#sandboxHud .sb-reset {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--dim);
  cursor: pointer;
  visibility: hidden;
}
#sandboxHud .sb-stat.sb-changed .sb-reset {
  visibility: visible;
}
#sandboxHud .sb-reset:hover {
  color: #fff;
}
#sandboxHud .sb-section {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--soft-line);
  color: var(--gold-hi);
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
#sandboxHud .sb-crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  color: var(--dim);
  font-size: 11px;
}
#sandboxHud .sb-crumbs button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--gold);
  cursor: pointer;
}
#sandboxHud .sb-crumbs button:hover {
  color: #fff;
}
#sandboxHud .sb-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
#sandboxHud .sb-links .sb-btn {
  height: 22px;
  padding: 0 6px;
  font-size: 10px !important;
  text-transform: none;
  letter-spacing: 0;
}
#sandboxHud .sb-hint {
  color: var(--dim);
  font-size: 11px;
  line-height: 1.4;
}
#sandboxHud textarea.sb-input {
  height: 120px;
  padding: 6px 8px;
  resize: vertical;
  font-family: Consolas, 'Courier New', monospace;
  font-size: 11px;
}
#sandboxPlacing {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 41;
  padding: 6px 14px;
  background: rgba(5, 9, 14, 0.9);
  border: 1px solid rgba(195, 171, 2, 0.6);
  color: #fdf8d4;
  font-family: 'EmpireAtWar-Medium', 'Eurostile', 'Segoe UI', Arial, sans-serif;
  font-size: 12px;
  letter-spacing: 0.5px;
  pointer-events: none;
}
#sandboxPlacing b {
  color: #f0d64a;
  font-weight: 400;
}
#sandboxHud .sb-add-team {
  border-left-color: var(--soft-line);
  border-left-style: dashed;
}
#sandboxHud .sb-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding-top: 2px;
}
#sandboxHud .sb-swatches .sb-swatch {
  width: 18px;
  height: 18px;
  padding: 0;
  cursor: pointer;
}
#sandboxHud .sb-swatches .sb-swatch.sb-on {
  box-shadow: 0 0 0 2px var(--gold-hi);
}
#sandboxHud .sb-close:disabled {
  visibility: hidden;
}
#sandboxMenu {
  position: fixed;
  z-index: 45;
  min-width: 170px;
  padding: 4px;
  background: rgba(5, 9, 14, 0.96);
  border: 1px solid rgba(195, 171, 2, 0.55);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  color: #fdf8d4;
  font-family: 'EmpireAtWar-Medium', 'Eurostile', 'Segoe UI', Arial, sans-serif;
  font-size: 12px;
  user-select: none;
}
#sandboxMenu[hidden] {
  display: none;
}
#sandboxMenu .sb-menu-title {
  padding: 5px 10px 6px;
  margin-bottom: 3px;
  border-bottom: 1px solid rgba(195, 171, 2, 0.25);
  color: #f0d64a;
  letter-spacing: 1px;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}
#sandboxMenu .sb-menu-item {
  display: block;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: 1px;
  text-transform: uppercase;
  text-align: left;
  cursor: pointer;
}
#sandboxMenu .sb-menu-item:hover {
  background: rgba(195, 171, 2, 0.2);
  color: #fff;
}
#sandboxMenu .sb-menu-danger:hover {
  background: rgba(255, 106, 85, 0.18);
  color: #ff6a55;
}
#sandboxHud .sb-placed {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  padding: 2px 6px;
  background: var(--faint);
}
#sandboxHud .sb-placed span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#sandboxHud .sb-placed .sb-btn {
  height: 22px;
  padding: 0 7px;
  font-size: 10px !important;
}
