:root {
  --bg: #000000;
  --panel: rgba(16, 16, 16, 0.85);
  --panel-solid: #101010;
  --text: #f0f8ff;
  --muted: #9cb3c9;
  --accent: #5cd49d;
  --accent-2: #8ae8d8;
  --border: rgba(93, 212, 157, 0.15);
  --hover: rgba(26, 33, 41, 0.7);
  --success: #5cd49d;
  --warning: #f5a623;
  --danger: #e74c3c;
  --glass-bg: rgba(16, 16, 16, 0.6);
  --glass-border: rgba(93, 212, 157, 0.2);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial;
  background: 
    url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="chess-grid" patternUnits="userSpaceOnUse" width="16" height="16"><rect width="8" height="8" fill="rgba(93,212,157,0.02)"/><rect x="8" y="8" width="8" height="8" fill="rgba(93,212,157,0.02)"/></pattern></defs><rect width="100" height="100" fill="url(%23chess-grid)"/></svg>') repeat,
    radial-gradient(1200px 800px at 20% 0%, #0a0a0a, #000000 70%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  animation: chess-pattern-drift 60s linear infinite;
}

@keyframes chess-pattern-drift {
  0% { background-position: 0 0, center; }
  100% { background-position: 32px 32px, center; }
}

/* Navigation */
.main-nav {
  padding: 15px 40px;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.nav-brand {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s ease;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-brand:hover {
  color: var(--accent-2);
}

.nav-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  transition: border-color 0.2s ease;
}

.nav-brand:hover .nav-avatar {
  border-color: var(--accent-2);
}

/* Hamburger Menu Button */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px;
  width: 30px;
  height: 30px;
  position: relative;
}

.nav-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--accent);
  margin: 4px 0;
  transition: all 0.3s ease;
}

.nav-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(4px, 4px);
}

.nav-toggle.active span:nth-child(2) {
  opacity: 0;
}

.nav-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(4px, -4px);
}

.nav-links {
  display: flex;
  gap: 30px;
  align-items: center;
}

.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  transition: color 0.2s ease;
  position: relative;
}

.nav-link:hover {
  color: var(--text);
}

.nav-link.active {
  color: var(--accent);
}

.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
}

/* Header */
header {
  padding: 20px 40px;
  border-bottom: 1px solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}

.header-text {
  flex: 1;
  min-width: 0;
  max-width: calc(100% - 300px); /* Reserve space for badges */
}

.header-text h1 {
  margin: 0;
  font-size: 1.5rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.research-context {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.research-context strong {
  color: var(--text);
}

.research-context em {
  color: var(--accent-2);
  font-style: normal;
}

.author-link, .dataset-link {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s ease;
}

.author-link:hover, .dataset-link:hover {
  color: var(--accent-2);
  text-decoration: underline;
}

.metric-link {
  color: var(--accent-2);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.2s ease;
}

.metric-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.header-badges {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  align-items: flex-start;
}

/* Main Layout */
.app-container {
  flex: 1;
  display: block;
  width: 100%;
  padding: 20px;
  min-height: 0;
}

/* Board Panel */
.board-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(93, 212, 157, 0.1);
}

.board-container {
  width: 100%;
  max-width: 500px;
  margin: 0 auto 20px;
  position: relative;
}

#board {
  width: 100%;
}

/* Controls */
.controls {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.fen-input-row {
  margin-bottom: 15px;
}

#fen-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--panel-solid);
  border: 1px solid var(--glass-border);
  color: var(--text);
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.95rem;
  box-sizing: border-box;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
}

#fen-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 
    inset 0 2px 8px rgba(0, 0, 0, 0.4),
    0 0 0 3px rgba(93, 212, 157, 0.3);
}

.button-group {
  display: flex;
  gap: 10px;
}

button {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

button:hover {
  background: var(--hover);
  border-color: var(--accent);
}

button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0e11;
  border: none;
  font-weight: 600;
}

button.primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.position-btn {
  background: linear-gradient(135deg, var(--panel), var(--hover));
  color: var(--accent-2);
  border: 1px solid var(--accent);
  padding: 10px 20px;
  min-width: 160px;
  font-weight: 600;
}

