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

body {
  background: #0a0a0f;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: 'Courier New', monospace;
  overflow: hidden;
  color: #fff;
}

#game-wrapper {
  position: relative;
  width: 960px;
  height: 540px;
}

#gameCanvas {
  display: block;
  background: #0d0d1a;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ---------- HUD ---------- */
#ui-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}

#hud {
  position: absolute;
  top: 10px; left: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bar-label {
  font-size: 9px;
  letter-spacing: 2px;
  color: #aaa8c8;
  margin-right: 4px;
  display: inline-block;
  width: 50px;
}

#health-bar-container,
#mana-bar-container,
#xp-bar-container {
  display: flex;
  align-items: center;
}

#mana-bar-bg,
#xp-bar-bg {
  width: 160px;
  height: 8px;
  background: #1a1a2e;
  border: 1px solid #333;
  border-radius: 2px;
  overflow: hidden;
}

#hp-lanterns {
  display: flex;
  gap: 3px;
  align-items: center;
}

.lantern-icon {
  width: 10px;
  height: 14px;
  border-radius: 2px 2px 4px 4px;
  border: 1px solid #444;
  background: #1a1a2e;
  flex-shrink: 0;
}

.lantern-icon.lit {
  background: linear-gradient(180deg, #ffee88, #ff9900);
  border-color: #ffcc44;
  box-shadow: 0 0 4px #ffcc44;
}

#mana-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #4488ff, #aaddff);
  transition: width 0.2s;
}

#xp-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffcc00, #ffff88);
  transition: width 0.3s;
}

#level-display {
  font-size: 11px;
  color: #ffcc44;
  margin-top: 2px;
  letter-spacing: 1px;
}

#gold-display {
  font-size: 11px;
  color: #ffd700;
  letter-spacing: 1px;
}

#ability-slots {
  display: flex;
  gap: 5px;
  margin-top: 6px;
}

.ability-box {
  width: 40px;
  height: 40px;
  border: 2px solid #555;
  background: #111122;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  color: #aaa;
  position: relative;
}

.ability-box span {
  position: absolute;
  top: 2px; left: 3px;
  font-size: 8px;
  color: #888;
}

.ability-icon {
  width: 24px;
  height: 24px;
  border-radius: 2px;
}

