@font-face {
  font-family: 'PixelFont';
  src: local('Press Start 2P');
}

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

:root {
  --navy: #1a1c2c;
  --dark: #262b44;
  --mid: #3a4466;
  --cream: #f4f4e8;
  --green: #38b764;
  --red: #e43b44;
  --blue: #3978a8;
  --yellow: #fee761;
  --orange: #f77622;
  --purple: #7b5ea7;
  --cyan: #41a6f6;
  --pink: #e8546b;
  --brown: #6b4226;
  --light-blue: #73eff7;
  --pixel-shadow: 2px 2px 0px rgba(0,0,0,0.5);
  --pixel-shadow-sm: 1px 1px 0px rgba(0,0,0,0.5);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--navy);
  font-family: 'VT323', monospace;
  color: var(--cream);
}

#game-container {
  display: flex;
  width: 100%;
  height: calc(100% - 48px - 20px);
}

#canvas-wrapper {
  flex: 7;
  position: relative;
  overflow: hidden;
  background: #0d0e1a;
  border-right: 3px solid var(--dark);
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
}

#hud-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  pointer-events: none;
  padding: 8px;
}

#hud-top-left {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

#hud-top-left > div {
  background: rgba(26,28,44,0.85);
  padding: 4px 10px;
  border: 2px solid var(--mid);
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  box-shadow: var(--pixel-shadow-sm);
}

#entity-count { color: var(--green); }
#day-night-indicator { font-size: 14px; padding: 2px 8px; }
#fps-counter { color: var(--yellow); }

#goal-bubble {
  color: var(--yellow);
  max-width: 300px;
  border-color: var(--yellow) !important;
}

/* Notepad Panel */
#notepad-panel {
  flex: 3;
  min-width: 260px;
  max-width: 400px;
  background: #2a2136;
  background-image: 
    repeating-linear-gradient(
      transparent,
      transparent 27px,
      rgba(255,255,255,0.04) 27px,
      rgba(255,255,255,0.04) 28px
    );
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-left: 4px solid var(--purple);
}

#notepad-header {
  text-align: center;
  padding: 12px 8px 8px;
  border-bottom: 3px solid var(--purple);
  background: rgba(0,0,0,0.2);
}

.notepad-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  color: var(--yellow);
  text-shadow: var(--pixel-shadow);
  display: block;
}

.notepad-subtitle {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--purple);
  letter-spacing: 4px;
}

/* Summon Section */
#summon-section {
  padding: 10px;
  border-bottom: 2px solid rgba(255,255,255,0.08);
}

#summon-input-wrapper {
  position: relative;
}

#summon-input {
  width: 100%;
  padding: 10px 12px;
  font-family: 'VT323', monospace;
  font-size: 20px;
  color: var(--cream);
  background: rgba(0,0,0,0.4);
  border: 3px solid var(--mid);
  outline: none;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

#summon-input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 10px rgba(65,166,246,0.3), inset 0 2px 4px rgba(0,0,0,0.3);
}

#summon-input::placeholder {
  color: rgba(244,244,232,0.3);
  font-size: 16px;
}

#autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--dark);
  border: 2px solid var(--mid);
  border-top: none;
  z-index: 100;
  max-height: 150px;
  overflow-y: auto;
}

#autocomplete-dropdown .ac-item {
  padding: 6px 12px;
  font-family: 'VT323', monospace;
  font-size: 18px;
  cursor: pointer;
  color: var(--cream);
}

#autocomplete-dropdown .ac-item:hover,
#autocomplete-dropdown .ac-item.selected {
  background: var(--purple);
  color: var(--yellow);
}

#summon-btn {
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  color: var(--navy);
  background: var(--yellow);
  border: 3px solid var(--orange);
  cursor: pointer;
  box-shadow: 0 4px 0 var(--brown), var(--pixel-shadow);
  transition: transform 0.05s, box-shadow 0.05s;
  animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 4px 0 var(--brown), 0 0 5px rgba(254,231,97,0.3); }
  50% { box-shadow: 0 4px 0 var(--brown), 0 0 20px rgba(254,231,97,0.6); }
}

#summon-btn:hover {
  background: #fff080;
}

