:root {
  --navy: #2c3e50;
  --softgray: #e9ecef;
  --teal: #1abc9c;
  --gold: #f1c40f;
  --slate: #556366;
  --coral: #e74c3c;
  --white: #ffffff;
  --gray-100: #f7fafc;
  --gray-200: #edf2f7;
  --gray-300: #e2e8f0;
  --max-width: 1120px;
  --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);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial;
  color: var(--navy);
  background: linear-gradient(135deg, #ecf0f1 0%, #d6dbdf 100%);
  padding: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Responsive container */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
}

li {
  line-height: 2;
}

/* Page header */
.header-left {
  justify-self: start;
}

.page-header {
  text-align: center;
  color: var(--navy);
  padding: 1rem;
  position: relative;
}

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

.page-title {
  margin: 0;
  justify-self: center; /* ensures exact centering of the title cell */
  font-size: 2rem;
  font-weight: 700;
  font-family: 'Montserrat', sans-serif;
}

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

.cols {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* mobile: stack nicely */
@media (max-width: 767px) {
  .header-grid {
    grid-template-columns: 1fr; /* stack everything */
    grid-auto-flow: row;
    text-align: left;
  }
  .page-title { justify-self: start; }
  .header-actions { justify-self: start; width: 100%; margin-top: 8px; }
  .quiz-btn { width: 100%; max-width: 420px; }
}

/* Experiment area */
.experiment-area {
  background: var(--gray-100);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 24px;
}

.sim-area {
  background: var(--softgray);
  border-radius: 8px;
  padding: 12px;
  position: relative;
  overflow: hidden;
  height: 400px;
}

/* Controls */
.controls {
  background: white;
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

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

.label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--slate);
  font-weight: 600;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.range {
  flex: 1;
}

.value {
  display: inline-block;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(26, 188, 156, 0.12);
  color: var(--teal);
  min-width: 64px;
  text-align: center;
  font-weight: 700;
}

.value.coral {
  background: rgba(231, 76, 60, 0.12);
  color: var(--coral);
}

/* Button styles */
.teal-btn {
  background-color: rgba(26, 188, 156, 0.8);
  color: white;
}

.teal-btn:hover {
  background-color: rgba(26, 188, 156, 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);
}

.coral-btn {
  background-color: rgba(231, 76, 60, 0.8);
  color: white;
}

.coral-btn:hover {
  background-color: rgba(231, 76, 60, 0.7);
  transform: translateY(-2px);
}

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

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

.button-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 24px;
}

.btn {
  display: inline-block;
  border-radius: 0.375rem;
  text-decoration: none;
  text-align: center;
  transition: all 0.2s;
  cursor: pointer;
  border: 1px solid transparent;
  width: auto;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  padding: 12px 24px;
}

.btn.small {
  padding: 6px 10px;
  font-size: 13px;
}

.btn.soft {
  background: var(--softgray);
  color: var(--slate);
}

/* Panels */
.panel {
  margin-top: 24px;
  background: white;
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.panel h3 {
  margin: 0 0 12px 0;
  font-size: 18px;
}

.panel .panel-body {
  color: var(--navy);
}

.panel ol,
.panel ul {
  margin: 8px 0 0 20px;
}

/* Results table */
.table-wrap {
  overflow-x: auto;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border: 1px solid var(--softgray);
}

.results-table th,
.results-table td {
  border: 1px solid var(--softgray);
  padding: 8px;
  text-align: left;
}

.results-table thead tr {
  background: var(--softgray);
}

.results-table th {
  font-weight: 700;
}

/* Accessibility focus states */
a:focus,
button:focus,
input:focus {
  outline: 3px solid rgba(26, 188, 156, 0.18);
  outline-offset: 2px;
}

/* Small utilities */
.text-center {
  text-align: center;
}

.mt-4 {
  margin-top: 16px;
}

.mb-4 {
  margin-bottom: 16px;
}

.p-4 {
  padding: 16px;
}

/* Responsive */
@media (min-width: 768px) {
  body {
    padding: 24px;
  }

  .container {
    padding: 0;
  }

  .cols {
    flex-direction: row;
  }

  .sim-area {
    flex: 2;
    margin-right: 24px;
  }

  .controls {
    flex: 1;
  }

  .page-title {
    font-size: 32px;
  }
}

@media (max-width: 767px) {
  .container {
    padding: 0 12px;
  }
}

/* Tiny print adjustments */
@media print {
  .quiz-btn {
    display: none;
  }

  body {
    padding: 0;
  }
}

/* ==========================================================
   Velocity-Time Graphs additions
   ========================================================== */

/* Accessibility helpers */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--navy);
  color: var(--white);
  padding: 8px 16px;
  z-index: 1000;
  text-decoration: none;
}

