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

/* --------------------------------
   Generic 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;
}

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

.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: #fff;
}

.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: #fff;
}

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

.teal-btn:active,
.gold-btn:active,
.coral-btn:active,
.navy-btn:active {
  transform: translateY(1px);
  opacity: 0.95;
}

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

/* --------------------------------
   Layout
----------------------------------- */
.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;
}

.main-content {
  flex-grow: 1;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1rem;
}

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

.content-container {
  max-width: 1200px;
  margin: 0 auto;
}

.grid-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

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

/* --------------------------------
   Header
----------------------------------- */
.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;
  font-size: clamp(1.25rem, 3vw, 2rem);
  font-weight: 700;
  font-family: 'Montserrat', sans-serif;
}

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

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

/* --------------------------------
   Panels
----------------------------------- */
.simulation-panel {
  background-color: var(--white);
  padding: 1.5rem;
  border-radius: 0.75rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.control-panel {
  background-color: var(--white);
  padding: 1.5rem;
  border-radius: 0.75rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.experiment-area {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

.experiment-area canvas {
  display: block;
  border-radius: 8px;
  max-width: 100%;
}

.button-container {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

/* --------------------------------
   Control sections
----------------------------------- */
.control-section {
  margin-bottom: 1.5rem;
}

.control-section h3 {
  font-weight: 600;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
}

.slider-group {
  margin-bottom: 1rem;
}

.slider-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--slate);
  margin-bottom: 4px;
}

.slider-group input[type='range'] {
  width: 100%;
  accent-color: var(--teal);
  cursor: pointer;
}

select {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid var(--gray-300);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--navy);
  background: var(--white);
  cursor: pointer;
  margin-top: 4px;
}

/* --------------------------------
   Measurements
----------------------------------- */
.measurements {
  background-color: var(--gray-100);
  padding: 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1.5rem;
}

.measurements h3 {
  font-weight: 600;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
}

.measurement-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.measurement-label {
  font-size: 0.8rem;
  color: var(--slate);
  margin: 0 0 2px;
}

.measurement-value {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
}

.highlight-value {
  color: var(--teal);
}

/* --------------------------------
   Formula box
----------------------------------- */
.formula-box {
  background: rgba(26, 188, 156, 0.08);
  border-left: 4px solid var(--teal);
  border-radius: 0 8px 8px 0;
  padding: 12px 16px;
  font-size: 0.875rem;
  color: var(--navy);
  margin-bottom: 1rem;
}

.formula-box strong {
  display: block;
  font-size: 1rem;
  margin-bottom: 4px;
}

/* --------------------------------
   Data table
----------------------------------- */
.data-section {
  margin-bottom: 1rem;
}

.data-section h3 {
  font-weight: 600;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.table-container {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  border: 1px solid var(--gray-300);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

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

.record-btn-container {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.control-btn {
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  border: none;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  font-family: inherit;
  font-size: 0.875rem;
}

.control-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

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

.record-btn {
  background-color: var(--teal);
  color: var(--white);
}

.record-btn:hover {
  background-color: #16a085;
}

.clear-btn {
  background-color: var(--coral);
  color: var(--white);
}

.clear-btn:hover {
  background-color: #d32f2f;
}

.reset-btn {
  background-color: var(--slate);
  color: var(--white);
}

.reset-btn:hover {
  background-color: #6c757d;
}

/* --------------------------------
   Instructions
----------------------------------- */
.instructions {
  background-color: var(--softgray);
  padding: 1rem;
  border-radius: 0.5rem;
  margin-top: 1rem;
}

.instructions h3 {
  font-weight: 600;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.instructions ol {
  padding-left: 1.25rem;
  margin: 0;
}

.instructions li {
  margin-bottom: 0.25rem;
  font-size: 0.875rem;
  line-height: 1.6;
}

/* --------------------------------
   Graph area
----------------------------------- */
.graph-section {
  background-color: var(--white);
  padding: 1.5rem;
  border-radius: 0.75rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  margin-top: 1.5rem;
}

.graph-section h3 {
  font-weight: 600;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.graph-section canvas {
  display: block;
  max-width: 100%;
  border-radius: 6px;
}

.graph-hint {
  font-size: 0.8rem;
  color: var(--slate);
  margin-top: 6px;
}

/* --------------------------------
   Toast
----------------------------------- */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  background-color: #4caf50;
  color: white;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 1000;
}

.toast.show {
  opacity: 1;
}

.initialized {
  display: none;
}

/* --------------------------------
   Desktop
----------------------------------- */
@media (min-width: 768px) {
  .grid-layout {
    grid-template-columns: 2fr 1fr;
  }
}

@media (min-width: 1024px) {
  .content-container {
    padding: 0 2rem;
  }
}

/* --------------------------------
   Mobile
----------------------------------- */
@media (max-width: 767px) {
  .container {
    padding: 12px;
    gap: 16px;
  }

  .content-area {
    padding: 16px;
    margin-bottom: 16px;
  }

  .simulation-panel,
  .control-panel {
    padding: 16px;
  }

  .header-grid {
    grid-template-columns: 1fr;
    grid-auto-flow: row;
    text-align: left;
  }

  .page-title {
    justify-self: start;
    font-size: 1.5rem;
  }

  .header-actions {
    justify-self: start;
    width: 100%;
    margin-top: 8px;
  }

  .measurement-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .record-btn-container {
    justify-content: center;
    flex-direction: column;
  }

  .record-btn-container .control-btn {
    width: 100%;
    max-width: 220px;
    align-self: center;
  }

  .data-table th,
  .data-table td {
    padding: 0.375rem 0.5rem;
    font-size: 0.8rem;
  }

  .button-container {
    flex-direction: column;
    align-items: center;
  }
}