#summon-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--brown);
}

/* Section Label */
.section-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--purple);
  padding: 6px 10px;
  background: rgba(0,0,0,0.2);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  letter-spacing: 1px;
}

/* Entity List */
#entity-list-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-bottom: 2px solid rgba(255,255,255,0.08);
}

#entity-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px;
}

.entity-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  cursor: pointer;
  border: 2px solid transparent;
  margin-bottom: 2px;
  font-size: 16px;
  font-family: 'VT323', monospace;
}

.entity-item:hover {
  background: rgba(255,255,255,0.06);
  border-color: var(--mid);
}

.entity-item.selected {
  border-color: var(--cyan);
  background: rgba(65,166,246,0.1);
}

.entity-icon {
  width: 16px;
  height: 16px;
  border: 1px solid rgba(255,255,255,0.2);
  flex-shrink: 0;
}

.entity-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entity-hp {
  width: 40px;
  height: 6px;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--mid);
  flex-shrink: 0;
}

.entity-hp-fill {
  height: 100%;
  background: var(--green);
  transition: width 0.3s;
}

.entity-delete {
  cursor: pointer;
  color: var(--red);
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  opacity: 0.5;
  flex-shrink: 0;
}

.entity-delete:hover {
  opacity: 1;
}

/* Inventory */
#inventory-section {
  border-bottom: 2px solid rgba(255,255,255,0.08);
}

#inventory-bar {
  display: flex;
  gap: 4px;
  padding: 8px;
  overflow-x: auto;
}

.inv-slot {
  width: 36px;
  height: 36px;
  background: rgba(0,0,0,0.3);
  border: 2px solid var(--mid);
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  position: relative;
}

.inv-slot:hover {
  border-color: var(--cyan);
}

.inv-slot.filled {
  border-color: var(--purple);
}

.inv-slot .inv-icon {
  width: 24px;
  height: 24px;
}

.inv-slot .inv-label {
  position: absolute;
  bottom: -14px;
  font-size: 9px;
  font-family: 'VT323', monospace;
  white-space: nowrap;
  color: var(--cream);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

.inv-slot:hover .inv-label {
  opacity: 1;
}

/* Puzzle Section */
#puzzle-section {
  padding-bottom: 4px;
}

#puzzle-info {
  padding: 8px 10px;
}

#puzzle-goal {
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: var(--yellow);
  margin-bottom: 6px;
  padding: 6px 8px;
  background: rgba(0,0,0,0.3);
  border: 2px solid var(--mid);
}

#puzzle-controls {
  display: flex;
  gap: 6px;
}

.small-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  padding: 6px 10px;
  background: var(--dark);
  color: var(--cream);
  border: 2px solid var(--mid);
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0,0,0,0.4);
}

.small-btn:hover {
  background: var(--mid);
}

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

#level-select {
  flex: 1;
  font-family: 'VT323', monospace;
  font-size: 14px;
  padding: 4px 6px;
  background: var(--dark);
  color: var(--cream);
  border: 2px solid var(--mid);
  cursor: pointer;
}

/* Context Menu */
#context-menu {
  position: absolute;
  background: var(--dark);
  border: 3px solid var(--mid);
  box-shadow: 4px 4px 0 rgba(0,0,0,0.5);
  z-index: 200;
  min-width: 160px;
}

.ctx-item {
  padding: 8px 14px;
  font-family: 'VT323', monospace;
  font-size: 18px;
  cursor: pointer;
  color: var(--cream);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.ctx-item:hover {
  background: var(--purple);
  color: var(--yellow);
}

.ctx-item:last-child {
  border-bottom: none;
}

/* Tooltip */
#tooltip {
  position: absolute;
  background: var(--navy);
  border: 2px solid var(--cyan);
  padding: 6px 10px;
  font-family: 'VT323', monospace;
  font-size: 14px;
  pointer-events: none;
  z-index: 150;
  box-shadow: var(--pixel-shadow);
  max-width: 200px;
}

/* Toolbar */
#toolbar {
  height: 48px;
  background: var(--dark);
  border-top: 3px solid var(--mid);
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 4px;
  overflow-x: auto;
}

