/* Reset & base */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  overflow-x: hidden;
  margin: 0;
  min-height: 100vh;
}
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  background: #f5f7fa;
  color: #333;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
}
header, footer {
  /* Replace solid background with gradient */
  background: linear-gradient(135deg, #e74c3c 0%, #8e44ad 50%, #3498db 100%);
  color: #fff;
  text-align: center;
  padding: 1.5rem 2rem;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1, h2, h3 { font-weight: 600; }
h1 { 
  font-size: 2rem; 
  letter-spacing: 0.5px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
h2 { font-size: 1.25rem; margin-bottom: .75rem; }
h3 { font-size: 1rem; margin-top: 1.25rem; margin-bottom: .5rem; }

/* Intro */
#intro {
  background: #fff;
  padding: 2rem;
  border-bottom: 1px solid #ddd;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  flex-shrink: 0;
}
#intro h2 {
  font-size: 1.5rem;
  color: #2c3e50;
  margin-bottom: 1rem;
}
/* Intro content and steps */
.intro-content {
  max-width: 900px;
  margin: 0 auto;
}
.intro-content > p {
  margin-bottom: 1.25rem;
  line-height: 1.6;
  font-size: 1.05rem;
  text-align: center;
}
.intro-steps {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}
.intro-step {
  flex: 1;
  min-width: 200px;
  background: #f8f9fa;
  padding: 1rem;
  border-radius: 6px;
  border-left: 3px solid;
}
.intro-step:nth-child(1) {
  border-left-color: #3498db;
}
.intro-step:nth-child(2) {
  border-left-color: #e74c3c;
}
.intro-step:nth-child(3) {
  border-left-color: #8e44ad;
}
.intro-step strong {
  display: block;
  margin-bottom: 0.5rem;
  color: #2c3e50;
  font-size: 1.1rem;
}
.intro-step p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #555;
}

/* Layout */
.container {
  flex: 1;
  display: flex;
  gap: 1.25rem;
  padding: 1.25rem;
}

/* Controls sidebar */
.controls {
  width: 300px;
  background: #fff;
  padding: 1.25rem;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  height: auto;
  overflow: visible;
  position: sticky;
  top: 1.25rem;
  align-self: flex-start;
}

/* Control section headers */
.controls h2 {
  font-size: 1.35rem;
  margin-bottom: 1.25rem;
  color: #2c3e50;
}
.controls h3 {
  font-size: 1.1rem;
  margin-top: 1.75rem;
  margin-bottom: 1.25rem;
  color: #2c3e50;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid #eee;
}

/* Form fields */
.controls .field {
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
}
.controls .field label {
  flex: 0 0 80px;
  font-size: 0.95rem;
  color: #555;
}
.controls .field input[type="number"],
.controls .field input[type="text"] {
  flex: 1;
  padding: 0.6rem 0.8rem;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
  transition: all 0.2s ease;
  max-width: 180px; /* Limit width of text boxes */
}
.controls .field input[type="number"] {
  max-width: 100px; /* Shorter width for number inputs */
}
.controls .field input[type="number"]:focus,
.controls .field input[type="text"]:focus {
  border-color: #3498db;
  box-shadow: 0 0 0 2px rgba(52,152,219,0.15);
  outline: none;
}

/* Range inputs */
.controls .field.range {
  margin-bottom: 1.25rem;
  display: grid;
  grid-template-columns: 80px 1fr 40px;
  align-items: center;
  gap: 0.5rem;
}
.controls .field.range label {
  flex: 0;
}
.controls .field.range input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: #e0e0e0;
  border-radius: 3px;
  outline: none;
}
.controls .field.range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: #3498db;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.controls .field.range output {
  width: 35px;
  text-align: right;
  font-size: 0.95rem;
  font-weight: 500;
  color: #444;
}