.position-btn:hover {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--bg);
  border-color: var(--accent-2);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(76, 195, 138, 0.3);
}

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

/* iOS-style Toggle Switch */
.autoplay-control {
  text-align: center;
  margin-bottom: 15px;
}

.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}

.toggle-switch input[type="checkbox"] {
  display: none;
}

.toggle-slider {
  position: relative;
  width: 60px;
  height: 30px;
  background: var(--border);
  border-radius: 15px;
  transition: all 0.3s ease;
  border: 2px solid var(--border);
}

.toggle-slider:before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: var(--text);
  border-radius: 50%;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
  border-color: var(--accent);
  animation: pulse-toggle 2s ease-in-out infinite;
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(30px);
  background: var(--bg);
}

.toggle-label {
  font-weight: 600;
  color: var(--text);
  font-size: 1rem;
}

.toggle-switch input:checked ~ .toggle-label {
  color: var(--accent);
}

@keyframes pulse-toggle {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(76, 195, 138, 0.4);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(76, 195, 138, 0);
  }
}

.current-fen {
  padding: 12px;
  background: var(--panel-solid);
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
}

.current-fen label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 5px;
}

.current-fen code {
  color: var(--accent-2);
  font-size: 0.9rem;
  word-break: break-all;
}

.visualization-toggles {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.visualization-toggles label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
}

.visualization-toggles input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.legend {
  margin-top: 10px;
  padding: 8px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.legend small {
  color: var(--muted);
  line-height: 1.4;
}

/* Analysis Panel */
.analysis-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(93, 212, 157, 0.1);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.status {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Top Moves */
.top-moves {
  flex: 1;
  min-height: 300px;
}

.top-moves h3 {
  margin: 0 0 15px;
  font-size: 1rem;
  color: var(--text);
}

.moves-list {
  background: var(--panel-solid);
  border-radius: 12px;
  padding: 15px;
  min-height: 250px;
  border: 1px solid var(--border);
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.3);
}

.move-item {
  display: grid;
  grid-template-columns: 40px 80px 1fr auto;
  align-items: center;
  padding: 10px;
  margin-bottom: 8px;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  transition: all 0.3s ease;
}

.move-item:hover {
  background: var(--hover);
  border-color: var(--accent);
}

.illegal-move {
  background: rgba(231, 76, 60, 0.1) !important;
  border-color: rgba(231, 76, 60, 0.3) !important;
}

.illegal-move:hover {
  background: rgba(231, 76, 60, 0.15) !important;
  border-color: rgba(231, 76, 60, 0.5) !important;
}

.illegal-bar {
  background: linear-gradient(90deg, var(--danger), #ff6b6b) !important;
}

.illegal-indicator {
  color: var(--danger);
  font-weight: bold;
  margin-left: 5px;
}

.illegal-summary {
  background: rgba(231, 76, 60, 0.1);
  border: 1px solid rgba(231, 76, 60, 0.3);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 10px;
  color: var(--danger);
  text-align: center;
}

.move-rank {
  font-weight: 600;
  color: var(--accent);
}

.move-notation {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 500;
  color: var(--text);
}

.move-bar {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.move-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.3s ease;
}

.move-score {
  font-weight: 500;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}

/* Attention Info */
.attention-info h3 {
  margin: 0 0 15px;
  font-size: 1rem;
}

#attention-details {
  background: var(--bg);
  border-radius: 8px;
  padding: 15px;
  min-height: 100px;
}

/* Model Info */
.model-info {
  background: var(--bg);
  border-radius: 8px;
  padding: 15px;
}

.model-info h4 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: var(--accent);
}

.model-info ul {
  margin: 0;
  padding-left: 20px;
  list-style: none;
}

.model-info li {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 5px;
  position: relative;
  padding-left: 15px;
}

.model-info li:before {
  content: "▸";
  position: absolute;
  left: 0;
  color: var(--accent);
}

.tooltip-trigger {
  text-decoration: underline dotted;
  cursor: help;
}

