: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;
  --radius: 10px;
  --shadow-sm: 0 6px 18px rgba(0, 0, 0, 0.06);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.06);
}

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

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

h1, h2, h3, h4, h5, h6 {
  font-family: 'Montserrat', sans-serif;
  font-weight: 600;
}

li {
  line-height: 2;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
}

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

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

.page-title {
  margin: 0;
  justify-self: center;
  font-size: 2rem;
  font-weight: 700;
  font-family: 'Montserrat', sans-serif;
}

@media (max-width: 767px) {
  .header-grid {
    grid-template-columns: 1fr;
    grid-auto-flow: row;
    text-align: left;
  }
  .page-title { justify-self: start; font-size: 24px; }
  .header-actions { justify-self: start; width: 100%; margin-top: 8px; }
}

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

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

/* ── Summary banner ── */
.summary {
  background: rgba(26, 188, 156, 0.1);
  border: 2px solid var(--teal);
  border-radius: 10px;
  padding: 15px 20px;
  text-align: center;
  color: var(--navy);
  font-size: 0.95rem;
}

/* ── Main layout ── */
.cols {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

@media (min-width: 768px) {
  .cols {
    flex-direction: row;
  }
  .sim-area { flex: 2; margin-right: 24px; }
  .controls-panel { flex: 1; }
}

/* ── Simulation canvas area ── */
.sim-area {
  background: var(--softgray);
  border-radius: 8px;
  padding: 12px;
  position: relative;
  min-height: 420px;
}

.sim-area canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: white;
  border-radius: 6px;
  touch-action: none;
  cursor: default;
}

.sim-area canvas.grab { cursor: grab; }
.sim-area canvas.grabbing { cursor: grabbing; }

/* ── Controls sidebar (white, matches other electricity sims) ── */
.controls-panel {
  background: white;
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.control-section h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 10px;
}

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

.control-group:last-child {
  margin-bottom: 0;
}

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

/* ── Material selector ── */
.material-selector {
  display: flex;
  gap: 6px;
}

.material-btn {
  flex: 1;
  padding: 10px 8px;
  border: 2px solid var(--gray-300);
  border-radius: 8px;
  background: var(--gray-100);
  color: var(--slate);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.material-btn:hover {
  border-color: var(--gray-300);
  background: var(--gray-200);
  color: var(--navy);
}

.material-btn.active {
  border-color: var(--teal);
  background: rgba(26, 188, 156, 0.12);
  color: var(--navy);
}

/* ── Rub button ── */
.rub-btn {
  width: 100%;
  padding: 12px;
  border-radius: 0.375rem;
  border: none;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  background: rgba(26, 188, 156, 0.8);
  color: white;
}

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

.rub-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Charge indicators ── */
.charge-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--gray-100);
  font-size: 13px;
  font-weight: 500;
  color: var(--navy);
}

.charge-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gray-300);
  transition: background 0.3s;
}

.charge-dot.negative { background: #3498db; }
.charge-dot.positive { background: var(--coral); }

/* ── Drag hint ── */
.drag-hint {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(241, 196, 15, 0.12);
  border: 1px dashed rgba(241, 196, 15, 0.6);
  color: var(--slate);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  line-height: 1.4;
  transition: opacity 0.3s;
  margin-top: 6px;
}

.drag-hint.hidden { opacity: 0.3; }

/* ── Reset ── */
.reset-btn {
  width: 100%;
  padding: 10px;
  border-radius: 0.375rem;
  border: none;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  background: rgba(231, 76, 60, 0.8);
  color: white;
  margin-top: 6px;
}

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

/* ── Dividers inside controls ── */
.control-divider {
  border: none;
  border-top: 1px solid var(--softgray);
  margin: 4px 0;
}

/* ── Results table (light theme, matches other electricity sims) ── */
.results-wrapper {
  background: white;
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.results-title {
  text-align: center;
  margin: 0 0 12px 0;
  font-weight: 700;
  font-size: 18px;
  color: var(--navy);
}

.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;
  color: var(--navy);
  font-size: 0.8rem;
}

.results-table td {
  color: var(--navy);
  vertical-align: middle;
}

/* Row number column */
.results-table td:first-child {
  font-weight: 700;
  color: var(--slate);
  width: 40px;
  text-align: center;
}

/* Select inputs in the table */
.results-table select {
  width: 100%;
  max-width: 160px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--gray-300);
  background: white;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--navy);
  cursor: pointer;
  appearance: auto;
}

.results-table select:focus {
  outline: 3px solid rgba(26, 188, 156, 0.18);
  outline-offset: 2px;
}

/* Correct / incorrect feedback */
.results-table select.correct {
  border-color: var(--teal);
  background: rgba(26, 188, 156, 0.1);
}

.results-table select.incorrect {
  border-color: var(--coral);
  background: rgba(231, 76, 60, 0.1);
}

/* Check button row */
.check-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
}

.check-btn {
  padding: 12px 32px;
  border-radius: 0.375rem;
  border: none;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  background: rgba(26, 188, 156, 0.8);
  color: white;
}

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

.check-feedback {
  font-size: 14px;
  font-weight: 600;
  min-height: 20px;
}

.check-feedback.all-correct { color: var(--teal); }
.check-feedback.has-errors { color: var(--coral); }

/* ── Instructions panel (matches .panel pattern from other sims) ── */
.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 ol,
.panel ul {
  margin: 8px 0 0 20px;
}

/* ── Responsive tweaks ── */
@media (max-width: 767px) {
  body { padding: 8px; }
  .container { padding: 0 12px; gap: 14px; }
  .sim-area { min-height: 320px; }
  .btn { padding: 14px 20px; font-size: 16px; min-height: 48px; }
}

@media (min-width: 768px) {
  body { padding: 24px; }
  .page-title { font-size: 32px; }
}

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

/* ── Touch device optimizations ── */
@media (hover: none) and (pointer: coarse) {
  .btn, .material-btn, .rub-btn, .reset-btn, .check-btn {
    min-height: 50px;
    font-size: 17px;
  }
  .control-group {
    margin-bottom: 20px;
  }
}
