:root {
  --navy: #2c3e50;
  --softgray: #ecf0f1;
  --teal: #1abc9c;
  --gold: #f1c40f;
  --slate: #7f8c8d;
  --coral: #e74c3c;
  --white: #ffffff;
  --gray-100: #f7fafc;
  --gray-200: #edf2f7;
  --gray-300: #e2e8f0;
  --max-width: 1200px;
  --container-pad: 16px;
  --radius: 10px;
  --shadow-sm: 0 6px 18px rgba(0, 0, 0, 0.06);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.06);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: 'Montserrat', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    sans-serif;
  font-weight: 400;
  color: var(--navy);
  background: linear-gradient(135deg, #ecf0f1 0%, #d6dbdf 100%);
  min-height: 100vh;
  padding: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--container-pad);
}

/* ── Header ── */
.page-header {
  padding: 1rem 0 0.5rem;
}

.header-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

.header-left {
  justify-self: start;
}

.header-right {
  justify-self: end;
}

.header-title-block {
  justify-self: center;
  text-align: center;
}

.page-title {
  margin: 0;
  font-size: clamp(1.5rem, 3.4vw, 2.25rem);
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.page-subtitle {
  margin: 6px 0 0;
  font-size: clamp(0.95rem, 1.6vw, 1.05rem);
  font-weight: 400;
  color: var(--slate);
  line-height: 1.4;
}

/* ── Buttons ── */
.btn {
  display: inline-block;
  border-radius: 0.375rem;
  text-decoration: none;
  text-align: center;
  transition: all 0.2s;
  cursor: pointer;
  border: 1px solid transparent;
  font-size: 16px;
  font-weight: 600;
  padding: 12px 24px;
  width: auto;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.navy-btn {
  background-color: rgba(44, 62, 80, 0.8);
  color: #fff;
}

.navy-btn:hover {
  background-color: rgba(44, 62, 80, 0.7);
  transform: translateY(-2px);
}

.gold-btn {
  background-color: rgba(241, 196, 15, 1);
  color: var(--navy);
  opacity: 0.9;
}

.gold-btn:hover {
  background-color: rgba(241, 196, 15, 0.5);
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* ── Main layout ── */
.experiment-area {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 16px 0 64px;
}

.content-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
  align-items: start;
}

.sim-area {
  width: 100%;
  display: flex;
  justify-content: center;
}

.stage {
  display: block;
  width: 100%;
  max-width: 720px;
  height: auto;
  aspect-ratio: 720 / 480;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  touch-action: none;
  box-shadow: var(--shadow-sm);
}

.stage:focus,
.stage:focus-visible {
  outline: none;
}

/* ── Controls ── */
.controls {
  width: 100%;
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.control-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-group {
  border: none;
  padding: 0;
  margin: 0;
}

.control-legend {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--slate);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 8px;
  padding: 0;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--navy);
  background: var(--white);
  border: 1.5px solid var(--navy);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease,
    box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pill:hover {
  background: var(--gray-100);
}

.pill:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.pill.is-selected {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--white);
  box-shadow: 0 2px 6px rgba(26, 188, 156, 0.3);
}

.pill.is-selected:hover {
  background: var(--teal);
}

.btn-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  background: var(--white);
  color: var(--navy);
  border: 1.5px solid var(--navy);
  padding: 8px 16px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  width: 100%;
}

.btn-text:hover {
  color: var(--teal);
  border-color: var(--teal);
}

.btn-text:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.btn-text.coral-btn {
  background: rgba(231, 76, 60, 0.85);
  color: var(--white);
  border-color: rgba(231, 76, 60, 0.85);
}

.btn-text.coral-btn:hover {
  background: rgba(231, 76, 60, 0.75);
  border-color: rgba(231, 76, 60, 0.75);
  color: var(--white);
}

.control-row {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 4px 6px;
  margin: -4px -6px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--navy);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.toggle input[type='checkbox'] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--navy);
  border-radius: 3px;
  background: var(--white);
  cursor: pointer;
  position: relative;
  margin: 0;
  flex-shrink: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.toggle input[type='checkbox']:checked {
  background: var(--teal);
  border-color: var(--teal);
}

.toggle input[type='checkbox']:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 0px;
  width: 4px;
  height: 9px;
  border: solid var(--white);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.toggle input[type='checkbox']:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.toggle-label {
  line-height: 1;
}