.ab-beam { background: radial-gradient(circle, #88ccff, #0044aa); }
.ab-nova { background: radial-gradient(circle, #ffffaa, #ff8800); }
.ab-shadow { background: radial-gradient(circle, #aa88ff, #220044); }

.ability-box.on-cooldown::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  border-radius: 2px;
}

#minimap-container {
  position: absolute;
  top: 10px; right: 10px;
  border: 1px solid #333;
  background: #050510;
}

/* ---------- SCREENS ---------- */
.overlay-screen {
  position: fixed;
  inset: 0;
  display: none;
  justify-content: center;
  align-items: center;
  background: rgba(0,0,0,0.85);
  z-index: 100;
  flex-direction: column;
}

.overlay-screen.active {
  display: flex;
}

.screen-panel {
  background: #0d0d1e;
  border: 2px solid #3344aa;
  padding: 30px 40px;
  min-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  box-shadow: 0 0 40px #1133aaaa;
}

.screen-panel.wide {
  min-width: 700px;
  max-height: 80vh;
  overflow-y: auto;
}

.screen-panel h2 {
  font-size: 20px;
  letter-spacing: 4px;
  color: #aabcff;
  text-shadow: 0 0 10px #4466ff;
}

/* TITLE */
.title-art {
  text-align: center;
  margin-bottom: 30px;
}

.lamp-logo {
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
  background: radial-gradient(circle at 50% 60%, #ffe066, #ff8800, #220000);
  border-radius: 30% 30% 50% 50%;
  box-shadow: 0 0 30px #ffaa00, 0 0 60px #ff440055;
  position: relative;
}

.lamp-logo::before {
  content: '';
  position: absolute;
  top: -18px; left: 32px;
  width: 16px; height: 20px;
  background: #888;
  border-radius: 2px 2px 0 0;
}

.lamp-logo::after {
  content: '';
  position: absolute;
  bottom: -10px; left: 25px;
  width: 30px; height: 12px;
  background: #666;
  border-radius: 50%;
}

h1 {
  font-size: 28px;
  letter-spacing: 5px;
  color: #fff;
  text-shadow: 0 0 20px #ffaa00, 0 0 40px #ff660088;
  margin-bottom: 8px;
}

.subtitle {
  color: #8899bb;
  font-size: 12px;
  letter-spacing: 2px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.menu-btn {
  background: transparent;
  border: 2px solid #3355aa;
  color: #aabcff;
  font-family: 'Courier New', monospace;
  font-size: 14px;
  letter-spacing: 3px;
  padding: 10px 30px;
  cursor: pointer;
  transition: all 0.15s;
  width: 220px;
  text-align: center;
}

.menu-btn:hover:not(:disabled) {
  background: #2233aa33;
  border-color: #88aaff;
  color: #fff;
  box-shadow: 0 0 12px #4466ffaa;
  text-shadow: 0 0 8px #aaccff;
}

.menu-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.menu-btn.small {
  width: 140px;
  font-size: 11px;
  padding: 6px 14px;
}

.version-tag {
  position: absolute;
  bottom: 10px;
  right: 15px;
  font-size: 10px;
  color: #333;
}

/* CONTROLS */
.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 20px;
  margin: 10px 0;
  width: 100%;
}

.ctrl-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

kbd {
  background: #1a1a2e;
  border: 1px solid #4455aa;
  color: #aabcff;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 11px;
  white-space: nowrap;
}

/* INVENTORY */
#inv-layout {
  display: flex;
  gap: 20px;
  width: 100%;
}

#inv-items, #inv-upgrades, #inv-stats {
  flex: 1;
}

#inv-items h3, #inv-upgrades h3, #inv-stats h3 {
  font-size: 12px;
  letter-spacing: 2px;
  color: #8899cc;
  border-bottom: 1px solid #2233aa;
  padding-bottom: 4px;
  margin-bottom: 8px;
}

#item-grid {
  display: grid;
  grid-template-columns: repeat(4, 40px);
  gap: 4px;
}

.item-slot {
  width: 40px;
  height: 40px;
  border: 1px solid #333;
  background: #0a0a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  position: relative;
}

.item-slot:hover { border-color: #6688ff; }

.upgrade-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid #111133;
  font-size: 11px;
  gap: 6px;
}

.upgrade-entry .upg-name { flex: 1; color: #ccd; }
.upgrade-entry .upg-level { color: #ffcc44; width: 40px; text-align: center; }
.upgrade-btn {
  background: #1a2255;
  border: 1px solid #3355aa;
  color: #aabcff;
  font-size: 10px;
  cursor: pointer;
  padding: 2px 6px;
  font-family: 'Courier New', monospace;
}
.upgrade-btn:hover { background: #2233aa; }
.upgrade-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  padding: 3px 0;
  border-bottom: 1px solid #111122;
}
.stat-row .sn { color: #8899bb; }
.stat-row .sv { color: #ffcc66; }

/* QUESTS */
#quest-layout {
  display: flex;
  gap: 20px;
  width: 100%;
  min-height: 300px;
}

#quest-list-panel {
  flex: 1;
  border-right: 1px solid #2233aa;
  padding-right: 14px;
}

#quest-detail-panel {
  flex: 2;
  font-size: 12px;
  line-height: 1.7;
  color: #aab;
}

.quest-entry {
  padding: 7px;
  cursor: pointer;
  border-bottom: 1px solid #111133;
  font-size: 11px;
}
.quest-entry:hover { background: #11112a; }
.quest-entry.active-q { color: #ffdd55; }
.quest-entry.done-q { color: #44cc44; }
.quest-entry.inactive-q { color: #556; }

#quest-detail-text .qd-title { font-size: 14px; color: #aabcff; margin-bottom: 6px; }
#quest-detail-text .qd-desc { margin-bottom: 8px; }
#quest-detail-text .qd-obj  { color: #ffdd88; font-size: 11px; }

/* DIALOGUE */
#dialogue-box {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: 700px;
  background: #08081a;
  border: 2px solid #4455aa;
  display: flex;
  gap: 14px;
  padding: 14px 18px;
  z-index: 200;
  box-shadow: 0 0 20px #2244bb88;
}

#dialogue-box.hidden { display: none; }

#dialogue-portrait {
  width: 60px;
  height: 60px;
  background: #0d0d22;
  border: 1px solid #333;
  flex-shrink: 0;
  border-radius: 4px;
}

#dialogue-content { flex: 1; }
#dialogue-name {
  font-size: 12px;
  letter-spacing: 2px;
  color: #ffcc44;
  margin-bottom: 5px;
}
#dialogue-text { font-size: 13px; line-height: 1.7; color: #ccd; }
#dialogue-choices { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.dialogue-choice {
  background: none;
  border: 1px solid #3355aa;
  color: #aabcff;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  cursor: pointer;
  padding: 4px 10px;
  text-align: left;
}
.dialogue-choice:hover { background: #1a2255; }
#dialogue-continue { font-size: 10px; color: #556; text-align: right; margin-top: 4px; }

/* NOTIFICATIONS */
#notification-area {
  position: fixed;
  top: 80px; right: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 300;
  pointer-events: none;
}

.notification {
  background: #0a0a1edd;
  border: 1px solid #3355aa;
  color: #aabcff;
  font-size: 11px;
  padding: 6px 14px;
  letter-spacing: 1px;
  animation: notifIn 0.2s ease, notifOut 0.3s ease 2.7s forwards;
}

@keyframes notifIn { from { opacity:0; transform: translateX(20px); } to { opacity:1; transform: translateX(0); } }
@keyframes notifOut { to { opacity:0; transform: translateX(20px); } }

/* DEATH / LEVEL UP */
.death-title { color: #ff4444 !important; text-shadow: 0 0 20px #ff0000 !important; }

#level-up-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 250;
  text-align: center;
}

#level-up-popup.hidden { display: none; }

.lu-inner {
  background: #0a0a1e;
  border: 2px solid #ffcc00;
  box-shadow: 0 0 40px #ffcc0088;
  padding: 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  animation: luPop 0.3s ease;
}

@keyframes luPop { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.lu-title {
  font-size: 11px;
  letter-spacing: 4px;
  color: #ffcc44;
  text-shadow: 0 0 10px #ffcc00;
}

.lu-level {
  font-size: 28px;
  color: #fff;
  text-shadow: 0 0 15px #ffcc00;
}

.lu-stats {
  font-size: 12px;
  color: #aab;
  line-height: 1.8;
}

/* =====================================================
   CUTSCENE SCREENS
   ===================================================== */
.cutscene-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 400;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.cutscene-screen.active { display: flex; }

#cutscene-canvas,
#outro-canvas {
  width: 960px;
  max-width: 100vw;
  height: auto;
  image-rendering: pixelated;
}

#cutscene-text-box {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: min(780px, 90vw);
  background: rgba(4,4,20,0.92);
  border: 2px solid #3344aa;
  padding: 18px 24px 14px;
  box-shadow: 0 0 20px #2244bb88;
}

#cutscene-text {
  font-family: 'Courier New', monospace;
  font-size: clamp(12px, 2vw, 15px);
  color: #dde4ff;
  line-height: 1.8;
  letter-spacing: 0.5px;
  min-height: 60px;
}

