/* AIDriver Simulator - Custom Styles */
/* Bootstrap 5 overrides and custom components */

:root {
  --arena-bg: #1a1a2e;
  --arena-border: #4a4a6a;
  --path-color: #00ff88;
  --robot-color: #ff6b6b;
  --wall-color: #ffffff;
  --obstacle-color: #ff4444;
  --success-color: #28a745;
  --failure-color: #dc3545;
}

/* Body and Layout */
body {
  min-height: 100vh;
  padding-bottom: 60px; /* Space for status bar */
}

/* Editor Styling */
#editor {
  width: 100%;
  height: 500px;
  min-height: 400px;
  font-size: 14px;
  transition: height 0.3s ease-in-out, min-height 0.3s ease-in-out;
  /* Match card border-radius for bottom corners */
  border-bottom-left-radius: var(--bs-card-inner-border-radius, 0.375rem);
  border-bottom-right-radius: var(--bs-card-inner-border-radius, 0.375rem);
}

/* ACE Editor content also needs border-radius */
#editor .ace_scroller,
#editor .ace_content,
#editor .ace_gutter {
  border-bottom-left-radius: var(--bs-card-inner-border-radius, 0.375rem);
}

#editor .ace_scroller,
#editor .ace_content {
  border-bottom-right-radius: var(--bs-card-inner-border-radius, 0.375rem);
}

/* Reduced editor height for gamepad mode (Challenge 7) */
#editor.gamepad-mode {
  height: 250px !important;
  min-height: 200px !important;
}

/* Reduced editor height when running code */
#editor.running-mode {
  height: 250px !important;
  min-height: 200px !important;
}

/* Editor card shrinks to fit content in gamepad mode */
#editorCard.gamepad-mode {
  height: auto !important;
}

/* Debug panel under editor - always visible */
#debugPanelContainer {
  transition: max-height 0.3s ease-in-out;
}

/* Debug panel visible when running */
#debugPanelContainer.visible {
  max-height: 400px;
}

/* Arena Container */
.arena-container {
  position: relative;
  width: 100%;
  padding-top: 100%; /* 1:1 aspect ratio */
  background-color: var(--arena-bg);
  border: 2px solid var(--arena-border);
  border-radius: var(--bs-card-inner-border-radius, 0.375rem);
  overflow: hidden;
}

#arenaCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

/* Fix for card-body p-0 - ensure inner elements clip to card corners */
.card-body.p-0 > *:last-child {
  border-bottom-left-radius: var(--bs-card-inner-border-radius, 0.375rem);
  border-bottom-right-radius: var(--bs-card-inner-border-radius, 0.375rem);
}

.card-body.p-0 > *:first-child:last-child {
  border-radius: var(--bs-card-inner-border-radius, 0.375rem);
}

/* Card without header - first child needs top radius too */
.card > .card-body.p-0:first-child > *:first-child {
  border-top-left-radius: var(--bs-card-inner-border-radius, 0.375rem);
  border-top-right-radius: var(--bs-card-inner-border-radius, 0.375rem);
}

/* Debug Console */
.debug-console {
  background-color: #0d1117;
  color: #c9d1d9;
  font-family: "Consolas", "Monaco", "Courier New", monospace;
  font-size: 12px;
  padding: 10px;
  height: 150px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  /* Match card border-radius for bottom corners */
  border-bottom-left-radius: var(--bs-card-inner-border-radius, 0.375rem);
  border-bottom-right-radius: var(--bs-card-inner-border-radius, 0.375rem);
}

.debug-console .error {
  color: #f85149;
}

.debug-console .success {
  color: #3fb950;
}

.debug-console .warning {
  color: #d29922;
}

.debug-console .info {
  color: #58a6ff;
}

/* BLE Gamepad */
.gamepad-status {
  gap: 0.75rem;
}

.gamepad-layout {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  justify-content: center;
  align-items: stretch;
}

.joystick-column {
  flex: 1 1 280px;
  max-width: 360px;
}

.joystick-wrapper {
  display: flex;
  justify-content: center;
}

.joystick-track {
  position: relative;
  width: 100%;
  max-width: 320px;
  aspect-ratio: 1/1;
  background: radial-gradient(
    circle at center,
    #1f3a5f 0%,
    #112240 65%,
    #0b1628 100%
  );
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.6);
  touch-action: none;
}

.joystick-deadzone {
  position: absolute;
  inset: 30%;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  pointer-events: none;
}

.joystick-handle {
  position: absolute;
  width: 32%;
  height: 32%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #5fa8ff, #0056d6 70%);
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  transition: transform 0.08s ease;
}

