/* FLL Robot Simulator - Dark Robotic Theme */

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-elevated: #2d333b;

  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;

  --accent-primary: #f97316;
  --accent-secondary: #22c55e;
  --accent-tertiary: #3b82f6;
  --accent-glow: rgba(249, 115, 22, 0.3);

  --border-color: #30363d;
  --border-glow: rgba(249, 115, 22, 0.5);

  --field-bg: #1a2332;
  --grid-line: rgba(59, 130, 246, 0.15);
  --grid-major: rgba(59, 130, 246, 0.3);

  --robot-body: #f97316;
  --robot-wheel: #1f2937;
  --trail-color: rgba(34, 197, 94, 0.7);

  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-display: 'Outfit', 'Inter', sans-serif;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 30px var(--accent-glow);
}

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

html, body {
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-display);
  line-height: 1.5;
}

body {
  background:
    radial-gradient(ellipse at 20% 20%, rgba(59, 130, 246, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(249, 115, 22, 0.06) 0%, transparent 50%),
    linear-gradient(180deg, var(--bg-primary) 0%, #0a0f14 100%);
  min-height: 100vh;
}

.app-container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent-primary), #fb923c);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

.badge {
  padding: 6px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.badge.secondary {
  border-color: var(--accent-tertiary);
  color: var(--accent-tertiary);
}

/* Main Content */
.main-content {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 20px;
}

/* Field Section */
.field-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
}

.field-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.field-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.robot-config {
  display: flex;
  gap: 20px;
}

.robot-config label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.robot-config input {
  width: 60px;
  padding: 6px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-align: right;
}

.robot-config input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.toggle-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-primary);
  cursor: pointer;
}

.canvas-container {
  flex: 1;
  position: relative;
  background: var(--field-bg);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 2px solid var(--border-color);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.5);
  /* Maintain 2:1 aspect ratio for 8'x4' table */
  aspect-ratio: 2 / 1;
  max-height: calc(100vh - 300px);
}

#fieldCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}

.field-overlay {
  position: absolute;
  pointer-events: none;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1;
}

#mapImage {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.field-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.position-display,
.mouse-display {
  display: flex;
  gap: 24px;
  color: var(--text-secondary);
}

.position-display span span,
.mouse-display span span {
  color: var(--accent-secondary);
  font-weight: 600;
}

.mouse-display span span {
  color: var(--accent-tertiary);
}

/* Code Section */
.code-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.code-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.code-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-tertiary);
  padding: 4px;
  border-radius: var(--radius-sm);
}

.tab {
  padding: 6px 16px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.tab.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.tab-content {
  display: none;
  flex: 1;
  min-height: 0;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
}

#codeEditor {
  flex: 1;
  min-height: 280px;
  padding: 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.7;
  resize: none;
  tab-size: 2;
}

#codeEditor:focus {
  outline: none;
  border-color: var(--accent-tertiary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Help Content */
.help-content {
  flex: 1;
  padding: 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow-y: auto;
  font-size: 0.85rem;
}

.help-content h3 {
  font-size: 1rem;
  margin-bottom: 16px;
  color: var(--accent-primary);
}

.api-section {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.api-section:last-child {
  border-bottom: none;
}

.api-section h4 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.api-section code {
  display: inline-block;
  padding: 4px 10px;
  margin-bottom: 6px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  color: var(--accent-secondary);
}

.api-section p {
  color: var(--text-secondary);
  margin-bottom: 10px;
  padding-left: 8px;
}

.api-section em {
  color: var(--accent-tertiary);
  font-style: normal;
}

/* Execution Controls */
.execution-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

.btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn:hover {
  background: var(--bg-elevated);
  border-color: var(--text-muted);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent-primary), #ea580c);
  border-color: transparent;
  color: white;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.btn.secondary {
  border-color: var(--accent-tertiary);
  color: var(--accent-tertiary);
}

.btn.secondary:hover {
  background: rgba(59, 130, 246, 0.15);
}

.btn .icon {
  font-size: 0.85rem;
}

.speed-control {
  margin-left: auto;
}

.speed-control label {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.speed-control input[type="range"] {
  width: 80px;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  -webkit-appearance: none;
  appearance: none;
}

.speed-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent-primary);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-glow);
}

/* Execution Log */
.execution-log {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

.execution-log h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#logOutput {
  max-height: 150px;
  overflow-y: auto;
  padding: 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

#logOutput .log-entry {
  padding: 4px 0;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  gap: 10px;
}

#logOutput .log-entry:last-child {
  border-bottom: none;
}

#logOutput .log-step {
  color: var(--text-muted);
  min-width: 30px;
}

#logOutput .log-command {
  color: var(--accent-secondary);
}

#logOutput .log-result {
  color: var(--text-secondary);
  margin-left: auto;
}

#logOutput .log-entry.active {
  background: rgba(249, 115, 22, 0.1);
  margin: 0 -12px;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
}

#logOutput .log-entry.active .log-command {
  color: var(--accent-primary);
}

#logOutput .log-error {
  color: #ef4444;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* Responsive */
@media (max-width: 1200px) {
  .main-content {
    grid-template-columns: 1fr;
  }

  .field-section {
    min-height: 500px;
  }
}

/* Animations */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.executing .btn.primary {
  animation: pulse 1s ease-in-out infinite;
}