.info-btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 12px;
  margin-left: 5px;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.info-btn:hover {
  background: var(--accent-2);
}

/* Header Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s ease;
  border: 1px solid;
  min-width: 90px;
  justify-content: center;
  white-space: nowrap;
  flex-shrink: 0;
}

.hf-badge {
  background: var(--bg);
  color: #ff7c00;
  border-color: #ff7c00;
}

.hf-badge:hover {
  background: #ff7c00;
  color: white;
  transform: translateY(-1px);
}

.github-badge {
  background: var(--bg);
  color: #666;
  border-color: #666;
}

.github-badge:hover {
  background: #666;
  color: white;
  transform: translateY(-1px);
}

.research-badge {
  background: var(--bg);
  color: var(--accent);
  border-color: var(--accent);
}

.research-badge:hover {
  background: var(--accent);
  color: var(--bg);
  transform: translateY(-1px);
}

/* Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideIn 0.3s ease-out;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  color: var(--accent);
}

.close-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.close-btn:hover {
  background: var(--hover);
  color: var(--text);
}

.modal-body {
  padding: 24px;
}

.modal-body h4 {
  color: var(--accent-2);
  margin: 20px 0 10px;
}

.modal-body ol {
  padding-left: 20px;
}

.modal-body ol li {
  margin-bottom: 8px;
  line-height: 1.5;
}

.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 15px;
  margin: 15px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9rem;
}

.code-block code {
  color: var(--accent-2);
  word-break: break-all;
}

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

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

.placeholder {
  color: var(--muted);
  font-style: italic;
  text-align: center;
  padding: 20px;
}

/* Move Arrows Overlay */
.move-arrow {
  position: absolute;
  pointer-events: none;
  z-index: 10;
}

/* Attention Heatmap Overlay */
.attention-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

.attention-square {
  position: absolute;
  background: radial-gradient(circle, rgba(76, 195, 138, 0.6), transparent);
  pointer-events: none;
}

/* Override chessboard.js drag selection color */
.square-55d63.highlight1-32417 {
  background-color: var(--accent) !important;
  box-shadow: inset 0 0 3px rgba(76, 195, 138, 0.8) !important;
}

.square-55d63.highlight2-9c5d2 {
  background-color: var(--accent-2) !important;
  box-shadow: inset 0 0 3px rgba(124, 226, 213, 0.8) !important;
}

/* Override piece dragging highlight */
.piece-417db.dragging-222b0 {
  opacity: 0.8 !important;
}

/* Pulse animation for selected move arrow */
.selected-arrow {
  animation: pulse-arrow 1.5s ease-in-out infinite;
}

@keyframes pulse-arrow {
  0%, 100% {
    opacity: 1;
    filter: drop-shadow(0 0 4px rgba(76, 195, 138, 0.8));
  }
  50% {
    opacity: 0.6;
    filter: drop-shadow(0 0 8px rgba(76, 195, 138, 1));
  }
}

/* Responsive Design */
@media (max-width: 1024px) {
  .app-container {
    grid-template-columns: 1fr;
  }
  
  .board-container {
    max-width: 400px;
  }
}

