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

:root {
  --c64-dark-blue: #413d71;
  --c64-light-blue: #7f7fc3;
  --c64-white: #ffffff;
  --c64-red: #a83333;
  --c64-green: #55a855;
  --c64-black: #000000;
  --c64-brown: #713d41;
  --c64-cyan: #6fc3df;
  --c64-yellow: #b8c76f;
}

body {
  font-family: 'Press Start 2P', monospace;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f0f23 100%);
  min-height: 100vh;
  color: var(--c64-light-blue);
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

.app-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100vh;
}

.control-panel {
  background: linear-gradient(180deg, var(--c64-brown) 0%, #5a3035 100%);
  border: 4px solid var(--c64-black);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 
    inset 0 2px 0 rgba(255,255,255,0.1),
    0 4px 20px rgba(0,0,0,0.5);
}

.panel-title {
  font-size: 14px;
  color: var(--c64-cyan);
  text-align: center;
  margin-bottom: 16px;
  text-shadow: 2px 2px 0 var(--c64-black);
}

.input-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

@media (min-width: 600px) {
  .input-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-group label {
  font-size: 8px;
  color: var(--c64-yellow);
}

.c64-input {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  padding: 8px;
  background: var(--c64-dark-blue);
  border: 2px solid var(--c64-light-blue);
  color: var(--c64-white);
  outline: none;
}

.c64-input:focus {
  border-color: var(--c64-cyan);
  box-shadow: 0 0 10px var(--c64-cyan);
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.c64-button {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  padding: 10px 16px;
  background: var(--c64-dark-blue);
  border: 3px solid var(--c64-light-blue);
  color: var(--c64-white);
  cursor: pointer;
  transition: all 0.1s;
  text-transform: uppercase;
}

.c64-button:hover {
  background: var(--c64-light-blue);
  color: var(--c64-dark-blue);
  transform: scale(1.05);
}

.c64-button:active {
  transform: scale(0.95);
}

.c64-button.primary {
  background: var(--c64-green);
  border-color: #77cc77;
}

.c64-button.primary:hover {
  background: #77cc77;
  color: var(--c64-black);
}

.c64-button.danger {
  background: var(--c64-red);
  border-color: #cc5555;
}

.c64-button.danger:hover {
  background: #cc5555;
}

.c64-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.c64-screen {
  position: relative;
  background: #222;
  border-radius: 20px;
  padding: 20px;
  box-shadow: 
    inset 0 0 50px rgba(0,0,0,0.5),
    0 10px 40px rgba(0,0,0,0.7);
}

.screen-bezel {
  background: linear-gradient(145deg, #333 0%, #1a1a1a 100%);
  border-radius: 12px;
  padding: 15px;
  border: 3px solid #444;
}

.screen-inner {
  position: relative;
  width: 100%;
  aspect-ratio: 16/10;
  background: var(--c64-dark-blue);
  border: 4px solid var(--c64-black);
  overflow: hidden;
  border-radius: 4px;
}

.screen-shake {
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.glitch {
  animation: glitch 0.15s linear;
}

@keyframes glitch {
  0% { filter: hue-rotate(0deg); }
  25% { filter: hue-rotate(90deg) saturate(2); transform: skewX(2deg); }
  50% { filter: hue-rotate(180deg); transform: skewX(-2deg); }
  75% { filter: hue-rotate(270deg) saturate(0.5); }
  100% { filter: hue-rotate(360deg); }
}

.crt-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 100;
}

.scanlines {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0,0,0,0.15) 0px,
    rgba(0,0,0,0.15) 1px,
    transparent 1px,
    transparent 3px
  );
}

.crt-flicker {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(100, 150, 200, 0.02);
  animation: flicker 0.15s infinite;
}

@keyframes flicker {
  0%, 100% { opacity: 0.97; }
  50% { opacity: 1; }
}

/* Boot Screen */
.boot-screen {
  padding: 20px;
  height: 100%;
  display: flex;
  flex-direction: column;
  font-size: 10px;
  line-height: 1.8;
}

.boot-line {
  color: var(--c64-light-blue);
  white-space: pre;
}

.cursor-blink {
  animation: blink 0.5s step-end infinite;
  color: var(--c64-light-blue);
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Title Screen */
.title-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, var(--c64-dark-blue) 0%, #2a2855 100%);
  position: relative;
}

.title-container {
  opacity: 0;
  transform: scale(0.5);
  transition: all 1s ease-out;
  text-align: center;
  z-index: 10;
}

.title-container.title-visible {
  opacity: 1;
  transform: scale(1);
}

.game-title {
  font-size: clamp(20px, 6vw, 48px);
  color: var(--c64-red);
  text-shadow: 
    4px 4px 0 var(--c64-black),
    -2px -2px 0 var(--c64-yellow);
  animation: titlePulse 2s ease-in-out infinite;
  letter-spacing: 4px;
}

@keyframes titlePulse {
  0%, 100% { text-shadow: 4px 4px 0 var(--c64-black), -2px -2px 0 var(--c64-yellow), 0 0 20px var(--c64-red); }
  50% { text-shadow: 4px 4px 0 var(--c64-black), -2px -2px 0 var(--c64-yellow), 0 0 40px var(--c64-red); }
}

.title-subtitle {
  font-size: 10px;
  color: var(--c64-cyan);
  margin-top: 10px;
  letter-spacing: 2px;
}

.title-hero-sprite {
  position: absolute;
  bottom: 60px;
  right: 20px;
  width: 100px;
  height: 100px;
  animation: heroFloat 3s ease-in-out infinite;
  opacity: 0.8;
}

@keyframes heroFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.press-start {
  position: absolute;
  bottom: 30px;
  font-size: 12px;
  color: var(--c64-white);
  cursor: pointer;
  z-index: 10;
}

.blink {
  animation: blink 1s step-end infinite;
}

/* Game Screen */
.game-screen {
  height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
}

.game-background {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 40%;
  background-size: cover;
  background-position: center;
  opacity: 0.7;
  image-rendering: pixelated;
}

.dialogue-ui {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 55%;
  background: linear-gradient(180deg, transparent 0%, rgba(65, 61, 113, 0.95) 20%);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.portraits-container {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.portrait-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.portrait-section.left {
  align-items: flex-start;
}

.portrait-section.right {
  align-items: flex-end;
}

.portrait-box {
  transition: all 0.3s;
}

.portrait-frame {
  width: 64px;
  height: 64px;
  border: 3px solid var(--c64-light-blue);
  background: var(--c64-black);
  overflow: hidden;
}

.portrait-active .portrait-frame {
  border-color: var(--c64-cyan);
  box-shadow: 0 0 15px var(--c64-cyan);
  animation: portraitGlow 1s ease-in-out infinite;
}

@keyframes portraitGlow {
  0%, 100% { box-shadow: 0 0 15px var(--c64-cyan); }
  50% { box-shadow: 0 0 25px var(--c64-cyan), 0 0 35px var(--c64-light-blue); }
}

.portrait-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.portrait-name {
  font-size: 8px;
  color: var(--c64-yellow);
  margin-top: 2px;
}

.health-bar-container {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 80px;
}

.health-label {
  font-size: 6px;
  color: var(--c64-white);
  width: 35px;
}

.health-bar-bg {
  flex: 1;
  height: 8px;
  background: var(--c64-black);
  border: 2px solid var(--c64-light-blue);
}

.health-bar-fill {
  height: 100%;
  transition: width 0.3s;
}

.dialogue-box {
  flex: 1;
  background: rgba(0, 0, 0, 0.8);
  border: 3px solid var(--c64-brown);
  padding: 10px;
  min-height: 60px;
}

.dialogue-speaker {
  font-size: 8px;
  color: var(--c64-yellow);
  margin-bottom: 6px;
}

.dialogue-text {
  font-size: 10px;
  color: var(--c64-white);
  line-height: 1.6;
}

.weapon-icons {
  display: flex;
  justify-content: center;
  gap: 15px;
  padding: 5px;
}

.weapon-icon {
  font-size: 20px;
  filter: grayscale(0.3);
  transition: all 0.2s;
  cursor: pointer;
}

.weapon-icon:hover {
  filter: grayscale(0);
  transform: scale(1.2);
}

.pilder-flash {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--c64-cyan);
  opacity: 0.8;
  animation: flash 0.3s ease-out forwards;
  z-index: 50;
}

@keyframes flash {
  0% { opacity: 0.8; }
  100% { opacity: 0; }
}

/* Complete Screen */
.complete-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: radial-gradient(ellipse at center, var(--c64-dark-blue) 0%, #1a1833 100%);
}

.complete-title {
  font-size: clamp(16px, 4vw, 28px);
  color: var(--c64-green);
  text-shadow: 3px 3px 0 var(--c64-black);
  animation: titlePulse 2s ease-in-out infinite;
}

.complete-text {
  font-size: 10px;
  color: var(--c64-light-blue);
  text-align: center;
  padding: 0 20px;
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 15px;
  font-size: 8px;
  color: var(--c64-light-blue);
  opacity: 0.7;
}

.app-footer a {
  color: var(--c64-cyan);
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

/* Mobile Adjustments */
@media (max-width: 500px) {
  .app-container {
    padding: 10px;
  }
  
  .control-panel {
    padding: 12px;
  }
  
  .c64-button {
    font-size: 8px;
    padding: 8px 12px;
  }
  
  .portrait-frame {
    width: 48px;
    height: 48px;
  }
  
  .dialogue-box {
    padding: 8px;
  }
  
  .dialogue-text {
    font-size: 8px;
  }
  
  .boot-screen {
    font-size: 7px;
    padding: 10px;
  }
}