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

body {
  background: #0d0d1a;
  color: #c0c0c0;
  font-family: 'JetBrains Mono', monospace;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #1a1a2e;
  border-bottom: 1px solid #2a2a4a;
  padding: 0 16px;
  height: 48px;
  flex-shrink: 0;
  z-index: 10;
}

#toolbar-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

#app-title {
  font-size: 18px;
  font-weight: 800;
  color: #00ff41;
  text-shadow: 0 0 10px #00ff4166, 0 0 20px #00ff4133;
  letter-spacing: 1px;
}

#app-subtitle {
  font-size: 11px;
  font-weight: 300;
  color: #5a5a7a;
  letter-spacing: 0.5px;
}

#toolbar-center {
  font-size: 11px;
  color: #5a5a7a;
}

#toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

#toolbar-right button, #toolbar-right select {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 5px 10px;
  background: #252545;
  color: #a0a0c0;
  border: 1px solid #3a3a5a;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

#toolbar-right button:hover, #toolbar-right select:hover {
  background: #303060;
  border-color: #00ff41;
  color: #00ff41;
}

#toolbar-right select {
  appearance: none;
  padding-right: 20px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%235a5a7a'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
}

#toolbar-right select option {
  background: #1a1a2e;
  color: #a0a0c0;
}

#main-area {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

#palette {
  width: 160px;
  background: #141428;
  border-right: 1px solid #2a2a4a;
  overflow-y: auto;
  flex-shrink: 0;
  padding: 8px 0;
  z-index: 5;
}

#palette::-webkit-scrollbar {
  width: 4px;
}
#palette::-webkit-scrollbar-track {
  background: #141428;
}
#palette::-webkit-scrollbar-thumb {
  background: #2a2a4a;
  border-radius: 2px;
}

.palette-header {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #4a4a6a;
  padding: 8px 12px 4px;
}

.palette-divider {
  height: 1px;
  background: #2a2a4a;
  margin: 6px 12px;
}

.palette-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 8px;
  margin: 1px 6px;
  border-radius: 6px;
  cursor: grab;
  transition: all 0.15s;
  border: 1px solid transparent;
}

.palette-item:hover {
  background: #1e1e3a;
  border-color: #3a3a5a;
}

.palette-item:active {
  cursor: grabbing;
  border-color: #00ff41;
  background: #1a2a1a;
}

.palette-item span {
  font-size: 9px;
  font-weight: 500;
  color: #7a7a9a;
  margin-top: 1px;
  letter-spacing: 1px;
}

.palette-item:hover span {
  color: #00ff41;
}

.palette-canvas {
  pointer-events: none;
}

#canvas {
  flex: 1;
  display: block;
  cursor: crosshair;
}

/* Truth Table Panel */
#truth-panel {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 340px;
  background: #141428;
  border-left: 1px solid #2a2a4a;
  z-index: 20;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

#truth-panel.hidden {
  transform: translateX(100%);
}

#truth-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #2a2a4a;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #00ff41;
}

#truth-panel-header button {
  background: none;
  border: none;
  color: #5a5a7a;
  cursor: pointer;
  font-size: 16px;
  font-family: 'JetBrains Mono', monospace;
}

#truth-panel-header button:hover {
  color: #ff4444;
}

#truth-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  font-size: 11px;
}

#truth-panel-content table {
  width: 100%;
  border-collapse: collapse;
}

#truth-panel-content th {
  color: #00ff41;
  border-bottom: 2px solid #2a2a4a;
  padding: 6px 8px;
  text-align: center;
  font-weight: 700;
}

#truth-panel-content td {
  text-align: center;
  padding: 4px 8px;
  border-bottom: 1px solid #1a1a2e;
  color: #a0a0c0;
}

#truth-panel-content tr:nth-child(even) td {
  background: #181830;
}

#truth-panel-content td.val-1 {
  color: #00ff41;
  font-weight: 700;
}

#truth-panel-content td.val-0 {
  color: #555;
}

#truth-panel-content .no-data {
  color: #5a5a7a;
  text-align: center;
  padding: 30px;
}

/* JS Export Modal */
#js-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.75);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

#js-modal.hidden {
  display: none;
}

#js-modal-inner {
  width: 720px;
  max-width: 90vw;
  max-height: 80vh;
  background: #141428;
  border: 1px solid #2a2a4a;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 60px rgba(0,255,65,0.1);
}

#js-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid #2a2a4a;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #00ff41;
}

#js-modal-header div {
  display: flex;
  gap: 6px;
}

#js-modal-header button {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 5px 10px;
  background: #252545;
  color: #a0a0c0;
  border: 1px solid #3a3a5a;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