.given-panel {
  margin-top: 8px;
  display: inline-flex;
  padding: 8px 12px;
  border: 1.5px solid var(--navy);
  border-radius: 6px;
  background: var(--gray-100);
  color: var(--navy);
  font-size: 0.82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.given-panel[hidden] {
  display: none;
}

.given-line {
  line-height: 1;
}

/* ── Guided Investigation ── */
.guided-section {
  width: 100%;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-top: 16px;
}

.guided-toggle {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.guided-toggle:hover {
  background: var(--gray-100);
}

.guided-toggle:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: -2px;
}

.guided-title {
  letter-spacing: -0.005em;
}

.guided-chevron {
  font-size: 0.95rem;
  color: var(--slate);
  transition: transform 0.3s ease;
  display: inline-block;
  line-height: 1;
}

.guided-toggle[aria-expanded='true'] .guided-chevron {
  transform: rotate(90deg);
}

.guided-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
}

.guided-content-inner {
  padding: 4px 22px 22px;
  max-width: 70ch;
  color: var(--navy);
  line-height: 1.6;
  font-size: 0.95rem;
}

.guided-content-inner h3 {
  margin: 22px 0 8px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.005em;
}

.guided-content-inner h3:first-child {
  margin-top: 8px;
}

.guided-content-inner p {
  margin: 0 0 10px;
}

.guided-list,
.guided-bullets {
  margin: 6px 0 14px;
  padding-left: 24px;
}

.guided-list li,
.guided-bullets li {
  margin-bottom: 8px;
}

.guided-list li:last-child,
.guided-bullets li:last-child {
  margin-bottom: 0;
}

.guided-list {
  list-style: decimal;
}

.guided-list > li::marker {
  color: var(--teal);
  font-weight: 700;
}

.guided-bullets {
  list-style: disc;
}

.guided-bullets > li::marker {
  color: var(--teal);
}

.guided-list .guided-bullets {
  margin: 6px 0 6px;
}

.guided-discussion {
  background: var(--gray-100);
  border-left: 3px solid var(--teal);
  padding: 10px 14px;
  border-radius: 0 6px 6px 0;
  margin: 6px 0 14px;
}

.guided-fill {
  margin: 8px 0 0;
  font-weight: 500;
}

.guided-blank {
  display: inline-block;
  min-width: 8ch;
  border-bottom: 1.5px solid var(--navy);
  margin: 0 4px;
  padding: 0 4px;
}

.sample-table-wrap {
  margin: 22px 0 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.sample-data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  color: var(--navy);
}

.sample-data caption {
  caption-side: top;
  text-align: left;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--slate);
  margin-bottom: 10px;
  text-transform: none;
  letter-spacing: 0;
}

.sample-data thead {
  background: var(--gray-100);
}

.sample-data th {
  text-align: right;
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
}

.sample-data th:first-child,
.sample-data td:first-child {
  text-align: left;
}

.sample-data td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--gray-200);
  text-align: right;
}

.sample-data tbody tr:last-child td {
  border-bottom: none;
}

/* ── Footer ── */
.site-footer {
  background: var(--navy);
  color: var(--white);
  text-align: center;
  padding: 16px;
  font-size: 0.8rem;
  margin-top: 32px;
}

.site-footer p {
  margin: 0;
}

/* ── Results Table ── */
.results-section {
  width: 100%;
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-top: 16px;
}

.results-title {
  margin: 0 0 16px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.005em;
}

.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  color: var(--navy);
}

.results-table thead {
  background: var(--gray-100);
}

.results-table th {
  text-align: center;
  font-weight: 600;
  padding: 10px 8px;
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
  font-size: 0.8rem;
}

.results-table td {
  padding: 8px;
  border-bottom: 1px solid var(--gray-200);
  text-align: center;
}

.result-input {
  width: 100%;
  padding: 6px 4px;
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  text-align: center;
  color: var(--navy);
}

.result-input:focus {
  outline: 2px solid var(--teal);
  outline-offset: 0;
  border-color: var(--teal);
}

.result-input::placeholder {
  color: var(--slate);
  opacity: 0.6;
}

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

  .controls {
    max-width: 400px;
    margin: 0 auto;
  }
}

@media (max-width: 640px) {
  .header-grid {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .header-left,
  .header-right,
  .header-title-block {
    justify-self: start;
    text-align: left;
  }

  .header-title-block {
    text-align: left;
  }

  .pill {
    padding: 6px 10px;
    font-size: 0.75rem;
  }

  .btn {
    padding: 10px 16px;
    font-size: 14px;
  }

  .guided-toggle {
    padding: 14px 16px;
  }

  .guided-content-inner {
    padding: 4px 16px 16px;
    font-size: 0.92rem;
  }
}

/* Validation indicators */
.validation-indicator {
  margin-left: 4px;
  display: inline-block;
  font-size: 1.2rem;
  font-weight: 700;
  vertical-align: middle;
}

.validation-tick {
  color: #27ae60;
}

.validation-cross {
  color: #e74c3c;
}
