/* ===== BASE STYLES ===== */
*,
*::before,
*::after {
  box-sizing: border-box; /* Include padding and borders in width */
}

body {
  margin: 0;
  overflow: hidden;
  background-color: #050505;
  font-family:
    'Segoe UI',
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app-container {
  display: flex;
  flex-direction: row;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#canvas-container {
  flex: 1;
  height: 100%;
  position: relative;
  background-color: #050505;
  touch-action: pan-y; /* Allow touch gestures for OrbitControls */
}

#btn-fullscreen {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 100;
  width: 48px;
  height: 48px;
  background: rgba(30, 40, 60, 0.8);
  border: 1px solid rgba(79, 172, 254, 0.4);
  border-radius: 12px;
  color: rgba(79, 172, 254, 0.9);
  font-size: 24px;
  display: none; /* Hidden by default (desktop) */
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: all 0.2s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#btn-fullscreen:active {
  transform: scale(0.92);
  background: rgba(79, 172, 254, 0.2);
}

/* Show fullscreen button on mobile devices (portrait) AND when in landscape mode with limited height */
@media screen and (max-width: 768px),
  screen and (max-height: 500px) and (orientation: landscape) {
  #btn-fullscreen {
    display: flex;
  }
}

/* ===== CONTROL PANEL ===== */
#ui-panel {
  flex-shrink: 0;
  width: 340px;
  height: 100vh;
  color: #eee;
  background: rgba(20, 20, 30, 1); /* Opaque for separate pane */
  padding: 20px;
  border-left: 1px solid #333;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 10;
  scrollbar-width: thin;
  scrollbar-color: #4facfe #333;
  box-sizing: border-box; /* Include padding in width calculation */
  touch-action: pan-y; /* Allow only vertical scrolling */
}

/* Webkit scrollbar styling */
#ui-panel::-webkit-scrollbar {
  width: 8px;
}

#ui-panel::-webkit-scrollbar-track {
  background: #222;
}

#ui-panel::-webkit-scrollbar-thumb {
  background: #4facfe;
  border-radius: 4px;
}

h1 {
  margin: 0 0 15px 0;
  font-size: 1.4rem;
  color: #4facfe;
  text-align: center;
  border-bottom: 1px solid #333;
  padding-bottom: 10px;
}

/* ===== STATISTICS ===== */
.stat-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
  font-size: 0.9rem;
}

.highlight {
  color: #00f260;
  font-weight: bold;
}

.stat-clickable {
  cursor: help;
  padding: 4px 6px;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.stat-clickable:hover {
  background-color: rgba(79, 172, 254, 0.1);
}

.stat-clickable:active {
  background-color: rgba(79, 172, 254, 0.2);
}

/* Tooltip for Statistics */
.stat-tooltip {
  position: fixed;
  background: rgba(20, 30, 40, 0.98);
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid #4facfe;
  font-size: 0.85rem;
  line-height: 1.5;
  max-width: 280px;
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.stat-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===== FORM CONTROLS ===== */
select {
  width: 100%;
  padding: 10px;
  margin-bottom: 15px;
  background: #333;
  color: white;
  border: 1px solid #4facfe;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  min-height: 44px; /* Touch-friendly */
}

select:focus {
  outline: none;
  border-color: #00f260;
  box-shadow: 0 0 0 2px rgba(0, 242, 96, 0.2);
}

/* ===== PARAMETER CONTROLS ===== */
.control-group {
  margin-top: 15px;
  border-top: 1px solid #333;
  padding-top: 15px;
}

.sub-control {
  margin-left: 10px;
  margin-bottom: 10px;
  padding-left: 10px;
  border-left: 2px solid #555;
}

label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: #ccc;
  line-height: 1.4;
}

input[type='range'] {
  width: 100%;
  margin-bottom: 12px;
  cursor: pointer;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #444;
  border-radius: 3px;
  outline: none;
  touch-action: none; /* Crucial for mobile dragging */
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: #4facfe;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
}

input[type='range']::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: #4facfe;
  border-radius: 50%;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

input[type='range']::-webkit-slider-thumb:hover {
  background: #00f260;
  transform: scale(1.2);
}

input[type='range']::-moz-range-thumb:hover {
  background: #00f260;
  transform: scale(1.2);
}

input[type='checkbox'] {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: #4facfe;
}

/* ===== BUTTONS ===== */
.btn-container {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  margin-bottom: 15px;
}

button {
  flex: 1;
  padding: 12px 16px;
  background: #333;
  border: 1px solid #555;
  color: white;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
  font-weight: bold;
  font-size: 14px;
  min-height: 44px; /* Touch-friendly */
}

button:hover {
  background: #4facfe;
  border-color: #4facfe;
  color: black;
}

button:active {
  transform: scale(0.98);
}

button.active {
  background: #00f260;
  border-color: #00f260;
  color: black;
}

/* ===== INFO BOX ===== */
#analogy-box {
  margin-top: 5px;
  padding: 12px;
  background: rgba(79, 172, 254, 0.1);
  border-left: 4px solid #4facfe;
  font-size: 0.85rem;
  line-height: 1.5;
  font-style: italic;
  margin-bottom: 15px;
  border-radius: 4px;
}

