:root {
  --primary-color: #007bff;
  --secondary-color: #6c757d;
  --success-color: #28a745;
  --warning-color: #fd7e14;
  --danger-color: #dc3545;
  --highlight-color: #6f42c1;
  --normal-curve-color: #17a2b8;
  --light-bg: #f8f9fa;
  --dark-text: #343a40;
  --medium-text: #6c757d;
  --border-color: #dee2e6;
  --canvas-bg: #ffffff;
  --pop-line-color: var(--primary-color);
  --pop-fill-color: rgba(0, 123, 255, 0.15);
  --sample-bar-fill: var(--success-color);
  --sample-bar-stroke: #1c7430;
  --sampling-bar-fill: var(--success-color);
  --sampling-bar-stroke: #1c7430;
  --anim-marker-color: rgba(40, 167, 69, 0.8);
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.3;
  padding: 1px;
  background-color: var(--light-bg);
  color: var(--dark-text);
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 13px;
}

h1 {
  font-size: 1.1em;
  margin-bottom: 1px;
  text-align: center;
  width: 100%;
  color: var(--dark-text);
  font-weight: 600;
}

h2 {
  font-size: 0.9em;
  margin-bottom: 1px;
  text-align: left;
  width: 100%;
  font-weight: 600;
  color: var(--dark-text);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 3px;
}

h3 {
  font-size: 0.8em;
  margin-bottom: 3px;
  margin-top: 1px;
  text-align: left;
  width: 100%;
  font-weight: 600;
  color: var(--dark-text);
}

.main-container {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  max-width: 480px;
  gap: 1px;
}

.simulation-section {
  background-color: var(--canvas-bg);
  padding: 6px;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
  border: 1px solid var(--border-color);
  margin-bottom: 10px;
}

.reset-container {
  width: 100%;
  max-width: 480px;
  text-align: right;
  margin-bottom: 6px;
  box-sizing: border-box;
  padding-right: 0;
}

.reset-button {
  padding: 3px 8px;
  font-size: 0.9em;
  cursor: pointer;
  background-color: var(--danger-color);
  color: white;
  border: none;
  border-radius: 3px;
  transition: background-color 0.2s ease;
}

.reset-button:hover {
  background-color: #c82333;
}

.reset-button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

.controls {
  background-color: #ffffff;
  padding: 3px 6px;
  border-radius: 3px;
  border: 1px solid #dee2e6;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
  text-align: left;
  margin-bottom: 6px;
  width: 100%;
  box-sizing: border-box;
  font-size: 0.85em;
}

#sampleControls,
#samplingDistControls {
  background-color: transparent;
  border: none;
  box-shadow: none;
  padding: 4px 0;
  margin-bottom: 5px;
}

.controls label {
  margin: 0 4px 0 1px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}

.controls input[type="radio"],
.controls input[type="checkbox"] {
  margin-right: 3px;
  cursor: pointer;
  vertical-align: middle;
  transform: scale(0.85);
  margin-top: -1px;
}

.controls > span:first-of-type {
  font-weight: 600;
  margin-right: 4px;
  flex-shrink: 0;
}

.control-group {
  margin-bottom: 5px;
}

.button-group {
  margin-top: 5px;
  text-align: left;
}

#sampleControls .button-group button {
  padding: 1px 5px;
  font-size: 0.9em;
  cursor: pointer;
  background-color: var(--success-color);
  color: white;
  border: none;
  border-radius: 3px;
  margin-right: 6px;
  margin-left: 0;
  transition: background-color 0.2s ease;
}

#sampleControls .button-group button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

#sampleControls .button-group button:hover:not(:disabled) {
  background-color: #218838;
}

.controls .checkbox-label {
  margin-left: 15px;
}

.content-area {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
}

.canvas-container {
  position: relative;
  flex-grow: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
  max-width: 80%;
}

.population-canvas,
.sample-canvas,
.sampling-dist-canvas {
  border: 1px solid var(--border-color);
  background-color: var(--canvas-bg);
  width: 100%;
  height: 125px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05) inset;
  display: block;
  max-width: none;
}

.population-canvas {
  cursor: crosshair;
}

.sample-canvas,
.sampling-dist-canvas {
  cursor: default;
}

.stats-display {
  border: 1px solid var(--border-color);
  padding: 4px 8px;
  background-color: #fdfdfd;
  border-radius: 4px;
  width: 130px;
  min-width: 115px;
  box-shadow: none;
  flex-shrink: 0;
  font-size: 0.75em;
  align-self: stretch;
}

.stats-display h2 {
  margin-top: 0;
  font-size: 1.05em;
  border-bottom: 1px solid #eee;
  padding-bottom: 2px;
  margin-bottom: 4px;
  font-weight: 600;
}

.stats-display p {
  margin: 1px 0;
  clear: both;
  display: flex;
  justify-content: space-between;
}

.stats-display span {
  font-weight: bold;
  color: var(--primary-color);
  text-align: right;
}

.stats-display .count {
  font-weight: bold;
  color: var(--dark-text);
}

p.instructions {
  text-align: left;
  margin: 0 0 6px 0;
  color: var(--medium-text);
  font-style: italic;
  font-size: 0.8em;
  width: 100%;
}

@media (max-width: 500px) {
  body {
    font-size: 12px;
  }

  .main-container {
    max-width: 97%;
    gap: 8px;
  }

  .reset-container {
    padding-right: 0;
    margin-bottom: 6px;
  }

  .simulation-section {
    padding: 10px;
  }

  .content-area {
    flex-wrap: wrap;
    gap: 8px;
  }

  .canvas-container {
    width: 100%;
    max-width: none;
    margin-bottom: 8px;
    flex-grow: 0;
  }

  .population-canvas,
  .sample-canvas,
  .sampling-dist-canvas {
    width: 100%;
    max-width: none;
    height: auto;
    aspect-ratio: 2 / 1;
  }

  .stats-display {
    width: 100%;
    max-width: none;
    min-width: 0;
    margin-top: 5px;
    align-self: auto;
    width: auto;
  }

  .controls {
    font-size: 0.9em;
    padding: 4px 0;
  }

  #presetControls {
    background-color: #ffffff;
    padding: 3px 6px;
    border-radius: 3px;
    border: 1px solid #dee2e6;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
  }

  h1 {
    font-size: 1.1em;
  }

  h2 {
    font-size: 0.9em;
  }

  h3 {
    font-size: 0.85em;
  }

  .button-group {
    margin-top: 6px;
    text-align: center;
  }

  #sampleControls .button-group button {
    margin-right: 4px;
    padding: 2px 5px;
  }

  .controls label {
    margin-right: 2px;
  }

  .controls .checkbox-label {
    margin-left: 10px;
  }

  .reset-button {
    font-size: 0.9em;
    padding: 3px 8px;
  }
}
