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

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

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

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

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

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

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

.sim-area {
  background: var(--softgray);
  border-radius: 8px;
  padding: 12px;
  position: relative;
  overflow: hidden;
  height: 100%;
}

/* Controls */
.controls {
  background: white;
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

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

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

.range-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.range {
  flex: 1;
}

.value {
  display: inline-block;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(26, 188, 156, 0.12);
  color: var(--teal);
  min-width: 64px;
  text-align: center;
  font-weight: 700;
}

.value.coral {
  background: rgba(231, 76, 60, 0.12);
  color: var(--coral);
}

/* Button styles */
.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);
}

.button-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 24px;
}

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

.btn.small {
  padding: 6px 10px;
  font-size: 13px;
}

/* Panels */
.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 .panel-body {
  color: var(--navy);
}

.panel ol,
.panel ul {
  margin: 8px 0 0 20px;
}

/* Range input styling */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: transparent;
}

input[type="range"]:focus {
  outline: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: linear-gradient(90deg, #d0d0d0, #bdbdbd);
  border-radius: 6px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--navy);
  margin-top: -6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

input[type="range"]::-moz-range-track {
  height: 6px;
  background: linear-gradient(90deg, #d0d0d0, #bdbdbd);
  border-radius: 6px;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--navy);
  border: none;
}

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

/* Circuit-specific styles */
.component-bank {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

.component-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  border: 2px solid var(--softgray);
  border-radius: 8px;
  cursor: grab;
  transition: all 0.2s;
  background-color: var(--white);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.component-item:hover {
  border-color: var(--teal);
  background-color: rgba(26, 188, 156, 0.05);
  transform: translateY(-2px);
}

.component-item:active {
  cursor: grabbing;
}

.component-item.dragging {
  opacity: 0.5;
}

.component-item.picked {
  outline: 2px solid #f1c40f;
  border-radius: 10px;
}

.component-icon {
  width: 60px;
  height: 32px;
  color: var(--navy);
  margin-bottom: 6px;
}

.component-item span {
  font-size: 11px;
  font-weight: 600;
  color: var(--navy);
  text-align: center;
}

#circuit-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  background: white;
  border-radius: 6px;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#circuit-canvas.delete-mode {
  cursor: not-allowed;
}

.component-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 99999;
  pointer-events: none;
  opacity: 0.92;
  will-change: transform;
}

/* Responsive - Desktop */
@media (min-width: 768px) {
  body {
    padding: 24px;
  }

  .container {
    padding: 0;
  }

  .cols {
    flex-direction: row;
    align-items: stretch;
  }

  .sim-area {
    flex: 3;
    margin-right: 24px;
    height: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .controls {
    flex: 1;
  }

  .page-title {
    font-size: 32px;
  }

  #circuit-canvas {
    flex: 1;
    min-height: 0;
  }

  .component-bank {
    grid-template-columns: repeat(3, 1fr);
  }

  .component-icon {
    width: 55px;
    height: 30px;
  }
}

/* Responsive - Mobile */
@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;
  }

  .container {
    padding: 0 8px;
  }

  body {
    padding: 8px;
  }

  .sim-area {
    height: 400px;
    min-height: 300px;
  }

  .controls {
    max-height: none;
    overflow-y: visible;
  }

  .btn {
    padding: 14px 20px;
    font-size: 16px;
    min-height: 48px;
  }

  .component-item {
    padding: 14px 10px;
    min-height: 80px;
  }

  .component-bank {
    grid-template-columns: repeat(3, 1fr);
  }

  .component-icon {
    width: 50px;
    height: 28px;
  }

  /* Larger sliders for touch */
  input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
    margin-top: -9px;
  }

  input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }

  input[type="range"] {
    height: 10px;
  }

  input[type="checkbox"] {
    width: 22px;
    height: 22px;
  }
}

/* Touch device improvements */
@media (hover: none) and (pointer: coarse) {
  .component-item {
    padding: 16px 12px;
    min-height: 90px;
  }

  .component-icon {
    width: 65px;
    height: 35px;
  }

  .btn {
    min-height: 50px;
    font-size: 17px;
  }

  canvas {
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
  }

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

  .button-stack {
    gap: 12px;
  }
}

/* Tablet landscape */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
  .sim-area {
    height: 450px;
  }

  .controls {
    overflow-y: auto;
    max-height: 450px;
  }
}
