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

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

:root {
  --bg:          #07040f;
  --panel:       #110d22;
  --panel-inner: #0d091c;
  --border:      #5030a0;
  --border-hi:   #9060e0;
  --gold:        #d4a020;
  --pink:        #d040a0;
  --pink-hi:     #f060c0;
  --text:        #ece4f8;
  --text-dim:    #7060a0;
  --red:         #e03068;
  --green:       #50b888;
  --yellow:      #f0d000;
  --font-body:   'Space Grotesk', sans-serif;
}

html, body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-size: 8px;
  line-height: 1.8;
}

/* pixel grid background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(144, 80, 220, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(144, 80, 220, 0.06) 1px, transparent 1px);
  background-size: 32px 32px;
}

/* CRT scanlines — above everything for full immersion */
.crt-lines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9990;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 3px,
    rgba(0, 0, 0, 0.18) 3px,
    rgba(0, 0, 0, 0.18) 4px
  );
}

/* Page layout */
.wrap {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 40px 16px 64px;
}

/* Main panel */
.panel {
  width: 100%;
  max-width: 500px;
  background: var(--panel);
  border: 4px solid var(--border);
  box-shadow:
    0 0 0 2px var(--bg),
    0 0 0 6px var(--border),
    0 0 60px rgba(144, 80, 220, 0.2),
    inset 0 0 0 1px rgba(144, 80, 220, 0.08);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── NPC row ── */
.npc-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 14px;
  background: var(--panel-inner);
  border: 2px solid var(--border);
}

.portrait {
  flex-shrink: 0;
  width: 88px;
  height: 88px;
  background: #1a0d30;
  border: 2px solid var(--border-hi);
  display: flex;
  align-items: center;
  justify-content: center;
  image-rendering: pixelated;
  position: relative;
  overflow: hidden;
}

.portrait::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.05) 0%, transparent 55%);
  pointer-events: none;
}

.sprite-img {
  width: 84px;
  height: 84px;
  object-fit: contain;
  image-rendering: pixelated;
}

.npc-info {
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex: 1;
  min-width: 0;
}

.npc-name {
  font-size: 13px;
  color: var(--pink-hi);
  text-shadow: 0 0 12px rgba(240, 96, 192, 0.5);
  letter-spacing: 2px;
}

.npc-class  { font-family: var(--font-body); font-size: 11px; color: var(--text-dim); }
.npc-lvl    { font-family: var(--font-body); font-size: 11px; color: var(--pink); }
.npc-record { font-family: var(--font-body); font-size: 10px; color: var(--text-dim); margin-top: 1px; }

.hp-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}
.hp-label { font-family: var(--font-body); font-size: 10px; color: var(--text-dim); width: 22px; }
.hp-track {
  flex: 1;
  height: 8px;
  background: #1a0d30;
  border: 1px solid var(--border);
  overflow: hidden;
}
.hp-fill {
  display: block;
  height: 100%;
  background: var(--pink);
  transition: width 0.3s ease;
  position: relative;
}
.hp-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to right,
    transparent, transparent 3px,
    rgba(0,0,0,0.2) 3px, rgba(0,0,0,0.2) 4px
  );
}
.hp-num { font-family: var(--font-body); font-size: 10px; color: var(--text-dim); }

/* ── Dialog box ── */
.dialog {
  background: var(--panel-inner);
  border: 3px solid var(--text);
  box-shadow: inset 0 0 0 2px var(--panel);
  padding: 14px 14px 24px;
  min-height: 96px;
  position: relative;
  cursor: pointer;
  user-select: none;
}

.dialog:focus { outline: 2px solid var(--yellow); outline-offset: 2px; }

.dialog-speaker {
  position: absolute;
  top: -9px;
  left: 10px;
  font-size: 6px;
  background: var(--panel);
  padding: 0 5px;
  color: var(--pink-hi);
}

.dialog-body {
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.75;
  color: var(--text);
  white-space: pre-wrap;
  min-height: 56px;
}

.dialog-next {
  position: absolute;
  bottom: 6px;
  right: 10px;
  font-size: 8px;
  color: var(--text);
}

.dialog-hint {
  font-family: var(--font-body);
  text-align: center;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: -6px;
}

/* ── Menu ── */
.menu-header {
  text-align: center;
  font-size: 7px;
  color: var(--border-hi);
  letter-spacing: 1px;
}

.menu {
  display: flex;
  flex-direction: column;
  background: var(--panel-inner);
  border: 2px solid var(--border);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  position: relative;
  transition: background 0.08s;
}
.menu-item:last-child { border-bottom: none; }

