:root {
  --bg-color: #7F1D1D;
  --bg-panel: rgba(0, 0, 0, 0.2);
  --primary: #EF4444;
  --secondary: #F87171;
  --accent: #FECACA;
  --text-color: #FECACA; /* Accent as text for contrast */
  --text-muted: rgba(254, 202, 202, 0.7);
  --border-color: #EF4444;

  --x-color: #FECACA;
  --o-color: #F87171;
  --grid-color: rgba(239, 68, 68, 0.5);
  --active-board-highlight: rgba(254, 202, 202, 0.1);
  --win-highlight: rgba(254, 202, 202, 0.3);
}

body {
  margin: 0;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.container {
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: 1fr 300px;
  width: 95vw;
  height: 95vh;
  max-width: 1200px;
  gap: 20px;
}

header {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: var(--bg-panel);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.controls {
  display: flex;
  gap: 20px;
  align-items: center;
}

.btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  transition: transform 0.1s, background 0.2s;
}

.btn:hover {
  background: var(--secondary);
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(0);
}

.mode-selector {
  display: flex;
  gap: 10px;
  background: rgba(0,0,0,0.3);
  padding: 5px;
  border-radius: 6px;
}

.mode-selector label {
  cursor: pointer;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 0.9rem;
}

.mode-selector input {
  display: none;
}

.mode-selector input:checked + span {
  background: var(--accent);
  color: var(--bg-color);
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 4px;
}

main {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  height: 100%;
  overflow: hidden;
}

.game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-panel);
  border-radius: 12px;
  padding: 20px;
  position: relative;
}

.scoreboard {
  display: flex;
  justify-content: space-around;
  width: 100%;
  margin-bottom: 20px;
  font-size: 1.2rem;
}

.score-card {
  padding: 10px 20px;
  background: rgba(0,0,0,0.3);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 100px;
}

.score-card.active {
  border: 2px solid var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.score {
  font-size: 2rem;
  font-weight: bold;
}

.canvas-container {
  width: 100%;
  height: 100%;
  max-width: 600px;
  max-height: 600px;
  display: flex;
  justify-content: center;
  align-items: center;
}

canvas {
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.1);
  border-radius: 4px;
  cursor: crosshair;
}

.history-panel {
  background: var(--bg-panel);
  border-radius: 12px;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.history-panel h3 {
  margin-top: 0;
  border-bottom: 1px solid var(--grid-color);
  padding-bottom: 10px;
}

#move-history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
  overflow-y: auto;
}

#move-history-list li {
  padding: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

#move-history-list li:last-child {
  border-bottom: none;
  font-weight: bold;
  background: rgba(255,255,255,0.05);
}

.status-message {
  position: absolute;
  bottom: 20px;
  font-size: 1.2rem;
  color: var(--accent);
  font-weight: bold;
  background: rgba(0,0,0,0.5);
  padding: 10px 20px;
  border-radius: 20px;
  opacity: 0;
  transition: opacity 0.3s;
}

.status-message.visible {
  opacity: 1;
}

@media (max-width: 900px) {
  .container {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    height: 100vh;
    padding: 10px;
    width: 100vw;
  }

  main {
    grid-template-columns: 1fr;
  }

  .history-panel {
    display: none; /* Hide history on mobile to save space */
  }
}
