/* Chess with Barriers - Styles */

:root {
  --cell-size: 52px;
  --board-border: 2px solid #2c1810;
  --light-square: #f0d9b5;
  --dark-square: #b58863;
  --highlight: rgba(255, 255, 0, 0.4);
  --valid-move: rgba(0, 128, 0, 0.35);
  --fence-color: #8b4513;
  --fence-highlight: #cd853f;
  --watchtower-color: #4a5568;
  --watchtower-highlight: #718096;
  --edge-hover: rgba(139, 69, 19, 0.5);
  --vertex-hover: rgba(74, 85, 104, 0.5);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
}

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem;
}

.header {
  text-align: center;
  margin-bottom: 1rem;
}

.header h1 {
  margin: 0 0 0.5rem 0;
  font-size: 1.5rem;
}

.status {
  font-size: 0.9rem;
  color: #aaa;
}

.game-status {
  font-size: 1rem;
  margin-top: 0.25rem;
  min-height: 1.5em;
}

.timer-row {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 0.5rem;
  font-variant-numeric: tabular-nums;
}

.timer {
  font-size: 1.1rem;
  padding: 0.25rem 0.5rem;
  background: #0f3460;
  border-radius: 4px;
  min-width: 4rem;
  text-align: center;
}

.timer.running {
  box-shadow: 0 0 0 2px #e94560;
}

.header-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.btn-undo {
  padding: 0.4rem 0.8rem;
  background: #0f3460;
  color: #eee;
  border: 1px solid #1a4a7a;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.btn-undo:hover:not(:disabled) {
  background: #1a4a7a;
}

.btn-undo:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-next-move {
  padding: 0.4rem 0.8rem;
  background: #2d5a27;
  color: #eee;
  border: 1px solid #3d7a35;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.btn-next-move:hover {
  background: #3d7a35;
}

.btn-auto-play {
  padding: 0.4rem 0.8rem;
  background: #5a4a7a;
  color: #eee;
  border: 1px solid #6a5a8a;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.btn-auto-play:hover {
  background: #6a5a8a;
}

.btn-next-move.hidden,
.btn-undo.hidden,
.btn-auto-play.hidden {
  display: none;
}

.move-log-panel {
  margin-top: 1rem;
  background: #16213e;
  border-radius: 8px;
  padding: 1rem;
  border: 1px solid #0f3460;
}

.move-log-panel h3 {
  margin: 0 0 0.5rem 0;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #aaa;
}

.move-log {
  max-height: 200px;
  overflow-y: auto;
  font-size: 0.8rem;
  font-family: ui-monospace, monospace;
}

.move-log-entry {
  padding: 0.2rem 0;
  border-bottom: 1px solid #0f3460;
}

.move-log-entry:last-child {
  border-bottom: none;
}

.move-log-entry.move-log-white {
  color: #e0e0e0;
}

.move-log-entry.move-log-black {
  color: #b0b0b0;
}