/* ===== CHART ===== */
.chart-container {
  margin-top: 20px;
  height: 150px;
  border-top: 1px solid #333;
  padding-top: 10px;
}

/* ===== SPECIAL BUTTONS ===== */
#btn-compare {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  color: #000; /* High contrast: Black on Light Blue */
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 800;
  border: none;
  padding: 12px;
  border-radius: 8px;
  width: 100%;
  margin-bottom: 15px;
  box-shadow: 0 4px 15px rgba(79, 172, 254, 0.3);
}

#btn-compare:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(79, 172, 254, 0.4);
}

#btn-compare:active {
  transform: translateY(0);
}

#btn-export {
  width: 100%;
  margin-bottom: 20px;
  background: #222;
  border-color: #666;
  font-size: 0.85rem;
}

/* ===== TABLET BREAKPOINT (Portrait iPads, small tablets) ===== */
@media screen and (max-width: 1024px) and (min-width: 769px) {
  #ui-panel {
    width: 300px;
    padding: 16px;
  }

  h1 {
    font-size: 1.2rem;
  }

  .chart-container {
    height: 130px;
  }
}

/* ===== MOBILE BREAKPOINT (Phones and small tablets) ===== */
@media screen and (max-width: 768px) {
  #ui-panel {
    width: 300px; /* Narrower panel for landscape mobile */
    padding: 16px 12px;
    padding-bottom: 80px; /* Extra bottom padding for chart visibility */
    background: rgba(20, 25, 35, 0.98); /* Softer dark background */
    box-sizing: border-box;
  }

  h1 {
    font-size: 1.25rem;
    margin-bottom: 16px;
    padding-bottom: 12px;
    position: relative;
    color: rgba(79, 172, 254, 0.95); /* Softer blue */
    border-bottom-color: rgba(255, 255, 255, 0.1); /* Subtle separator */
  }

  /* Softer select styling */
  select {
    background: rgba(30, 35, 45, 0.8);
    border-color: rgba(79, 172, 254, 0.3);
    box-sizing: border-box;
    width: 100%;
  }

  select:focus {
    border-color: rgba(79, 172, 254, 0.6);
    box-shadow: 0 0 0 2px rgba(79, 172, 254, 0.15);
  }

  /* Softer button styling */
  button {
    background: rgba(30, 35, 45, 0.8);
    border-color: rgba(255, 255, 255, 0.15);
    box-sizing: border-box;
  }

  button:hover {
    background: rgba(79, 172, 254, 0.2);
    border-color: rgba(79, 172, 254, 0.5);
    color: rgba(79, 172, 254, 1);
  }

  button.active {
    background: rgba(0, 242, 96, 0.15);
    border-color: rgba(0, 242, 96, 0.5);
    color: rgba(0, 242, 96, 1);
  }

  /* Softer range slider */
  input[type='range'] {
    background: rgba(255, 255, 255, 0.1);
    width: 100%;
    box-sizing: border-box;
    touch-action: none; /* Prevent panel scroll while sliding */
  }

  input[type='range']::-webkit-slider-thumb {
    background: rgba(79, 172, 254, 0.9);
  }

  input[type='range']::-moz-range-thumb {
    background: rgba(79, 172, 254, 0.9);
  }

  input[type='range']::-webkit-slider-thumb:hover {
    background: rgba(79, 172, 254, 1);
  }

  input[type='range']::-moz-range-thumb:hover {
    background: rgba(79, 172, 254, 1);
  }

  /* Larger touch targets */
  select,
  button {
    min-height: 48px;
    font-size: 16px; /* Prevent zoom on iOS */
  }

  input[type='range'] {
    height: 8px;
  }

  input[type='range']::-webkit-slider-thumb {
    width: 26px;
    height: 26px;
  }

  input[type='range']::-moz-range-thumb {
    width: 26px;
    height: 26px;
  }

  input[type='checkbox'] {
    width: 22px;
    height: 22px;
    accent-color: rgba(79, 172, 254, 0.9);
  }

  .chart-container {
    height: 140px; /* Increased height for better visibility */
    border-top-color: rgba(255, 255, 255, 0.1);
    margin-bottom: 20px; /* Space at bottom */
    width: 100%;
    box-sizing: border-box;
  }

  .chart-container canvas {
    max-width: 100%;
    height: auto !important;
  }

  /* Better visual separation with softer borders */
  .control-group {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }

  label {
    font-size: 0.9rem;
    margin-bottom: 6px;
    color: rgba(255, 255, 255, 0.7); /* Softer label color */
  }

  .stat-row {
    font-size: 0.95rem;
    padding: 4px 0;
  }

  .highlight {
    color: rgba(0, 242, 96, 0.95); /* Softer green */
  }

  #analogy-box {
    font-size: 0.85rem;
    padding: 10px;
    margin-bottom: 12px;
    line-height: 1.5;
    background: rgba(79, 172, 254, 0.08); /* Softer background */
    border-left-color: rgba(79, 172, 254, 0.5); /* Softer accent */
  }

  /* Softer special buttons */
  #btn-compare {
    background: linear-gradient(
      135deg,
      rgba(79, 172, 254, 0.9) 0%,
      rgba(0, 242, 254, 0.9) 100%
    );
    border: 1px solid rgba(79, 172, 254, 0.4);
    color: #000; /* High contrast for mobile as well */
    width: 100%;
    box-sizing: border-box;
    font-weight: 800;
  }

  #btn-compare:hover {
    background: linear-gradient(
      135deg,
      rgba(79, 172, 254, 0.4) 0%,
      rgba(0, 242, 254, 0.4) 100%
    );
    box-shadow: 0 6px 20px rgba(79, 172, 254, 0.2);
  }

  #btn-export {
    background: rgba(20, 25, 30, 0.8);
    border-color: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.8);
    width: 100%;
    box-sizing: border-box;
  }
}

