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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "SF Pro Display", sans-serif;
  background: #000000;
  background-image: 
    radial-gradient(circle at 20% 50%, rgba(34, 197, 94, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(16, 185, 129, 0.06) 0%, transparent 50%),
    radial-gradient(circle at 40% 80%, rgba(5, 150, 105, 0.05) 0%, transparent 50%),
    radial-gradient(circle at 60% 30%, rgba(34, 197, 94, 0.04) 0%, transparent 50%);
  background-attachment: fixed;
  color: #ffffff;
  min-height: 100vh;
  padding: clamp(1rem, 3vw, 2rem);
  line-height: 1.6;
  overflow-x: hidden;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.header {
  text-align: center;
  color: #ffffff;
  margin-bottom: clamp(1.5rem, 3vh, 2.5rem);
}

.header h1 {
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff 0%, #86efac 30%, #22c55e 60%, #10b981 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
  text-shadow: 0 0 40px rgba(34, 197, 94, 0.2);
  filter: drop-shadow(0 0 20px rgba(16, 185, 129, 0.15));
}

.header p {
  color: #888888;
  font-size: clamp(0.875rem, 2vw, 1.125rem);
  font-weight: 400;
}

.search-section {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(20px);
  padding: clamp(1rem, 3vw, 2rem);
  border-radius: clamp(12px, 2vw, 16px);
  border: 1px solid rgba(34, 197, 94, 0.2);
  margin-bottom: clamp(1rem, 2vh, 2rem);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(34, 197, 94, 0.1), inset 0 1px 0 rgba(16, 185, 129, 0.1);
}

.search-box {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2rem;
}

.search-box input {
  flex: 1 1 200px;
  padding: 0.875rem 1.25rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  font-size: 1rem;
  transition: all 0.3s ease;
  font-family: inherit;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}

.search-box input:focus {
  border-color: rgba(34, 197, 94, 0.5);
  outline: none;
  background: rgba(0, 0, 0, 0.8);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

.search-box input::placeholder {
  color: #666666;
}

.search-box button {
  flex: 0 0 auto;
  padding: 0.875rem 2rem;
  background: linear-gradient(135deg, #22c55e 0%, #10b981 100%);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #ffffff;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
  box-shadow: 0 8px 24px rgba(34, 197, 94, 0.3), 0 0 0 1px rgba(16, 185, 129, 0.1);
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}

@media (hover: hover) and (pointer: fine) {
  .search-box button:hover {
    transform: translateY(-2px);
    background: linear-gradient(135deg, #16a34a 0%, #059669 100%);
    box-shadow: 0 12px 32px rgba(34, 197, 94, 0.4), 0 0 0 1px rgba(16, 185, 129, 0.2);
  }
}

.search-box button:active {
  transform: scale(0.98);
}

.search-box button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.games-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 2rem;
}

.game-card {
  background: linear-gradient(135deg, rgba(0, 0, 0, 0.6) 0%, rgba(20, 20, 20, 0.4) 100%);
  padding: 1.5rem;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid rgba(34, 197, 94, 0.15);
  position: relative;
  overflow: hidden;
}

.game-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #22c55e, #10b981, #059669);
  opacity: 0;
  transition: opacity 0.3s ease;
}

@media (hover: hover) and (pointer: fine) {
  .game-card:hover {
    transform: translateY(-4px);
    border-color: rgba(34, 197, 94, 0.3);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(34, 197, 94, 0.2), inset 0 1px 0 rgba(16, 185, 129, 0.1);
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.8) 0%, rgba(20, 20, 20, 0.6) 100%);
  }

  .game-card:hover::before {
    opacity: 1;
  }
}

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

.game-card-header h3 {
  color: #ffffff;
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  letter-spacing: -0.01em;
}

.game-card-details p {
  color: #cccccc;
  font-size: 0.875rem;
  line-height: 1.6;
  margin-bottom: 0.25rem;
}

.game-card-details .label {
  color: #888888;
  font-weight: 500;
}

.analyzer-section {
  display: none;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(20px);
  padding: clamp(1rem, 3vw, 2rem);
  border-radius: clamp(12px, 2vw, 16px);
  border: 1px solid rgba(34, 197, 94, 0.2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(34, 197, 94, 0.1), inset 0 1px 0 rgba(16, 185, 129, 0.1);
}

.analyzer-section.active {
  display: block;
}

.back-button {
  padding: 0.875rem 1.5rem;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  border: 1px solid rgba(34, 197, 94, 0.2);
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 1.5rem;
  transition: all 0.3s ease;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
}

@media (hover: hover) and (pointer: fine) {
  .back-button:hover {
    background: rgba(0, 0, 0, 0.8);
    border-color: rgba(34, 197, 94, 0.4);
    transform: translateX(-4px);
    box-shadow: 0 8px 20px rgba(34, 197, 94, 0.2);
  }
}

.back-button:active {
  transform: scale(0.98);
}

.analyzer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(1rem, 2vw, 2rem);
  align-items: start;
}

@media (min-width: 1024px) {
  .analyzer-grid {
    grid-template-columns: 1fr minmax(300px, 400px);
  }
}

