:root {
  --primary: #f97316;
  --primary-dark: #ea580c;
  --primary-light: #fb923c;
  --secondary: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --dark: #1e293b;
  --darker: #0f172a;
  --gray: #64748b;
  --light-gray: #334155;
  --white: #f8fafc;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4);
  --radius: 0.75rem;
  --radius-lg: 1rem;
  --xo-red: #ef4444;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  min-height: 100vh;
  padding: 1.5rem;
  color: var(--white);
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

.app-container {
  max-width: 1600px;
  margin: 0 auto;
}

/* ========== LAYOUT ========== */
.lobby-section, .game-section {
  animation: fadeInUp 0.4s ease-out;
}

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

/* ========== HEADERS ========== */
.lobby-header, .game-header {
  background: var(--darker);
  border-radius: var(--radius-lg);
  padding: 1rem 1.5rem;
  margin-bottom: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--light-gray);
}

/* כותרות בצבע לבן */
.lobby-header h1, 
.game-header h1,
h1, 
h2, 
h3, 
.section-title-row h2, 
.chat-area h3, 
.modal-content h3 {
  color: var(--white) !important;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.lobby-header h1 {
  font-size: 1.5rem;
  font-weight: 800;
}

.game-header h1 {
  font-size: 1.5rem;
  font-weight: 800;
}

/* החלפת האימוג'י ב-XO אדום בלובי */
.lobby-header h1::before {
  content: "X O";
  color: var(--xo-red);
  font-weight: 900;
  font-size: 1.6rem;
  letter-spacing: 2px;
}

.game-header h1::before {
  content: "X O";
  color: var(--xo-red);
  font-weight: 900;
  font-size: 1.6rem;
  letter-spacing: 2px;
}

/* הסרת האימוג'י מה-header */
.lobby-header h1, .game-header h1 {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ========== BUTTONS ========== */
button {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.625rem 1.25rem;
  border-radius: 2rem;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: inherit;
}

button:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  background: var(--gray);
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-secondary {
  background: var(--secondary);
}

.btn-secondary:hover:not(:disabled) {
  background: #059669;
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}

.btn-outline:hover:not(:disabled) {
  background: var(--primary);
  color: white;
}

.btn-danger {
  background: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

/* ========== INPUTS ========== */
input, textarea {
  padding: 0.625rem 1rem;
  border: 2px solid var(--light-gray);
  border-radius: 2rem;
  font-size: 0.875rem;
  transition: all 0.2s ease;
  font-family: inherit;
  background: var(--dark);
  color: var(--white);
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.2);
}

input::placeholder, textarea::placeholder {
  color: var(--gray);
}

.lobby-controls {
  background: var(--darker);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  margin-bottom: 1.5rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: center;
  box-shadow: var(--shadow);
  border: 1px solid var(--light-gray);
}

.lobby-controls input {
  flex: 1;
  min-width: 200px;
}

/* ========== TABLES SECTION ========== */
.tables-section {
  margin-bottom: 2rem;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding: 0 0.5rem;
}

.section-title-row h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.section-count {
  background: var(--primary);
  padding: 0.25rem 0.75rem;
  border-radius: 2rem;
  font-weight: 700;
  color: white;
  font-size: 0.875rem;
}

.lobby-tables {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
}

.lobby-table {
  background: var(--darker);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  transition: all 0.3s ease;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  border: 1px solid var(--light-gray);
}

.lobby-table::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--primary);
}

.lobby-table:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.lobby-table.full-table {
  opacity: 0.7;
}

.lobby-table.full-table::before {
  background: var(--gray);
}

.table-name {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--white);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.table-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: var(--gray);
}

.status-badge {
  padding: 0.25rem 0.75rem;
  border-radius: 2rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-waiting {
  background: #064e3b;
  color: #34d399;
}

.status-playing {
  background: #7f1d1d;
  color: #fca5a5;
}

.table-players {
  background: var(--dark);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin: 1rem 0;
  font-size: 0.875rem;
  color: var(--white);
}

.table-players span {
  color: var(--xo-red);
  font-weight: bold;
}

.table-room-code {
  font-family: monospace;
  font-size: 0.875rem;
  background: var(--dark);
  padding: 0.25rem 0.5rem;
  border-radius: 0.5rem;
}

.join-table-btn {
  width: 100%;
  background: var(--primary);
  margin-top: 0.5rem;
}

.join-table-btn:disabled {
  background: var(--gray);
}

/* ========== GAME SECTION ========== */
.game-container {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
  justify-content: center;
}

.game-area {
  flex: 1;
  min-width: 320px;
  max-width: 450px;
}

.chat-area {
  flex: 1;
  min-width: 300px;
  max-width: 400px;
  background: var(--darker);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  height: 550px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  border: 1px solid var(--light-gray);
}

.chat-area h3 {
  padding: 1rem 1.25rem;
  background: var(--dark);
  border-bottom: 1px solid var(--light-gray);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* החלפת האימוג'י בצ'אט */
.chat-area h3::before {
  content: "💬";
  margin-right: 8px;
}

.panel {
  background: var(--darker);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  border: 1px solid var(--light-gray);
}

/* מרווח בין כפתור איפוס לשורת מצב משחק */
.panel .row {
  padding: 1rem 1rem 0.5rem 1rem;
}

.panel #status {
  margin-top: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--dark);
  border-radius: var(--radius);
  margin: 0.5rem 1rem 1rem 1rem;
  color: var(--white);
  font-size: 0.875rem;
  border-left: 3px solid var(--primary);
}

