* {
  box-sizing: border-box;
  font-family:
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    "Helvetica Neue",
    Arial;
}

body {
  padding: 12px;
  background: linear-gradient(135deg, #5C258D 0%, #4389A2 100%);
  min-height: 100vh;
  margin: 0;
  color: #e6eef8;
  display: flex;
  flex-direction: column;
}

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* server message banner fixed, centered above content */
.server-message {
  display: none;
  position: fixed;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  z-index: 9999;
  width: clamp(280px, 70%, 900px);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  padding: 10px 14px;
  text-align: left;
}

.server-message .msg-box {
  display: flex;
  gap: 12px;
  align-items: flex-start
}

.server-message .msg-icon {
  font-size: 22px;
  line-height: 1.1
}

.server-message .msg-header {
  font-weight: 700;
  margin-bottom: 4px
}

.server-message .msg-text {
  font-size: 14px;
  color: inherit
}

.server-message.alert {
  background: #4a3b12;
  color: #fff8db;
  border: 1px solid #6b5420;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

.server-message.info {
  background: #0b2540;
  color: #dcebff;
  border: 1px solid #2a5aa8;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

.header {
  display: flex;
  justify-content: center;
  align-items: center;
}

.board-and-log {
  display: flex;
  gap: 24px;
  margin-top: 18px;
  flex: 1;
  align-items: flex-start;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: 100%;
  max-width: calc(100vh - 200px);
  aspect-ratio: 1 / 1;
  justify-content: center;
  border: 2px solid #9aa4b2;
}

.board {
  margin: 0 auto;
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  font-size: clamp(20px, 5.5vw, 40px);
  font-weight: 700;
  cursor: pointer;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}

.square.light {
  background: #d6c4a6;
}

.square.dark {
  background: #6b512f;
}

.square.selected {
  outline: 4px solid #0a84ff;
}

.board-column {
  display: flex;
  flex-direction: column;
  align-items: center
}


.turn-row {
  margin-top: 8px;
  font-weight: 600;
  text-align: center
}

.title-row {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%
}

.subtitle {
  text-align: center;
  color: #eee;
  font-size: 14px;
  margin-top: -6px
}

.status-row {
  display: flex;
  justify-content: center;
  margin-bottom: 6px
}

.cooldown-display {
  text-align: center;
  margin-top: 6px;
  font-size: 10px;
  color: #eee
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.log {
  max-height: 384px;
  overflow: auto;
}

.messages {
  margin-top: 12px;
  color: #a33;
}

.messages {
  text-align: center;
  margin-top: 6px
}

.messages.error {
  color: #a33
}

.messages.info {
  color: #166534
}

/* Promotion modal */
.promo-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000
}

.promo-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.promo-box {
  position: relative;
  z-index: 10001;
  background: #071024;
  color: #e6eef8;
  padding: 16px;
  border-radius: 10px;
  min-width: 240px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  border: 1px solid #15314a;
}

.promo-title {
  font-weight: 700
}

.promo-options {
  display: flex;
  gap: 12px
}

.promo-btn {
  background: transparent;
  border: 1px solid #234;
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  font-size: 28px
}

.promo-btn i {
  pointer-events: none
}

.promo-btn:hover {
  background: #0c2a44
}

.promo-cancel {
  background: #071024;
  border: 1px solid #234;
  padding: 6px 10px;
  border-radius: 8px;
  color: #e6eef8
}

/* ensure move list sits to the right when wide */
@media (min-width: 900px) {
  .board-and-log {
    align-items: flex-start;
    justify-content: center
  }

  .log {
    margin-left: 24px
  }
}

/* stronger layout on wide screens: fix widths so board is centered and move-list sits right */
@media (min-width: 1100px) {
  .board-and-log {
    justify-content: center
  }

  .board-column {
    flex: 0 0 auto;
    margin-right: 56px
  }

  .board {
    width: 512px
  }

  .log {
    flex: 0 0 320px;
    max-width: 320px
  }
}

#meta,
.debug-info {
  font-size: 13px;
  color: #9aa4b2;
}

#ipRow,
#cfRow,
#uuidRow {
  font-size: 13px;
  color: #bbb;
}

/* header right side */
.header-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.header-right #turnRow {
  font-weight: 600;
  margin-right: 8px;
}

.debug-panels-container {
  position: absolute;
  right: 12px;
  top: 56px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  z-index: 1000;
}

.side-panel {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
}

.debug-panel {
  background: #081226;
  padding: 8px;
  border: 1px solid #1f2a3a;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  width: max-content;
}

/* piece icon styling */
.piece {
  font-size: clamp(20px, 6vw, 48px);
  line-height: 1;
}

.piece.white {
  color: #fff;
  text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}

.piece.black {
  color: #111;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* Ensure Font Awesome font is used with the correct weight for solid icons */
.piece {
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
}

/* ghost move visuals */
.ghost-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
}

.ghost {
  position: absolute;
  transition: transform 420ms cubic-bezier(.2, .8, .2, 1), opacity 220ms;
  will-change: transform, opacity;
  opacity: 0.45
}

.ghost .piece {
  font-size: clamp(22px, 7vw, 52px)
}

/* moving piece (for valid moves) - quicker, snappy */
.moving {
  position: absolute;
  transition: transform 160ms cubic-bezier(.2, .9, .2, 1), opacity 140ms;
  will-change: transform, opacity;
  z-index: 10000
}

.moving .piece {
  font-size: clamp(20px, 6vw, 48px)
}


/* best move ghost piece */
.ghost-best-move-piece {
  position: absolute;
  color: #9aa4b2;
  opacity: 0.25;
  pointer-events: none;
  z-index: 50;
  font-size: clamp(20px, 6vw, 48px);
  transition: opacity 0.4s ease-out;
}

/* best move checkmark */
.best-move-checkmark {
  position: absolute;
  top: 0;
  right: 0;
  color: #22c55e;
  font-size: clamp(14px, 4vw, 24px);
  z-index: 100;
  background: #0f172a;
  border-radius: 50%;
  pointer-events: none;
  transition: opacity 0.4s ease-out;
  box-shadow: 0 0 0 2px #0f172a;
}
.ghost-best-move-piece.white {
  text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}
.ghost-best-move-piece.black {
  text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff;
}

/* move list toggle (mobile) */
.move-list-toggle {
  display: none;
  margin-top: 8px;
  padding: 6px 10px
}

/* best move toggle button */
.best-move-toggle-btn {
  margin-top: auto;
  padding: 8px 12px;
  background: #162a44;
  color: #e6eef8;
  border: 1px solid #234;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s ease;
}
.best-move-toggle-btn:hover {
  background: #1d3a5c;
}
.best-move-toggle-btn.active {
  background: #16a34a;
  border-color: #15803d;
  font-weight: bold;
  color: #fff;
}
.best-move-toggle-btn.active:hover {
  background: #15803d;
}

button {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #ccc;
  background: #fff;
}

input {
  padding: 6px;
  border: 1px solid #ccc;
  border-radius: 6px;
}

/* Responsive: stack board and moves on small screens */
@media (max-width: 720px) {
  .board-and-log {
    flex-direction: column;
    gap: 12px
  }

  .log {
    display: none;
    width: 90%;
    max-width: 520px
  }

  .log.show {
    display: block
  }

  .move-list-toggle {
    display: inline-block
  }
}

/* place debug area beneath last move row */
.debug-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 8px
}

