/**
 * Chess Game Viewer Styles
 * Responsive design inspired by archive viewer
 */

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

:root {
  /* Color scheme */
  --color-primary: #4d6f94;
  --color-primary-dark: #3f5e79;
  --color-text-dark: #003558;
  --color-bg-light: #eff8fd;
  --color-gray-dark: #81898c;
  --color-gray-light: #d3d5d7;
  --color-gray-lighter: #f5f5f5;
  --color-white: #ffffff;
  --color-success: #28a745;
  --color-info: #17a2b8;
  --color-warning: #ffc107;
  --color-danger: #dc3545;

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;

  /* Fonts */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
    Arial, sans-serif;
  --font-mono: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.12);
  --shadow-md: 0 3px 12px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.2);
}

/* Global Styles */
html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text-dark);
  background-color: var(--color-white);
}

body {
  overflow-x: hidden;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--color-primary-dark);
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
}

/* Header */
.header {
  background-color: var(--color-primary);
  color: var(--color-white);
  padding: var(--spacing-lg);
  box-shadow: var(--shadow-md);
  margin-bottom: var(--spacing-lg);
}

.header h1 {
  font-size: 1.75rem;
  margin: 0;
}

.header .subtitle {
  font-size: 0.9rem;
  opacity: 0.9;
  margin-top: var(--spacing-sm);
}

/* Breadcrumbs */
.breadcrumbs {
  margin: var(--spacing-md) 0;
  padding: var(--spacing-md);
  background-color: var(--color-bg-light);
  border-radius: 4px;
  font-size: 0.9rem;
}

.breadcrumbs a {
  color: var(--color-primary);
}

.breadcrumbs .separator {
  margin: 0 var(--spacing-sm);
  color: var(--color-gray-light);
}

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--spacing-lg);
}

.container[style*="padding-top: 0"] {
  padding-top: var(--spacing-md);
}

/* Cards and Lists */
.card,
.list-item {
  background: var(--color-white);
  border: 1px solid var(--color-gray-light);
  border-radius: 4px;
  padding: var(--spacing-lg);
  margin-bottom: var(--spacing-md);
  transition: all 0.2s ease;
  cursor: pointer;
}

.card:hover,
.list-item:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
  transform: translateY(-2px);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-lg);
}

/* List Styles */
.list {
  list-style: none;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--color-gray-lighter);
  border-left: 3px solid transparent;
  transition: border-left-color 0.2s ease;
}

.list-item:last-child {
  border-bottom: none;
}

.list-item-content {
  flex: 1;
}

.list-item-actions {
  display: flex;
  gap: var(--spacing-sm);
}

/* Tournament Card */
.tournament-card {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.tournament-card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: var(--spacing-sm);
}

.tournament-card-meta {
  font-size: 0.85rem;
  color: var(--color-gray-dark);
  margin-top: auto;
}

.tournament-card-meta div {
  margin: var(--spacing-sm) 0;
}

/* Game Pairing */
.game-pairing {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-md);
  border: 1px solid var(--color-gray-light);
  border-radius: 4px;
  margin-bottom: var(--spacing-sm);
}

.game-pairing:hover {
  background-color: var(--color-bg-light);
}

