/* ============================================
   MODERN TIC-TAC-TOE UI - STARTUP READY
   ============================================ */

:root {
  --bg-primary: #f8f9fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f0f2f5;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --text-light: #999999;
  --accent-green: #10b981;
  --accent-green-light: #d1fae5;
  --accent-green-dark: #059669;
  --accent-blue: #3b82f6;
  --accent-red: #ef4444;
  --accent-yellow: #fbbf24;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   GLOBAL STYLES
   ============================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: linear-gradient(135deg, var(--bg-primary) 0%, #fafbfc 100%);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  margin-bottom: 0;
}

header {
  display: none;
}

footer {
  display: none;
}

main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.container {
  max-width: 600px;
  width: 100%;
  padding: 0;
}

/* ============================================
   TYPOGRAPHY
   ============================================ */

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
  margin-bottom: 1rem;
}

h1 {
  font-size: 2rem;
  font-weight: 700;
}

h2 {
  font-size: 1.5rem;
}

h3 {
  font-size: 1.25rem;
}

p {
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

a {
  color: var(--accent-green);
  text-decoration: none;
  transition: var(--transition);
}

a:hover {
  color: var(--accent-green-dark);
  text-decoration: underline;
}

/* ============================================
   CARDS & CONTAINERS
   ============================================ */

.card {
  background: var(--bg-secondary);
  border: none;
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 2rem;
  margin-bottom: 1.5rem;
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

.btn:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.btn-primary {
  background: var(--accent-green);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--accent-green-dark);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid #e5e7eb;
}

.btn-secondary:hover {
  background: #e5e7eb;
  border-color: #d1d5db;
}

.btn-success {
  background: var(--accent-green);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-success:hover {
  background: var(--accent-green-dark);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--accent-red);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

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

/* ============================================
   FORMS & INPUTS
   ============================================ */

input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  transition: var(--transition);
  background: var(--bg-secondary);
  color: var(--text-primary);
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent-green);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

input::placeholder {
  color: var(--text-light);
}

/* ============================================
   LOBBY PAGE
   ============================================ */

.lobby-container {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

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

.lobby-header h1 {
  font-size: 2.5rem;
  background: linear-gradient(135deg, var(--accent-green), var(--accent-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}

.lobby-header p {
  color: var(--text-secondary);
  font-size: 1.1rem;
}

.name-input-group {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.name-input-group input {
  flex: 1;
}

.name-input-group button {
  flex-shrink: 0;
}

.welcome-section {
  background: var(--accent-green-light);
  border-left: 4px solid var(--accent-green);
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
}

.welcome-section p {
  margin: 0;
  color: var(--accent-green-dark);
  font-weight: 500;
}

.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 2rem;
}

@media (max-width: 600px) {
  .action-buttons {
    grid-template-columns: 1fr;
  }
}

.action-buttons button {
  width: 100%;
  padding: 1rem;
  font-size: 1rem;
}

.games-section {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow-md);
}

.games-section h3 {
  margin-top: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.connection-status {
  font-size: 0.875rem;
  color: var(--text-light);
  margin-left: auto;
}

.connection-status.connected {
  color: var(--accent-green);
}

.connection-status.disconnected {
  color: var(--accent-red);
}

.games-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.game-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  background: var(--bg-tertiary);
  border-radius: 8px;
  transition: var(--transition);
  border: 1px solid transparent;
}

.game-item:hover {
  background: #e5e7eb;
  border-color: var(--accent-green);
}

.game-item-info {
  flex: 1;
  color: var(--text-secondary);
}

.game-item-info strong {
  color: var(--text-primary);
}

.game-item a {
  padding: 0.5rem 1rem;
  background: var(--accent-green);
  color: white;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: var(--transition);
}

.game-item a:hover {
  background: var(--accent-green-dark);
  text-decoration: none;
  transform: translateY(-1px);
}

.no-games {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-light);
}

/* ============================================
   GAME PAGE
   ============================================ */

.game-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

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

.game-header h2 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.player-info {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.player-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg-tertiary);
  border-radius: 8px;
  font-weight: 500;
}

.player-symbol {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 6px;
  font-weight: 700;
  font-size: 1.25rem;
  color: white;
}

.player-symbol.x {
  background: var(--accent-blue);
}

.player-symbol.o {
  background: var(--accent-red);
}

.waiting-message {
  background: var(--accent-green-light);
  border-left: 4px solid var(--accent-green);
  padding: 1.5rem;
  border-radius: 8px;
  text-align: center;
  animation: slideIn 0.5s ease-out;
}

.waiting-message h3 {
  color: var(--accent-green-dark);
  margin-top: 0;
}

.waiting-message p {
  color: var(--accent-green-dark);
  margin-bottom: 0.5rem;
}

.game-link-container {
  background: var(--bg-tertiary);
  padding: 1rem;
  border-radius: 8px;
  margin-top: 1rem;
}

.game-link-container input {
  font-size: 0.875rem;
  padding: 0.5rem;
}

.game-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin: 2rem auto;
  width: fit-content;
  animation: slideIn 0.5s ease-out;
}

