@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=Inter:wght@400;500;600;700&display=swap");

:root {
  color-scheme: light;

  /* The Thinking Experiment Design System */
  --bg: #ffffff;
  --surface: #ffffff;
  --card: #ffffff;
  --border: #c8dbe3;
  --border-subtle: #e2edf2;

  --teal: #0f7e9b;
  --teal-dark: #0a5d74;
  --teal-light: #eaf4f7;
  --teal-surface: #f4f9fb;

  --amber: #d67b19;
  --amber-hover: #be6a11;
  --amber-active: #a85a0c;
  --amber-light: #fef5ea;
  --amber-border: #f5cf9e;

  --ink: #123140;
  --muted: #4b6570;
  --muted-light: #61808b;

  --ok: #1a7f4e;
  --ok-bg: #edf8f2;
  --warn: #c25e00;
  --warn-bg: #fff6eb;

  --shadow-sm: 0 2px 6px rgba(15, 126, 155, 0.06);
  --shadow: 0 4px 16px rgba(15, 126, 155, 0.08);
  --shadow-lg: 0 10px 28px rgba(15, 126, 155, 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  margin: 0;
  min-height: 100%;
  color-scheme: light;
  background-color: #ffffff;
}

body {
  font-family: "Inter", "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: #ffffff;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Subtle blueprint background grid */
.bg-grid {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(15, 126, 155, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 126, 155, 0.04) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(circle at center, #000 65%, transparent 98%);
  pointer-events: none;
}

.shell {
  width: min(1440px, calc(100% - 2.5rem));
  margin-inline: auto;
  padding-block: 1.25rem 3rem;
}

/* Hero Header */
.hero {
  border: 1px solid var(--border);
  border-left: 8px solid var(--teal);
  border-radius: 14px;
  padding: 1.35rem 1.6rem;
  background: #ffffff;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.25rem;
}

.title-section {
  display: flex;
  flex-direction: column;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--teal);
  background: var(--teal-light);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  text-decoration: none;
  transition: all 0.15s ease;
}

.brand-badge:hover {
  background: #d4ecf4;
  color: var(--teal-dark);
}

.lab-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--amber-hover);
  background: var(--amber-light);
  border: 1px solid var(--amber-border);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
}

.hero h1 {
  margin-top: 0.35rem;
  font-size: clamp(1.5rem, 2.3vw, 2.2rem);
  font-weight: 700;
  color: var(--teal-dark);
  line-height: 1.2;
}