.board-container {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.board-wrapper {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.rank-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  padding: 2px 0;
  color: #888888;
  font-weight: 600;
  font-size: 0.875rem;
}

.rank-labels div {
  height: calc(100% / 8);
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-and-files {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#chessboard {
  width: 100%;
  max-width: min(520px, 90vw, calc(100vh - 300px));
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 4px solid rgba(34, 197, 94, 0.3);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(34, 197, 94, 0.1), inset 0 1px 0 rgba(16, 185, 129, 0.1);
  flex-shrink: 0;
}

@media (max-width: 1023px) {
  #chessboard {
    max-width: min(90vw, calc(100vh - 400px));
  }
}

@media (max-width: 767px) {
  #chessboard {
    max-width: min(95vw, calc(100vh - 350px));
  }
}

.file-labels {
  display: flex;
  justify-content: space-around;
  color: #888888;
  font-weight: 600;
  font-size: clamp(0.75rem, 1.5vw, 0.875rem);
  max-width: min(520px, 90vw, calc(100vh - 300px));
  width: 100%;
}

@media (max-width: 1023px) {
  .file-labels {
    max-width: min(90vw, calc(100vh - 400px));
  }
}

@media (max-width: 767px) {
  .file-labels {
    max-width: min(95vw, calc(100vh - 350px));
  }
}

.file-labels span {
  flex: 1;
  text-align: center;
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(20px, 3.5vw, 44px);
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  position: relative;
  font-family: "Segoe UI Symbol", "DejaVu Sans", "Noto Sans Symbols", "Apple Symbols", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 767px) {
  .square {
    font-size: clamp(18px, 5vw, 32px);
  }
}

.square.light {
  background: #2a2a2a;
}

.square.dark {
  background: #1a1a1a;
}

.square.highlight {
  background: linear-gradient(135deg, #00ff88 0%, #00cc66 100%) !important;
  box-shadow: inset 0 0 20px rgba(0, 255, 136, 0.4);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: inset 0 0 20px rgba(0, 255, 136, 0.4);
  }
  50% {
    box-shadow: inset 0 0 30px rgba(0, 255, 136, 0.6);
  }
}

.controls {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: auto auto auto;
  gap: 0.75rem;
  width: 100%;
  max-width: min(520px, 90vw, calc(100vh - 300px));
}

@media (max-width: 1023px) {
  .controls {
    max-width: min(90vw, calc(100vh - 400px));
  }
}

@media (max-width: 767px) {
  .controls {
    max-width: min(95vw, calc(100vh - 350px));
    gap: 0.5rem;
  }
}

.controls button {
  padding: clamp(0.625rem, 1.5vw, 0.875rem) clamp(0.75rem, 2vw, 1rem);
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(34, 197, 94, 0.2);
  color: #ffffff;
  border-radius: 12px;
  cursor: pointer;
  font-size: clamp(0.75rem, 1.5vw, 0.875rem);
  font-weight: 600;
  transition: all 0.3s ease;
  font-family: inherit;
  grid-column: span 1;
  touch-action: manipulation;
}

@media (hover: hover) and (pointer: fine) {
  .controls button:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.8);
    border-color: rgba(34, 197, 94, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(34, 197, 94, 0.2);
  }
}

.controls button:active:not(:disabled) {
  transform: scale(0.98);
  background: rgba(0, 0, 0, 0.8);
  border-color: rgba(34, 197, 94, 0.4);
}

.controls button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.controls .analyze-btn {
  grid-column: 1 / 3;
  background: linear-gradient(135deg, #22c55e 0%, #10b981 100%);
  border: 1px solid rgba(34, 197, 94, 0.3);
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(34, 197, 94, 0.3);
}

@media (hover: hover) and (pointer: fine) {
  .controls .analyze-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #16a34a 0%, #059669 100%);
    box-shadow: 0 12px 32px rgba(34, 197, 94, 0.4);
    transform: translateY(-2px);
  }
}

.controls .analyze-btn:active:not(:disabled) {
  transform: scale(0.98);
  background: linear-gradient(135deg, #15803d 0%, #047857 100%);
}

.move-info {
  font-size: clamp(1rem, 2.5vw, 1.125rem);
  margin: 1rem 0;
  color: #ffffff;
  font-weight: 600;
  padding: 0.875rem 1.5rem;
  background: linear-gradient(135deg, rgba(0, 0, 0, 0.6) 0%, rgba(20, 20, 20, 0.4) 100%);
  border-radius: 12px;
  border: 1px solid rgba(34, 197, 94, 0.2);
  text-align: center;
}

.analysis-panel {
  background: linear-gradient(135deg, rgba(0, 0, 0, 0.6) 0%, rgba(20, 20, 20, 0.4) 100%);
  padding: clamp(1rem, 2vw, 1.5rem);
  border-radius: 16px;
  border: 1px solid rgba(34, 197, 94, 0.2);
  max-height: min(70vh, 600px);
  overflow-y: auto;
  overflow-x: hidden;
}

@media (max-width: 1023px) {
  .analysis-panel {
    max-height: 50vh;
  }
}

.analysis-panel::-webkit-scrollbar {
  width: 8px;
}

.analysis-panel::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.3);
}