@media (max-width: 768px) {
  /* Navigation Mobile */
  .main-nav {
    padding: 15px 20px;
  }
  
  .nav-toggle {
    display: block;
  }
  
  .nav-links {
    position: fixed;
    top: 60px;
    right: -100%;
    width: 250px;
    height: calc(100vh - 60px);
    background: var(--panel-solid);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid var(--glass-border);
    flex-direction: column;
    gap: 0;
    padding: 20px;
    transition: right 0.3s ease;
    overflow-y: auto;
    z-index: 999;
  }
  
  .nav-links.active {
    right: 0;
  }
  
  .nav-link {
    width: 100%;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
  }
  
  .nav-link.active::after {
    display: none;
  }
  
  /* Header Mobile */
  header {
    padding: 15px 20px;
  }
  
  .header-text h1 {
    font-size: 1.3rem;
  }
  
  .subtitle {
    font-size: 0.85rem;
  }
  
  .header-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 15px;
  }
  
  .header-text {
    max-width: 100%;
  }
  
  .research-context {
    font-size: 0.75rem;
  }
  
  .header-badges {
    align-self: stretch;
    justify-content: space-between;
  }
  
  .badge {
    flex: 1;
    min-width: 0;
    font-size: 0.75rem;
    padding: 6px 12px;
  }
  
  .app-container {
    padding: 15px;
    gap: 15px;
    grid-template-columns: 1fr; /* Single column for mobile */
  }
  
  
  /* Clean panel styling on mobile */
  .board-panel,
  .analysis-panel {
    /* Removed debug borders */
  }
  
  .button-group {
    flex-direction: column;
  }
  
  .board-container {
    max-width: 100%;
    min-width: 300px; /* Ensure board stays usable */
  }
  
  /* Ensure chess board scales properly */
  #board {
    width: 100% !important;
    max-width: 400px;
    margin: 0 auto;
  }
  
  .position-btn {
    width: 100%;
    padding: 14px 16px;
    font-size: 0.9rem;
    min-height: 44px; /* iOS recommended touch target */
  }
  
  .toggle-switch {
    padding: 8px 0; /* More touch area around toggle */
  }
  
  .autoplay-control {
    padding: 12px;
  }
}

@media (max-width: 480px) {
  .nav-brand {
    font-size: 1rem;
  }
  
  .nav-avatar {
    width: 28px;
    height: 28px;
  }
  
  .header-text h1 {
    font-size: 1.1rem;
  }
  
  .move-item {
    grid-template-columns: 30px 60px 1fr auto;
    padding: 8px;
    font-size: 0.85rem;
  }
}
/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-content {
  text-align: center;
  max-width: 400px;
  padding: 40px;
}

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

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

.loading-content h2 {
  color: var(--accent);
  margin-bottom: 10px;
  font-size: 1.5rem;
}

.loading-status {
  color: var(--muted);
  margin-bottom: 20px;
  font-size: 0.9rem;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--panel);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 15px;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  width: 0%;
  transition: width 0.3s ease;
  border-radius: 3px;
}

.loading-details {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

/* Component Navigation */
.component-nav {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  padding: 0 40px;
  position: sticky;
  top: 72px;
  z-index: 90;
}

.component-nav-container {
  max-width: 1200px;
  margin: 0 auto;
}

.component-tabs {
  display: flex;
  gap: 0;
  width: 100%;
  justify-content: space-between;
}

.component-tab {
  background: var(--panel-solid);
  border: none;
  border-radius: 0 !important;
  padding: 16px 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s ease;
  position: relative;
  flex: 1;
  margin-right: 1px;
}

.component-tab:last-child {
  margin-right: 0;
}

.component-tab:hover {
  color: var(--text);
  background: var(--hover);
}

.component-tab.active {
  color: var(--accent);
  background: rgba(93, 212, 157, 0.15);
}

.tab-icon {
  font-size: 1.1rem;
}

.tab-text {
  font-weight: inherit;
}

.tab-badge {
  background: var(--warning);
  color: #000;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 600;
}

/* Component Container System */
.component-container {
  display: none;
  width: 100%;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease;
  position: relative;
}

.component-container.active {
  display: block;
  opacity: 1;
  visibility: visible;
}

/* Selfplay override - needs special handling for grid layout */
#selfplay-component {
  display: none !important;
}

#selfplay-component.active {
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 20px !important;
  grid-column: 1 / -1 !important; /* Span both columns of parent grid */
  opacity: 1 !important;
  visibility: visible !important;
  width: 100% !important;
}

/* Ensure panels are proper grid items */
#selfplay-component .board-panel {
  grid-column: 1;
}

#selfplay-component .analysis-panel {
  grid-column: 2;
}

/* Benchmark and interpretability components use full width */
#benchmark-component,
#interpretability-component {
  grid-column: 1 / -1;
}

