/* =================================
   Global and Page Layout Styles
   ================================= */
body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background-color: #f4f4f4;
  color: #333;
  line-height: 1.4;
}
.hidden {
  display: none !important;
}

/* =====/* 3D Effect for Carousel Shape Pieces */
.carousel-shape-cell[style*="background-color"]:not(
    [style*="transparent"]
  )::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.6) 0%,
    rgba(255, 255, 255, 0.2) 25%,
    rgba(0, 0, 0, 0.1) 75%,
    rgba(0, 0, 0, 0.3) 100%
  );
  border-radius: inherit;
}

/* Shape Preview Styles for Carousel */
.shapes-carousel-wrapper {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
}

.shapes-carousel-scroll {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  padding: 1rem 0;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  /* Hide scrollbar */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
}

.shapes-carousel-scroll::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.shape-preview {
  min-width: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  animation: shapeFloat 3s ease-in-out infinite;
  animation-delay: calc(var(--shape-index, 0) * 0.1s);
}

.shape-preview:hover {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

/* Carousel shape squares */
#shapes-carousel .shape-grid {
  display: grid;
  gap: 1px;
}

#shapes-carousel .shape-grid > div {
  border-radius: 1px;
}

/* Ensure shape names wrap properly */
#shapes-carousel .text-center {
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

/* Shape Labels Caption */
.shape-labels-caption {
  text-align: center;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e5e7eb;
}

.shape-label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin: 0 0.5rem 0.25rem 0;
  font-size: 0.75rem;
  font-weight: 500;
  color: #6b7280;
}

.shape-label-color {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* =================================
   Fluid Connected Design - Simple & Clean
   ================================= */

.fluid-container {
  position: relative;
  width: 100%;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  border-radius: 20px;
  border: 2px solid #475569;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.fluid-section {
  position: relative;
  background: transparent;
  border: none;
  box-shadow: none;
}

/* Game Board Section */
.game-board-fluid {
  padding: 2rem 1.5rem 1rem 1.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

/* Simple connecting waist */
.game-board-fluid::after {
  content: "";
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 70%;
  height: 20px;
  background: inherit;
  border-radius: 0 0 50px 50px;
  z-index: 1;
}

/* Control Panel Section */
.control-panel-fluid {
  padding: 1rem 1.5rem 2rem 1.5rem;
  position: relative;
  margin-top: -10px;
}

/* Simple connecting neck */
.control-panel-fluid::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 70%;
  height: 20px;
  background: inherit;
  border-radius: 50px 50px 0 0;
  z-index: 1;
}

/* Enhanced Game Board */
.fluid-section .game-board {
  border-radius: 12px;
  background: #0f172a;
  border: 2px solid #334155;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
}

.fluid-section .game-board .cell {
  background: #1e293b;
  border: 1px solid #334155;
}

.fluid-section .game-board .cell.filled {
  background: #3b82f6;
  border-color: #60a5fa;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.3);
}

/* =================================
   Main Layout Containers
   ================================= */

/* Used by player.html */
.game-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 40px;
  margin-top: 20px;
  position: relative;
}
/* Used by ai_trainer.html */
.trainer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 1400px;
  padding: 20px;
  box-sizing: border-box;
}

/* =================================
   AI Trainer Page Specific Layout
   ================================= */
.top-section {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 40px;
  width: 100%;
  margin-bottom: 40px;
}
.data-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 450px;
  flex-grow: 1;
}
#agents-container {
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
  background-color: #e9e9e9;
  border-radius: 8px;
  margin-bottom: 20px;
}
#agents-container h3 {
  text-align: center;
  margin-top: 0;
}
#agents-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

/* =================================
   Player Page Right Panel
   ================================= */
.right-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 450px;
}
#player-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
}
.score-container,
.hint-container,
#model-loader-container,
#model-output-container,
#highscore-container,
.chart-container,
.mode-switch {
  width: 100%;
  box-sizing: border-box;
}

/* =================================
   Shared Components (Board, Cells, Shapes, etc.)
   ================================= */
.game-board {
  display: grid;
  border: 3px solid #333;
  background-color: #fff;
  width: fit-content;
  height: fit-content;
}

.grid-8x8 {
  grid-template-columns: repeat(8, 50px);
  grid-template-rows: repeat(8, 50px);
}

.cell {
  width: 50px;
  height: 50px;
  border: 1px solid #e0e0e0;
  box-sizing: border-box;
  background-color: #fff;
  position: relative;
}

.cell.occupied {
  border: 1px solid rgba(0, 0, 0, 0.2);
}

