/* ============================================================================
   styles.css — Discord-inspired dark theme for the International Draughts
   Activity. Organized top-to-bottom: tokens, layout, header, player cards,
   board + pieces, overlays, toasts, responsive breakpoints, motion.
   ============================================================================ */

:root {
  --background: #1e1f22;
  --surface: #2b2d31;
  --surface-hover: #313338;
  --surface-raised: #35373c;
  --accent: #5865f2;
  --accent-hover: #4752c4;

  --board-light: #e8d5b5;
  --board-dark: #8f6248;

  --white-piece: #f5f5f5;
  --black-piece: #292b2f;

  --gold: #f0b232;

  --text-primary: #f2f3f5;
  --text-secondary: #b5bac1;
  --text-muted: #80848e;

  --success: #23a55a;
  --danger: #ed4245;
  --warn: #f0b232;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;

  --shadow-soft: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-deep: 0 10px 30px rgba(0, 0, 0, 0.5);

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--background);
  color: var(--text-primary);
  font-family: 'gg sans', 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
  min-height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: clamp(10px, 2.5vw, 22px);
  gap: 12px;
}

button {
  font-family: inherit;
}

/* ----------------------------------------------------------------------- */
/* Header                                                                   */
/* ----------------------------------------------------------------------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  box-shadow: var(--shadow-soft);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.app-title {
  font-size: clamp(15px, 2.2vw, 19px);
  font-weight: 800;
  letter-spacing: 0.04em;
  margin: 0;
  text-transform: uppercase;
  color: var(--text-primary);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-dot--connected {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}
.status-dot--connecting {
  background: var(--warn);
  animation: pulse 1.4s ease-in-out infinite;
}
.status-dot--lost {
  background: var(--danger);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.turn-label {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-raised);
}
.turn-label--mine {
  color: var(--background);
  background: var(--gold);
}

.role-badge {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--text-secondary);
}
.role-badge--white {
  background: var(--white-piece);
  color: #1a1a1a;
}
.role-badge--black {
  background: var(--black-piece);
  color: var(--text-primary);
  border: 1px solid #444;
}
.role-badge--spectator {
  background: transparent;
  border: 1px dashed var(--text-muted);
  color: var(--text-muted);
}

.status-line {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  min-height: 18px;
}

/* ----------------------------------------------------------------------- */
/* Layout                                                                   */
/* ----------------------------------------------------------------------- */

.game-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.player-cards {
  display: flex;
  justify-content: center;
  gap: clamp(10px, 3vw, 28px);
  width: min(94vw, 760px);
  flex-wrap: wrap;
}

/* ----------------------------------------------------------------------- */
/* Player cards                                                             */
/* ----------------------------------------------------------------------- */

.player-card {
  flex: 1 1 220px;
  max-width: 320px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  border: 1px solid transparent;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.player-card--active-turn {
  border-color: var(--gold);
  background: var(--surface-hover);
}

.player-card--offline {
  opacity: 0.6;
}

.player-card--empty {
  color: var(--text-muted);
  font-style: italic;
}

.player-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-raised);
}
.player-avatar--fallback,
.player-avatar--empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-secondary);
  background: var(--surface-raised);
}

.player-info {
  min-width: 0;
  flex: 1;
}