/* Benchmark Component Styles */
.benchmark-content {
  padding: 20px;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.benchmark-header {
  text-align: center;
  padding: 0 0 20px 0;
  border-bottom: 1px solid var(--border);
}

.benchmark-header h2 {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 1.8rem;
}

.benchmark-description {
  color: var(--muted);
  font-size: 1rem;
  margin: 0;
}

.benchmark-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  padding: 15px 20px;
  border-radius: 8px;
  border: 1px solid var(--border);
  gap: 20px;
}

.benchmark-selector {
  display: flex;
  align-items: center;
  gap: 15px;
}

.benchmark-selector label {
  color: var(--text);
  font-weight: 600;
  min-width: 80px;
}

.benchmark-selector select {
  background: var(--panel-solid);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  min-width: 250px;
}

.benchmark-actions {
  display: flex;
  gap: 10px;
}

.benchmark-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.85rem;
}

.benchmark-btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #000;
}

.benchmark-btn.primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(93, 212, 157, 0.3);
}

.benchmark-btn.secondary {
  background: var(--panel-solid);
  color: var(--text);
  border: 1px solid var(--border);
}

.benchmark-btn.secondary:hover:not(:disabled) {
  background: var(--hover);
}

.benchmark-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Benchmark Description Section */
.benchmark-description-section {
  margin-bottom: 20px;
}

.benchmark-info-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.info-header {
  background: var(--panel-solid);
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.info-header h3 {
  margin: 0;
  color: var(--accent);
  font-size: 1.3rem;
}

.info-badges {
  display: flex;
  gap: 10px;
}

.info-badge {
  background: var(--accent);
  color: #000;
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 0.8rem;
  font-weight: 600;
}

.info-content {
  padding: 20px;
}

.info-section {
  margin-bottom: 25px;
}

.info-section:last-child {
  margin-bottom: 0;
}

.info-section h4 {
  margin: 0 0 12px 0;
  color: var(--text);
  font-size: 1.1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.info-section p {
  margin: 0 0 15px 0;
  color: var(--text);
  line-height: 1.6;
}

.source-links {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.source-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--glass-bg);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.source-link:hover {
  background: var(--hover);
  color: var(--accent-2);
  transform: translateY(-1px);
}

.methodology-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 15px;
}

.methodology-original,
.methodology-adapted {
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 15px;
}

.methodology-original h5,
.methodology-adapted h5 {
  margin: 0 0 10px 0;
  color: var(--accent-2);
  font-size: 0.95rem;
}

.method-example {
  margin-top: 10px;
}

.method-example code {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
}

.method-example pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px;
  margin: 6px 0;
  font-size: 0.75rem;
  color: var(--text);
  overflow-x: auto;
}

.method-example p {
  margin: 8px 0 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.citation-box {
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 15px;
  font-style: italic;
}

.citation-box p {
  margin: 0;
  color: var(--text);
  font-size: 0.9rem;
}

/* Main benchmark content area - 2 column layout */
.benchmark-main {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  flex: 1;
  min-height: 0;
}

.benchmark-left {
  display: flex;
  flex-direction: column;
  gap: 15px;
  min-height: 0;
}

.benchmark-right {
  display: flex;
  flex-direction: column;
  gap: 15px;
  min-height: 0;
}

/* Benchmark Metrics */
.benchmark-metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.metric-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 15px;
  text-align: center;
  backdrop-filter: blur(10px);
}

.metric-label {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 6px;
  font-weight: 500;
}

.metric-value {
  color: var(--accent);
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0;
}

/* Smaller auxiliary metric inside metric-value */
.metric-value .aux-metric {
  color: var(--muted);
  font-size: 0.8em;
  font-weight: 600;
  margin-left: 6px;
}

/* Benchmark Progress */
.benchmark-progress-bar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 15px;
}

.progress-bar-container {
  background: var(--panel-solid);
  border-radius: 8px;
  height: 8px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  width: 0%;
  transition: width 0.3s ease;
}

/* Benchmark Visualization - Now prominently placed */
.benchmark-visualization {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 15px;
  flex: 1;
  min-height: 300px;
  display: flex;
  flex-direction: column;
}

.benchmark-visualization h3 {
  margin: 0 0 15px 0;
  color: var(--accent);
  font-size: 1.1rem;
}