/* ===== SMALL MOBILE BREAKPOINT (Small phones) ===== */
@media screen and (max-width: 480px) {
  #ui-panel {
    width: 100%; /* Full width on small screens */
    max-width: 100%;
  }

  h1 {
    font-size: 1.15rem;
    padding-right: 36px;
  }

  .btn-container {
    gap: 8px;
  }

  button {
    padding: 10px 12px;
    font-size: 15px;
  }

  #analogy-box {
    font-size: 0.8rem;
    padding: 8px;
    line-height: 1.4;
  }

  .chart-container {
    height: 120px;
  }

  .control-group {
    margin-top: 12px;
    padding-top: 12px;
  }

  label {
    font-size: 0.85rem;
  }
}

/* Modern Mini Button */
.modern-mini-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  background: rgba(40, 40, 40, 0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  padding: 0;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.modern-mini-btn:hover {
  background: rgba(79, 172, 254, 0.6);
  border-color: rgba(79, 172, 254, 0.8);
  transform: scale(1.1) translateY(-2px);
  box-shadow: 0 6px 20px rgba(79, 172, 254, 0.4);
}

.modern-mini-btn:active {
  transform: scale(0.95);
}

.chart-container {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 5px;
  margin-top: 5px;
  overflow: hidden;
}

/* ===== ROTATE DEVICE PROMPT ===== */
#rotate-prompt {
  display: none; /* Hidden by default */
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    135deg,
    rgba(5, 5, 5, 0.98) 0%,
    rgba(20, 30, 50, 0.98) 100%
  );
  z-index: 9999; /* Above everything */
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(10px);
  animation: fadeIn 0.4s ease;
}

.rotate-prompt-content {
  text-align: center;
  padding: 40px;
  max-width: 90%;
}

.rotate-icon {
  font-size: 80px;
  margin-bottom: 20px;
  animation: rotatePhone 2s ease-in-out infinite;
  display: inline-block;
}

.rotate-prompt-content h2 {
  color: #4facfe;
  font-size: 1.8rem;
  margin: 0 0 15px 0;
  font-weight: 600;
  text-shadow: 0 2px 10px rgba(79, 172, 254, 0.3);
}

.rotate-prompt-content p {
  color: rgba(255, 255, 255, 0.8);
  font-size: 1rem;
  margin: 0;
  line-height: 1.6;
}

/* Show prompt only on mobile in portrait mode */
@media screen and (max-width: 768px) and (orientation: portrait) {
  #rotate-prompt {
    display: flex;
  }
}

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

@keyframes rotatePhone {
  0%,
  100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-15deg);
  }
  75% {
    transform: rotate(15deg);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translate(-50%, -50%);
  }
  10%,
  30%,
  50%,
  70%,
  90% {
    transform: translate(-52%, -50%);
  }
  20%,
  40%,
  60%,
  80% {
    transform: translate(-48%, -50%);
  }
}

