/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #252525;
  --bg-hover: #333;
  --border-color: #444;
  --text-primary: #fff;
  --text-secondary: #e5e5e5;
  --text-muted: #999;
  --color-red: #ef4444;
  --color-green: #22c55e;
  --color-blue: #3b82f6;
  --color-yellow: #eab308;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 3rem;
}

header h1 {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--color-red), var(--color-green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.1rem;
}

/* Landing page */
.landing {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  max-width: 900px;
  margin: 0 auto;
}

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 2rem;
}

.card h2, .card h3 {
  margin-bottom: 1.5rem;
  color: var(--text-primary);
}

.card.info {
  background: var(--bg-tertiary);
}

.card ul {
  list-style-position: inside;
  color: var(--text-secondary);
}

.card li {
  margin-bottom: 0.5rem;
}

/* Forms */
.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-group select,
.form-group input {
  width: 100%;
  padding: 0.75rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 1rem;
  transition: border-color 0.2s;
}

.form-group select:focus,
.form-group input:focus {
  outline: none;
  border-color: var(--color-blue);
}

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--color-blue);
  color: white;
}

.btn-primary:hover {
  background: #2563eb;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

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

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

/* 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: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 2rem;
  max-width: 500px;
  width: 90%;
}

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

.share-link {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0 1.5rem;
}

.share-link input {
  flex: 1;
  padding: 0.75rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
}

/* Game page */
.game-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.game-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 2rem;
  margin: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.turn-indicator {
  font-size: 1.2rem;
  font-weight: 600;
}

.score-info {
  display: flex;
  gap: 2rem;
}

.player-score {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

.color-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: inline-block;
}

.color-dot.red {
  background: var(--color-red);
  box-shadow: 0 0 8px var(--color-red);
}

.color-dot.green {
  background: var(--color-green);
  box-shadow: 0 0 8px var(--color-green);
}

/* Game main layout */
.game-main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.board-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  position: relative;
  background: var(--bg-primary);
  overflow: hidden;
}

#gameBoard {
  border: 2px solid var(--border-color);
  border-radius: 4px;
  cursor: crosshair;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
}

#previewCanvas {
  position: absolute;
  pointer-events: none;
}

.placement-hint {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(59, 130, 246, 0.9);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  animation: pulse 2s infinite;
}

.placement-hint.hidden {
  display: none;
}

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

/* Tile inventory */
.tile-inventory {
  width: 320px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  padding: 0 1rem 1rem 1rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.tile-inventory h3 {
  margin: 0.5rem 0 0.5rem 0;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.controls {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

.control-btn {
  flex: 1;
  padding: 0.5rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.control-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--color-blue);
}

.control-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tile-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  align-content: start;
  padding: 0.25rem;
  margin: -0.25rem;
}

.tile-item {
  aspect-ratio: 1;
  background: var(--bg-tertiary);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.tile-item:hover {
  border-color: var(--color-blue);
  transform: scale(1.03);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.tile-item.selected {
  border-color: var(--color-blue);
  background: rgba(59, 130, 246, 0.1);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.5);
  transform: scale(1.02);
}

.tile-item canvas {
  max-width: 100%;
  max-height: 100%;
}

.tile-label {
  position: absolute;
  bottom: 0.25rem;
  right: 0.5rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Toast notifications */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-tertiary);
  border: 1px solid var(--color-red);
  padding: 1rem 1.5rem;
  border-radius: 8px;
  color: var(--color-red);
  font-weight: 500;
  z-index: 1000;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.toast.hidden {
  display: none;
}

/* Responsive design */
@media (max-width: 1024px) {
  .game-main {
    flex-direction: column;
  }

  .tile-inventory {
    width: 100%;
    flex: 1;
    min-height: 150px;
    border-left: none;
    border-top: 1px solid var(--border-color);
    overflow-y: hidden;
  }

  .tile-list {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    overflow-y: auto;
  }

  .board-container {
    padding: 0.5rem;
    flex: 0 0 auto;
    align-items: flex-start;
    justify-content: center;
  }

  #gameBoard {
    width: 100%;
    height: auto;
    object-fit: contain;
  }
}

@media (max-width: 768px) {
  .landing {
    grid-template-columns: 1fr;
  }

  .container {
    padding: 1rem;
  }

  header h1 {
    font-size: 2rem;
  }

  .game-header {
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.75rem;
  }

  .score-info {
    gap: 1rem;
    font-size: 0.85rem;
  }

  .controls {
    flex-wrap: wrap;
  }

  .control-btn {
    font-size: 0.85rem;
    padding: 0.6rem;
    min-height: 44px;
  }

  .board-container {
    padding: 0.5rem;
  }

  .tile-inventory {
    flex: 1;
    min-height: 120px;
    padding: 0.75rem;
    overflow-y: hidden;
  }

  .tile-inventory h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
  }

  .tile-list {
    grid-template-columns: repeat(auto-fill, minmax(65px, 1fr));
    gap: 0.4rem;
    overflow-y: auto;
  }
}

/* Final scores in game over modal */
#finalScores {
  margin: 1.5rem 0;
  padding: 1rem;
  background: var(--bg-tertiary);
  border-radius: 8px;
}

#finalScores .score-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-color);
}

#finalScores .score-row:last-child {
  border-bottom: none;
}
