:root {
  --navy: #2c3e50;
  --teal: #1abc9c;
  --teal-dark: #0d7a63;
  --teal-darker: #0b6e58;
  --gold: #f1c40f;
  --coral: #e74c3c;
  --coral-dark: #c0392b;
  --coral-darker: #a93226;
  --slate: #7f8c8d;
  --slate-dark: #556366;
  --bg: #f0f4f8;
  --card: #ffffff;
  --border: #dde3ea;
  --gray-100: #f7fafc;
  --gray-300: #e2e8f0;
}

/* --------------------------------
   Accessibility
----------------------------------- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--navy);
  color: #fff;
  padding: 8px 16px;
  z-index: 1000;
  font-size: 0.9rem;
  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;
}

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

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

body {
  font-family: 'Montserrat', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    sans-serif;
  color: var(--navy);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

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

.instructions {
  background: rgba(26, 188, 156, 0.1);
  border: 2px solid var(--teal);
  border-radius: 10px;
  padding: 15px 20px;
  margin-bottom: 20px;
  color: var(--navy);
}

.instructions p {
  margin: 0 0 8px;
}

.instructions p:last-child {
  margin-bottom: 0;
}

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

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

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

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

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

/* --------------------------------
   Buttons (SimpliPhys standard)
----------------------------------- */
.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;
  font-family: inherit;
}

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

.teal-btn {
  background-color: var(--teal-dark);
  color: #fff;
}

.teal-btn:hover {
  background-color: var(--teal-darker);
  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: var(--coral-dark);
  color: #fff;
}

.coral-btn:hover {
  background-color: var(--coral-darker);
  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);
}

.outline-btn {
  background: transparent;
  color: var(--coral-dark);
  border: 1.5px solid var(--coral-dark);
}

.outline-btn:hover {
  background: var(--coral-dark);
  color: #fff;
}

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

/* --------------------------------
   Two-panel layout
----------------------------------- */
.sim-layout {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 24px;
  align-items: start;
}

.panel {
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

.apparatus-panel {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

.apparatus-panel canvas {
  display: block;
  max-width: 100%;
  /* !important beats the inline height set by the devicePixelRatio setup,
     keeping the aspect ratio when max-width shrinks the canvas */
  height: auto !important;
  border-radius: 8px;
  background: #0d1526;
}

.apparatus-panel canvas:focus {
  outline: 3px solid var(--navy);
  outline-offset: 2px;
}

.controls-panel {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.control-block h2 {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 700;
}

/* --------------------------------
   Star Inspector
----------------------------------- */
.inspector {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  background: var(--gray-100);
}

.inspector-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.swatch {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
}

.swatch.empty {
  background: repeating-linear-gradient(
    45deg,
    var(--gray-300),
    var(--gray-300) 3px,
    var(--gray-100) 3px,
    var(--gray-100) 6px
  );
}

.inspector-name {
  font-size: 1.05rem;
  font-weight: 700;
}

.readout-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
}

.readout-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--slate);
}

.readout-value {
  font-variant-numeric: tabular-nums;
  font-family: 'Consolas', 'SFMono-Regular', Menlo, monospace;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
}

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

.note-text {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--navy);
}

/* --------------------------------
   Data table
----------------------------------- */
.data-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 8px;
}

.data-table-heading {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

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

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

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

.data-table th {
  background: var(--bg);
  font-weight: 600;
  font-size: 0.85rem;
}

.data-table th[scope='row'] {
  text-align: left;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}

.table-input {
  width: 110px;
  padding: 4px 6px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.85rem;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}

.table-input:focus {
  border-color: var(--teal);
}

.results-panel {
  margin-top: 24px;
  padding: 20px;
}

/* --------------------------------
   Investigation section
----------------------------------- */
.investigation-section {
  margin-top: 24px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.investigation-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: var(--navy);
  color: #fff;
  border: none;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}

.investigation-toggle:hover {
  background: #34495e;
}

.chevron {
  transition: transform 0.3s;
}

.investigation-toggle.open .chevron {
  transform: rotate(180deg);
}

.investigation-body {
  display: none;
  background: var(--card);
  padding: 20px 24px;
}

.investigation-body.open {
  display: block;
}

.investigation-aim {
  margin: 0 0 14px;
  font-size: 0.9rem;
}

.investigation-body h3 {
  margin: 18px 0 8px;
  font-size: 0.95rem;
  font-weight: 700;
}

.investigation-body h3:first-of-type {
  margin-top: 0;
}

.investigation-body ol {
  margin: 0;
  padding-left: 1.5rem;
}

.investigation-body li {
  margin-bottom: 10px;
  font-size: 0.9rem;
  line-height: 1.65;
}

.investigation-body li:last-child {
  margin-bottom: 0;
}

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

.site-footer p {
  margin: 0;
}

/* --------------------------------
   Reduced motion
----------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .chevron,
  .investigation-toggle {
    transition: none;
  }
}

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

  .container {
    padding: 16px 12px;
  }

  .controls-panel {
    padding: 16px;
  }

  .data-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .table-input {
    width: 90px;
  }
}

@media (max-width: 540px) {
  .header-grid {
    grid-template-columns: 1fr;
    grid-auto-flow: row;
    text-align: left;
  }

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

  .header-actions,
  .header-left {
    justify-self: start;
    width: 100%;
  }
}


/* Comfortable touch targets on touch devices (excludes in-table data cells) */
@media (pointer: coarse) {
  button:not([class*="cell"]):not([class*="table"]):not(.progress-dot):not(.col-type-badge):not(.col-delete),
  a.btn,
  .btn,
  select:not([class*="cell"]):not([class*="table"]) {
    min-height: 44px;
  }
  .row-delete,
  .col-delete,
  .delete-btn,
  .delete-row-btn,
  .remove-btn {
    min-width: 44px;
    min-height: 44px;
  }
  input[type="range"]::-webkit-slider-thumb { width: 24px; height: 24px; }
  input[type="range"]::-moz-range-thumb { width: 24px; height: 24px; }
}