.menu-item::after {
  content: attr(data-tip);
  position: absolute;
  right: 12px;
  font-size: 6px;
  color: var(--text-dim);
  transition: color 0.08s;
}

.menu-item:hover,
.menu-item:focus { background: #261450; outline: none; }
.menu-item:hover::after,
.menu-item:focus::after { color: var(--border-hi); }

.menu-item .sel { font-size: 8px; color: var(--yellow); visibility: hidden; flex-shrink: 0; width: 10px; }
.menu-item:hover .sel,
.menu-item:focus .sel { visibility: visible; }

.menu-item .ico { font-size: 11px; width: 18px; text-align: center; flex-shrink: 0; }
.menu-item .lbl { font-size: 8px; flex: 1; }

.p-ico {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.35;
  color: var(--text-dim);
  margin-right: 72px;
  transition: opacity 0.08s, color 0.08s;
}

.menu-item:hover .p-ico,
.menu-item:focus .p-ico {
  opacity: 0.9;
  color: var(--pink-hi);
}

/* ── Duel trigger ── */
.duel-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  background: var(--panel-inner);
  border: 2px solid var(--pink);
  color: var(--pink-hi);
  cursor: pointer;
  text-align: left;
  transition: background 0.08s, box-shadow 0.08s;
}

.duel-trigger:hover {
  background: #3a1060;
  box-shadow: 0 0 16px rgba(208, 64, 160, 0.3);
}

.duel-cur { width: 10px; flex-shrink: 0; }
.duel-ico { width: 18px; text-align: center; flex-shrink: 0; }
.duel-lbl { flex: 1; }
.duel-hint { font-size: 6px; color: var(--pink); }

/* ── Status bar ── */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 10px;
  border-top: 2px solid var(--border);
  font-size: 6px;
  color: var(--text-dim);
  flex-wrap: wrap;
  gap: 6px;
}

.gold-badge { color: var(--gold); cursor: pointer; }

@keyframes gold-glow {
  0%, 100% { text-shadow: none; }
  50%       { text-shadow: 0 0 8px var(--gold); }
}
.gold-icon { animation: gold-glow 2s ease-in-out infinite; }

/* ── Blink ── */
@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
.blink      { animation: blink 0.75s step-end infinite; }
.blink-slow { animation: blink 1.5s step-end infinite; }

/* ── Utility ── */
.is-hidden { display: none !important; }

/* ── Responsive ── */
@media (max-width: 400px) {
  .npc-row { flex-direction: column; align-items: center; }
  .npc-info { width: 100%; }
  .npc-name { font-size: 10px; }
  .menu-item::after { display: none; }
}


/* ════════════════════════════════════════
   BOOT SCREEN
   ════════════════════════════════════════ */

.boot-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: pointer;
  font-family: 'Press Start 2P', 'Courier New', monospace;
}

.boot-screen.fade-out {
  animation: boot-fade 0.6s ease forwards;
  pointer-events: none;
}

@keyframes boot-fade { to { opacity: 0; } }

.boot-box {
  max-width: 380px;
  width: 100%;
}

.boot-logo {
  font-size: 16px;
  margin-bottom: 6px;
  letter-spacing: 2px;
}

.logo-pink { color: var(--pink-hi); text-shadow: 0 0 14px rgba(240,96,192,0.6); }
.logo-dim  { color: var(--text-dim); }
.logo-ver  { font-size: 7px; color: var(--text-dim); margin-left: 8px; vertical-align: middle; }

.boot-sub {
  font-size: 7px;
  color: var(--text-dim);
  margin-bottom: 32px;
}

.boot-lines {
  font-size: 7px;
  line-height: 2.6;
}

.boot-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  opacity: 0;
  animation: line-in 0.12s forwards;
}

@keyframes line-in { to { opacity: 1; } }

.boot-lbl { color: var(--text); }
.boot-status.ok   { color: var(--green); }
.boot-status.fail { color: var(--red); }
.boot-status.warn { color: var(--gold); }

.boot-prompt {
  margin-top: 32px;
  font-size: 8px;
  color: var(--pink-hi);
  text-align: center;
  display: none;
}

.boot-prompt.visible { display: block; }


/* ════════════════════════════════════════
   BATTLE SYSTEM
   ════════════════════════════════════════ */

.battle-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(7, 4, 15, 0.93);
  z-index: 999;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

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

.battle-panel {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 4px solid var(--border);
  box-shadow:
    0 0 0 2px var(--bg),
    0 0 0 6px var(--border),
    0 0 80px rgba(208, 64, 160, 0.3);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.battle-title {
  text-align: center;
  font-size: 10px;
  color: var(--pink-hi);
  letter-spacing: 2px;
  text-shadow: 0 0 12px rgba(240, 96, 192, 0.4);
}

.battle-fighter {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--panel-inner);
  border: 2px solid var(--border);
}