.last-move-row {
  display: flex;
  justify-content: center;
  margin-top: 7px;
  font-size: 13px;
}

.square {
  position: relative;
}

.square-name {
  position: absolute;
  bottom: 2px;
  right: 2px;
  font-size: 10px;
  color: rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.dark .square-name {
  color: rgba(255, 255, 255, 0.4);
}

.square.valid-move::after {
  content: '';
  position: absolute;
  width: 25%;
  height: 25%;
  background: rgba(10, 132, 255, 0.5);
  border-radius: 50%;
}

@media (min-width: 800px) {
  .board-and-log {
    display: flex;
    justify-content: center;
    align-items: stretch;
    gap: 20px;
  }

  /* Add margin-top to align the side panel with the board, compensating for .turn-row */
  .log.side-panel,
  .right-placeholder {
    margin-top: 31px;
  }

  .log {
    display: flex;
    flex-direction: column;
    max-height: 85vh;
  }

  #movesList {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
  }

  .scoreboard {
    flex-shrink: 0;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #444;
  }
}

/* Username picker in debug popup */
.username-section {
  margin-top: 8px;
}

.username-section label {
  font-size: 12px;
  color: #9aa4b2;
  display: block;
  margin-bottom: 4px;
}

.username-row {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}

.username-row select {
  padding: 4px 6px;
  border-radius: 5px;
  border: 1px solid #234;
  background: #0c1a2e;
  color: #e6eef8;
  font-size: 12px;
  max-width: 110px;
}

.username-row button {
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 5px;
  border: 1px solid #234;
  background: #162a44;
  color: #e6eef8;
  cursor: pointer;
}

.username-row button:hover {
  background: #1d3a5c;
}

.username-current {
  font-size: 13px;
  color: #7eb8da;
  margin-bottom: 6px;
  margin-top: 2px;
}

.panel-hr {
  width: 100%;
  border: 0;
  border-top: 1px solid #5a6575;
  margin: 10px 0;
}



.admin-panel h4 {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: #7eb8da;
  letter-spacing: 0.5px;
}

.admin-section {
}

.admin-section label {
  font-size: 13px;
  color: #8899aa;
  display: block;
  margin-bottom: 3px;
}

.admin-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.admin-row input,
.admin-row select {
  padding: 5px 8px;
  border-radius: 5px;
  border: 1px solid #234;
  background: #0c1a2e;
  color: #e6eef8;
  font-size: 12px;
}

.admin-row input {
  flex: 1;
  min-width: 60px;
}

.admin-row input[type="checkbox"] {
  flex: none;
  min-width: 0;
  width: auto;
  margin-right: 6px;
  cursor: pointer;
}

.admin-row select {
  min-width: 70px;
}

.admin-btn {
  padding: 5px 12px;
  font-size: 12px;
  border-radius: 5px;
  border: 1px solid #234;
  background: #162a44;
  color: #e6eef8;
  cursor: pointer;
  white-space: nowrap;
}

.admin-btn:hover {
  background: #1d3a5c;
}

.admin-btn.danger {
  background: #3a1520;
  border-color: #5a2030;
}

.admin-btn.danger:hover {
  background: #4a1a28;
}

.admin-btn.warning {
  background: #524716;
  border-color: #6e601f;
}

.admin-btn.warning:hover {
  background: #63561a;
}

.admin-status {
  font-size: 11px;
  color: #6a8;
}

.admin-status.error {
  color: #d66;
}

.admin-status:empty {
  display: none;
}