.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(70px, 85px));
  gap: 0.6rem;
  background: var(--darker);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow-lg);
  justify-content: center;
  margin: 0 auto;
  width: fit-content;
  border: 1px solid var(--light-gray);
}

.cell {
  width: 100%;
  aspect-ratio: 1;
  min-width: 65px;
  max-width: 85px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  font-weight: 800;
  background: var(--dark);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s ease;
  border: 2px solid var(--light-gray);
}

.cell:hover:not(.disabled) {
  background: var(--primary);
  color: white !important;
  transform: scale(1.05);
  border-color: var(--primary);
}

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

/* X ו-O בצבע אדום */
.cell {
  color: var(--xo-red);
}

.cell[data-value="X"], 
.cell[data-value="O"],
.cell:has(> :contains("X")),
.cell:has(> :contains("O")) {
  color: var(--xo-red);
}

/* ========== CHAT ========== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-message {
  padding: 0.5rem 0.75rem;
  border-radius: 1rem;
  animation: slideIn 0.2s ease;
  max-width: 90%;
}

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

.chat-message.user {
  background: var(--primary);
  color: white;
  align-self: flex-end;
}

.chat-message.system {
  background: var(--dark);
  color: var(--gray);
  text-align: center;
  font-style: italic;
  font-size: 0.75rem;
  align-self: center;
}

.chat-message .sender {
  font-size: 0.7rem;
  opacity: 0.8;
  margin-bottom: 0.25rem;
  display: block;
}

.chat-message.user .sender {
  color: rgba(255, 255, 255, 0.8);
}

.chat-message .text {
  word-break: break-word;
}

.chat-input-area {
  padding: 1rem;
  border-top: 1px solid var(--light-gray);
  display: flex;
  gap: 0.5rem;
}

.chat-input-area input {
  flex: 1;
}

/* ========== STATUS PANEL ========== */
#status {
  background: var(--dark);
  color: var(--white);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-weight: 500;
  text-align: center;
  line-height: 1.5;
  white-space: pre-line;
}

/* ========== MODAL ========== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

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

.modal-content {
  background: var(--darker);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 90%;
  max-width: 400px;
  animation: slideUp 0.3s ease;
  border: 1px solid var(--light-gray);
}

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

.modal-content h3 {
  margin-bottom: 1rem;
}

.modal-content input {
  width: 100%;
  margin: 1rem 0;
}

.modal-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.empty-lobby {
  background: var(--darker);
  border-radius: var(--radius-lg);
  padding: 3rem;
  text-align: center;
  color: var(--gray);
  font-size: 1rem;
  border: 1px solid var(--light-gray);
}

.join-by-code {
  background: var(--darker);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-top: 1rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  border: 1px solid var(--light-gray);
}

.join-by-code hr {
  display: none;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  body {
    padding: 0.75rem;
  }
  
  .lobby-header, .game-header {
    flex-direction: column;
    text-align: center;
  }
  
  .board {
    gap: 0.5rem;
    padding: 0.75rem;
  }
  
  .cell {
    min-width: 55px;
    font-size: 2rem;
  }
  
  .game-container {
    flex-direction: column;
    align-items: center;
  }
  
  .game-area {
    max-width: 100%;
  }
  
  .chat-area {
    max-width: 100%;
    height: 400px;
  }
  
  .lobby-tables {
    grid-template-columns: 1fr;
  }
}

/* ========== LOADING ========== */
.loading {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========== RECONNECT NOTIFICATION ========== */
.reconnect-notification {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--primary);
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: 2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: var(--shadow-lg);
  animation: slideInRight 0.3s ease;
  z-index: 100;
}

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

/* אפקט הובר לתאים */
.cell:hover:not(.disabled) {
  background: var(--primary);
  color: white !important;
}
.cell[data-value="X"],
.cell.x,
.cell.X {
  color: #10b981 !important; /* ירוק */
}

.cell[data-value="O"],
.cell.o,
.cell.O {
  color: #2563eb !important; /* כחול */
}
.lobby-header {
  justify-content: center;
  position: relative;
}

.lobby-header h1 {
  flex: 0 1 auto;
  margin: 0;
  text-align: center;
}

#createTableBtn {
  position: absolute;
  left: 1.5rem;
}

#backToGameBtn {
  position: absolute;
  right: 1.5rem;
}