/* Modern dark, glassmorphic design for Chess OCR Scanner */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #0b0f19;
  --bg-secondary: rgba(17, 24, 39, 0.7);
  --card-bg: rgba(30, 41, 59, 0.45);
  --card-border: rgba(255, 255, 255, 0.08);
  
  --accent-primary: #6366f1; /* Indigo */
  --accent-secondary: #06b6d4; /* Cyan */
  --accent-success: #10b981; /* Emerald */
  --accent-warning: #f59e0b; /* Amber */
  --accent-error: #ef4444; /* Rose */
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  
  /* Chess Board Colors (Classic Blue-Grey Theme) */
  --board-light: #eceeed;
  --board-dark: #4b7399;
  --board-highlight: rgba(245, 158, 11, 0.5); /* Amber highlight for edited square */
  --board-border: #1e293b;
}

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

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.1) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(6, 182, 212, 0.1) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 3rem;
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 2.5rem;
  animation: fadeInDown 0.8s ease-out;
}

.logo-container {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.logo-icon {
  width: 42px;
  height: 42px;
  fill: url(#logo-grad);
}

h1 {
  font-size: 2.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, #a5b4fc 0%, #6366f1 50%, #06b6d4 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.025em;
}

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

/* Loading Overlay */
#loading_model_overlay {
  position: fixed;
  inset: 0;
  background-color: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease;
}

.spinner {
  width: 64px;
  height: 64px;
  border: 4px solid rgba(99, 102, 241, 0.1);
  border-left-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 1.5rem;
}

.loading-text {
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.loading-subtext {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Main Layout Grid */
.main-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  opacity: 0;
  animation: fadeIn 0.8s ease-out forwards;
}

@media (min-width: 1024px) {
  .main-grid {
    grid-template-columns: 1.1fr 0.9fr;
  }
}

/* Glassmorphic Panel Card */
.panel {
  background-color: var(--bg-secondary);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: 1.25rem;
  padding: 1.75rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.panel-title {
  font-size: 1.3rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--card-border);
  padding-bottom: 0.75rem;
  color: #fff;
}

.panel-title svg {
  fill: var(--accent-secondary);
}

/* Drag-Drop Zone */
.upload-zone {
  border: 2px dashed rgba(99, 102, 241, 0.3);
  border-radius: 1rem;
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  background: rgba(30, 41, 59, 0.2);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.upload-zone:hover {
  border-color: var(--accent-primary);
  background: rgba(30, 41, 59, 0.4);
}

.upload-zone.dragover {
  border-color: var(--accent-secondary);
  background: rgba(6, 182, 212, 0.1);
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.2);
}

.upload-icon {
  width: 48px;
  height: 48px;
  margin-bottom: 1rem;
  fill: var(--text-muted);
  transition: transform 0.3s ease;
}

.upload-zone:hover .upload-icon {
  transform: translateY(-5px);
  fill: var(--accent-primary);
}

.upload-text {
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.upload-subtext {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

/* File Input Hack */
.file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* Canvas Viewport */
.canvas-container {
  position: relative;
  width: 100%;
  border-radius: 0.75rem;
  overflow: hidden;
  background-color: #000;
  border: 1px solid var(--card-border);
  aspect-ratio: 1.333; /* Standard aspect ratio box */
  display: flex;
  align-items: center;
  justify-content: center;
}

#imageCanvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

/* Crop Bounding Box Styling */
.crop-overlay {
  position: absolute;
  border: 3px solid var(--accent-secondary);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6);
  cursor: move;
  display: none;
}

/* Crop handles */
.crop-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background-color: var(--text-main);
  border: 2px solid var(--accent-secondary);
  border-radius: 50%;
}

.crop-handle.tl { top: -7px; left: -7px; cursor: nwse-resize; }
.crop-handle.tr { top: -7px; right: -7px; cursor: nesw-resize; }
.crop-handle.bl { bottom: -7px; left: -7px; cursor: nesw-resize; }
.crop-handle.br { bottom: -7px; right: -7px; cursor: nwse-resize; }

.viewport-info {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(30, 41, 59, 0.2);
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
}

/* Chessboard Result Viewport */
.result-section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Interactive Chessboard */
.board-outer {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  aspect-ratio: 1;
  background-color: var(--board-border);
  border-radius: 0.75rem;
  padding: 6px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--card-border);
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border-radius: 0.5rem;
  overflow: hidden;
}

.board-square {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background-color 0.15s ease;
}

.board-square.light {
  background-color: var(--board-light);
}

.board-square.dark {
  background-color: var(--board-dark);
}

.board-square img {
  width: 90%;
  height: 90%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
  z-index: 2;
  transition: transform 0.15s ease;
}

.board-square:hover img {
  transform: scale(1.05);
}

.board-square.selected {
  background-color: var(--board-highlight) !important;
}

/* Square Coordinates */
.square-coord {
  position: absolute;
  font-size: 0.65rem;
  font-weight: 600;
  z-index: 1;
  opacity: 0.5;
}

.square-coord.rank {
  left: 3px;
  top: 3px;
}

.square-coord.file {
  right: 3px;
  bottom: 3px;
}

.board-square.light .square-coord {
  color: var(--board-dark);
}

.board-square.dark .square-coord {
  color: var(--board-light);
}

/* FEN Output Card */
.fen-card {
  background: rgba(30, 41, 59, 0.3);
  border: 1px solid var(--card-border);
  border-radius: 0.75rem;
  padding: 1rem;
}

.fen-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.fen-input-wrapper {
  display: flex;
  gap: 0.5rem;
}

.fen-input {
  flex: 1;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--card-border);
  border-radius: 0.5rem;
  padding: 0.6rem 0.8rem;
  color: var(--text-main);
  font-family: monospace;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.fen-input:focus {
  border-color: var(--accent-primary);
}

.btn {
  background: var(--accent-primary);
  border: none;
  color: white;
  padding: 0.6rem 1.2rem;
  border-radius: 0.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

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

.btn-secondary {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--card-border);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: rgba(51, 65, 85, 0.8);
  border-color: var(--text-muted);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

/* Piece Selector Dialog */
.piece-selector-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.piece-selector-dialog {
  background: #111827;
  border: 1px solid var(--card-border);
  border-radius: 1rem;
  width: 320px;
  padding: 1.5rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.selector-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.5rem;
  margin-top: 1rem;
  margin-bottom: 1rem;
}

.selector-title {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 0.25rem;
  font-weight: 600;
}

.selector-piece {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid var(--card-border);
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.selector-piece:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--accent-primary);
  transform: scale(1.05);
}

.selector-piece img {
  width: 80%;
  height: 80%;
  object-fit: contain;
}

.btn-danger-link {
  background: transparent;
  color: var(--accent-error);
  border: 1px solid rgba(239, 68, 68, 0.2);
  width: 100%;
}

.btn-danger-link:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* Lichess Integration Panel */
.analysis-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 640px) {
  .analysis-panel {
    grid-template-columns: 1fr 1fr;
  }
}

.analysis-card {
  background: rgba(30, 41, 59, 0.2);
  border: 1px solid var(--card-border);
  border-radius: 0.75rem;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: transform 0.2s ease;
}

.analysis-card:hover {
  transform: translateY(-2px);
}

.analysis-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.analysis-card-title {
  font-weight: 600;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.player-dot.white {
  background: #ffffff;
  box-shadow: 0 0 8px #ffffff;
}

.player-dot.black {
  background: #374151;
  box-shadow: 0 0 8px #4b5563;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.actions-row {
  display: flex;
  gap: 0.5rem;
}

.actions-row .btn {
  flex: 1;
}

/* Utility classes & animations */
.hidden {
  display: none !important;
}

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

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

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--accent-success);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 2rem;
  font-weight: 600;
  box-shadow: 0 10px 20px rgba(16, 185, 129, 0.3);
  z-index: 10000;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