.tool-btn {
  width: 40px;
  height: 36px;
  background: var(--navy);
  border: 2px solid var(--mid);
  color: var(--cream);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 0 rgba(0,0,0,0.4);
  flex-shrink: 0;
}

.tool-btn:hover {
  background: var(--mid);
  border-color: var(--cyan);
}

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

.tool-btn.active {
  background: var(--purple);
  border-color: var(--yellow);
}

.tool-separator {
  width: 2px;
  height: 24px;
  background: var(--mid);
  margin: 0 4px;
  flex-shrink: 0;
}

/* Modal */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

#modal-box {
  background: var(--dark);
  border: 4px solid var(--purple);
  box-shadow: 6px 6px 0 rgba(0,0,0,0.5);
  padding: 20px;
  max-width: 400px;
  width: 90%;
}

#modal-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  color: var(--yellow);
  margin-bottom: 14px;
  text-align: center;
}

#modal-content {
  font-family: 'VT323', monospace;
  font-size: 18px;
  color: var(--cream);
  margin-bottom: 16px;
  line-height: 1.4;
}

#modal-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.modal-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 8px 14px;
  background: var(--navy);
  color: var(--cream);
  border: 2px solid var(--mid);
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0,0,0,0.4);
}

.modal-btn:hover {
  background: var(--mid);
}

.modal-btn.primary {
  background: var(--purple);
  border-color: var(--yellow);
  color: var(--yellow);
}

/* Welcome */
#welcome-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13,14,26,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 600;
  animation: fadeIn 0.5s;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

#welcome-box {
  background: var(--dark);
  border: 4px solid var(--yellow);
  box-shadow: 8px 8px 0 rgba(0,0,0,0.5);
  padding: 28px;
  max-width: 460px;
  width: 90%;
  text-align: center;
}

.welcome-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  color: var(--yellow);
  margin-bottom: 16px;
  text-shadow: var(--pixel-shadow);
}

.welcome-text {
  font-family: 'VT323', monospace;
  font-size: 20px;
  color: var(--cream);
  margin-bottom: 18px;
  line-height: 1.3;
}

.welcome-examples {
  margin-bottom: 20px;
}

.example-item {
  font-family: 'VT323', monospace;
  font-size: 18px;
  color: rgba(244,244,232,0.7);
  margin: 6px 0;
}

.example-cmd {
  color: var(--cyan);
  background: rgba(0,0,0,0.3);
  padding: 2px 8px;
  border: 1px solid var(--mid);
}

#welcome-dismiss {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  padding: 12px 24px;
  background: var(--yellow);
  color: var(--navy);
  border: 3px solid var(--orange);
  cursor: pointer;
  box-shadow: 0 4px 0 var(--brown);
}

#welcome-dismiss:hover {
  background: #fff080;
}

#welcome-dismiss:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--brown);
}

/* Footer */
#game-footer {
  height: 20px;
  background: var(--navy);
  text-align: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: rgba(244,244,232,0.4);
  line-height: 20px;
  border-top: 1px solid var(--dark);
}

#game-footer a {
  color: var(--purple);
  text-decoration: none;
}

#game-footer a:hover {
  color: var(--yellow);
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.2);
}

::-webkit-scrollbar-thumb {
  background: var(--mid);
  border: 1px solid var(--dark);
}

.hidden {
  display: none !important;
}

/* Mobile responsive */
@media (max-width: 1024px) {
  #game-container {
    flex-direction: column;
    height: calc(100% - 48px - 20px);
  }
  
  #canvas-wrapper {
    flex: 1;
    border-right: none;
    border-bottom: 3px solid var(--dark);
  }
  
  #notepad-panel {
    max-width: none;
    min-width: auto;
    max-height: 45%;
    border-left: none;
    border-top: 4px solid var(--purple);
  }
}

@media (max-width: 600px) {
  .notepad-title { font-size: 11px; }
  .notepad-subtitle { font-size: 7px; }
  #summon-input { font-size: 16px; padding: 8px; }
  #summon-btn { font-size: 10px; padding: 8px; }
  .tool-btn { width: 34px; height: 30px; font-size: 14px; }
  #toolbar { height: 40px; }
  #game-container { height: calc(100% - 40px - 20px); }
}