@keyframes shakeDialog {
  0%,
  100% {
    transform: translateX(0);
  }
  10%,
  30%,
  50%,
  70%,
  90% {
    transform: translateX(-8px);
  }
  20%,
  40%,
  60%,
  80% {
    transform: translateX(8px);
  }
}

/* ===== LANDSCAPE MOBILE OPTIMIZATION ===== */
@media screen and (max-height: 500px) and (orientation: landscape) {
  #ui-panel {
    padding: 10px 8px;
    padding-top: 40px;
  }

  h1 {
    font-size: 1rem;
    margin-bottom: 6px;
    padding-bottom: 6px;
  }

  .control-group {
    margin-top: 8px;
    padding-top: 8px;
  }

  .chart-container {
    height: 180px; /* Increased from 80px */
    margin-top: 15px;
    padding-bottom: 15px;
  }

  #analogy-box {
    margin-bottom: 8px;
    padding: 6px;
    font-size: 0.7rem;
  }

  label {
    margin-bottom: 2px;
    font-size: 0.75rem;
  }

  input[type='range'] {
    margin-bottom: 6px;
    touch-action: none;
  }

  button {
    min-height: 40px;
    font-size: 13px;
    padding: 8px 10px;
  }

  .stat-row {
    font-size: 0.85rem;
    padding: 2px 0;
  }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .rotate-icon {
    animation: none !important;
  }

  #rotate-prompt {
    animation: none !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  #ui-panel {
    background: rgba(0, 0, 0, 0.98);
    border-left: 2px solid #4facfe;
  }

  button {
    border-width: 2px;
  }
}
/* ===== CHART MODAL STYLES ===== */
.modal {
  display: none;
  position: fixed;
  z-index: 20000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: #111;
  width: 90%;
  height: 85%;
  border-radius: 16px;
  border: 1px solid #333;
  display: flex;
  flex-direction: column;
  box-shadow: 0 15px 50px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.modal-header {
  padding: 15px 25px;
  background: #1a1a1a;
  border-bottom: 1px solid #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.2rem;
  color: #fff;
}

.modal-controls {
  display: flex;
  gap: 12px;
  align-items: center;
}

.modal-controls button {
  background: #333;
  border: 1px solid #444;
  color: #fff;
  padding: 6px 15px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.2s;
}

.modal-controls button:hover {
  background: #444;
}

.modal-controls .close-btn {
  background: #c00;
  border-color: #f33;
}

.modal-controls .close-btn:hover {
  background: #f00;
}

.modal-body {
  flex: 1;
  padding: 20px;
  position: relative;
  min-height: 0; /* Important for flex child canvas scaling */
}

@media screen and (max-width: 768px) {
  .modal-content {
    width: 98%;
    height: 95%;
  }

  .modal-header {
    padding: 10px 15px;
  }

  .modal-controls {
    gap: 6px;
  }

  .modal-controls button {
    padding: 6px 10px;
    font-size: 0.9rem;
  }
}

/* ===== ALGORITHM INFO BUTTON ===== */
.info-icon {
  all: unset; /* Reset everything */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: rgba(79, 172, 254, 0.15);
  border: 1px solid rgba(79, 172, 254, 0.4);
  border-radius: 50%;
  color: #4facfe;
  font-size: 0.85rem;
  cursor: pointer;
  transition:
    background 0.2s,
    transform 0.2s;
}

.info-icon:hover {
  background: rgba(79, 172, 254, 0.3);
  transform: scale(1.05);
}

/* ===== ALGORITHM INFO MODAL ===== */
.algo-info-content {
  background: #151520;
  border: 1px solid #333;
  border-radius: 12px;
  width: 90%;
  max-width: 420px;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.algo-info-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background: #1a1a28;
  border-bottom: 1px solid #333;
}

.algo-info-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #4facfe;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.algo-info-header button {
  all: unset; /* Reset all inherited button styles */
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  color: #777;
  font-size: 1rem;
  cursor: pointer;
  transition:
    color 0.2s,
    background 0.2s;
}

.algo-info-header button:hover {
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.1);
}

.algo-info-body {
  padding: 20px;
  color: #ccc;
  font-size: 0.92rem;
  line-height: 1.65;
}

.algo-info-body p {
  margin: 0;
}

/* Mobile adjustments */
@media screen and (max-width: 480px) {
  .algo-info-content {
    width: 95%;
  }

  .algo-info-body {
    padding: 16px;
    font-size: 0.88rem;
  }
}
