:root {
  --navy: #2c3e50;
  --teal: #1abc9c;
  --gold: #f1c40f;
  --coral: #e74c3c;
  --slate: #556366;
  --white: #ffffff;
  --gray-100: #f7fafc;
  --gray-200: #edf2f7;
  --gray-300: #e2e8f0;
  --border: #dde3ea;
  --max-width: 1120px;
  --radius: 10px;
  --shadow-sm: 0 2px 12px 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, Arial, sans-serif;
  color: var(--navy);
  background: linear-gradient(135deg, #ecf0f1 0%, #d6dbdf 100%);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.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;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--navy);
  color: var(--white);
  padding: 8px 16px;
  border-radius: 0 0 8px 0;
  z-index: 100;
}

.skip-link:focus {
  left: 0;
}

/* --------------------------------
   Layout shell
----------------------------------- */
.main-content {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px;
  flex: 1;
}

/* --------------------------------
   Header
----------------------------------- */
.page-header {
  text-align: center;
  margin-bottom: 20px;
}

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

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

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

.page-title {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2rem);
  font-weight: 700;
}

.page-subtitle {
  margin: 6px 0 0;
  font-style: italic;
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--slate);
}

/* --------------------------------
   Buttons
----------------------------------- */
.btn {
  display: inline-block;
  border-radius: 0.375rem;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 20px;
  min-height: 44px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
}

.teal-btn {
  background-color: rgba(26, 188, 156, 0.8);
  color: var(--white);
}

.teal-btn:hover {
  background-color: rgba(26, 188, 156, 0.7);
  transform: translateY(-2px);
}

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

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

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

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

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

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

/* --------------------------------
   Mode selector
----------------------------------- */
.mode-tabs {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 20px;
}

.mode-tab {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 10px 26px;
  min-height: 44px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--white);
  color: var(--slate);
  cursor: pointer;
  transition: all 0.2s;
}

.mode-tab:hover {
  border-color: var(--teal);
  color: var(--navy);
}

.mode-tab.active {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--white);
}

/* --------------------------------
   Main two-column layout
----------------------------------- */
.sim-layout {
  display: grid;
  grid-template-columns: 5fr 4fr;
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--white);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

/* --------------------------------
   Apparatus panel
----------------------------------- */
.apparatus-panel {
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.context-head {
  width: 100%;
  text-align: center;
  border-bottom: 1.5px solid var(--gray-200);
  padding-bottom: 12px;
}

.context-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.context-note {
  margin: 4px 0 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--slate);
}

.instrument {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.instrument-label {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--slate);
  text-transform: none;
}

#gauge-canvas {
  border-radius: 8px;
  max-width: 100%;
  height: auto;
}

.readout {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  background: var(--gray-100);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  min-width: 130px;
  text-align: center;
}

.y-readout {
  font-size: 1.3rem;
}

.y-readout.over-range {
  color: var(--coral);
  border-color: var(--coral);
}

.x-readout {
  font-size: 1.05rem;
}

/* --------------------------------
   x-control
----------------------------------- */
.x-control {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.x-control .instrument-label {
  text-align: center;
}

.slider-wrap {
  display: flex;
  flex-direction: column;
}

#x-ticks {
  width: 100%;
  height: 30px;
  display: block;
}

/* The slider: navy track with a groove, teal handle */
#x-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 44px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}

#x-slider::-webkit-slider-runnable-track {
  height: 12px;
  border-radius: 6px;
  background: var(--navy);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.45);
}

#x-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--teal);
  border: 3px solid var(--white);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  margin-top: -7px;
}

#x-slider::-moz-range-track {
  height: 12px;
  border-radius: 6px;
  background: var(--navy);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.45);
}

#x-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--teal);
  border: 3px solid var(--white);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

#x-slider:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.x-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.x-set {
  display: flex;
  gap: 8px;
}

.x-set input {
  width: 110px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  color: var(--navy);
  text-align: center;
}

/* --------------------------------
   Workspace panel
----------------------------------- */
.workspace-panel {
  padding: 20px;
}

.workspace-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}

.workspace-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.round-counter {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--slate);
  white-space: nowrap;
}

.ws-section {
  border-top: 1.5px solid var(--gray-200);
  padding: 16px 0;
  transition: opacity 0.3s;
}