.battle-sprite {
  width: 60px;
  height: 60px;
  image-rendering: pixelated;
  object-fit: contain;
  flex-shrink: 0;
}

.player-icon {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
  background: #1a0d30;
  border: 2px solid var(--border);
}

.fighter-stats { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.fighter-name  { font-size: 8px; color: var(--text); }
.hp-player     { background: #4080e0 !important; }

.battle-log {
  font-family: var(--font-body);
  background: var(--panel-inner);
  border: 2px solid var(--border);
  padding: 10px 12px;
  min-height: 62px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
}

.battle-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.battle-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  background: var(--panel-inner);
  border: 2px solid var(--border);
  color: var(--text);
  padding: 10px 8px;
  cursor: pointer;
  transition: background 0.08s, border-color 0.08s;
}

.battle-btn:hover:not(:disabled) {
  background: #261450;
  border-color: var(--border-hi);
  color: var(--pink-hi);
}

.battle-btn:disabled { opacity: 0.35; cursor: default; }

.full-btn { grid-column: 1 / -1; width: 100%; }

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

.result-msg {
  text-align: center;
  font-size: 8px;
  line-height: 2.4;
  white-space: pre-wrap;
  color: var(--pink-hi);
}

/* Sprite hit flash */
@keyframes sprite-hit {
  0%,100% { filter: none; }
  25%     { filter: brightness(8) saturate(0); }
  50%     { filter: none; }
  75%     { filter: brightness(8) saturate(0); }
}
.battle-sprite.hit { animation: sprite-hit 0.4s linear !important; }

/* Player HP bar shake on hit */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-4px); }
  40%,80% { transform: translateX(4px); }
}
.shake { animation: shake 0.35s ease; }

/* Battle panel shake on rage hit */
@keyframes panel-shake {
  0%,100% { transform: translate(0,0) rotate(0deg); }
  15%,45%,75% { transform: translate(-6px,-3px) rotate(-0.4deg); }
  30%,60%,90% { transform: translate(6px,3px) rotate(0.4deg); }
}
.battle-panel.panel-shake { animation: panel-shake 0.45s ease !important; }


/* ════════════════════════════════════════
   PARTICLES & FX
   ════════════════════════════════════════ */

.particle {
  position: fixed;
  pointer-events: none;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--gold);
  text-shadow: 0 0 6px var(--gold);
  z-index: 2000;
  animation: particle-fly var(--dur) ease-out forwards;
}

@keyframes particle-fly {
  0%   { transform: translate(0,0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx),var(--dy)) scale(0.3); opacity: 0; }
}

.konami-flash {
  position: fixed;
  inset: 0;
  background: var(--pink-hi);
  z-index: 9991;
  pointer-events: none;
  animation: konami-flash-anim 0.5s ease forwards;
}

@keyframes konami-flash-anim {
  0%   { opacity: 0.45; }
  100% { opacity: 0; }
}


/* ════════════════════════════════════════
   DUNGEON TRIGGER BUTTON
   ════════════════════════════════════════ */

.dungeon-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  background: var(--panel-inner);
  border: 2px solid var(--green);
  color: var(--green);
  cursor: pointer;
  text-align: left;
  transition: background 0.08s, box-shadow 0.08s;
}

.dungeon-trigger:hover {
  background: #0d2a1e;
  box-shadow: 0 0 16px rgba(80, 184, 136, 0.3);
  color: #7fffcc;
  border-color: #7fffcc;
}


/* ════════════════════════════════════════
   DUNGEON OVERLAY
   ════════════════════════════════════════ */

.dungeon-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(7, 4, 15, 0.97);
  z-index: 997;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow-y: auto;
}

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