.game-pairing-players {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.game-player {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.player-name {
  font-weight: 500;
}

.player-info {
  font-size: 0.85rem;
  color: var(--color-gray-dark);
}

.game-pairing-result {
  font-size: 1.1rem;
  font-weight: 600;
  min-width: 80px;
  text-align: center;
}

.result-white-won {
  background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
  color: white;
}

.result-black-won {
  background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
  color: white;
}

.result-draw {
  background: linear-gradient(135deg, #ffc107 0%, #fd7e14 100%);
  color: #333;
}

.result-in-progress {
  background: linear-gradient(135deg, #dc3545 0%, #e83e8c 100%);
  color: white;
  animation: pulse 2s infinite;
}

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

/* Live Game Indicators */
.live-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #dc3545;
  animation: pulse 2s infinite;
  vertical-align: middle;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background-color: #ffe0e6;
  color: #c4184e;
  padding: 0.35rem 0.65rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
  width: fit-content;
}

.tournament-card.has-live-games {
  border-left: 4px solid #dc3545;
}

.list-item.has-live {
  border-left-color: #dc3545;
  border-left-width: 3px;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: var(--spacing-sm) var(--spacing-md);
  border: none;
  border-radius: 4px;
  font-size: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  text-decoration: none;
}

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

.btn-primary:hover {
  background-color: var(--color-primary-dark);
}

.btn-secondary {
  background-color: var(--color-gray-light);
  color: var(--color-text-dark);
}

.btn-secondary:hover {
  background-color: var(--color-gray-dark);
  color: var(--color-white);
}

.btn-small {
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: 0.85rem;
}

.btn-group {
  display: flex;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
}

/* Chess Board Container */
.game-viewer {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: auto;
}

.game-header {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: var(--color-white);
  padding: var(--spacing-sm) var(--spacing-md);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
}

.header-row-1,
.header-row-2 {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--spacing-md);
  align-items: center;
  padding-bottom: 10px;
}

.header-row-1 {
  align-items: flex-start;
  background-color: rgba(0, 0, 0, 0.3);
  margin: 0 -16px -8px -16px;
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.header-row-2 {
  align-items: flex-start;
  margin: 0 -16px -8px -16px;
  padding: 12px 16px;
}

.header-col-1,
.header-col-2,
.header-col-3 {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.header-row-1 .header-col-2 {
  justify-content: flex-end;
  align-items: flex-end;
}

.header-col-3 {
  justify-content: flex-end;
}

.header-logo {
  width: 100px;
  height: 40px;
  border-radius: 8px;
  flex-shrink: 0;
}

.brand-name {
  font-size: 1.3rem;
  padding-left: 10px;
  opacity: 0.9;
  font-weight: 600;
  line-height: 1.2;
}

.tournament-name {
  font-size: 1.5rem;
  font-weight: 600;
  color: #ffd700;
  text-align: right;
}

.header-col-2 {
  flex-direction: column;
  gap: 0.1rem;
}

.game-players {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  padding: 0.5rem;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.game-players:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.player-row {
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
}

.white-player {
  color: #f0f0f0;
}

.black-player {
  color: #b0b0b0;
}

.vs-text {
  font-size: 0.9rem;
  opacity: 0.7;
  font-weight: 500;
}

.game-result-section {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  align-items: flex-end;
}

.game-result {
  font-size: 1.3rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  display: inline-block;
}

.round-info {
  font-size: 1.75rem;
  opacity: 0.8;
  line-height: 1.2;
  padding: 0.5rem;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.round-info:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.round-date {
  font-size: 1.25rem;
  opacity: 0.8;
  line-height: 1.2;
}

.game-content {
  display: flex;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm);
  overflow: hidden;
  min-height: 0;
  height: calc(100vh - 200px);
}

.board-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  background-color: var(--color-primary-dark);
}

.player-info-top,
.player-info-bottom {
  flex-shrink: 0;
  height: auto;
  display: flex-start;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0;
  background-color: var(--color-primary-dark);
  min-height: auto;
}

.player-info-top {
    background-color: black;
    color: white;
}

.player-info-bottom {
    background-color: white;
    color: black;
}

.player-info-display {
  font-size: 1.25rem;
  font-weight: 600;
  /* color: var(--color-white); */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  padding: 0 1rem;
}

.player-clock {
  font-size: 1.25rem;
  font-weight: 600;
  white-space: nowrap;
  padding: 0 1rem;
  min-width: 70px;
  text-align: right;
}

.board-container {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: var(--color-primary-dark);
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

#board {
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
}

.simple-board {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.chess-square {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  font-weight: normal;
  cursor: pointer;
  position: relative;
  user-select: none;
}

.chess-square:hover {
  opacity: 0.8;
}

.chess-square.last-move {
  background-color: #baca44 !important;
}

.white-piece {
  color: #8c3c00;
}

.black-piece {
  color: #2c2c2c;
}

.move-list-container {
  width: 220px;
  min-width: 220px;
  max-width: 220px;
  background-color: var(--color-gray-lighter);
  border: 1px solid var(--color-gray-light);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 100%;
}

.move-list-header {
  background-color: var(--color-primary);
  color: var(--color-white);
  padding: var(--spacing-sm) var(--spacing-md);
  font-weight: 600;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.move-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--spacing-md);
  min-height: 0;
}

.move-pair {
  display: grid;
  grid-template-columns: 2rem 1fr 1fr;
  gap: var(--spacing-xs);
  padding: var(--spacing-xs) var(--spacing-sm);
  margin-bottom: 2px;
  align-items: center;
}

.move-number {
  font-weight: 600;
  color: var(--color-gray-dark);
  font-size: 0.85rem;
  text-align: right;
  padding-right: var(--spacing-xs);
}

.move-san {
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  text-align: center;
}

.move-san:hover {
  background-color: var(--color-white);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.move-san.selected {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: var(--color-white);
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.white-move {
  background-color: rgba(240, 240, 240, 0.3);
}

.black-move {
  background-color: rgba(100, 100, 100, 0.2);
}

/* Game Controls */
.game-controls {
  padding: var(--spacing-md);
  background-color: var(--color-bg-light);
  border-top: 1px solid var(--color-gray-light);
  display: flex;
  flex-direction: row;
  justify-content: center;
  gap: var(--spacing-md);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  gap: var(--spacing-sm);
}

.control-group label {
  font-weight: 600;
  margin-right: var(--spacing-sm);
}

/* Game footer sections */
.game-viewer > div:not(.game-header):not(.game-content):not(.game-controls) {
  flex-shrink: 0;
  overflow-y: auto;
  max-height: 15vh;
}

/* Responsive Design */
@media (max-width: 768px) {
  .card-grid {
    grid-template-columns: 1fr;
  }

  .game-content {
    flex-direction: column;
  }

  .move-list-container {
    width: 100%;
    height: 200px;
  }

  .game-pairing {
    flex-direction: column;
    align-items: flex-start;
  }

  .header {
    padding: var(--spacing-md);
  }

  .header h1 {
    font-size: 1.25rem;
  }

  .container {
    padding: var(--spacing-md);
  }

  /* Game Viewer Mobile Adjustments */
  .game-header {
    padding: var(--spacing-xs) var(--spacing-sm);
    gap: 4px;
  }

  .header-row-1,
  .header-row-2 {
    gap: var(--spacing-xs);
  }

  .header-logo {
    width: 60px;
    height: 24px;
  }

  .brand-name {
    padding-left: 10px;
    font-size: 0.95rem;
  }

  .tournament-name {
    font-size: 1.2rem;
  }

  .header-col-2 {
    gap: 2px;
  }

  .game-players {
    gap: 2px;
    font-size: 0.85rem;
  }

  .player-row {
    font-size: 0.85rem;
  }

  .vs-text {
    font-size: 0.7rem;
  }

  .game-result {
    font-size: 0.95rem;
    padding: 0.15rem 0.4rem;
  }

  .round-info {
    font-size: 1.25rem;
  }

  .round-date {
    font-size: 0.85rem;
  }

  /* Board and Content */
  .game-content {
    flex: none;
    height: auto;
    overflow: visible;
  }

  .board-wrapper {
    gap: 0;
  }

  .player-info-top,
  .player-info-bottom {
    min-height: auto;
    padding: 0.2rem 0;
  }

  .player-info-display {
    font-size: 0.9rem;
    padding: 0 0.75rem;
  }

  .player-clock {
    font-size: 0.9rem;
    padding: 0 0.75rem;
    min-width: 60px;
  }

  .board-container {
    height: 60vh;
  }

  #board {
    width: 100%;
    height: 100%;
    aspect-ratio: 1 / 1;
  }

  .move-list-container {
    height: 280px;
    width: 100%;
    min-width: 100%;
    max-width: 100%;
  }

  .move-pair {
    grid-template-columns: 1.5rem 1fr 1fr;
    gap: 2px;
    padding: var(--spacing-xs) 2px;
  }

  .move-number {
    font-size: 0.75rem;
    padding-right: 2px;
  }

  .move-san {
    padding: 0.25rem 0.35rem;
    font-size: 0.8rem;
  }

  .chess-square {
    font-size: 2rem;
  }

  /* Game Controls */
  .game-controls {
    flex-wrap: wrap;
    padding: var(--spacing-sm);
    gap: var(--spacing-xs);
  }

  .control-group {
    width: 100%;
    gap: var(--spacing-xs);
    flex-wrap: wrap;
    justify-content: center;
  }

  .control-group label {
    width: 100%;
    text-align: center;
    font-size: 0.85rem;
    margin-right: 0;
  }

  .btn {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.75rem;
  }

  .btn-small {
    padding: 2px 4px;
    font-size: 0.7rem;
  }

  #moveCounter {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  .game-header {
    padding: 4px 6px;
    gap: 3px;
  }

  .header-row-1,
  .header-row-2 {
    gap: 6px;
  }

  .header-logo {
    width: 50px;
    height: 20px;
  }

  .header-col-2 {
    gap: 1px;
  }

  .brand-name {
    font-size: 0.85rem;
  }

  .tournament-name {
    font-size: 1rem;
  }

  .player-row {
    font-size: 0.75rem;
  }

  .game-result {
    font-size: 0.85rem;
  }

  .board-wrapper {
    gap: 0;
  }

  .player-info-top,
  .player-info-bottom {
    min-height: auto;
    padding: 0.15rem 0;
  }

  .player-info-display {
    font-size: 0.8rem;
    padding: 0 0.5rem;
  }

  .player-clock {
    font-size: 0.8rem;
    padding: 0 0.5rem;
    min-width: 50px;
  }

  .board-container {
    height: 55vh;
  }

  #board {
    width: 100%;
    height: 100%;
    aspect-ratio: 1 / 1;
  }

  .move-list-container {
    height: 200px;
  }

  .chess-square {
    font-size: 1.5rem;
  }

  .move-pair {
    grid-template-columns: 1.2rem 1fr 1fr;
    gap: 1px;
  }

  .move-number {
    font-size: 0.65rem;
  }

  .move-san {
    padding: 2px 2px;
    font-size: 0.7rem;
  }

  .control-group label {
    font-size: 0.75rem;
  }

  .btn {
    padding: 2px 4px;
    font-size: 0.65rem;
  }

  #moveCounter {
    font-size: 0.7rem;
    padding: 0.2rem 0.35rem;
  }

  /* Back buttons footer */
  .game-viewer > div:last-child {
    padding: var(--spacing-sm) !important;
  }

  .game-viewer > div:last-child div {
    gap: var(--spacing-xs) !important;
  }

  .game-viewer > div:last-child a {
    padding: var(--spacing-xs) var(--spacing-sm) !important;
    font-size: 0.7rem !important;
  }
}

/* Error Container */
.error-container {
  padding: var(--spacing-xl);
  text-align: center;
  background-color: #f8d7da;
  border: 1px solid #f5c6cb;
  border-radius: 4px;
  color: #721c24;
  margin: var(--spacing-xl);
}

.error-container h1 {
  margin-bottom: var(--spacing-md);
}

.error-container p {
  margin-bottom: var(--spacing-lg);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  word-break: break-all;
}

/* Loading State */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
  color: var(--color-gray-dark);
}

.spinner {
  border: 4px solid var(--color-gray-light);
  border-top: 4px solid var(--color-primary);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Print styles */
@media print {
  .game-controls,
  .header,
  .breadcrumbs {
    display: none;
  }

  body {
    padding: 0;
    margin: 0;
  }

  .container {
    max-width: 100%;
  }
}