.skip-link:focus {
  left: 8px;
  top: 8px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Clearly visible keyboard focus (the canonical 0.18 teal ring is too faint) */
button:focus-visible,
input:focus-visible,
canvas:focus-visible,
a:focus-visible {
  outline: 3px solid var(--navy);
  outline-offset: 2px;
}

.btn:disabled,
.btn:disabled:hover {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Sim area holds the road canvas above the instrument row */
#simArea {
  height: auto;
  min-height: 400px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.road-canvas {
  display: block;
  width: 100%;
  height: 200px;
  border-radius: 6px;
  background: var(--white);
}

.instrument-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.dial-wrap {
  width: 164px;
  height: 164px;
  flex: 0 0 auto;
}

.dial-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.timer-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.timer-display {
  min-width: 132px;
  padding: 10px 16px;
  border-radius: 6px;
  border: 2px solid var(--slate);
  background: #dfe8d6;
  color: var(--navy);
  font-family: "Courier New", ui-monospace, monospace;
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  letter-spacing: 1px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.12);
}

/* Journey selector (segmented buttons) */
.journey-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.journey-btn {
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 10px 8px;
  border-radius: 0.375rem;
  border: 2px solid var(--navy);
  background: var(--white);
  color: var(--navy);
  cursor: pointer;
  transition: all 0.2s;
}

.journey-btn:hover {
  background: var(--gray-200);
}

.journey-btn[aria-pressed="true"] {
  background: var(--navy);
  color: var(--white);
}

.controls .button-stack {
  margin-top: 0;
}

.key-hint {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--slate);
}

/* Results table inputs */
.results-table input {
  width: 100%;
  min-width: 64px;
  padding: 6px 8px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-family: inherit;
  font-size: 15px;
  color: var(--navy);
}

.panel-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.inline-confirm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.inline-confirm[hidden] {
  display: none;
}

/* Guided Investigation toggle */
.gi-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  font-family: inherit;
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
  text-align: left;
  cursor: pointer;
}

.gi-chevron {
  display: inline-block;
  transition: transform 0.2s;
}

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

.panel h3:has(.gi-toggle) {
  margin: 0;
}

.gi-body {
  margin-top: 12px;
}

.gi-body h4 {
  margin: 18px 0 0;
  font-size: 16px;
}

/* Dev harness (only created under ?dev) */
.dev-panel {
  margin-top: 18px;
  padding: 12px;
  border: 2px dashed var(--coral);
  border-radius: 8px;
  font-size: 13px;
}

.dev-panel .range-row input {
  width: 90px;
  padding: 6px;
  font-family: inherit;
}

.dev-readout {
  margin: 8px 0 0;
  font-family: ui-monospace, monospace;
  white-space: pre;
}

.site-footer {
  background: var(--navy);
  color: var(--white);
  text-align: center;
  padding: 16px;
  font-size: 0.8rem;
}

.site-footer p {
  margin: 0;
}

@media (max-width: 767px) {
  .page-header {
    padding: 0.5rem 0;
  }
}

@media (max-width: 480px) {
  body {
    padding: 8px;
  }

  .container {
    padding: 0 4px;
  }

  .experiment-area {
    padding: 10px;
  }

  .sim-area {
    padding: 8px;
  }

  .instrument-row {
    gap: 12px;
  }

  .dial-wrap {
    width: 150px;
    height: 150px;
  }

  .timer-display {
    font-size: 26px;
    min-width: 116px;
  }

  .page-title {
    font-size: 1.6rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