/* 3D Effect for Main Board Pieces */
.cell.occupied::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.6) 0%,
    rgba(255, 255, 255, 0.2) 25%,
    rgba(0, 0, 0, 0.1) 75%,
    rgba(0, 0, 0, 0.3) 100%
  );
  pointer-events: none;
}

.cell.preview {
  opacity: 0.6;
}

#shapes-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  min-height: 250px;
}

.shape {
  display: grid;
  cursor: grab;
  border: 2px solid #333;
  width: fit-content;
  transition: all 0.2s ease-in-out;
  background-color: #fff;
  border-radius: 2px;
}

.shape.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.shape-cell {
  width: 30px;
  height: 30px;
  box-sizing: border-box;
  border: none;
  position: relative;
}

.shape-cell[style*="background-color"]:not([style*="transparent"]) {
  border: 1px solid rgba(0, 0, 0, 0.2);
}

/* 3D Effect for Shape Pieces */
.shape-cell[style*="background-color"]:not([style*="transparent"])::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.6) 0%,
    rgba(255, 255, 255, 0.2) 25%,
    rgba(0, 0, 0, 0.1) 75%,
    rgba(0, 0, 0, 0.3) 100%
  );
  pointer-events: none;
}

/* =================================
   Modals, Buttons, and AI Stats
   ================================= */
#game-over-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.75);
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 48px;
  font-weight: bold;
  text-align: center;
  z-index: 100;
}
#game-over-overlay.hidden {
  display: none;
}
#final-score {
  font-size: 32px;
  margin-top: 20px;
}
#game-over-overlay #reset-button {
  margin-top: 30px;
  padding: 15px 30px;
  font-size: 20px;
  font-weight: bold;
  color: white;
  background-color: #e74c3c;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.2s ease;
}
#game-over-overlay #reset-button:hover {
  background-color: #c0392b;
  transform: scale(1.05);
}

#ai-stats {
  display: flex;
  gap: 20px;
  font-size: 1.2em;
  background-color: #eee;
  padding: 10px;
  border-radius: 5px;
  margin-bottom: 20px;
}
.mode-switch {
  display: flex;
  width: 100%;
}
.mode-switch button,
.mode-switch a {
  width: 50%;
  text-decoration: none;
}
.mode-switch a button {
  width: 100%;
}
.mode-switch button {
  padding: 10px;
  border: 1px solid #ccc;
  background-color: #f0f0f0;
  cursor: pointer;
}
.mode-switch button.active {
  background-color: #3498db;
  color: white;
  border-color: #2980b9;
}

/* =================================
   Component-Specific Styles
   ================================= */
/* =================================
   Compact High Score List
   ================================= */
#highscore-list {
  list-style-type: none;
  padding: 0;
  margin: 0;
}
#highscore-list li {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 0.375rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
  font-weight: 500;
}
#highscore-list li:first-child {
  background: linear-gradient(135deg, #fef3c7 0%, #fbbf24 100%);
  border-color: #f59e0b;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(245, 158, 11, 0.2);
}
#highscore-list li:nth-child(2) {
  background: linear-gradient(135deg, #f1f5f9 0%, #cbd5e1 100%);
  border-color: #94a3b8;
  font-weight: 600;
}
#highscore-list li:nth-child(3) {
  background: linear-gradient(135deg, #fed7aa 0%, #fb923c 100%);
  border-color: #ea580c;
  font-weight: 600;
}

/* =================================
   Shapes Carousel
   ================================= */
#shapes-carousel {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.carousel-shape {
  display: grid;
  border: 2px solid #333;
  background-color: #fff;
  border-radius: 4px;
  padding: 8px;
  flex-shrink: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: float 3s ease-in-out infinite;
}

.carousel-shape:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.carousel-shape-cell {
  width: 20px;
  height: 20px;
  border: none;
  box-sizing: border-box;
  position: relative;
}

.carousel-shape-cell[style*="background-color"]:not([style*="transparent"]) {
  border: 1px solid rgba(0, 0, 0, 0.2);
}

/* 3D Effect for Carousel Shape Pieces */
.carousel-shape-cell[style*="background-color"]:not(
    [style*="transparent"]
  )::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.6) 0%,
    rgba(255, 255, 255, 0.2) 25%,
    rgba(0, 0, 0, 0.1) 75%,
    rgba(0, 0, 0, 0.3) 100%
  );
  pointer-events: none;
}

/* Floating animation for carousel shapes */
@keyframes float {
  0%,
  100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-3px);
  }
}