.status-column {
  flex: 1 1 220px;
  max-width: 320px;
  display: flex;
  flex-direction: column;
}

.info-panel {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--bs-border-radius-lg, 0.5rem);
  padding: 1rem 1.25rem;
  color: #f8f9fa;
}

.info-heading {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(248, 249, 250, 0.6);
  margin-bottom: 0.25rem;
}

.info-value {
  font-size: 1.75rem;
  font-weight: 600;
  color: #f8f9fa;
}

.info-value.warning {
  color: #ffc107;
}

.info-value.danger {
  color: #ff6b6b;
}

.info-subtle {
  font-size: 0.75rem;
  color: rgba(248, 249, 250, 0.5);
}

#bleStateBadge {
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.status-column .info-panel + .info-panel {
  margin-top: 1rem;
}

@media (max-width: 576px) {
  .gamepad-status {
    flex-direction: column;
    align-items: stretch !important;
  }

  .gamepad-status > div:last-child {
    width: 100%;
    display: flex;
    justify-content: space-between;
  }

  .status-column {
    flex-direction: column;
    max-width: none;
  }

  .joystick-column {
    max-width: none;
  }
}

/* Speed Slider */
#speedSlider {
  max-width: 150px;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.loading-overlay.hidden {
  display: none;
}

/* Status Bar Variants */
.alert-success-status {
  background-color: var(--success-color);
  color: white;
}

.alert-failure-status {
  background-color: var(--failure-color);
  color: white;
}

/* Ultrasonic Display Animation */
#ultrasonicDisplay {
  min-width: 120px;
  text-align: center;
  transition: background-color 0.3s ease;
}

#ultrasonicDisplay.warning {
  background-color: #ffc107 !important;
  color: #000;
}

#ultrasonicDisplay.danger {
  background-color: #dc3545 !important;
}

/* Path on Canvas */
.path-line {
  stroke: var(--path-color);
  stroke-width: 3;
  fill: none;
  stroke-dasharray: 10, 5;
}

/* Robot Trail */
.robot-trail {
  stroke: rgba(255, 107, 107, 0.3);
  stroke-width: 2;
  fill: none;
}

/* Card heights for consistent layout */
.card.h-100 {
  display: flex;
  flex-direction: column;
}

.card.h-100 .card-body {
  flex: 1;
}

/* Collapse icon rotation */
#debugToggleIcon {
  transition: transform 0.3s ease;
}

[aria-expanded="false"] #debugToggleIcon {
  transform: rotate(-90deg);
}

/* Responsive adjustments */
@media (max-width: 991.98px) {
  #editor {
    height: 300px;
    min-height: 300px;
  }

  .arena-container {
    padding-top: 75%; /* Slightly less square on mobile */
  }

  .debug-console {
    height: 100px;
  }
}

@media (max-width: 575.98px) {
  .navbar-brand {
    font-size: 1rem;
  }

  .btn-group .btn {
    padding: 0.375rem 0.5rem;
  }

  .btn-group .btn span {
    display: none;
  }

  #speedSlider {
    max-width: 100px;
  }
}

/* Tooltip custom styles */
.tooltip-inner {
  max-width: 250px;
}

/* Offcanvas code styling */
.offcanvas code {
  background-color: #2d2d2d;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.85em;
}

/* Challenge dropdown active state */
.dropdown-item.active {
  background-color: #0d6efd;
}

/* Canvas success/failure overlays */
.arena-container.success::after {
  content: "✓ SUCCESS";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2rem;
  font-weight: bold;
  color: var(--success-color);
  text-shadow: 0 0 10px rgba(40, 167, 69, 0.8);
  pointer-events: none;
}

.arena-container.failure::after {
  content: "✗ FAILED";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2rem;
  font-weight: bold;
  color: var(--failure-color);
  text-shadow: 0 0 10px rgba(220, 53, 69, 0.8);
  pointer-events: none;
}

/* ACE Editor gutter error marker */
.ace_gutter-cell.ace_error {
  background-color: #ff4444 !important;
}

/* Execution line highlight */
.ace_executing-line {
  background-color: rgba(255, 255, 0, 0.2) !important;
}

/* Scrollbar styling for debug console */
.debug-console::-webkit-scrollbar {
  width: 8px;
}

.debug-console::-webkit-scrollbar-track {
  background: #1a1a1a;
}

.debug-console::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 4px;
}

.debug-console::-webkit-scrollbar-thumb:hover {
  background: #555;
}