#cutscene-tap {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  color: #445;
  text-align: right;
  margin-top: 8px;
  letter-spacing: 1px;
  animation: tapBlink 1.2s ease infinite;
}

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

.cs-speaker {
  color: #ffcc44;
  font-size: 11px;
  letter-spacing: 2px;
  display: block;
  margin-bottom: 6px;
}

/* =====================================================
   TOUCH CONTROLS  (hidden by default, shown via JS on coarse-pointer devices)
   ===================================================== */
#touch-controls {
  display: none;          /* shown via JS on touch screens */
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 180px;
  padding: 8px 16px;
  justify-content: space-between;
  align-items: flex-end;
  z-index: 500;
  pointer-events: none;   /* children re-enable */
  user-select: none;
  -webkit-user-select: none;
}

#touch-dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: all;
}

#touch-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  pointer-events: all;
}

.tc-row, .tc-row-top, .tc-row-bot, .tc-row-extra {
  display: flex;
  gap: 4px;
  align-items: center;
}

.tc-mid { width: 48px; height: 48px; }

.tc-btn {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  border: 2px solid rgba(120,150,255,0.5);
  background: rgba(10,10,40,0.75);
  color: rgba(180,200,255,0.9);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.08s, transform 0.08s;
  pointer-events: all;
  backdrop-filter: blur(4px);
}

.tc-btn:active {
  background: rgba(50,80,200,0.8);
  transform: scale(0.92);
  border-color: rgba(150,180,255,0.9);
}

.tc-action {
  width: 58px;
  height: 58px;
  font-size: 20px;
}

.tc-jump   { background: rgba(20,60,20,0.75); border-color: rgba(80,200,80,0.6); }
.tc-beam   { background: rgba(40,20,60,0.75); border-color: rgba(180,120,255,0.6); }
.tc-nova   { background: rgba(60,40,0,0.75);  border-color: rgba(255,200,80,0.6); }
.tc-melee  { background: rgba(60,10,10,0.75); border-color: rgba(255,80,80,0.6); }

.tc-small {
  width: 52px;
  height: 34px;
  font-size: 9px;
  letter-spacing: 1px;
  font-family: 'Courier New', monospace;
  border-radius: 6px;
}

/* Responsive scaling for small phones */
@media (max-width: 600px) {
  #touch-controls { height: 160px; padding: 6px 10px; }
  .tc-btn  { width: 44px; height: 44px; font-size: 15px; }
  .tc-action { width: 50px; height: 50px; font-size: 17px; }
  .tc-small { width: 44px; height: 30px; font-size: 8px; }
  .tc-mid   { width: 40px; height: 40px; }
}

/* Scale canvas to fill mobile viewport */
@media (pointer: coarse) {
  body { align-items: flex-start; overflow-y: hidden; }
  #game-wrapper {
    width: 100vw;
    height: auto;
    aspect-ratio: 16/9;
  }
  #gameCanvas {
    width: 100%;
    height: 100%;
  }
  #touch-controls { display: flex; }
}