.carousel-shape:nth-child(even) {
  animation-delay: 1.5s;
}

.carousel-shape:nth-child(3n) {
  animation-delay: 0.5s;
}

/* Custom scrollbar styling */
.scrollbar-thin {
  scrollbar-width: thin;
}

.scrollbar-thumb-gray-400::-webkit-scrollbar-thumb {
  background-color: #9ca3af;
  border-radius: 6px;
}

.scrollbar-track-gray-200::-webkit-scrollbar-track {
  background-color: #e5e7eb;
}

.scrollbar-thin::-webkit-scrollbar {
  height: 8px;
}

/* =================================
   Clean Minimal Agent Cards
   ================================= */
.agent-card {
  background-color: white;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  padding: 0.5rem; /* Reduced padding */
  width: 140px;
  height: 180px; /* Reduced height */
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px; /* Reduced gap */
  font-size: 0.8rem;
  transition: all 0.15s ease;
}
.agent-card.active {
  background-color: #f0fdf4;
  border-color: #22c55e;
  border-width: 2px;
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.2);
}
.agent-card.done {
  background-color: #fef2f2;
  border-color: #ef4444;
  opacity: 0.8;
}

/* Agent Header - Top row with ID and Copy button */
.agent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  margin-bottom: 6px;
}
.agent-id {
  font-weight: bold;
  color: #374151;
  font-size: 0.8rem;
}

/* Agent Info Row - 2 columns for shapes and score */
.agent-info-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.agent-score {
  font-weight: bold;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid;
  font-size: 0.8rem;
  white-space: nowrap;
}

/* Agent Mini Board - Match Live Preview Styling */
.agent-mini-board {
  display: grid;
  border: 2px solid #333;
  background-color: #fff;
  width: fit-content;
  height: fit-content;
  margin: 4px auto;
  border-radius: 2px;
  grid-template-columns: repeat(8, 10px);
  grid-template-rows: repeat(8, 10px);
  flex-shrink: 0; /* Prevent shrinking */
}
.agent-mini-board-cell {
  width: 10px;
  height: 10px;
  background-color: #fff;
  border: 1px solid #e0e0e0;
  box-sizing: border-box;
}
.agent-mini-board-cell.occupied {
  border: 1px solid rgba(0, 0, 0, 0.2);
  position: relative;
}

/* 3D Effect for Pieces */
.agent-mini-board-cell.occupied::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.6) 0%,
    rgba(255, 255, 255, 0.2) 25%,
    rgba(0, 0, 0, 0.1) 75%,
    rgba(0, 0, 0, 0.3) 100%
  );
  border-radius: 1px;
}

/* Shape Batch Container - Fixed height */
.agent-batch-container {
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 0.25rem;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 28px; /* Reduced height */
  padding: 2px;
  gap: 2px;
  flex-wrap: nowrap;
  overflow: hidden; /* Hide overflow if shapes are too tall */
  flex-shrink: 0; /* Prevent shrinking */
}

/* Agent Mini Shapes */
.agent-mini-shape {
  display: grid;
  gap: 0;
  max-height: 20px; /* Reduced max height */
  overflow: hidden;
}
.agent-mini-shape-cell {
  width: 3px; /* Even smaller to fit more shapes */
  height: 3px;
  border: none;
  box-sizing: border-box;
  position: relative;
}
.agent-mini-shape-cell[style*="background-color"]:not([style*="transparent"]) {
  border: 1px solid rgba(0, 0, 0, 0.2);
}

/* 3D Effect for Mini Shape Pieces */
.agent-mini-shape-cell[style*="background-color"]:not(
    [style*="transparent"]
  )::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.7) 0%,
    rgba(255, 255, 255, 0.3) 25%,
    rgba(0, 0, 0, 0.1) 75%,
    rgba(0, 0, 0, 0.4) 100%
  );
  border-radius: 1px;
  pointer-events: none;
}

.agent-copy-btn {
  background-color: #6366f1;
  color: white;
  font-size: 7px;
  padding: 0.125rem 0.25rem;
  border-radius: 0.25rem;
  cursor: pointer;
  border: none;
  transition: background-color 0.15s ease;
  flex-shrink: 0;
}
.agent-copy-btn:hover {
  background-color: #4f46e5;
}

