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

body {
  font-family: 'Comic Sans MS', 'Trebuchet MS', 'Segoe UI', sans-serif;
  min-height: 100vh;
  background: linear-gradient(160deg, #d6f5e3 0%, #c9e4ff 50%, #ffe9b3 100%);
  color: #1a202c;
}

.hidden { display: none !important; }

#screen-mode-select, #screen-level-select, #screen-game { padding: 24px; }
#screen-mode-select, #screen-level-select { position: relative; overflow: hidden; min-height: 100vh; }

.bg-electronics {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}
.bg-electronics svg { width: 100%; height: 100%; }

#btn-to-dashboard, #btn-back-to-mode, #btn-back-from-game {
  display: inline-block;
  margin-bottom: 12px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: bold;
  color: #2b6cb0;
  background: rgba(255, 255, 255, 0.75);
  border: none;
  border-radius: 10px;
  text-decoration: none;
  cursor: pointer;
}
#btn-to-dashboard:hover, #btn-back-to-mode:hover, #btn-back-from-game:hover { background: rgba(255, 255, 255, 0.95); }

h1 { font-size: 24px; color: #2b6cb0; margin-bottom: 4px; }
#screen-mode-select p, #screen-level-select p { font-size: 14px; color: #2d3748; margin-bottom: 4px; }
#screen-mode-select p.game-intro { max-width: 640px; font-size: 13px; line-height: 1.7; color: #4a5568; margin: 20px 0 4px; padding-top: 16px; border-top: 1px dashed rgba(0, 0, 0, 0.15); }

#mode-cards { display: flex; gap: 18px; margin-top: 18px; flex-wrap: wrap; }
.mode-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 22px 26px;
  border: none;
  border-radius: 18px;
  background: linear-gradient(145deg, #ffffff, #eaf6ff);
  cursor: pointer;
  text-align: left;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.12), 0 8px 14px rgba(0, 0, 0, 0.1);
  transition: transform 0.15s ease;
}
.mode-card:hover { transform: translateY(-3px); }
.mode-card:active { transform: translateY(2px); }
.mode-card-title { font-size: 18px; font-weight: bold; color: #2b6cb0; }
.mode-card-desc { font-size: 13px; color: #4a5568; }

#level-cards { display: flex; gap: 16px; margin-top: 16px; flex-wrap: wrap; }
.level-card {
  padding: 20px 26px;
  font-size: 16px;
  font-weight: bold;
  border: none;
  border-radius: 14px;
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
}
.level-card-1 { background: linear-gradient(135deg, #48bb78, #38a169); }
.level-card-2 { background: linear-gradient(135deg, #4299e1, #667eea); }
.level-card-3 { background: linear-gradient(135deg, #ed8936, #dd6b20); }
.level-card-4 { background: linear-gradient(135deg, #9f7aea, #6b46c1); }
.level-card:hover { transform: translateY(-2px); }
.level-card:active { transform: translateY(1px); }

#game-header { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
#status-text {
  font-size: 17px;
  font-weight: bold;
  flex: 1;
  text-align: center;
  color: #2d3748;
  background: rgba(255, 255, 255, 0.65);
  border-radius: 12px;
  padding: 8px 14px;
}
#btn-reset {
  padding: 10px 16px;
  font-size: 14px;
  font-weight: bold;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #f6ad55, #ed8936);
  color: white;
  cursor: pointer;
  box-shadow: 0 3px 0 #c05621;
}
#btn-reset:hover { transform: translateY(-1px); }
#btn-reset:active { transform: translateY(1px); box-shadow: 0 1px 0 #c05621; }

#target-panel {
  background: rgba(255, 255, 255, 0.7);
  border: 2px dashed #9f7aea;
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 14px;
  font-weight: bold;
  color: #553c9a;
}

#game-body { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }

#grid-container {
  display: grid;
  grid-template-columns: repeat(5, 40px 26px) 40px;
  grid-template-rows: repeat(5, 40px 26px) 40px;
  background: rgba(255, 255, 255, 0.5);
  padding: 6px;
  border-radius: 14px;
  width: fit-content;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

@keyframes celebrate-bounce {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.03) rotate(-1deg); }
  50% { transform: scale(1.06) rotate(1deg); }
  75% { transform: scale(1.03) rotate(-1deg); }
}
#grid-container.celebrate { animation: celebrate-bounce 0.8s ease; }

.circuit-cell {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
}
.circuit-cell svg { width: 34px; height: 34px; }
.cell-empty { background: rgba(255, 255, 255, 0.4); border: 2px dashed #cbd5e0; }
.cell-baterai { background: #c6f6d5; cursor: default; }
.cell-kabel { background: #edf2f7; }
.cell-saklar { background: #edf2f7; }
.cell-lampu { background: #fffbea; }

@keyframes switch-flip {
  from { transform: scale(0.8); }
  to { transform: scale(1); }
}
.cell-saklar.just-changed { animation: switch-flip 0.2s ease; }

@keyframes lamp-pulse {
  from { filter: drop-shadow(0 0 2px rgba(246, 224, 94, 0.4)); }
  to { filter: drop-shadow(0 0 8px rgba(246, 224, 94, 0.9)); }
}
.lamp-terang svg { animation: lamp-pulse 1s ease-in-out infinite alternate; }

.connector {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.connector-horizontal { width: 26px; height: 40px; }
.connector-vertical { width: 40px; height: 26px; }
.connector-bar {
  background: #fff5e6;
  border: 2px dashed #dd8b1e;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.connector-bar::before {
  content: '+';
  font-size: 12px;
  font-weight: bold;
  color: #dd8b1e;
  line-height: 1;
}
.connector-horizontal.connected .connector-bar { width: 100%; height: 6px; border-radius: 3px; }
.connector-vertical.connected .connector-bar { width: 6px; height: 100%; border-radius: 3px; }

@keyframes connector-appear {
  from { transform: scale(0); }
  to { transform: scale(1); }
}
.connector.connected .connector-bar {
  background: #48bb78;
  border: none;
}
.connector.connected .connector-bar::before {
  content: '';
}
.connector.connected.just-changed .connector-bar {
  animation: connector-appear 0.3s ease;
}
.connector-disabled { visibility: hidden; cursor: default; }
.connector-full {
  visibility: visible;
  cursor: not-allowed;
}
.connector-full .connector-bar {
  background: #e2e8f0;
  border: 2px dashed #a0aec0;
}
.connector-full .connector-bar::before {
  content: '✕';
  font-size: 10px;
  color: #a0aec0;
}

#palette { display: flex; gap: 10px; flex-wrap: wrap; min-width: 160px; }

#connector-tip {
  margin-top: 12px;
  padding: 8px 12px;
  font-size: 12px;
  color: #744210;
  background: rgba(246, 173, 85, 0.25);
  border-radius: 10px;
  max-width: 220px;
}
.palette-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #fbd38d, #f6ad55);
  cursor: pointer;
  box-shadow: 0 3px 0 #dd8b1e;
  transition: transform 0.1s ease;
}
.palette-item:hover { transform: translateY(-2px); }
.palette-item.armed {
  background: linear-gradient(135deg, #f6e05e, #ecc94b);
  transform: scale(1.06);
  box-shadow: 0 0 10px rgba(246, 224, 94, 0.8);
}
.palette-icon { width: 32px; height: 32px; display: block; }
.palette-icon svg { width: 100%; height: 100%; }
.palette-label { font-size: 12px; font-weight: bold; color: #742a2a; }

.ad-slot {
  max-width: 728px;
  min-height: 90px;
  margin: 160px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.4);
  border: 2px dashed rgba(255, 255, 255, 0.8);
  border-radius: 14px;
  color: rgba(45, 55, 72, 0.55);
  font-size: 13px;
  font-weight: bold;
}