.main {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.sidebar {
  flex: 0 0 140px;
  min-width: 120px;
}

.player-panel {
  background: #16213e;
  border-radius: 8px;
  padding: 1rem;
  border: 1px solid #0f3460;
}

.player-panel h3 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.barriers {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.barrier-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  background: #0f3460;
  cursor: pointer;
  transition: background 0.15s;
}

.barrier-item:hover:not(.disabled) {
  background: #1a4a7a;
}

.barrier-item.selected {
  outline: 2px solid #e94560;
  outline-offset: 2px;
}

.barrier-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.barrier-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.fence-icon {
  background: var(--fence-color);
  clip-path: polygon(0 45%, 100% 45%, 100% 55%, 0 55%);
}

.watchtower-icon {
  background: var(--watchtower-color);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

.barrier-label {
  flex: 1;
  font-size: 0.85rem;
}

.barrier-count {
  font-weight: bold;
  min-width: 1.2em;
  text-align: right;
}

/* Board */
.board-container {
  position: relative;
  flex-shrink: 0;
}

.board {
  width: calc(var(--cell-size) * 8);
  height: calc(var(--cell-size) * 8);
  border: var(--board-border);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  background: var(--dark-square);
}

.board-inner {
  position: relative;
  width: 100%;
  height: 100%;
}

.squares-layer,
.edges-layer,
.vertices-layer,
.barriers-layer,
.pieces-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.squares-layer {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  pointer-events: auto;
}

.square {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.square.light {
  background: var(--light-square);
}

.square.dark {
  background: var(--dark-square);
}

.square.highlight {
  background: var(--highlight) !important;
}

.square.valid-move::after {
  content: '';
  width: 40%;
  height: 40%;
  border-radius: 50%;
  background: var(--valid-move);
  pointer-events: none;
}

.square.valid-capture::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 4px solid var(--valid-move);
  border-radius: 4px;
  pointer-events: none;
}

/* Edges layer: invisible hit areas for fence placement */
.edges-layer {
  pointer-events: none;
}

.edges-layer.placement-mode {
  pointer-events: auto;
}

.edge-hit {
  position: absolute;
  background: transparent;
  cursor: pointer;
  transition: background 0.1s;
}

.edge-hit:hover {
  background: var(--edge-hover);
}

.edge-hit.horizontal {
  height: 8px;
  /* position/size set in JS */
}

.edge-hit.vertical {
  width: 8px;
  /* position/size set in JS */
}

/* Vertices layer */
.vertices-layer {
  pointer-events: none;
}

.vertices-layer.placement-mode {
  pointer-events: auto;
}

.vertex-hit {
  position: absolute;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  margin-top: -7px;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transition: background 0.1s;
  /* left/top set in JS to vertex center */
}

.vertex-hit:hover {
  background: var(--vertex-hover);
}

/* Rendered barriers on board */
.barriers-layer {
  pointer-events: none;
}

.barrier-fence,
.barrier-watchtower {
  position: absolute;
  pointer-events: none;
}

.barrier-fence {
  background: var(--fence-color);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.3);
}

.barrier-fence.placed-by-white {
  background: linear-gradient(180deg, #c9b896 0%, #8b7355 100%);
  box-shadow: 0 0 0 2px #fff, 0 0 6px rgba(255,255,255,0.4);
}

.barrier-fence.placed-by-black {
  background: linear-gradient(180deg, #5c4a32 0%, #2d2318 100%);
  box-shadow: 0 0 0 2px #333, 0 0 6px rgba(0,0,0,0.5);
}

.barrier-watchtower.placed-by-white {
  background: linear-gradient(135deg, #94a3b8 0%, #475569 100%);
  box-shadow: 0 0 0 2px #fff, 0 0 6px rgba(255,255,255,0.3);
}

.barrier-watchtower.placed-by-black {
  background: linear-gradient(135deg, #334155 0%, #0f172a 100%);
  box-shadow: 0 0 0 2px #1e293b, 0 0 6px rgba(0,0,0,0.5);
}

.barrier-fence.horizontal {
  width: calc(var(--cell-size) + 4px);
  height: 6px;
  left: -2px;
  top: 50%;
  transform: translateY(-50%);
}

.barrier-fence.vertical {
  width: 6px;
  height: calc(var(--cell-size) + 4px);
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
}

.barrier-watchtower {
  width: 12px;
  height: 12px;
  margin-left: -6px;
  margin-top: -6px;
  background: var(--watchtower-color);
  border-radius: 2px;
  transform: rotate(45deg);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.3);
}

/* Pieces */
.pieces-layer {
  pointer-events: none;
}

.piece {
  position: absolute;
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 42px;
  line-height: 1;
  cursor: grab;
  pointer-events: auto;
  user-select: none;
  z-index: 2;
}

.piece.dragging {
  cursor: grabbing;
  z-index: 10;
  opacity: 0.9;
}

.piece.white {
  color: #ffffff;
  text-shadow: 0 0 3px #000000;
}
.piece.black {
  color: #000000;
  text-shadow: 0 0 3px #ffffff;
}

.turn-indicator {
  text-align: center;
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: #aaa;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 12px;
  padding: 2rem;
  max-width: 360px;
  text-align: center;
}

.modal h2 {
  margin: 0 0 1rem 0;
  font-size: 1.25rem;
}

.modal p {
  margin: 0 0 1rem 0;
  color: #bbb;
}

.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.modal-buttons .btn-primary {
  width: 100%;
}

.btn-primary {
  background: #e94560;
  color: #fff;
  border: none;
  padding: 0.6rem 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
}

.btn-primary:hover {
  background: #ff6b6b;
}

/* Promotion overlay */
.promotion-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.promotion-overlay.hidden {
  display: none;
}

.promotion-modal {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 12px;
  padding: 1.5rem;
}

.promotion-modal p {
  margin: 0 0 1rem 0;
}

.promotion-pieces {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.promotion-pieces .piece {
  position: static;
  cursor: pointer;
}

.promotion-pieces .piece:hover {
  opacity: 0.9;
  transform: scale(1.05);
}

.hidden {
  display: none !important;
}
