:root {
  --color-bg: #f0f4f8;
  --color-sidebar: #ffffff;
  --color-primary: #ff5e5e;
  --color-secondary: #4a90e2;
  --color-accent: #f7d716;
  --color-success: #43ca83;
  --color-text: #2d3436;
  --shadow-soft: 0 4px 6px rgba(0, 0, 0, 0.05), 0 10px 15px rgba(0, 0, 0, 0.1);
  --border-radius: 16px;
}

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

body {
  font-family: 'Segoe UI', 'Roboto', sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  overflow: hidden;
  height: 100vh;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

header {
  background: white;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--color-primary);
}

.controls {
  display: flex;
  gap: 1rem;
}

.btn {
  padding: 0.6rem 1.2rem;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  transition: transform 0.2s, background 0.2s;
  box-shadow: 0 4px 0 rgba(0,0,0,0.1);
}

.btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

.btn-primary { background: var(--color-primary); color: white; }
.btn-secondary { background: var(--color-secondary); color: white; }
.btn-danger { background: #ff4757; color: white; }

main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

#sidebar {
  width: 280px;
  background: var(--color-sidebar);
  border-right: 1px solid rgba(0,0,0,0.05);
  padding: 1.5rem;
  overflow-y: auto;
}

.sidebar-section h3 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05rem;
  color: #95a5a6;
  margin-bottom: 1rem;
}

.nodon-palette {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.nodon-item {
  background: #f8f9fa;
  border: 2px solid transparent;
  padding: 1rem;
  border-radius: var(--border-radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  cursor: grab;
  transition: all 0.2s;
}

.nodon-item:hover {
  background: white;
  border-color: var(--color-secondary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
}

.nodon-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #dfe6e9;
}

.nodon-icon.ball { border-radius: 50%; background: #ff7675; }
.nodon-icon.ramp { background: #74b9ff; clip-path: polygon(0 100%, 100% 100%, 100% 0); }
.nodon-icon.box { background: #fab1a0; }
.nodon-icon.floor { height: 10px; background: #636e72; }
.nodon-icon.sensor { background: #55efc4; border: 2px dashed #00b894; }
.nodon-icon.fan { background: #81ecec; border-radius: 50%; }
.nodon-icon.button { background: #fdcb6e; border-radius: 4px; border-bottom: 4px solid #e17055; }

#canvas-container {
  flex: 1;
  position: relative;
  background: #f0f4f8;
  background-image: radial-gradient(#d1d8e0 1px, transparent 1px);
  background-size: 20px 20px;
}

#physics-canvas {
  width: 100%;
  height: 100%;
}

#instructions {
  position: absolute;
  bottom: 20px;
  left: 20px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(4px);
  padding: 1rem;
  border-radius: 12px;
  pointer-events: none;
  font-size: 0.85rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nodon-icon.goal { background: #fd9644; border: 4px solid #fa8231; border-radius: 8px 8px 2px 2px; position: relative; }
.nodon-icon.goal::after { content: '★'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: white; font-size: 1.2rem; }

#success-msg {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  background: rgba(255, 255, 255, 0.95);
  padding: 2rem 4rem;
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
  text-align: center;
  z-index: 100;
  pointer-events: none;
  transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#success-msg.show {
  transform: translate(-50%, -50%) scale(1);
}

#success-msg h2 { color: var(--color-primary); font-size: 3rem; margin-bottom: 0.5rem; }
#success-msg p { font-size: 1.2rem; color: #636e72; }

#wiring-layer circle.port {
  cursor: pointer;
  pointer-events: auto;
  transition: r 0.2s, stroke-width 0.2s;
}

#wiring-layer circle.port:hover {
  r: 10;
  stroke-width: 4;
}

#wiring-layer circle.port.input { fill: #f7d716; stroke: #d4b40a; }
.nodon-icon.timer { background: #eb3b5a; border-radius: 50%; border: 3px solid #fc5c65; }
.nodon-icon.timer::after { content: '⏱'; color: white; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }

.nodon-icon.warp-a { background: #8854d0; border-radius: 50%; border: 3px dashed #a55eea; }
.nodon-icon.warp-b { background: #3867d6; border-radius: 50%; border: 3px dashed #4b7bec; }

.nodon-icon.magnet { background: #2f3542; position: relative; border-radius: 4px; border-bottom: 4px solid #747d8c; }
.nodon-icon.magnet::after { content: 'U'; color: #ff4757; font-weight: bold; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 1.5rem; }

/* Settings Panel */
#settings-panel {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 200px;
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-soft);
  padding: 1rem;
  z-index: 100;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#settings-panel.hidden {
  transform: translateX(250px);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  border-bottom: 1px solid #f1f2f6;
  padding-bottom: 0.5rem;
}

.panel-header span { font-weight: 800; color: var(--color-primary); }

#node-delete {
  background: #ff4757;
  color: white;
  border: none;
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
}

.prop-group {
  margin-bottom: 1rem;
}

.prop-group label {
  display: block;
  font-size: 0.75rem;
  color: #747d8c;
  margin-bottom: 0.3rem;
}

.prop-group input {
  width: 100%;
}

@keyframes pulse-logic {
  0% { filter: brightness(1); }
  50% { filter: brightness(1.5); }
  100% { filter: brightness(1); }
}

/* Hover Tooltip */
#hover-tooltip {
  position: absolute;
  background: rgba(45, 52, 54, 0.95);
  color: white;
  padding: 0.8rem 1.2rem;
  border-radius: 12px;
  font-size: 0.8rem;
  pointer-events: none;
  z-index: 1000;
  max-width: 250px;
  box-shadow: 0 10px 20px rgba(0,0,0,0.2);
  transform: translate(10px, 10px);
}

.tooltip-title { font-weight: 800; margin-bottom: 0.3rem; color: var(--color-accent); }
.tooltip-body { line-height: 1.4; opacity: 0.9; }

/* Modal */
.modal {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  display: flex; justify-content: center; align-items: center;
  z-index: 2000;
}

.modal-content {
  background: white;
  padding: 2rem;
  border-radius: 24px;
  width: 90%; max-width: 400px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.modal-content h2 { margin-bottom: 1.5rem; font-weight: 800; }

.setting-item {
  margin-bottom: 1.2rem;
  display: flex; justify-content: space-between; align-items: center;
}

.setting-item label { font-weight: 600; color: #636e72; }
.setting-item select { padding: 0.5rem; border-radius: 8px; border: 1px solid #dfe6e9; }

/* Dark Theme */
body.theme-dark {
  --color-bg: #2d3436;
  --color-sidebar: #1e272e;
  --color-text: #f1f2f6;
}

body.theme-dark header, 
body.theme-dark #sidebar,
body.theme-dark .modal-content,
body.theme-dark #settings-panel {
  background: #1e272e;
  color: #f1f2f6;
  border-color: rgba(255,255,255,0.1);
}

body.theme-dark .nodon-item { background: #2f3542; }
body.theme-dark #canvas-container { background: #2d3436; background-image: radial-gradient(#4b4b4b 1px, transparent 1px); }
body.theme-dark .setting-item label { color: #b2bec3; }