#js-modal-header button:hover {
  background: #303060;
  border-color: #00ff41;
  color: #00ff41;
}

#js-modal-content {
  flex: 1;
  overflow: auto;
  padding: 16px 20px;
  font-size: 12px;
  line-height: 1.6;
  color: #c8d0c8;
  white-space: pre-wrap;
  word-break: break-word;
  tab-size: 2;
}

/* ROM Modal */
#rom-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.75);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

#rom-modal.hidden { display: none; }

#rom-modal-inner {
  width: 340px;
  background: #141428;
  border: 1px solid #2a2a4a;
  border-radius: 10px;
  box-shadow: 0 0 40px rgba(0,255,65,0.08);
}

#rom-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid #2a2a4a;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #ffaa00;
}

#rom-modal-header button {
  background: none; border: none;
  color: #5a5a7a; cursor: pointer;
  font-size: 16px; font-family: 'JetBrains Mono', monospace;
}

#rom-modal-header button:hover { color: #ff4444; }

#rom-modal-content {
  padding: 16px;
}

#rom-modal-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
}

#rom-modal-content th {
  color: #ffaa00;
  border-bottom: 2px solid #2a2a4a;
  padding: 6px 10px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
}

#rom-modal-content td {
  text-align: center;
  padding: 6px 10px;
  border-bottom: 1px solid #1a1a2e;
}

#rom-modal-content .rom-bit {
  width: 32px;
  height: 28px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  background: #1a1a2e;
  color: #00ff41;
  border: 1px solid #3a3a5a;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

#rom-modal-content .rom-bit:hover {
  border-color: #ffaa00;
}

#rom-modal-content .rom-bit.val-0 { color: #555; }
#rom-modal-content .rom-bit.val-1 { color: #00ff41; border-color: #00ff4166; }

#rom-modal-content .rom-save-btn {
  width: 100%;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 8px;
  background: #1a3a1a;
  color: #00ff41;
  border: 1px solid #00ff4166;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

#rom-modal-content .rom-save-btn:hover {
  background: #2a4a2a;
  border-color: #00ff41;
}

/* Context Menu */
#context-menu {
  position: absolute;
  background: #1e1e3a;
  border: 1px solid #3a3a5a;
  border-radius: 6px;
  padding: 4px 0;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  min-width: 160px;
}

#context-menu.hidden {
  display: none;
}

.ctx-item {
  padding: 8px 14px;
  font-size: 12px;
  cursor: pointer;
  color: #a0a0c0;
  transition: all 0.1s;
}

.ctx-item.hidden {
  display: none;
}

.ctx-item:hover {
  background: #2a2a4a;
  color: #fff;
}

#ctx-delete:hover {
  color: #ff4444;
}

#ctx-program:hover {
  color: #ffaa00;
}

#tooltip {
  position: absolute;
  background: #1e1e3aee;
  border: 1px solid #3a3a5a;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  color: #00ff41;
  z-index: 50;
  pointer-events: none;
  white-space: nowrap;
}

#tooltip.hidden {
  display: none;
}

#celebration {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  background: linear-gradient(135deg, #1a3a1a, #0d2d0d);
  border: 2px solid #00ff41;
  border-radius: 16px;
  padding: 24px 48px;
  font-size: 20px;
  font-weight: 800;
  color: #00ff41;
  text-shadow: 0 0 20px #00ff4166;
  z-index: 200;
  pointer-events: none;
  box-shadow: 0 0 60px #00ff4133;
}

#celebration.show {
  animation: celebPop 2.5s ease forwards;
}

#celebration.hidden {
  display: none;
}

@keyframes celebPop {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  15% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
  25% { transform: translate(-50%, -50%) scale(1); }
  80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
}

#footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #111122;
  border-top: 1px solid #2a2a4a;
  padding: 6px 16px;
  font-size: 10px;
  color: #3a3a5a;
  flex-shrink: 0;
  height: 28px;
}

#footer a {
  color: #4a4a6a;
  text-decoration: none;
  transition: color 0.15s;
}

#footer a:hover {
  color: #00ff41;
}

@media (max-width: 768px) {
  #palette {
    width: 60px;
  }
  .palette-item span {
    font-size: 7px;
  }
  .palette-canvas {
    width: 48px !important;
    height: 30px !important;
  }
  #toolbar-left {
    gap: 4px;
  }
  #app-subtitle {
    display: none;
  }
  #app-title {
    font-size: 14px;
  }
  #toolbar-center {
    display: none;
  }
  #toolbar-right button, #toolbar-right select {
    font-size: 9px;
    padding: 4px 6px;
  }
  #truth-panel {
    width: 260px;
  }
  #js-modal-inner {
    width: 95vw;
  }
}