.ws-section h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 600;
}

.ws-hint {
  margin: 0 0 10px;
  font-size: 0.8rem;
  color: var(--slate);
}

.ws-section.inactive {
  opacity: 0.45;
  pointer-events: none;
}

.btn.small {
  font-size: 0.8rem;
  padding: 8px 14px;
  min-height: 40px;
}

/* results table — always typed by the student */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  border: 1px solid var(--gray-300);
  padding: 0;
  text-align: center;
}

.data-table th {
  background: var(--gray-100);
  font-weight: 600;
  padding: 8px;
}

.data-table td input {
  width: 100%;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--navy);
  text-align: center;
  padding: 9px 6px;
  min-height: 38px;
}

.data-table td input:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: -3px;
}

/* guided investigation */
.prompt-list {
  margin: 0 0 12px;
  padding-left: 20px;
}

.prompt-list:empty {
  margin: 0;
}

.prompt-list li {
  font-size: 0.875rem;
  line-height: 1.6;
  margin-bottom: 8px;
}

/* classification */
.classify-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.classify-card {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 44px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.classify-card:hover {
  border-color: var(--teal);
}

.classify-card:has(input:checked) {
  border-color: var(--teal);
  background: rgba(26, 188, 156, 0.08);
}

.classify-card:has(input:focus-visible) {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.classify-card input {
  accent-color: var(--teal);
  width: 18px;
  height: 18px;
  flex: none;
  margin: 0;
}

.classify-card em {
  color: var(--slate);
  font-style: normal;
  font-weight: 600;
}

#classify-section.locked .classify-card {
  cursor: default;
  opacity: 0.7;
}

/* prediction */
.predict-question {
  margin: 0 0 10px;
  font-size: 0.9rem;
}

.predict-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.predict-row input {
  width: 120px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  color: var(--navy);
  text-align: center;
}

/* reveal & summary cards */
.reveal-card {
  border: 2px solid var(--teal);
  border-radius: 10px;
  padding: 18px;
  margin-top: 8px;
}

.reveal-card h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.reveal-equation {
  margin: 0 0 14px;
  font-size: 1.15rem;
  font-weight: 700;
}

.reveal-class {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.verdict-icon {
  flex: none;
  display: inline-flex;
}

.reveal-prediction {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.9rem;
  margin-bottom: 14px;
}

.pred-verdict {
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 6px;
  color: var(--white);
}

.pred-verdict.good {
  background: var(--teal);
}

.pred-verdict.bad {
  background: var(--coral);
}

.reveal-line {
  margin: 0 0 16px;
  font-size: 0.9rem;
  color: var(--slate);
  line-height: 1.6;
}

.summary-text {
  font-size: 0.95rem;
  line-height: 2;
  margin: 0 0 16px;
}

.reveal-footer {
  margin: 0 0 16px;
  font-size: 0.85rem;
}

.reveal-footer a {
  color: var(--teal);
  font-weight: 600;
}

/* --------------------------------
   Help overlay
----------------------------------- */
.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(44, 62, 80, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  z-index: 50;
}

.help-overlay[hidden] {
  display: none;
}

.help-panel {
  background: var(--navy);
  color: var(--white);
  border-radius: 12px;
  padding: 24px 28px;
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.help-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.help-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.help-close {
  background: transparent;
  border: none;
  color: var(--white);
  font-size: 1.8rem;
  line-height: 1;
  width: 44px;
  height: 44px;
  cursor: pointer;
  border-radius: 8px;
}

.help-close:hover {
  color: var(--gold);
}

.help-panel h3 {
  margin: 16px 0 6px;
  font-size: 0.95rem;
  color: var(--teal);
}

.help-panel p {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.7;
  font-weight: 500;
}

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

.site-footer p {
  margin: 0;
}

/* --------------------------------
   Mobile
----------------------------------- */
@media (max-width: 768px) {
  .sim-layout {
    grid-template-columns: 1fr;
  }

  .container {
    padding: 16px 12px;
  }

  .header-grid {
    grid-template-columns: 1fr;
  }

  .header-left,
  .header-actions {
    justify-self: center;
  }

  .x-row {
    justify-content: center;
  }
}
