/* CSS Reset & Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --color-bg: #f8f9fa;
  --color-text: #212529;
  --color-accent: #6c5ce7;
  --color-accent-hover: #5b4bc7;
  --color-border: #dee2e6;
  --color-shadow: rgba(0, 0, 0, 0.1);
  --color-overlay: rgba(0, 0, 0, 0.7);
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  font-family: var(--font-family);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Header */
.header {
  background: white;
  padding: 1rem 0;
  box-shadow: 0 2px 8px var(--color-shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header .container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header h1 {
  font-size: 2rem;
  font-weight: bold;
  color: var(--color-accent);
}

.progress {
  font-size: 1rem;
  font-weight: 600;
}

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

/* Battle Arena */
.battle-arena {
  min-height: calc(100vh - 80px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.battle-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

/* Painting Card */
.painting-card {
  position: relative;
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px var(--color-shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  background: white;
}

.painting-card:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 24px var(--color-shadow);
}

.painting-card:active {
  transform: scale(0.98);
}

.painting-wrapper {
  position: relative;
  width: 100%;
  padding-bottom: 133.33%;
  overflow: hidden;
}

.painting-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.3s ease-in;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  min-height: 400px;
}

.painting-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, var(--color-overlay), transparent);
  padding: 2rem 1.5rem;
  color: white;
}

.painting-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.painting-artist {
  font-size: 1.1rem;
  margin-bottom: 0.25rem;
}

.painting-year {
  font-size: 0.9rem;
  opacity: 0.9;
}

/* Loading State */
.loading {
  text-align: center;
  padding: 3rem;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 1rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading p {
  font-size: 1.1rem;
  color: #6c757d;
}

/* Error & Completion Containers */
.error-container,
.completion-container {
  text-align: center;
  padding: 3rem;
}

.error-message,
.completion-message {
  max-width: 500px;
  margin: 0 auto;
  background: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 4px 12px var(--color-shadow);
}

.error-message h2,
.completion-message h2 {
  font-size: 2rem;
  margin-bottom: 1rem;
  color: var(--color-accent);
}

.error-message p,
.completion-message p {
  font-size: 1.1rem;
  margin-bottom: 1.5rem;
  color: #6c757d;
}

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

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

.btn-primary:hover {
  background: var(--color-accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--color-shadow);
}

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

/* Results Page */
.results-page {
  padding: 2rem 0;
  min-height: calc(100vh - 80px);
}

.section {
  margin-bottom: 4rem;
}

.section-title {
  font-size: 2rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.section-description {
  font-size: 1.1rem;
  color: #6c757d;
  margin-bottom: 2rem;
}

/* Personal Rankings Grid */
.rankings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.ranking-card {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px var(--color-shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}

.ranking-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 16px var(--color-shadow);
}

.ranking-card.rank-1 {
  border: 3px solid var(--color-accent);
}

.ranking-card-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.ranking-card-content {
  padding: 1rem;
}

.ranking-card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.ranking-card-artist {
  font-size: 0.9rem;
  color: #6c757d;
  margin-bottom: 0.5rem;
}

.ranking-card-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-border);
}

.win-rate {
  font-size: 1.25rem;
  font-weight: bold;
  color: var(--color-accent);
}

.record {
  font-size: 0.875rem;
  color: #6c757d;
}

/* Sort Controls */
.sort-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.sort-select {
  padding: 0.5rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: white;
  cursor: pointer;
}

/* Global Rankings Table */
.table-container {
  overflow-x: auto;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px var(--color-shadow);
}

.rankings-table {
  width: 100%;
  border-collapse: collapse;
}

.rankings-table thead {
  background: var(--color-accent);
  color: white;
}

.rankings-table th,
.rankings-table td {
  padding: 1rem;
  text-align: left;
}

.rankings-table th {
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.rankings-table tbody tr {
  border-bottom: 1px solid var(--color-border);
}

.rankings-table tbody tr:hover {
  background: #f8f9fa;
}

.painting-cell {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.painting-thumbnail {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
}

.painting-details {
  flex: 1;
}

.painting-name {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.painting-meta {
  font-size: 0.875rem;
  color: #6c757d;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin-top: 2rem;
}

.pagination button {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.pagination button:hover:not(:disabled) {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination .current-page {
  padding: 0.5rem 1rem;
  font-weight: 600;
}

/* Actions */
.actions {
  text-align: center;
  margin-top: 3rem;
}

/* Mobile Responsive */
@media (max-width: 767px) {
  .header h1 {
    font-size: 1.5rem;
  }

  .battle-container {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .painting-wrapper {
    padding-bottom: 75%;
  }

  .painting-title {
    font-size: 1.2rem;
  }

  .painting-artist {
    font-size: 1rem;
  }

  .rankings-grid {
    grid-template-columns: 1fr;
  }

  .table-container {
    border-radius: 0;
  }

  .rankings-table {
    font-size: 0.875rem;
  }

  .rankings-table th,
  .rankings-table td {
    padding: 0.75rem 0.5rem;
  }

  .painting-cell {
    flex-direction: column;
    align-items: flex-start;
  }

  .painting-thumbnail {
    width: 100%;
    height: 120px;
  }
}

/* Tablet Responsive */
@media (min-width: 768px) and (max-width: 1023px) {
  .battle-container {
    gap: 1.5rem;
  }

  .rankings-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .battle-container {
    min-height: calc(100vh - 120px);
  }

  .painting-wrapper {
    padding-bottom: 100%;
  }

  .rankings-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Fade Animations */
.fade-in {
  animation: fadeIn 0.3s ease-in;
}

.fade-out {
  animation: fadeOut 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