#accuracy-chart {
  width: 100%;
  flex: 1;
  min-height: 250px;
  display: block;
  background: var(--panel-solid);
  border-radius: 6px;
}

/* Benchmark Results Table */
.benchmark-results {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 15px;
  flex: 1;
  min-height: 200px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.results-header {
  margin-bottom: 12px;
}

.results-header h3 {
  margin: 0;
  color: var(--text);
  font-size: 1rem;
}

.results-table {
  background: var(--panel-solid);
  border-radius: 6px;
  padding: 12px;
  flex: 1;
  overflow-y: auto;
}

.results-header {
  margin-bottom: 15px;
}

.results-header h3 {
  margin: 0;
  color: var(--text);
  font-size: 1.2rem;
}

.results-table {
  background: var(--panel-solid);
  border-radius: 8px;
  padding: 15px;
  min-height: 150px;
}

.results-placeholder {
  color: var(--muted);
  text-align: center;
  padding: 40px;
  font-style: italic;
}

/* Interpretability Component Styles */
.interpretability-content { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.interp-header h2 { margin: 0; color: var(--accent); }
.interp-subtitle { margin: 0; color: var(--muted); font-size: 0.9rem; }
.interp-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.interp-control-group { display: flex; gap: 8px; align-items: center; }
.interp-label { color: var(--muted); min-width: 40px; }
.interp-input { flex: 1; min-width: 320px; padding: 8px 10px; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; color: var(--text); }
.interp-layer-val { color: var(--muted); font-size: 0.9rem; min-width: 36px; text-align: right; }
.interp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.interp-section { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.interp-section h3 { margin: 0 0 6px; }
.interp-desc { color: var(--muted); font-size: 0.85rem; margin: 0 0 8px; }
.interp-span { grid-column: 1 / -1; }
.interp-canvas { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; max-width: 100%; height: auto; }
.interp-info { flex: 1; }
.interp-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .interp-row-2 { grid-template-columns: 1fr; } }
.meta-legend { margin-top: 8px; }
.meta-legend-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.meta-legend-title { color: var(--muted); margin-right: 6px; }
.meta-pill { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 2px 8px; font-size: 0.8rem; color: var(--text); }
.meta-row { display: grid; grid-template-columns: repeat(13, 1fr); gap: 2px; margin-top: 8px; }
.meta-row .meta-cell { display:flex; align-items:center; justify-content:center; font-weight:600; padding:6px 0; border-radius:4px; }
.meta-cell { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; text-align: center; font-family: ui-monospace, monospace; font-size: 0.9rem; }
.lens-container { overflow-x: auto; }
.lens-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.lens-table th, .lens-table td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }
.lens-table th { background: var(--panel); color: var(--accent); }
.lens-cell { cursor: pointer; }
.lens-cell:hover { background: var(--glass-bg); }
tbody tr.active td { background: rgba(92, 212, 157, 0.08); border-color: rgba(92, 212, 157, 0.3); }

/* Diagram */
.diagram-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.diagram-grid { display: grid; grid-template-columns: repeat(8, minmax(48px, 1fr)); gap: 6px; }
.diagram-layer { grid-column: 1 / -1; color: var(--muted); margin-top: 6px; }
.head-cell { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 8px; text-align: center; cursor: pointer; }
.head-cell.active { outline: 2px solid var(--accent); }

/* Removed dedicated board for interpretability for now; using a single heatmap canvas */

.coming-soon-description {
  color: var(--text);
  font-size: 1.1rem;
  margin-bottom: 30px;
  line-height: 1.6;
}

.planned-features {
  text-align: left;
  margin-bottom: 30px;
}

.planned-features h3 {
  color: var(--accent-2);
  font-size: 1.3rem;
  margin: 0 0 15px;
}

.planned-features ul {
  color: var(--text);
  line-height: 1.8;
  margin: 0;
  padding-left: 20px;
}

.planned-features li {
  margin-bottom: 8px;
}

.development-status {
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
}

.development-status p {
  margin: 0 0 10px;
  color: var(--muted);
}

.development-status p:last-child {
  margin: 0;
}

/* Tablet responsive design */
@media (max-width: 1024px) {
  .app-container {
    padding: 15px;
    gap: 15px;
  }
  
  .benchmark-content {
    padding: 20px 15px;
  }
  
  .component-tab {
    padding: 14px 20px;
    font-size: 0.9rem;
  }
}

/* Mobile responsive design */
@media (max-width: 768px) {
  .component-nav {
    padding: 0 15px;
    position: sticky;
    top: 60px; /* Proper sticky positioning */
  }
  
  .app-container {
    /* Clean mobile container */
  }
  
  .component-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  
  .component-tabs::-webkit-scrollbar {
    display: none;
  }
  
  .component-tab {
    min-width: 100px;
    padding: 18px 12px; /* Larger touch target */
    font-size: 0.85rem;
    flex-shrink: 0;
    gap: 6px;
    min-height: 44px; /* iOS touch target */
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .tab-text {
    font-size: 0.8rem;
  }
  
  .tab-icon {
    font-size: 1.2rem;
  }
  
  .benchmark-content,
  .interpretability-content {
    padding: 15px;
  }
  
  /* Stack benchmark layout on mobile */
  .benchmark-main {
    grid-template-columns: 1fr !important;
    gap: 15px !important;
  }
  
  /* Stack methodology examples on mobile */
  .methodology-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }
  
  .info-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  
  .source-links {
    gap: 8px;
  }
  
  .source-link {
    font-size: 0.8rem;
    padding: 6px 10px;
  }
  
  .benchmark-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 15px;
  }
  
  .benchmark-selector select {
    min-width: auto;
    width: 100%;
  }
  
  .benchmark-actions {
    justify-content: center;
    gap: 8px;
  }
  
  .benchmark-btn {
    min-height: 44px; /* iOS touch target */
    padding: 14px 18px;
    font-size: 0.9rem;
    width: 100%; /* Full width on mobile */
  }
  
  .benchmark-selector select {
    min-height: 44px;
    padding: 12px 15px;
    font-size: 0.9rem;
  }
  
  .benchmark-metrics {
    grid-template-columns: 1fr 1fr;
  }
  
  .metric-value {
    font-size: 1.2rem;
  }
  
  #accuracy-chart {
    min-height: 200px;
  }
}

