@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

:root {
  --sepia1: #1a1208;
  --sepia2: #2d1f0a;
  --sepia3: #4a3015;
  --sepia4: #6b4520;
  --sepia-warm: #c8a060;
  --sepia-light: #e8d4a8;
  --sepia-highlight: #f5e8c8;
  --ink: #1a1208;
  --gold: #d4a020;
  --gold2: #f0c040;
  --accent-blue: #4888c8;
  --accent-green: #48b848;
  --accent-red: #c83030;
  --heaven-white: #f8f4e8;
  --heaven-gold: #ffd060;
  --ui-bg: rgba(10,8,3,0.88);
  --ui-border: #8a6020;
  --pixel: 4px;
}

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

body {
  background: var(--sepia1);
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--sepia-light);
  overflow-x: auto;
  overflow-y: hidden;
  height: 100vh;
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12'%3E%3Crect x='4' y='0' width='4' height='12' fill='%23d4a020'/%3E%3Crect x='0' y='4' width='12' height='4' fill='%23d4a020'/%3E%3C/svg%3E") 6 6, crosshair;
  touch-action: pan-x pan-y;
}

/* Scrollbar styling */
body::-webkit-scrollbar { height: 6px; }
body::-webkit-scrollbar-track { background: #0a0800; }
body::-webkit-scrollbar-thumb { background: var(--ui-border); }

/* World container */
#world {
  display: flex;
  height: 100vh;
  width: max-content;
  position: relative;
}

/* Scene sections */
.scene {
  position: relative;
  height: 100vh;
  flex-shrink: 0;
  overflow: hidden;
}

/* Floor */
.floor {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 28%;
}

/* HUD */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: var(--ui-bg);
  border-bottom: 3px solid var(--ui-border);
  backdrop-filter: blur(2px);
}

#hud-left { display: flex; flex-direction: column; gap: 5px; }
#hud-name { color: var(--gold); font-size: 8px; letter-spacing: 1px; }
.bar-row { display: flex; align-items: center; gap: 6px; font-size: 6px; }
.bar-label { width: 18px; color: var(--sepia-warm); }
.bar-track { width: 80px; height: 7px; background: #111; border: 2px solid #444; overflow: hidden; }
.bar-fill { height: 100%; transition: width 0.5s steps(10); }
.bar-fill.hp { background: var(--accent-green); width: 100%; }
.bar-fill.mp { background: var(--accent-blue); width: 75%; }

#hud-center { text-align: center; }
#chapter-name { color: var(--sepia-warm); font-size: 7px; letter-spacing: 1px; }
#chapter-title { color: var(--gold); font-size: 9px; margin-top: 3px; }

#hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
#inventory-label { font-size: 6px; color: var(--sepia-warm); }
#inventory-slots { display: flex; gap: 3px; }
.inv-slot {
  width: 22px; height: 22px;
  background: #111;
  border: 2px solid #444;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  transition: border-color 0.3s, background 0.3s;
}
.inv-slot.filled { border-color: var(--gold); background: rgba(212,160,32,0.15); }

/* Dex character */
.dex {
  position: fixed;
  bottom: 28%;
  left: calc(40% - 24px);
  width: 48px;
  height: 64px;
  z-index: 100;
  image-rendering: pixelated;
}

/* Dialogue box */
.dialogue {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  width: min(640px, 90vw);
  background: var(--ui-bg);
  border: 3px solid var(--ui-border);
  padding: 14px 18px;
  z-index: 150;
  box-shadow: 4px 4px 0 #000;
  display: none;
  cursor: pointer;
}
.dialogue.visible { display: block; }
.dialogue-speaker { color: var(--gold); font-size: 7px; margin-bottom: 8px; letter-spacing: 2px; }
.dialogue-speaker::before { content: '▶ '; }
.dialogue-body {
  font-family: 'VT323', monospace;
  font-size: 19px;
  line-height: 1.5;
  color: var(--sepia-highlight);
}
.dialogue-body em { color: var(--gold); font-style: normal; }
.dialogue-continue {
  color: var(--gold);
  font-size: 7px;
  margin-top: 8px;
  text-align: right;
  animation: blink 1s steps(1) infinite;
}

/* Item popup */
#item-popup {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  width: min(480px, 88vw);
  background: var(--ui-bg);
  border: 3px solid var(--gold);
  padding: 14px 18px;
  z-index: 300;
  box-shadow: 0 0 20px rgba(212,160,32,0.4), 4px 4px 0 #000;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  cursor: pointer;
}
#item-popup.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
#item-popup-icon { font-size: 32px; flex-shrink: 0; }
#item-popup-body { flex: 1; }
#item-popup-label { font-size: 6px; color: var(--gold); margin-bottom: 6px; letter-spacing: 2px; }
#item-popup-name { color: #fff; font-size: 9px; margin-bottom: 8px; }
#item-popup-desc {
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: #aaa;
  line-height: 1.4;
}
#item-popup-desc li { list-style: none; }
#item-popup-desc li::before { content: '▸ '; color: var(--accent-blue); }
#item-popup-continue {
  color: var(--gold);
  font-size: 7px;
  margin-top: 8px;
  text-align: right;
  animation: blink 1s steps(1) infinite;
}

/* Chapter card */
#chapter-card {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s;
}
#chapter-card.show { opacity: 1; pointer-events: all; }
#chapter-card-num { color: var(--sepia-warm); font-size: 8px; letter-spacing: 4px; margin-bottom: 20px; }
#chapter-card-title { color: var(--gold); font-size: 22px; text-align: center; line-height: 1.5; text-shadow: 0 0 30px rgba(212,160,32,0.6); }
#chapter-card-sub { color: #888; font-size: 8px; margin-top: 16px; font-family: 'VT323', monospace; font-size: 20px; }
#chapter-card-continue { color: var(--gold); font-size: 7px; margin-top: 30px; animation: blink 1s steps(1) infinite; cursor: pointer; }

/* Loading screen */
#loading-screen {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
#loading-screen.show { opacity: 1; pointer-events: all; }
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #333;
  border-top: 4px solid var(--gold);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}
.loading-text {
  color: var(--gold);
  font-size: 8px;
  letter-spacing: 2px;
}

/* Animations */
@keyframes blink { 50% { opacity:0; } }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes walk-bob { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-3px)} }
@keyframes float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-6px)} }
@keyframes glitch { 0%,100%{transform:translateX(0)} 25%{transform:translateX(4px)} 75%{transform:translateX(-4px)} }
@keyframes sparkle { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:0.5;transform:scale(0.7)} }

/* Mobile optimizations */
@media (max-width: 768px) {
  body { font-size: 9px; }
  #hud { padding: 6px 12px; }
  #hud-name { font-size: 7px; }
  #chapter-name { font-size: 6px; }
  #chapter-title { font-size: 8px; }
  .bar-track { width: 60px; height: 6px; }
  .inv-slot { width: 20px; height: 20px; font-size: 10px; }
  .dialogue { width: 95vw; padding: 12px 14px; }
  .dialogue-body { font-size: 17px; }
  #item-popup { width: 95vw; }
  #item-popup-desc { font-size: 14px; }
  #chapter-card-title { font-size: 18px; }
  .dex { width: 40px; height: 56px; left: calc(50% - 20px); }
}