.analysis-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.analysis-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.4);
}

.analysis-panel h3 {
  color: #ffffff;
  margin-bottom: 1rem;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.analysis-result {
  background: rgba(0, 0, 0, 0.6);
  padding: 1.25rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  border: 1px solid rgba(34, 197, 94, 0.2);
  border-left: 3px solid #22c55e;
}

.evaluation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.evaluation.positive {
  background: rgba(0, 255, 136, 0.1);
  border-color: rgba(0, 255, 136, 0.3);
}

.evaluation.negative {
  background: rgba(255, 68, 68, 0.1);
  border-color: rgba(255, 68, 68, 0.3);
}

.eval-label {
  color: #cccccc;
  font-size: 0.875rem;
  font-weight: 500;
}

.eval-value {
  font-size: 1.5rem;
  color: #ffffff;
}

.evaluation.positive .eval-value {
  color: #00ff88;
}

.evaluation.negative .eval-value {
  color: #ff4444;
}

.move-quality {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.75rem;
  text-align: center;
}

.move-quality.excellent {
  background: rgba(0, 255, 136, 0.15);
  color: #00ff88;
  border: 1px solid rgba(0, 255, 136, 0.3);
}

.move-quality.good {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.move-quality.inaccuracy {
  background: rgba(255, 191, 0, 0.15);
  color: #ffbf00;
  border: 1px solid rgba(255, 191, 0, 0.3);
}

.move-quality.mistake {
  background: rgba(255, 140, 0, 0.15);
  color: #ff8c00;
  border: 1px solid rgba(255, 140, 0, 0.3);
}

.move-quality.blunder {
  background: rgba(255, 68, 68, 0.15);
  color: #ff4444;
  border: 1px solid rgba(255, 68, 68, 0.3);
}

.explanation {
  color: #cccccc;
  font-size: 0.875rem;
  line-height: 1.6;
  margin-bottom: 0.75rem;
}

.best-move {
  padding: 0.875rem 1rem;
  background: rgba(0, 255, 136, 0.1);
  border-radius: 8px;
  border: 1px solid rgba(0, 255, 136, 0.3);
  margin-bottom: 0.75rem;
}

.best-move-label {
  color: #888888;
  font-size: 0.875rem;
  font-weight: 500;
  display: block;
  margin-bottom: 0.5rem;
}

.best-move-value {
  color: #00ff88;
  font-size: 1.25rem;
  font-weight: 700;
  display: block;
  margin-bottom: 0.25rem;
}

.best-move-squares {
  color: #cccccc;
  font-size: 0.875rem;
  font-family: 'Courier New', monospace;
}

.analysis-note {
  color: #888888;
  font-size: 0.75rem;
  text-align: center;
  margin-top: 0.75rem;
  font-style: italic;
}

.loading {
  text-align: center;
  padding: 2rem 1rem;
  color: #888888;
  font-size: 0.875rem;
}

.spinner {
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top: 3px solid #ffffff;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 0.8s linear infinite;
  margin: 1rem auto;
}

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

@media (max-width: 1100px) {
  .analyzer-grid {
    grid-template-columns: 1fr;
  }

  .analysis-panel {
    max-height: 60vh;
  }
}

@media (max-width: 768px) {
  body {
    padding: 1rem 0.75rem;
  }

  .header {
    margin-bottom: 1.5rem;
  }

  .search-section,
  .analyzer-section {
    padding: 1rem;
    border-radius: 12px;
  }

  .games-list {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .analyzer-grid {
    gap: 1rem;
  }

  .analysis-panel {
    padding: 1rem;
    max-height: 40vh;
  }

  .rank-labels {
    font-size: 0.75rem;
  }

  .move-info {
    margin: 0.75rem 0;
    padding: 0.75rem 1rem;
  }
}

@media (max-width: 480px) {
  body {
    padding: 0.75rem 0.5rem;
  }

  .search-box {
    gap: 0.75rem;
  }

  .search-box input,
  .search-box button {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
  }

  .back-button {
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.75rem;
  }

  .game-card {
    padding: 1rem;
  }

  .game-card-header h3 {
    font-size: 1rem;
  }

  .controls {
    gap: 0.5rem;
  }
}

@media (orientation: landscape) and (max-height: 600px) {
  body {
    padding: 0.5rem;
  }

  .header {
    margin-bottom: 0.75rem;
  }

  .header h1 {
    margin-bottom: 0.25rem;
}

#chessboard {
    max-width: min(60vw, calc(100vh - 100px));
  }

  .file-labels,
  .controls {
    max-width: min(60vw, calc(100vh - 100px));
  }

  .analyzer-grid {
    grid-template-columns: auto 1fr;
    gap: 1rem;
  }

  .analysis-panel {
    max-height: calc(100vh - 120px);
  }

  .move-info {
    margin: 0.5rem 0;
    padding: 0.5rem 1rem;
  }
}