/* Run simulation button */
.controls button {
  margin-top: 1.75rem;
  width: 100%;
  padding: 0.9rem;
  background: linear-gradient(135deg, #e74c3c 0%, #8e44ad 50%, #3498db 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1.05rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.controls button:hover {
  background: linear-gradient(135deg, #c0392b 0%, #8e44ad 50%, #2980b9 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

/* Walkthrough Button */
.walkthrough-btn {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  background: linear-gradient(135deg, #e74c3c 0%, #8e44ad 50%, #3498db 100%);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
  display: block;
  margin: 1rem auto;
}
.walkthrough-btn:hover {
  background: linear-gradient(135deg, #c0392b 0%, #8e44ad 50%, #2980b9 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

/* Floating walkthrough button */
.walkthrough-floating {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e74c3c 0%, #8e44ad 50%, #3498db 100%);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0,0,0,0.25);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  transform: scale(0);
  transition: transform 0.3s ease;
}

.walkthrough-floating.visible {
  transform: scale(1);
}

.walkthrough-floating:hover {
  transform: scale(1.1);
  background: linear-gradient(135deg, #c0392b 0%, #8e44ad 50%, #2980b9 100%);
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.6);
  z-index: 100;
  overflow-y: auto;
}
.modal-content {
  background-color: white;
  margin: 2rem auto;
  padding: 2rem;
  width: 90%;
  max-width: 800px;
  border-radius: 8px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
  max-height: 85vh;
  overflow-y: auto;
}
.modal h2 {
  margin-top: 0;
  color: #2c3e50;
  border-bottom: 2px solid #f3f3f3;
  padding-bottom: 0.75rem;
}
.walkthrough-section {
  margin-bottom: 2rem;
}
.walkthrough-section h3 {
  color: #2c3e50;
  font-size: 1.1rem;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
}
.walkthrough-section p {
  margin-bottom: 1rem;
  line-height: 1.5;
}
.walkthrough-section ul, 
.walkthrough-section ol {
  margin-left: 1.5rem;
  margin-bottom: 1rem;
}
.walkthrough-section li {
  margin-bottom: 0.75rem;
  line-height: 1.5;
}
.close-modal {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  font-size: 1.5rem;
  cursor: pointer;
  color: #777;
}
.close-modal:hover {
  color: #333;
}
.close-walkthrough {
  display: block;
  margin: 1.5rem auto 0;
  padding: 0.75rem 1.5rem;
  background: #2c3e50;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
}
.close-walkthrough:hover {
  background: #1e2a38;
}

/* Visuals */
.visuals {
  flex: 1;
  display: grid;
  grid-template:
    "s s s s" auto
    "a b c d" auto
    "f f f f" auto / 1fr 1fr 1fr 1fr;
  gap: 1.25rem;
  height: auto;
}
.visuals > div,
.visuals > .hist-panel {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  padding: 1rem;
  position: relative;
}

/* Make scatter plot larger */
#scatter {
  grid-area: s;
  height: 500px; /* Make taller to better fit the 3D plot */
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* Ensure the plotly container fills the available space */
#scatter .js-plotly-plot {
  flex: 1;
  width: 100%;
  height: 100%;
}

/* Make fail count full width */
#failCount {
  grid-area: f;
  grid-template-columns: 1fr 1fr 1fr;
}

/* Histogram panels */
.hist-panel {
  display: flex;
  flex-direction: column;
  min-height: 300px;
}
.slider-under {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #eee;
}
/* Style histogram sliders to match the controls panel sliders */
.slider-under input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: #e0e0e0;
  border-radius: 3px;
  outline: none;
}
.slider-under input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: #e74c3c;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.slider-under output {
  width: 35px;
  text-align: right;
  font-size: 0.95rem;
  font-weight: 500;
  color: #444;
}
.slider-under label {
  font-size: 0.95rem;
  color: #555;
  margin-right: 0.5rem;
}
.slider-under {
  margin-top: 1rem;
  padding-top: 0.5rem;
  border-top: 1px solid #eee;
}
.caption {
  margin-top: 0.75rem;
  font-size: .85rem;
  color: #555;
  line-height: 1.4;
}

/* Histogram direction toggle */
.direction-toggle {
  margin-left: 0.5rem;
}

.toggle-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: #f5f5f5;
  border: 1px solid #ddd;
  cursor: pointer;
  transition: all 0.2s ease;
}

.toggle-btn:hover {
  background: #e0e0e0;
}

.toggle-btn.right .direction-icon {
  transform: rotate(180deg);
}

/* Fill-in paragraph styling */
.fill-in-paragraph {
  line-height: 1.6;
  margin-bottom: 1rem;
  font-size: 0.95rem;
  color: #444;
}

.fill-in-paragraph strong {
  color: #2c3e50;
  padding: 0 0.2rem;
}

/* Binary pie panel */
.binary-pie-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.binary-pie {
  width: 100%;
  height: 240px;
}

/* Histogram comparisons chart */
.compare-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.compare-chart {
  width: 100%;
  height: 240px;
}

/* Caption for binary and comparisons panels */
.binary-pie-panel .caption,
.compare-panel .caption {
  width: 90%;
  text-align: center;
  font-size: 0.95rem;
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: #f8f9fa;
  border-left: 4px solid #8e44ad;
  border-radius: 0 4px 4px 0;
  line-height: 1.6;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
  .visuals {
    grid-template:
      "s s" auto
      "a b" auto
      "c d" auto
      "f f" auto / 1fr 1fr;
  }
  #failCount {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  .container {
    flex-direction: column;
  }
  .controls {
    width: 100%;
    height: auto;
    position: static;
  }
  .visuals {
    grid-template:
      "s" auto
      "a" auto
      "b" auto
      "c" auto
      "d" auto
      "f" auto / 1fr;
  }
}

/* Attribution styling */
.attribution {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  opacity: 0.9;
}

.attribution a {
  color: #fff;
  text-decoration: none;
  border-bottom: 1px dotted rgba(255,255,255,0.6);
  transition: all 0.2s ease;
}

.attribution a:hover {
  border-bottom-color: #fff;
  text-shadow: 0 0 3px rgba(255,255,255,0.3);
}