/* Model I/O and Hint Panel */
#model-output-container,
#model-loader-container {
  background-color: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 5px;
  padding: 15px;
}
#model-output-container h4,
#model-loader-container h4 {
  margin: 0 0 10px 0;
  text-align: center;
}
#model-output-container p {
  font-size: 0.8em;
  text-align: center;
  margin: -5px 0 5px 0;
}
#model-output-container textarea,
.model-input-group textarea {
  width: 100%;
  box-sizing: border-box;
  font-family: monospace;
  font-size: 12px;
}
.model-input-group {
  margin-bottom: 10px;
}
.model-input-group label {
  display: block;
  margin-bottom: 3px;
  font-weight: bold;
}
#load-models-btn {
  width: 100%;
  padding: 8px;
  background-color: #28a745;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
#load-models-btn:hover {
  background-color: #218838;
}
#model-selection-container {
  margin-top: 10px;
  display: flex;
  justify-content: center;
  gap: 20px;
}
#hint-button {
  width: 100%;
}
#hint-button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
  color: #666;
}
.shape.hint-shape {
  border: 3px solid #007bff !important;
  box-shadow: 0 0 15px rgba(0, 123, 255, 0.7);
  transform: scale(1.05);
}
.cell.hint-placement {
  background-color: rgba(0, 123, 255, 0.25) !important;
  border: 2px dashed #0056b3 !important;
}

/* =================================
   NEW Comparison Page Layout
   ================================= */
.controls-panel {
  width: 95%;
  max-width: 1000px;
  padding: 20px;
  background-color: #e9ecef;
  border-radius: 8px;
  margin-bottom: 30px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-end;
  position: relative;
}
.controls-panel .model-input-group {
  flex-grow: 1;
  min-width: 300px;
}
.controls-panel button {
  padding: 10px 20px;
  font-size: 16px;
  height: fit-content;
}
#shared-shape-panel {
  text-align: center;
  min-width: 150px;
}
#shared-shape-panel h4 {
  margin: 0 0 5px 0;
}
#shared-shape-container {
  display: flex;
  justify-content: center;
}

.battle-ground {
  display: flex;
  justify-content: center;
  gap: 40px;
  flex-wrap: wrap;
  width: 100%;
}

.model-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

.board-wrapper {
  position: relative; /* For the overlay */
}
.status-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(120, 20, 20, 0.75);
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 3em;
  font-weight: bold;
  border-radius: 5px;
}
.score-container.winning {
  background-color: #d4edda;
  color: #155724;
  padding: 5px 10px;
  border-radius: 5px;
  border: 1px solid #c3e6cb;
  font-weight: bold;
}
.full-width-switch {
  width: 95%;
  max-width: 1000px;
  margin-top: 30px;
}

#shared-shape-panel {
  text-align: center;
  min-width: 250px; /* Wider to accommodate a batch */
  background-color: white;
  padding: 10px;
  border-radius: 5px;
  border: 1px solid #ddd;
}
#shared-shape-panel h4 {
  margin: 0 0 10px 0;
}
#shared-shape-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  min-height: 60px; /* Taller for the shapes */
}
.chart-wrapper {
  background-color: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  border: 1px solid #ddd;
}
.chart-wrapper h3 {
  text-align: center;
  margin: 0 0 15px 0;
}

.control-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}
.control-group label {
  font-weight: bold;
  font-size: 0.9em;
}
.control-group input[type="number"] {
  width: 100px;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1em;
}

/* NEW style for the progress indicator text */
#progress-indicator {
  text-align: center;
  width: 100%;
  margin-top: 10px;
  font-weight: bold;
  color: #0056b3;
}

.shape-panel {
  width: 100%;
  background-color: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 5px;
  padding: 10px;
  box-sizing: border-box;
}
.shape-panel h4 {
  margin: 0 0 10px 0;
  text-align: center;
  font-size: 0.9em;
}
.shape-panel .shape-container {
  display: flex;
  justify-content: space-around;
  align-items: center;
  min-height: 40px;
}
/* Use a smaller size for the batch display shapes */
.shape-panel .shape-container .shape {
  border: 2px solid #333;
  background-color: white;
  border-radius: 2px;
}
.shape-panel .shape-container .shape-cell {
  width: 15px;
  height: 15px;
  border: none;
  position: relative;
}

.shape-panel
  .shape-container
  .shape-cell[style*="background-color"]:not([style*="transparent"]) {
  border: 1px solid rgba(0, 0, 0, 0.2);
}

/* 3D Effect for Panel Shape Pieces */
.shape-panel
  .shape-container
  .shape-cell[style*="background-color"]:not([style*="transparent"])::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.6) 0%,
    rgba(255, 255, 255, 0.2) 25%,
    rgba(0, 0, 0, 0.1) 75%,
    rgba(0, 0, 0, 0.3) 100%
  );
  pointer-events: none;
}