.player-name {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.you-tag {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 12px;
}

.player-color {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.player-color--white {
  color: var(--white-piece);
}
.player-color--black {
  color: var(--text-secondary);
}

.player-turn-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.player-turn-indicator .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}
.player-turn-indicator .dot--active {
  background: var(--success);
  box-shadow: 0 0 5px var(--success);
}
.player-turn-indicator .dot--idle {
  background: var(--text-muted);
}
.player-turn-indicator .dot--offline {
  background: var(--danger);
}

.capture-count {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ----------------------------------------------------------------------- */
/* Board                                                                    */
/* ----------------------------------------------------------------------- */

.board-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.board-frame {
  width: min(92vw, 640px);
  aspect-ratio: 1;
  padding: clamp(6px, 1.4vw, 14px);
  background: linear-gradient(145deg, #4a3324, #2e2015);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-deep);
}

.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35);
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.square.light {
  background: var(--board-light);
}
.square.dark {
  background: var(--board-dark);
  cursor: pointer;
}
.square.dark:hover {
  filter: brightness(1.12);
}

.square.selected::before {
  content: '';
  position: absolute;
  inset: 4%;
  border-radius: 8px;
  box-shadow: 0 0 0 3px var(--accent), 0 0 12px 2px rgba(88, 101, 242, 0.7);
  pointer-events: none;
}

.square.legal-move::after,
.square.capture-target::after {
  content: '';
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.85;
  animation: pop-in 140ms ease-out;
  pointer-events: none;
}
.square.capture-target::after {
  width: 34%;
  height: 34%;
  background: transparent;
  border: 3px solid var(--danger);
  box-shadow: 0 0 8px rgba(237, 66, 69, 0.6);
}

.square.mandatory::before {
  content: '';
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(240, 178, 50, 0.55);
  pointer-events: none;
}

.square.last-move-from,
.square.last-move-to {
  box-shadow: inset 0 0 0 999px rgba(240, 178, 50, 0.18);
}

.square.invalid-flash {
  animation: shake 260ms ease;
}

/* ----------------------------------------------------------------------- */
/* Pieces                                                                   */
/* ----------------------------------------------------------------------- */

.piece {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: piece-in 140ms ease-out;
  transition: transform 120ms ease;
}

.piece-white {
  background: radial-gradient(circle at 35% 30%, #ffffff, var(--white-piece) 60%, #d8d8d8 100%);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.45), inset 0 -3px 4px rgba(0, 0, 0, 0.12);
}

.piece-black {
  background: radial-gradient(circle at 35% 30%, #3d3f45, var(--black-piece) 65%, #17181a 100%);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.55), inset 0 -3px 4px rgba(0, 0, 0, 0.35);
}

.piece-king {
  box-shadow: 0 0 0 3px var(--gold), 0 0 10px 2px rgba(240, 178, 50, 0.65), 0 3px 6px rgba(0, 0, 0, 0.5);
}

.king-crown {
  color: var(--gold);
  font-size: clamp(10px, 2.4vw, 18px);
  text-shadow: 0 0 4px rgba(240, 178, 50, 0.8);
  pointer-events: none;
}

.board-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(92vw, 640px);
  gap: 10px;
}

.spectator-count {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ----------------------------------------------------------------------- */
/* Buttons                                                                  */
/* ----------------------------------------------------------------------- */

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease;
}
.btn:active {
  transform: scale(0.97);
}
.btn--primary {
  background: var(--accent);
  color: white;
}
.btn--primary:hover {
  background: var(--accent-hover);
}
.btn--ghost {
  background: var(--surface-raised);
  color: var(--text-primary);
}
.btn--ghost:hover {
  background: var(--surface-hover);
}

/* ----------------------------------------------------------------------- */
/* Overlays                                                                 */
/* ----------------------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
  z-index: 50;
  padding: 16px;
}
.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px 36px;
  text-align: center;
  box-shadow: var(--shadow-deep);
  max-width: 380px;
  width: 100%;
  animation: overlay-in 180ms ease-out;
}
.overlay-card--small {
  padding: 24px 26px;
}

.overlay-title {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.03em;
  color: var(--gold);
  margin-bottom: 8px;
}
.overlay-title--error {
  color: var(--danger);
  font-size: 18px;
}

.overlay-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ----------------------------------------------------------------------- */
/* Toasts                                                                   */
/* ----------------------------------------------------------------------- */

.toast-container {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--surface-raised);
  color: var(--text-primary);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow-soft);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast--visible {
  opacity: 1;
  transform: translateY(0);
}
.toast--error {
  background: var(--danger);
}
.toast--warn {
  background: var(--warn);
  color: #2b2100;
}

/* ----------------------------------------------------------------------- */
/* Motion                                                                   */
/* ----------------------------------------------------------------------- */

@keyframes pop-in {
  from {
    transform: scale(0.4);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 0.85;
  }
}

@keyframes piece-in {
  from {
    transform: scale(0.75);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes overlay-in {
  from {
    transform: translateY(8px) scale(0.98);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ----------------------------------------------------------------------- */
/* Responsive                                                               */
/* ----------------------------------------------------------------------- */

@media (max-width: 480px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }
  .header-right {
    justify-content: center;
  }
  .player-cards {
    gap: 8px;
  }
  .player-card {
    flex: 1 1 100%;
    max-width: none;
  }
}

@media (max-height: 560px) {
  #app {
    gap: 6px;
  }
  .board-frame {
    width: min(60vh, 92vw);
  }
}