:root {
  --bg: #0b1222;
  --surface: #0f1724;
  --muted: #94a3b8;
  --text: #e6eef3;
  --accent-cyan: #00c2ff;
  --accent-rose: #ff6b6b;
  --glass: rgba(255, 255, 255, 0.03);
  --shadow: 0 6px 20px rgba(2, 6, 23, 0.6);
  --radius: 14px;
}

/* ========== RESET ========== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

html {
  min-height: 100%;
  background: linear-gradient(180deg, var(--bg) 0%, #060816 100%);
  background-attachment: fixed;
}

body {
  min-height: 100vh;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 24px;
  background: transparent;
}

/* ========== HEADER ========== */
.app-header {
  width: 100%;
  max-width: 1100px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.03);
  box-shadow: var(--shadow);
}

.app-title {
  font-size: 1.6rem;
  color: var(--accent-rose);
  letter-spacing: 0.6px;
  font-weight: 700;
}

/* ========== BUTTONS ========== */
.btn {
  border: none;
  padding: 10px 16px;
  min-width: 120px;
  text-align: center;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  background: transparent;
  color: var(--text);
  transition: background 0.2s ease, transform 0.12s ease;
}

.btn-primary {
  background: linear-gradient(90deg, var(--accent-cyan), #27b8ff);
  color: #021026;
  box-shadow: 0 6px 18px rgba(0, 194, 255, 0.12);
}

.btn-new-player {
  margin-left: auto;
  background: linear-gradient(90deg, var(--accent-rose), #ff5873);
  color: #fff;
  box-shadow: 0 6px 18px rgba(255, 107, 107, 0.08);
}

.btn-start {
  background: linear-gradient(90deg, var(--accent-cyan), #27b8ff);
  color: #021026;
  border-radius: 10px;
  padding: 8px 16px;
}

.btn-choose-x,
.btn-choose-o {
  background: linear-gradient(90deg, var(--accent-rose), #ff5873);
  color: #fff;
  font-weight: 600;
  border-radius: 8px;
  padding: 8px 14px;
  min-width: 110px;
  box-shadow: 0 4px 12px rgba(255, 107, 107, 0.15);
}

/* ========== LAYOUT ========== */
.game-wrap {
  width: 100%;
  max-width: 1100px;
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 28px;
  align-items: start;
}

.board-section {
  display: flex;
  justify-content: center;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ========== GRID / BOARD ========== */
.game-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 420px;
  height: 420px;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.35),
    rgba(255, 255, 255, 0.01)
  );
  border-radius: 12px;
  padding: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
  border: 2px solid rgba(255, 255, 255, 0.03);
}

.board-cell {
  width: 120px;
  height: 120px;
  background: var(--glass);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.02);
  flex-shrink: 0;
}

.cell-button {
  width: 100%;
  height: 100%;
  font-size: 2.6rem;
  line-height: 1; /* prevents vertical stretching */
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--accent-rose);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, color 0.12s ease;
}

.cell-button:hover:not(:disabled) {
  transform: scale(1.02);
  filter: brightness(1.1);
}

.cell-button:disabled {
  opacity: 0.7;
  cursor: default;
}

/* ========== GAME CONTROLS ========== */
.game-message {
  color: var(--muted);
  font-weight: 600;
}

.player-selects {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.select-block {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.select-player {
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.15);
  min-width: 150px;
  height: 36px;
  transition: opacity 0.2s ease;
}

/* keep space but hide visually */
.select-player.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ========== STATS / PLAYERS ========== */
.players {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: stretch;
}

.player-card {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.02),
    rgba(255, 255, 255, 0.01)
  );
  padding: 14px;
  border-radius: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.03);
  box-shadow: var(--shadow);
}

.player-card .avatar-box {
  width: 86px;
  height: 86px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.02);
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.02),
    rgba(0, 0, 0, 0.15)
  );
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-card .player-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.player-card .stats {
  flex: 1;
  color: var(--muted);
}