.hero .subtitle {
  margin-top: 0.45rem;
  max-width: 95ch;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.55;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* App Layout Grid */
.app-layout {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: start;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.35rem;
  background: var(--card);
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.panel:hover {
  box-shadow: var(--shadow-lg);
  border-color: #b5d2dd;
}

.panel-head {
  margin-bottom: 1rem;
}

.panel-head h2 {
  font-size: 1.22rem;
  font-weight: 700;
  color: var(--teal-dark);
}

.hint {
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.narrow {
  grid-column: span 5;
}

.wide {
  grid-column: span 7;
}

.full {
  grid-column: span 12;
}

/* Simulation Viewport & Canvas */
.simulation-viewport {
  position: relative;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  height: 420px;
}

#simulation-canvas {
  width: 100%;
  height: 100%;
  position: relative;
}

#simulation-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Live Metrics Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.metric-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0.85rem 0.6rem;
  background: var(--teal-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.metric-card:hover {
  border-color: var(--border);
  transform: translateY(-1px);
}

.metric-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

.metric-value {
  font-size: 1.22rem;
  font-weight: 700;
  color: var(--teal-dark);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

/* Tabs inside control panel */
.control-tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 2px solid var(--border-subtle);
  margin-bottom: 1.1rem;
}

.tab {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0.6rem 1rem;
  cursor: pointer;
  position: relative;
  transition: color 0.15s ease;
}

.tab:hover {
  color: var(--teal-dark);
}

.tab.active {
  color: var(--teal-dark);
  font-weight: 700;
}

.tab.active::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--amber);
  border-radius: 3px 3px 0 0;
}

.tab-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.tab-content.hidden {
  display: none;
}

/* Control Blocks */
.control-block {
  padding: 0.9rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.control-block h3 {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--teal-dark);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Method Selector Radio Cards */
.method-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.method-button {
  position: relative;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.65rem;
  background: var(--teal-surface);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  transition: all 0.15s ease;
}

.method-button input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.method-button:has(input[type="radio"]:checked) {
  border-color: var(--teal);
  background: #ffffff;
  box-shadow: 0 0 0 2px rgba(15, 126, 155, 0.18);
}

.method-icon {
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
}

.method-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
}

.method-description {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
  line-height: 1.35;
}

/* Slider */
.charge-slider-container {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.slider-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.charge-label {
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.charge-label.negative {
  color: var(--teal-dark);
}

.charge-label.positive {
  color: var(--amber-hover);
}

input[type="range"] {
  width: 100%;
  height: 6px;
  accent-color: var(--amber);
  cursor: pointer;
}

.val-badge {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--teal-dark);
  background: var(--teal-light);
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
  display: inline-block;
  align-self: flex-start;
}

.charge-value {
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
  color: var(--teal-dark);
  font-variant-numeric: tabular-nums;
}

.charge-value.positive {
  color: var(--amber-hover);
}

.charge-value.negative {
  color: var(--teal-dark);
}

/* Action Buttons */
.action-buttons {
  display: flex;
  gap: 0.65rem;
}

.action-button,
.btn {
  font-family: inherit;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  flex: 1;
  background: #ffffff;
  color: var(--ink);
  border: 1px solid var(--border);
}

.action-button:hover,
.btn:hover {
  background: var(--teal-light);
  border-color: #a4c7d4;
  color: var(--teal-dark);
  transform: translateY(-1px);
}

/* MANDATORY: High-energy CTA buttons MUST use Amber (#d67b19) */
.btn-primary {
  background: var(--amber);
  color: #ffffff;
  border: 1px solid #bf6a12;
}

.btn-primary:hover:not(:disabled) {
  background: var(--amber-hover);
  border-color: var(--amber-active);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(214, 123, 25, 0.28);
}

.btn-secondary {
  background: #ffffff;
  color: var(--ink);
  border: 1px solid var(--border);
}

/* Grounded state */
.action-button.grounded {
  background: var(--amber-light);
  border-color: var(--amber-border);
  color: var(--amber-hover);
  font-weight: 700;
}

/* Toggles */
.toggle-options {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.toggle-switch {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

input[type="checkbox"] {
  accent-color: var(--teal);
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* Quiz Container */
.quiz-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.quiz-question {
  padding: 0.9rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: border-color 0.15s ease;
}

.quiz-question.correct {
  border-color: var(--ok);
  background: var(--ok-bg);
}

.quiz-question.incorrect {
  border-color: var(--amber);
  background: var(--amber-light);
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.35rem;
}

.quiz-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  color: var(--ink);
  cursor: pointer;
}

.quiz-option input[type="radio"] {
  accent-color: var(--teal);
}

.answer-feedback {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: #ffffff;
  border-radius: 6px;
  border-left: 3px solid var(--teal);
  font-size: 0.86rem;
  line-height: 1.5;
}

.quiz-controls {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 0.5rem;
}

.quiz-score {
  font-weight: 700;
  color: var(--teal-dark);
  font-size: 0.95rem;
  padding: 0.35rem 0.75rem;
  background: var(--teal-light);
  border-radius: 6px;
}

/* Instructions & Bottom Section */
.instructions-container {
  margin-top: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.instructions-section h2 {
  font-size: 1.25rem;
  color: var(--teal-dark);
  margin-bottom: 0.9rem;
  font-weight: 700;
}

.instructions-section h3 {
  font-size: 1.05rem;
  color: var(--ink);
  margin-top: 1.1rem;
  margin-bottom: 0.45rem;
  font-weight: 700;
}

.instructions-section ul,
.instructions-section ol {
  padding-left: 1.4rem;
  color: var(--ink);
  line-height: 1.6;
  font-size: 0.94rem;
}

.instructions-section li {
  margin-bottom: 0.35rem;
}

.instructions-section p {
  color: var(--ink);
  line-height: 1.6;
  font-size: 0.94rem;
  margin-top: 0.35rem;
}

/* Modal Dialog */
.modal-dialog {
  position: fixed;
  inset: 0;
  background: rgba(18, 49, 64, 0.45);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-content,
.explanation-panel {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  max-width: 820px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.5rem;
  position: relative;
}

.modal-header,
.explanation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.75rem;
}

.modal-header h2,
.explanation-header h3 {
  color: var(--teal-dark);
  font-size: 1.3rem;
  font-weight: 700;
}

.close-button {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--muted);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  line-height: 1;
  transition: color 0.15s ease;
}

.close-button:hover {
  color: var(--ink);
}

.explanation-nav {
  display: flex;
  gap: 0.45rem;
  border-bottom: 2px solid var(--border-subtle);
  margin-bottom: 1.25rem;
}

.explanation-nav-btn {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  position: relative;
  transition: color 0.15s ease;
}

.explanation-nav-btn:hover {
  color: var(--teal-dark);
}

.explanation-nav-btn.active {
  color: var(--teal-dark);
  font-weight: 700;
}

.explanation-nav-btn.active::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--amber);
  border-radius: 3px 3px 0 0;
}

.explanation-section {
  display: none;
}

.explanation-section.active {
  display: block;
}

.explanation-card {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1.25rem;
  align-items: start;
}

.explanation-img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.feature-list {
  padding-left: 1.25rem;
  line-height: 1.6;
  font-size: 0.92rem;
}

.feature-list li {
  margin-bottom: 0.5rem;
}

/* Footer */
footer {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-subtle);
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
  .narrow {
    grid-column: span 12;
  }
  .wide {
    grid-column: span 12;
  }
  .explanation-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .shell {
    width: calc(100% - 1.5rem);
    padding-block: 1rem 2rem;
  }
  .hero {
    padding: 1.1rem;
  }
  .hero-top {
    flex-direction: column;
  }
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .method-buttons {
    grid-template-columns: 1fr;
  }
  .action-buttons {
    flex-direction: column;
  }
}

/* Embedded / Iframe Overlay styling support */
.physics-data-overlay {
  position: absolute;
  bottom: 12px;
  left: 12px;
  right: 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}

.physics-data-overlay .data-item {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: var(--shadow-sm);
  pointer-events: auto;
}

.physics-data-overlay .data-icon {
  display: none;
}

.physics-data-overlay .data-value {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--teal-dark);
  font-variant-numeric: tabular-nums;
}

.physics-data-overlay .data-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
