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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  color: #333;
  min-height: 100vh;
}

header {
  background: rgba(0, 0, 0, 0.3);
  color: white;
  padding: 15px;
  text-align: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

header h1 {
  font-size: 1.8rem;
  margin-bottom: 3px;
}

.subtitle {
  font-size: 0.85rem;
  opacity: 0.9;
}

.container {
  max-width: 1800px;
  margin: 10px auto;
  padding: 0 15px;
}

.control-panel {
  background: white;
  padding: 12px 15px;
  border-radius: 8px;
  margin-bottom: 15px;
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.controls-group {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.3s;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn-success {
  background: #28a745;
  color: white;
}

.btn-warning {
  background: #ffc107;
  color: #333;
}

.btn-info {
  background: #17a2b8;
  color: white;
}

.btn-danger {
  background: #dc3545;
  color: white;
}

.btn-primary {
  background: #007bff;
  color: white;
}

input[type="range"] {
  width: 150px;
  margin-left: 10px;
}

select {
  padding: 8px 16px;
  border: 2px solid #007bff;
  border-radius: 5px;
  background: white;
  color: #333;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
}

select:hover {
  background: #f0f8ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

select:focus {
  outline: none;
  border-color: #0056b3;
}

.main-grid {
  display: grid;
  grid-template-columns: 640px 400px 1fr;
  grid-template-rows: auto auto;
  gap: 15px;
  margin-bottom: 15px;
}

.display-section {
  grid-column: 1 / 2;
  grid-row: 1 / 2;
}

.registers-section {
  grid-column: 2 / 3;
  grid-row: 1 / 2;
}

.memory-section {
  grid-column: 3 / 4;
  grid-row: 1 / 2;
}

.status-section {
  grid-column: 1 / 2;
  grid-row: 2 / 3;
}

.stack-section {
  grid-column: 2 / 3;
  grid-row: 2 / 3;
}

.info-section {
  grid-column: 3 / 4;
  grid-row: 2 / 3;
}

.widget {
  background: white;
  border-radius: 8px;
  padding: 12px 15px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  height: 100%;
  overflow: hidden;
}

.widget-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 10px;
  color: #2a5298;
  border-bottom: 2px solid #2a5298;
  padding-bottom: 3px;
}

#display {
  background: #000;
  border: 3px solid #333;
  border-radius: 5px;
  display: block;
  margin: 0 auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.registers-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
  margin-bottom: 8px;
}

.register-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 8px;
  background: #f8f9fa;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
}

.flag-register {
  background: #fff3cd;
  border: 1px solid #ffc107;
}

.register-name {
  font-weight: 700;
  color: #2a5298;
}

.register-value {
  font-weight: 600;
  color: #28a745;
}

.register-binary {
  font-size: 0.65rem;
  color: #666;
}

.special-registers {
  display: flex;
  gap: 5px;
  padding-top: 8px;
  border-top: 1px solid #dee2e6;
}

.special-registers .register-item {
  flex: 1;
  font-size: 0.75rem;
}

.memory-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.memory-controls label {
  font-size: 0.75rem;
}

.memory-controls input {
  width: 50px;
  padding: 3px 5px;
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
  border: 1px solid #ccc;
  border-radius: 3px;
}

.memory-controls button {
  padding: 3px 8px;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.7rem;
}

.memory-controls button:hover {
  background: #0056b3;
}

.memory-grid {
  font-family: 'Courier New', monospace;
  font-size: 0.7rem;
  overflow-x: auto;
  max-height: 320px;
  overflow-y: auto;
}

.memory-header {
  display: grid;
  grid-template-columns: 50px repeat(16, 1fr);
  gap: 3px;
  margin-bottom: 3px;
  font-weight: 700;
  color: #2a5298;
  font-size: 0.65rem;
  position: sticky;
  top: 0;
  background: white;
  z-index: 1;
}

.memory-row {
  display: grid;
  grid-template-columns: 50px repeat(16, 1fr);
  gap: 3px;
  margin-bottom: 2px;
}

.memory-address {
  color: #666;
  font-weight: 600;
}

.memory-byte {
  text-align: center;
  padding: 2px;
  background: #f8f9fa;
  border-radius: 2px;
}

.pc-highlight {
  background: #28a745;
  color: white;
  font-weight: 700;
}

.index-highlight {
  background: #ffc107;
  font-weight: 600;
}

.stack-info {
  font-family: 'Courier New', monospace;
  font-weight: 700;
  margin-bottom: 8px;
  color: #2a5298;
  font-size: 0.85rem;
}

.stack-grid {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow-y: visible;
}

.stack-item {
  display: flex;
  justify-content: space-between;
  padding: 4px 8px;
  background: #f8f9fa;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
}

.stack-item.current {
  background: #28a745;
  color: white;
  font-weight: 700;
}

.stack-item.empty {
  opacity: 0.4;
}

.status-section h4 {
  color: #2a5298;
  margin-bottom: 5px;
  margin-top: 8px;
  font-size: 0.85rem;
}

.status-section h4:first-child {
  margin-top: 0;
}

.timer-item {
  margin-bottom: 6px;
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
}

.timer-label {
  font-weight: 600;
  color: #666;
}

.timer-value {
  font-weight: 700;
  color: #28a745;
  margin-left: 6px;
}

.timer-bar {
  width: 100%;
  height: 6px;
  background: #e9ecef;
  border-radius: 3px;
  margin-top: 2px;
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  background: linear-gradient(90deg, #28a745, #20c997);
  transition: width 0.1s;
}

.keyboard-layout {
  margin-top: 4px;
}

.keyboard-row {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}

.key {
  flex: 1;
  height: 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
  border: 2px solid #dee2e6;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  cursor: default;
  transition: all 0.1s;
  padding: 4px;
}

.key-pressed {
  background: #28a745;
  color: white;
  border-color: #28a745;
  transform: scale(0.95);
}

.key-hex {
  font-size: 0.7rem;
  font-weight: 700;
}

.key-map {
  font-size: 0.55rem;
  opacity: 0.7;
  margin-top: 1px;
}

.cpu-state {
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
  font-weight: 700;
  color: #28a745;
  padding: 6px;
  background: #f8f9fa;
  border-radius: 4px;
  text-align: center;
}

.cpu-speed {
  font-family: 'Courier New', monospace;
  margin-top: 6px;
  color: #666;
  font-size: 0.8rem;
}

.info-section .widget {
  height: 100%;
  overflow-y: auto;
}

.info-panel h2 {
  color: #2a5298;
  margin-bottom: 10px;
  font-size: 1rem;
}

.info-card {
  background: #f8f9fa;
  padding: 10px;
  border-radius: 6px;
  border-left: 3px solid #2a5298;
  margin-bottom: 10px;
}

.info-card h3 {
  color: #2a5298;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.info-card p {
  font-weight: 600;
  margin-bottom: 6px;
  color: #666;
  font-size: 0.8rem;
}

.info-card ul {
  list-style: none;
  padding-left: 0;
}

.info-card li {
  padding: 3px 0;
  color: #555;
  font-size: 0.75rem;
}

.info-card li::before {
  content: "▸ ";
  color: #2a5298;
  font-weight: 700;
}

footer {
  background: rgba(0, 0, 0, 0.3);
  color: white;
  text-align: center;
  padding: 12px;
  margin-top: 15px;
  font-size: 0.85rem;
}

@media (max-width: 1200px) {
  .main-grid {
    grid-template-columns: 1fr 1fr;
  }

  .display-section {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
  }

  .registers-section {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
  }

  .memory-section {
    grid-column: 1 / 3;
    grid-row: 2 / 3;
  }

  .stack-section {
    grid-column: 1 / 2;
    grid-row: 3 / 4;
  }

  .status-section {
    grid-column: 2 / 3;
    grid-row: 3 / 4;
  }
}

@media (max-width: 768px) {
  .main-grid {
    grid-template-columns: 1fr;
  }

  .display-section,
  .registers-section,
  .memory-section,
  .stack-section,
  .status-section {
    grid-column: 1 / 2;
    grid-row: auto;
  }
}