.player-card .player-name {
  font-size: 1.05rem;
  color: var(--accent-cyan);
  margin-bottom: 6px;
}

.stat {
  font-size: 0.95rem;
  color: var(--muted);
}

.player-card.active {
  border: 2px solid rgba(0, 194, 255, 0.14);
  box-shadow: 0 10px 30px rgba(0, 194, 255, 0.06);
  transform: translateY(-4px);
}

/* ========== MODAL ========== */
.modal {
  display: none;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  z-index: 1001;
  width: 360px;
  padding: 22px;
  border-radius: 14px;
  background: linear-gradient(
    180deg,
    var(--surface),
    rgba(255, 255, 255, 0.05)
  );
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.75);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.modal.active {
  display: block;
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ========== FORM INSIDE MODAL ========== */
.form-create-player {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-create-player h2 {
  margin: 0 0 8px;
  font-size: 1.4rem;
  text-align: center;
  color: var(--text-primary, #fff);
}

.input-player-name {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary, #fff);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.input-player-name:focus {
  border-color: var(--accent, #4ade80);
}

/* ===== Dropdown Styling ===== */
.input-avatar-select {
  width: 100%;
  padding: 10px 12px;
  margin: 10px 0 16px 0;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text, #f8fafc);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border 0.2s ease, background 0.2s ease;
}

.input-avatar-select:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.25);
}

.input-avatar-select:focus {
  border-color: #3b82f6; /* nice blue focus */
  background: rgba(255, 255, 255, 0.1);
}

.input-avatar-select option {
  background: var(--surface, #1e293b);
  color: #f8fafc;
  padding: 10px;
}

label {
  font-size: 0.85rem;
  color: var(--text-secondary, #aaa);
  margin-bottom: -6px;
}

#avatarPreview {
  margin: 0 auto;
  display: block;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  object-fit: cover;
  background: rgba(255, 255, 255, 0.05);
  padding: 4px;
}

/* ========== BUTTON ========== */
.btn {
  padding: 10px 14px;
  border-radius: 8px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--accent, #4ade80);
  color: #0f172a;
}

.btn-primary:hover {
  background: #22c55e;
}

/* ========== OVERLAY ========== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.7);
  z-index: 1000;
  display: none;
  backdrop-filter: blur(3px);
}

.overlay.active {
  display: block;
}

/* ========== MEDIA QUERIES ========== */

/* Tablets (≤ 768px) */
@media (max-width: 768px) {
  .game-wrap {
    grid-template-columns: 1fr; /* Stack board & sidebar */
    gap: 20px;
  }

  .game-board {
    width: 300px;
    height: 300px;
  }

  .board-cell {
    width: 85px;
    height: 85px;
  }

  .cell-button {
    font-size: 2rem;
  }

  .sidebar {
    align-items: center;
    padding-bottom: 1.25rem;
  }
}

/* Phones (≤ 480px) */
@media (max-width: 480px) {
  body {
    padding: 12px;
    gap: 14px;
  }

  /* keep header inline but smaller */
  .app-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
  }

  .app-title {
    font-size: 1.2rem;
  }

  .app-nav {
    gap: 6px;
  }

  .app-link {
    font-size: 0.85rem;
    padding: 4px 6px;
  }

  /* shrink board */
  .game-board {
    width: 260px;
    height: 260px;
    gap: 6px;
  }

  .board-cell {
    width: 75px;
    height: 75px;
  }

  .cell-button {
    font-size: 1.6rem;
  }

  .player-card {
    flex-direction: row;
    text-align: left;
    gap: 8px;
  }

  .player-card .avatar-box {
    width: 70px;
    height: 70px;
  }

  .player-card .player-name {
    font-size: 1rem;
  }

  .sidebar .btn,
  .controls .btn {
    min-width: unset;
    width: 100%;
    padding: 6px 10px;
    font-size: 0.9rem;
  }

  .app-header .btn {
    width: auto;
    padding: 6px 12px;
    font-size: 0.85rem;
  }
}
