* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 10px;
  color: #333;
  overflow-x: hidden;
  overflow-y: auto;
}

.container {
  max-width: 100%;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  text-align: center;
  margin-bottom: 10px;
}

h1 {
  color: white;
  font-size: 1.8em;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
  margin: 5px 0;
}

.controls {
  background: white;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  margin-bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.difficulty-controls {
  display: flex;
  gap: 15px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #7688f0 0%, #8659b0 100%);
}

.btn-secondary {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white;
}

.btn-secondary:hover:not(:disabled) {
  background: linear-gradient(135deg, #f5a3ff 0%, #ff677c 100%);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

select {
  padding: 10px 15px;
  border: 2px solid #667eea;
  border-radius: 8px;
  font-size: 16px;
  background: white;
  cursor: pointer;
  transition: all 0.3s ease;
}

select:focus {
  outline: none;
  border-color: #764ba2;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.game-area {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
  flex: 1;
  overflow: visible;
  min-height: 0;
  max-height: calc(100vh - 180px);
}

/* When preview is hidden (competition mode), use single column */
.game-area:has(.preview-container.hidden) {
  grid-template-columns: 1fr;
}

@media (max-width: 1024px) {
  .game-area {
    grid-template-columns: 1fr;
  }
}

.preview-container,
.puzzle-container {
  background: white;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: calc(100vh - 180px);
  overflow: visible;
  align-items: center;
  justify-content: flex-start;
}

h3 {
  margin-bottom: 8px;
  color: #667eea;
  font-size: 1.1em;
}

.preview-image {
  flex: 1;
  background: #f5f5f5;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 0;
  max-height: calc(100vh - 220px);
}

.preview-image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.preview-image p {
  color: #999;
  text-align: center;
  padding: 20px;
}

.puzzle-board {
  display: grid;
  gap: 2px;
  background: #ddd;
  border-radius: 10px;
  overflow: visible;
  padding: 2px;
  margin: 0 auto;
}

.puzzle-board p {
  grid-column: 1 / -1;
  color: #999;
  text-align: center;
  padding: 40px;
}

.puzzle-piece {
  background-color: white;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  min-height: 50px;
}

.puzzle-piece.empty-slot {
  background: white;
  cursor: default;
  border: 2px solid #ddd;
}

.puzzle-piece.completed {
  cursor: default;
  animation: fillSlot 0.5s ease;
}

@keyframes fillSlot {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.puzzle-piece:not(.empty-slot):hover {
  border-color: #667eea;
  transform: scale(1.05);
  z-index: 10;
}

.puzzle-piece.dragging {
  opacity: 0.4;
  transform: scale(0.95);
}

.puzzle-piece.drag-over {
  border-color: #667eea;
  background: #e6e9ff !important;
  transform: scale(1.05);
}

.success-message {
  margin-top: 20px;
  padding: 20px;
  background: linear-gradient(135deg, #84fab0 0%, #8fd3f4 100%);
  border-radius: 10px;
  text-align: center;
  font-size: 1.5em;
  font-weight: bold;
  color: #2c5282;
  animation: celebrate 0.5s ease;
}

@keyframes celebrate {
  0% {
    transform: scale(0.8);
    opacity: 0;
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.success-message.hidden {
  display: none;
}

/* Mode Selection */
.mode-selection {
  background: white;
  padding: 40px;
  border-radius: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  text-align: center;
  max-width: 500px;
  margin: 50px auto;
}

.mode-selection h2 {
  color: #667eea;
  margin-bottom: 30px;
  font-size: 2em;
}

.btn-large {
  padding: 20px 40px;
  font-size: 18px;
  margin: 10px;
  min-width: 250px;
}

/* Multiplayer Setup */
.multiplayer-setup {
  background: white;
  padding: 40px;
  border-radius: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  text-align: center;
  max-width: 500px;
  margin: 50px auto;
}

.multiplayer-setup h2 {
  color: #667eea;
  margin-bottom: 30px;
  font-size: 2em;
}

.setup-options {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

/* Panel Styles (Create Room, Join Room) */
.panel {
  background: white;
  padding: 30px;
  border-radius: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  max-width: 600px;
  margin: 30px auto;
}

.panel h2 {
  color: #667eea;
  margin-bottom: 25px;
  font-size: 1.8em;
  text-align: center;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: #555;
  font-weight: 600;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group select {
  width: 100%;
  padding: 12px 15px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  transition: all 0.3s ease;
}

.form-group input[type="text"]:focus,
.form-group input[type="email"]:focus,
.form-group select:focus {
  border-color: #667eea;
  outline: none;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-group input[type="checkbox"] {
  margin-right: 8px;
}

.form-actions {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-top: 25px;
}

.room-image-preview {
  padding: 15px;
  background: #e6f7ff;
  border: 2px solid #91d5ff;
  border-radius: 8px;
  text-align: center;
  color: #0050b3;
  font-weight: 600;
}

.btn-success {
  background: linear-gradient(135deg, #84fab0 0%, #8fd3f4 100%);
  color: #2c5282;
  font-weight: 700;
}

.btn-success:hover:not(:disabled) {
  background: linear-gradient(135deg, #94ffba 0%, #9fe3ff 100%);
}

.btn-warning {
  background: linear-gradient(135deg, #ffd89b 0%, #19547b 100%);
  color: white;
}

/* Waiting Room / Lobby */
.waiting-room {
  background: white;
  padding: 30px;
  border-radius: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  max-width: 700px;
  margin: 30px auto;
}

.waiting-room h2 {
  color: #667eea;
  margin-bottom: 20px;
  text-align: center;
  font-size: 1.8em;
}

.room-info {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 10px;
  margin-bottom: 25px;
  text-align: center;
}

.room-code {
  display: inline-block;
  font-size: 2.5em;
  font-weight: 900;
  color: #667eea;
  letter-spacing: 8px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  padding: 10px 20px;
  border: 3px dashed #667eea;
  border-radius: 10px;
  margin: 10px 0;
}

.countdown {
  background: #fff3cd;
  border: 2px solid #ffc107;
  padding: 15px;
  border-radius: 10px;
  margin-top: 15px;
  font-size: 1.2em;
  font-weight: 700;
  color: #856404;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.players-list {
  margin: 25px 0;
}

.players-list h3 {
  color: #667eea;
  margin-bottom: 15px;
  font-size: 1.3em;
}

.players-list ul {
  list-style: none;
  padding: 0;
}

.player-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  background: #f8f9fa;
  margin-bottom: 8px;
  border-radius: 8px;
  border-left: 4px solid #667eea;
}

.player-item span:first-child {
  font-weight: 600;
  color: #333;
}

.status-ready {
  color: #28a745;
  font-weight: 700;
}

.status-not-ready {
  color: #6c757d;
  font-weight: 600;
}

.lobby-actions {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-top: 25px;
  flex-wrap: wrap;
}

/* Multiplayer Stats */
.multiplayer-stats {
  background: white;
  padding: 15px;
  border-radius: 10px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.stat-item strong {
  color: #667eea;
  font-size: 0.9em;
  margin-bottom: 5px;
}

.stat-item span {
  font-size: 1.5em;
  font-weight: 700;
  color: #333;
}

/* Utility */
.hidden {
  display: none !important;
}

/* Camera Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: white;
  padding: 30px;
  border-radius: 15px;
  max-width: 700px;
  width: 90%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
  margin-bottom: 20px;
  color: #667eea;
}

video {
  width: 100%;
  border-radius: 10px;
  margin-bottom: 20px;
  background: #000;
}

.modal-buttons {
  display: flex;
  gap: 15px;
  justify-content: center;
}

/* Responsive */
@media (max-width: 768px) {
  body {
    padding: 5px;
    overflow-y: auto;
  }

  h1 {
    font-size: 1.5em;
    margin: 5px 0;
  }

  header {
    margin-bottom: 5px;
  }

  .controls {
    flex-direction: column;
    padding: 8px;
    margin-bottom: 5px;
  }

  .difficulty-controls {
    width: 100%;
    justify-content: center;
  }

  .btn {
    width: 100%;
    padding: 10px;
    font-size: 14px;
  }

  .game-area {
    gap: 5px;
    min-height: auto;
    overflow: visible;
  }

  .preview-container,
  .puzzle-container {
    padding: 8px;
    min-height: auto;
  }

  .puzzle-container {
    min-height: 300px;
  }

  .puzzle-board {
    width: 100%;
    max-width: 100%;
    aspect-ratio: 1;
    min-height: 250px;
    margin: 0 auto;
  }

  .puzzle-piece {
    min-height: 30px;
  }

  .preview-image {
    max-height: 200px;
  }
}
