:root {
  --bg: #0b1020;
  --panel: #161f3d;
  --panel-2: #1d2950;
  --text: #f3f7ff;
  --accent: #56c8ff;
  --grid: #2b3a6d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: radial-gradient(circle at 20% 20%, #16244d 0%, var(--bg) 60%);
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--grid);
  background: rgba(10, 16, 32, 0.8);
}

.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
}

.layout {
  display: grid;
  grid-template-columns: 260px 1fr 260px;
  gap: 0.75rem;
  padding: 0.75rem;
  min-height: calc(100vh - 58px);
  align-items: start;
}

.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--grid);
  border-radius: 8px;
  padding: 0.75rem;
}

.panel h2,
.panel h3 {
  margin-top: 0;
}

.battlefield-wrap {
  border: 1px solid var(--grid);
  border-radius: 8px;
  padding: 0.5rem;
  background: rgba(10, 16, 32, 0.5);
  height: 560px;
}

.battlefield {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  border-radius: 6px;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 48px 48px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 48px 48px,
    #0d1530;
}

.board-label {
  position: absolute;
  left: 0.75rem;
  top: 0.5rem;
  opacity: 0.7;
}

.deployment-zone {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  display: none;
  border-top: 1px dashed rgba(86, 200, 255, 0.7);
  border-bottom: 1px dashed rgba(86, 200, 255, 0.7);
}

.battlefield.show-deployment-zones .deployment-zone {
  display: block;
}

.deployment-zone.top {
  top: 0;
  height: 144px;
  background: rgba(86, 200, 255, 0.07);
}

.deployment-zone.bottom {
  bottom: 0;
  height: 144px;
  background: rgba(255, 130, 130, 0.07);
}

.ship,
.squadron {
  position: absolute;
  transform: translate(-50%, -50%);
}

.ship-icon {
  width: 96px;
  height: 96px;
  object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(86, 200, 255, 0.35));
}

.ship-icon.cr90-icon {
  width: 96px;
  height: 96px;
  max-width: 96px;
  max-height: 96px;
  object-fit: contain;
  filter: none !important;
  image-rendering: auto;
  transform: none !important;
}

.ship.cr90-ship {
  transform: translate(-50%, -50%) rotate(0deg) scale(1) !important;
}

.squadron-icon {
  width: 26px;
  height: 26px;
  filter: drop-shadow(0 0 6px rgba(255, 221, 120, 0.5));
}

.player-1 .ship-icon,
.player-1 .squadron-icon {
  filter: drop-shadow(0 0 8px rgba(141, 204, 255, 0.55));
}

.player-2 .ship-icon,
.player-2 .squadron-icon {
  filter: drop-shadow(0 0 8px rgba(255, 179, 179, 0.55));
}

#next-phase {
  width: 100%;
  padding: 0.6rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--text);
  background: #14325f;
  cursor: pointer;
}

#finish-setup {
  width: 100%;
  padding: 0.6rem;
  margin-bottom: 0.45rem;
  border: 1px solid #86ffcb;
  border-radius: 6px;
  color: var(--text);
  background: #1a5f47;
  cursor: pointer;
}

#next-phase:disabled,
#start-match:disabled,
#finish-setup:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#setup-form {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 0.8rem;
}

#setup-form label {
  font-size: 0.9rem;
}

#setup-form input {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--grid);
  background: #101a37;
  color: var(--text);
}

#setup-form select,
#objective-select {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--grid);
  background: #101a37;
  color: var(--text);
}

#setup-form button[type="button"] {
  width: 100%;
  padding: 0.55rem;
  border: 1px solid #5ea0ff;
  border-radius: 6px;
  color: var(--text);
  background: #173968;
  cursor: pointer;
}

#start-match {
  margin-top: 0.4rem;
  width: 100%;
  padding: 0.6rem;
  border: 1px solid #86ffcb;
  border-radius: 6px;
  color: var(--text);
  background: #1a5f47;
  cursor: pointer;
}

.error {
  min-height: 1.2rem;
  margin: 0 0 0.8rem;
  color: #ff8b8b;
  font-size: 0.9rem;
}

#setup-hint {
  opacity: 0.9;
  font-size: 0.95rem;
}

.setup-step {
  margin: 0.2rem 0 0.8rem;
  color: #b9dcff;
  font-size: 0.9rem;
}

.setup-controls {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 0.8rem;
}

.setup-controls button {
  width: 100%;
  padding: 0.55rem;
  border: 1px solid #5ea0ff;
  border-radius: 6px;
  color: var(--text);
  background: #173968;
  cursor: pointer;
}

.setup-controls button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.hidden {
  display: none;
}

.fleet-builder {
  margin-top: 0.4rem;
  padding: 0.55rem;
  border: 1px solid var(--grid);
  border-radius: 6px;
  background: rgba(10, 18, 38, 0.4);
}

.fleet-builder h3 {
  margin: 0 0 0.4rem;
}

.fleet-list {
  margin: 0.45rem 0 0.2rem;
  padding-left: 1rem;
  max-height: none;
  overflow: visible;
  font-size: 0.88rem;
}

.fleet-list li {
  margin-bottom: 0.2rem;
}

.fleet-list button {
  width: auto;
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.1rem 0.35rem;
  border: 1px solid #8aa7d6;
  border-radius: 4px;
  color: var(--text);
  background: #1c2e57;
  cursor: pointer;
}

.fleet-total {
  margin: 0.3rem 0 0;
  font-size: 0.9rem;
}

#start-match:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .battlefield-wrap {
    height: 420px;
  }

  .battlefield {
    min-height: 0;
  }
}