@media (max-width: 480px) {
  /* Very small screens - optimize for touch */
  .component-nav {
    padding: 0 10px;
  }
  
  .component-tab {
    min-width: 80px;
    padding: 14px 8px;
    font-size: 0.8rem;
  }
  
  .tab-text {
    font-size: 0.7rem;
  }
  
  .tab-icon {
    font-size: 1.1rem;
  }
  
  .tab-badge {
    display: none;
  }
  
  .benchmark-content {
    padding: 10px;
  }
  
  .benchmark-metrics {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  
  .metric-card {
    padding: 12px;
  }
  
  .metric-value {
    font-size: 1.3rem;
  }
  
  .benchmark-actions {
    flex-direction: column;
    gap: 8px;
  }
  
  .benchmark-btn {
    padding: 12px 20px;
    font-size: 0.9rem;
  }
  
  .methodology-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  
  .info-header {
    padding: 15px;
  }
  
  .info-content {
    padding: 15px;
  }
  
  .source-links {
    gap: 6px;
  }
  
  .source-link {
    font-size: 0.75rem;
    padding: 6px 8px;
  }
}

/* CRITICAL: Mobile selfplay stacking - must come after all other rules */
@media (max-width: 768px) {
  #selfplay-component.active {
    display: block !important; /* Switch to block layout on mobile */
    grid-template-columns: none !important; /* Remove grid */
    gap: 0 !important;
  }
  
  #selfplay-component.active .board-panel,
  #selfplay-component.active .analysis-panel {
    width: 100% !important;
    margin-bottom: 15px !important;
    grid-column: unset !important;
  }
  
  #selfplay-component.active .analysis-panel {
    margin-bottom: 0 !important;
  }
}