.cell {
  width: 100px;
  height: 100px;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  background: var(--bg-secondary);
  font-size: 2.5rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.cell:hover:not(:disabled) {
  border-color: var(--accent-green);
  box-shadow: var(--shadow-md);
  transform: scale(1.05);
  background: var(--accent-green-light);
}

.cell:active:not(:disabled) {
  transform: scale(0.98);
}

.cell:disabled {
  cursor: not-allowed;
}

.cell:not(:empty) {
  border-color: var(--accent-green);
}

/* Use data attributes for X and O styling */
.cell[data-player="X"] {
  color: var(--accent-blue);
  border-color: var(--accent-blue);
}

.cell[data-player="O"] {
  color: var(--accent-red);
  border-color: var(--accent-red);
}

.status-message {
  text-align: center;
  padding: 1rem;
  background: var(--bg-tertiary);
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-primary);
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.5s ease-out;
}

.status-message.waiting {
  background: var(--accent-green-light);
  color: var(--accent-green-dark);
}

.status-message.turn {
  background: var(--accent-yellow);
  color: #92400e;
}

.status-message.win {
  background: linear-gradient(135deg, var(--accent-green-light), #c7f0d8);
  color: var(--accent-green-dark);
  font-weight: 600;
  font-size: 1.25rem;
}

.status-message.lose {
  background: #fee2e2;
  color: #991b1b;
  font-weight: 600;
}

.status-message.draw {
  background: #fef3c7;
  color: #92400e;
  font-weight: 600;
}

.game-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 2rem;
  flex-wrap: wrap;
}

.game-actions button {
  min-width: 150px;
}

#gameOverActions {
  display: none;
  animation: slideUp 0.5s ease-out;
}

/* ============================================
   NOTIFICATIONS & ALERTS
   ============================================ */

.notification {
  position: fixed;
  top: 2rem;
  right: 2rem;
  padding: 1rem 1.5rem;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  animation: slideInRight 0.5s ease-out;
  z-index: 1000;
  max-width: 400px;
}

.notification.success {
  background: var(--accent-green);
  color: white;
}

.notification.error {
  background: var(--accent-red);
  color: white;
}

.notification.info {
  background: var(--accent-blue);
  color: white;
}

.notification.warning {
  background: var(--accent-yellow);
  color: #92400e;
}

@media (max-width: 600px) {
  .notification {
    right: 1rem;
    left: 1rem;
    top: auto;
    bottom: 2rem;
  }
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

.pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.bounce {
  animation: bounce 1s ease-in-out;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
  html {
    font-size: 14px;
  }

  h1 {
    font-size: 1.75rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  .card {
    padding: 1.5rem;
    border-radius: 12px;
  }

  .cell {
    width: 80px;
    height: 80px;
    font-size: 2rem;
    gap: 0.5rem;
  }

  .game-board {
    gap: 0.5rem;
  }

  .player-info {
    gap: 1rem;
  }

  .action-buttons {
    grid-template-columns: 1fr;
  }

  main {
    padding: 1rem;
  }
}

@media (max-width: 480px) {
  .cell {
    width: 70px;
    height: 70px;
    font-size: 1.75rem;
  }

  .game-header h2 {
    font-size: 1.5rem;
  }

  .lobby-header h1 {
    font-size: 1.75rem;
  }

  .btn {
    padding: 0.65rem 1.25rem;
    font-size: 0.95rem;
  }

  .card {
    padding: 1.25rem;
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.text-center {
  text-align: center;
}

.text-muted {
  color: var(--text-light);
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }

.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.p-3 { padding: 1.5rem; }
.p-4 { padding: 2rem; }

.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }

.hidden {
  display: none !important;
}

.visible {
  display: block !important;
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

.btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent-green);
  outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