.dungeon-panel {
  width: 100%;
  max-width: 640px;
  background: var(--panel);
  border: 4px solid var(--border);
  box-shadow:
    0 0 0 2px var(--bg),
    0 0 0 6px var(--border),
    0 0 80px rgba(80, 184, 136, 0.15);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dungeon-title {
  text-align: center;
  font-size: 9px;
  color: var(--green);
  letter-spacing: 2px;
  text-shadow: 0 0 12px rgba(80, 184, 136, 0.5);
  margin-bottom: 8px;
}

.dungeon-hud {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.d-hud-lbl { font-size: 6px; color: var(--text-dim); }
.d-hud-sep { font-size: 6px; color: var(--border); }
.d-hud-val { font-size: 6px; color: var(--text); }
.d-level-val { color: var(--yellow); }
.d-treasure-val { color: var(--gold); }

.d-bar {
  width: 60px;
  height: 6px;
  background: #1a0d30;
  border: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
}

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

.d-hp-fill  { background: var(--green); width: 100%; }
.d-xp-fill  { background: var(--yellow); width: 0%; }


/* ── Dungeon map grid ── */

.dungeon-map {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 1px;
  background: #000;
  border: 2px solid var(--border);
  width: 100%;
  aspect-ratio: 15 / 11;
}

.d-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  line-height: 1;
  aspect-ratio: 1;
  user-select: none;
}

/* Unseen (fog of war) */
.d-cell.d-unseen {
  background: #000;
}

/* Wall */
.d-cell.d-wall {
  background: #0a0718;
  border: 1px solid #1a0d30;
}

/* Floor */
.d-cell.d-floor {
  background: var(--panel-inner);
}

/* Player */
.d-cell.d-player {
  background: #0d2a1e;
  color: var(--green);
  font-size: 12px;
  text-shadow: 0 0 8px var(--green);
}

/* Enemy */
.d-cell.d-enemy {
  background: #1a0710;
  color: var(--red);
  font-size: 10px;
  animation: enemy-pulse 1.2s step-end infinite;
}

@keyframes enemy-pulse {
  0%, 60% { color: var(--red); }
  61%, 100% { color: #ff8080; }
}

/* Treasure */
.d-cell.d-treasure {
  background: #1a1200;
  color: var(--gold);
  text-shadow: 0 0 6px var(--gold);
  animation: treasure-glow 1.5s ease-in-out infinite;
}

@keyframes treasure-glow {
  0%, 100% { text-shadow: 0 0 4px var(--gold); }
  50%       { text-shadow: 0 0 12px var(--gold); }
}

/* Exit */
.d-cell.d-exit {
  background: #0d001a;
  color: var(--border-hi);
  font-size: 12px;
  text-shadow: 0 0 8px var(--border-hi);
}

/* Start */
.d-cell.d-start {
  background: var(--panel-inner);
  color: var(--text-dim);
  font-size: 8px;
}


/* ── Dungeon log ── */

.dungeon-log {
  font-family: var(--font-body);
  background: var(--panel-inner);
  border: 2px solid var(--border);
  padding: 8px 12px;
  font-size: 11px;
  color: var(--green);
  min-height: 28px;
  line-height: 1.7;
}


/* ── Dungeon footer (d-pad + hints) ── */

.dungeon-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.d-dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.d-dpad-row {
  display: flex;
  gap: 3px;
}

.d-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  width: 32px;
  height: 32px;
  background: var(--panel-inner);
  border: 2px solid var(--border);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.06s, border-color 0.06s;
}

.d-btn:hover, .d-btn:active {
  background: #0d2a1e;
  border-color: var(--green);
  color: var(--green);
}

.d-footer-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.d-hint {
  font-size: 6px;
  color: var(--text-dim);
}

.d-exit-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  background: var(--panel-inner);
  border: 2px solid var(--border);
  color: var(--text-dim);
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.06s, color 0.06s;
}

.d-exit-btn:hover {
  background: #2a0d0d;
  border-color: var(--red);
  color: var(--red);
}


/* ════════════════════════════════════════
   DUNGEON TREASURE DIALOG
   ════════════════════════════════════════ */

.dungeon-treasure-dialog {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(7, 4, 15, 0.88);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.dungeon-treasure-dialog.active { display: flex; }

.dt-panel {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 4px solid var(--gold);
  box-shadow:
    0 0 0 2px var(--bg),
    0 0 0 6px var(--gold),
    0 0 60px rgba(212, 160, 32, 0.3);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.dt-header {
  font-size: 8px;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(212, 160, 32, 0.6);
  letter-spacing: 2px;
  animation: treasure-glow 1s ease-in-out infinite;
}

.dt-icon {
  font-size: 28px;
  color: var(--gold);
  text-shadow: 0 0 16px var(--gold);
}

.dt-name {
  font-size: 8px;
  color: var(--pink-hi);
  text-align: center;
  letter-spacing: 1px;
}

.dt-url {
  font-size: 6px;
  color: var(--text-dim);
  text-align: center;
}

.dt-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-top: 4px;
}

.dt-actions .battle-btn {
  flex: 1;
}


/* ── Responsive dungeon ── */
@media (max-width: 480px) {
  .dungeon-map { gap: 0; }
  .d-cell { font-size: 8px; }
  .d-cell.d-player { font-size: 9px; }
  .dungeon-hud { gap: 4px; }
  .d-bar { width: 40px; }
}
