/* ========================================
   8-BIT PIXEL JRPG — STARRY NIGHT BATTLE
   ======================================== */

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

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

body {
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  font-family: 'Press Start 2P', monospace;
  image-rendering: pixelated;
  overflow: hidden;
}

#game-container {
  width: 640px;
  border: 4px solid #fff;
  box-shadow: 0 0 0 4px #555, 0 0 32px #000;
  background: #000;
  display: flex;
  flex-direction: column;
  transform-origin: center center;
}

/* ---- Battle Scene ---- */
#battle-scene {
  position: relative;
  width: 100%;
  height: 260px;
  overflow: hidden;
}

#sky {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 65%;
  background: linear-gradient(180deg, #0d0d2b 0%, #1a0a3c 50%, #3a0a1a 100%);
}

/* Stars */
#sky::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 10% 15%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 25% 8%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 40% 20%, #ddf 0%, transparent 100%),
    radial-gradient(1px 1px at 55% 5%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 70% 18%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 80% 10%, #ffd 0%, transparent 100%),
    radial-gradient(1px 1px at 90% 25%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 15% 35%, #ddf 0%, transparent 100%),
    radial-gradient(1px 1px at 60% 30%, #fff 0%, transparent 100%),
    radial-gradient(2px 2px at 33% 12%, #fff 0%, transparent 100%),
    radial-gradient(2px 2px at 85% 22%, #ffd 0%, transparent 100%);
}

#ground {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 40%;
  background: linear-gradient(180deg, #2a0800 0%, #4a1000 30%, #1a0500 100%);
  border-top: 4px solid #8b2200;
}

/* Lava cracks on ground */
#ground::after {
  content: '';
  position: absolute;
  top: 4px; left: 0; right: 0; bottom: 0;
  background-image:
    linear-gradient(90deg, transparent 20%, #ff4400 20.5%, transparent 21%),
    linear-gradient(90deg, transparent 50%, #ff6600 50.5%, transparent 51%),
    linear-gradient(90deg, transparent 75%, #ff4400 75.5%, transparent 76%);
  opacity: 0.4;
}

/* ---- Enemy Area ---- */
#enemy-area {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#enemy-sprite-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#enemy-canvas {
  image-rendering: pixelated;
  filter: drop-shadow(0 0 12px #ff4400);
}

#enemy-name-tag {
  font-size: 7px;
  color: #ff8844;
  text-shadow: 0 0 8px #ff4400;
  letter-spacing: 1px;
}

#enemy-hpbar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.bar-label {
  font-size: 6px;
  color: #ff8844;
  letter-spacing: 1px;
}

.hpbar-outer {
  width: 180px;
  height: 12px;
  border: 2px solid #888;
  background: #222;
  position: relative;
}

.hpbar-outer.small {
  width: 80px;
  height: 8px;
}

.hpbar-inner {
  height: 100%;
  background: linear-gradient(90deg, #22cc44, #88ff44);
  transition: width 0.4s ease, background 0.4s ease;
}

#enemy-hp-text {
  font-size: 6px;
  color: #ccc;
}

/* ---- Party Area ---- */
#party-area {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
}

.party-member {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px;
  border: 2px solid transparent;
  transition: border-color 0.2s, background 0.2s;
}

.party-member.active-turn {
  border-color: #ffdd00;
  background: rgba(255, 221, 0, 0.08);
}

.party-member.dead {
  opacity: 0.35;
  filter: grayscale(1);
}

.hero-canvas {
  image-rendering: pixelated;
}

.hero-name {
  font-size: 5px;
  color: #ffdd88;
  letter-spacing: 1px;
}

.hero-class {
  font-size: 4px;
  color: #aaa;
}

.hero-hpwrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.hero-hp-text {
  font-size: 4px;
  color: #ccc;
}

.mpbar-outer {
  border-color: #446 !important;
  background: #111 !important;
}

.mpbar-inner {
  height: 100%;
  background: linear-gradient(90deg, #2255cc, #66aaff);
  transition: width 0.4s ease;
}

.hero-mp-text {
  font-size: 4px;
  color: #88aaff;
}

/* ---- Battle Log ---- */
#battle-log {
  background: #0a0a1a;
  border-top: 3px solid #334;
  border-bottom: 3px solid #334;
  padding: 10px 14px;
  min-height: 54px;
  display: flex;
  align-items: center;
}

#log-text {
  font-size: 8px;
  color: #e8e8ff;
  line-height: 1.7;
  text-shadow: 0 0 6px #6688ff44;
}

/* ---- Action UI ---- */
#action-ui {
  background: #070714;
  padding: 10px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#turn-banner {
  font-size: 7px;
  color: #ffdd00;
  text-align: center;
  letter-spacing: 3px;
  text-shadow: 0 0 8px #ffdd00aa;
}

#turn-banner.enemy-turn {
  color: #ff4400;
  text-shadow: 0 0 8px #ff4400aa;
}

#active-hero-label {
  font-size: 6px;
  color: #aaa;
  text-align: center;
}

#active-hero-name {
  color: #ffdd88;
}

#action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 4px;
}

.action-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 7px 10px;
  border: 2px solid #556;
  background: #111128;
  color: #ccd;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  min-width: 120px;
  text-align: center;
}

.action-btn:hover:not(:disabled) {
  background: #222244;
  border-color: #ffdd00;
  color: #ffdd00;
}

.action-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.action-btn-wait {
  border-color: #445 !important;
  color: #778 !important;
}
.action-btn-wait:hover:not(:disabled) {
  border-color: #aabbcc !important;
  color: #aabbcc !important;
  background: #141428 !important;
}

.action-btn .btn-damage {
  display: block;
  font-size: 5px;
  color: #ff8844;
  margin-top: 3px;
}

.action-btn .btn-mp {
  display: block;
  font-size: 5px;
  color: #88aaff;
  margin-top: 2px;
}

/* ---- Overlay ---- */
#overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#overlay.hidden {
  display: none;
}

#overlay-box {
  border: 4px solid #ffdd00;
  background: #0a0a1a;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 380px;
  text-align: center;
}

#overlay-title {
  font-size: 14px;
  color: #ffdd00;
  text-shadow: 0 0 16px #ffdd00;
  letter-spacing: 2px;
}

#overlay-msg {
  font-size: 7px;
  color: #ccd;
  line-height: 2;
}

#overlay-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  padding: 10px 20px;
  border: 2px solid #ffdd00;
  background: #111128;
  color: #ffdd00;
  cursor: pointer;
  transition: background 0.15s;
}
#overlay-btn:hover {
  background: #22224a;
}

/* ---- Mute Button ---- */
#mute-wrap {
  background: #070714;
  border-top: 2px solid #223;
  display: flex;
  justify-content: flex-end;
  padding: 4px 10px 6px;
}

#mute-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  padding: 4px 8px;
  background: #111128;
  border: 1px solid #445;
  color: #888;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
#mute-btn:hover {
  color: #ffdd00;
  border-color: #ffdd00;
}

/* ---- Damage Flash Animations ---- */
@keyframes flashRed {
  0%   { filter: brightness(1) drop-shadow(0 0 0 transparent); }
  25%  { filter: brightness(3) drop-shadow(0 0 8px #ff0000); }
  50%  { filter: brightness(1); }
  75%  { filter: brightness(3) drop-shadow(0 0 8px #ff0000); }
  100% { filter: brightness(1); }
}

@keyframes flashGreen {
  0%   { filter: brightness(1); }
  50%  { filter: brightness(2.5) drop-shadow(0 0 8px #00ff88); }
  100% { filter: brightness(1); }
}

@keyframes shake {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-6px); }
  40%  { transform: translateX(6px); }
  60%  { transform: translateX(-4px); }
  80%  { transform: translateX(4px); }
  100% { transform: translateX(0); }
}

@keyframes enemyFlash {
  0%   { filter: drop-shadow(0 0 12px #ff4400) brightness(1); }
  30%  { filter: drop-shadow(0 0 24px #ffffff) brightness(4); }
  60%  { filter: drop-shadow(0 0 12px #ff4400) brightness(1); }
  80%  { filter: drop-shadow(0 0 24px #ffffff) brightness(4); }
  100% { filter: drop-shadow(0 0 12px #ff4400) brightness(1); }
}

.anim-hit-enemy {
  animation: enemyFlash 0.5s ease;
}

.anim-hit-hero {
  animation: flashRed 0.5s ease;
}

.anim-heal {
  animation: flashGreen 0.6s ease;
}

.anim-shake {
  animation: shake 0.4s ease;
}

/* Enemy bobbing */
@keyframes enemyBob {
  0%, 100% { transform: translateY(0px); }
  50%       { transform: translateY(-6px); }
}

#enemy-sprite-wrap {
  animation: enemyBob 2s ease-in-out infinite;
}

/* HP bar color thresholds handled in JS */

/* ---- Fade-to-black overlay ---- */
#fade-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  z-index: 500;
}

/* ---- Post-battle cinematic text ---- */
#post-battle-text {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 600;
  pointer-events: none;
}

#post-battle-text.hidden {
  display: none;
}

.post-battle-line {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #e8e8ff;
  text-align: center;
  line-height: 2.2;
  max-width: 520px;
  text-shadow: 0 0 14px #8899ff88;
  padding: 0 24px;
}

/* ---- Overworld canvas container ---- */
#overworld-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  background: #000;
  position: fixed;
  inset: 0;
  z-index: 200;
}

#overworld-container.hidden {
  display: none;
}

#ow-canvas-wrapper {
  position: relative;
  width:  min(100vw, calc(100vh * 640 / 448));
  height: min(100vh, calc(100vw * 448 / 640));
  flex-shrink: 0;
}

#overworld-canvas {
  width: 100%;
  height: 100%;
  aspect-ratio: 640 / 448;
  image-rendering: pixelated;
  touch-action: none;
  display: block;
}

/* ---- Overworld mobile inventory button ---- */
#ow-inventory-btn {
  position: absolute;
  bottom: clamp(6px, 2vw, 12px);
  right: clamp(6px, 2vw, 12px);
  width: clamp(36px, 9vw, 60px);
  height: clamp(36px, 9vw, 60px);
  font-size: clamp(18px, 4.5vw, 30px);
  background: rgba(8, 9, 28, 0.88);
  border: 2px solid #ffdd00;
  border-radius: clamp(8px, 2vw, 14px);
  color: #ffdd00;
  cursor: pointer;
  z-index: 10;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  user-select: none;
  line-height: 1;
}

#ow-inventory-btn:active {
  background: rgba(255, 221, 0, 0.22);
  border-color: #fff;
}

#ow-inventory-btn.inv-open {
  background: rgba(255, 221, 0, 0.18);
  border-color: #fff;
}

/* ---- Title Screen ---- */
#title-screen {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 50% 30%, #1a0a3c 0%, #0a0a1e 60%, #000 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  overflow: hidden;
}

#title-screen.hidden {
  display: none;
}

/* Star field backdrop */
#title-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at  8% 12%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 18%  6%, #ffd 0%, transparent 100%),
    radial-gradient(1px 1px at 28% 18%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 38%  8%, #ddf 0%, transparent 100%),
    radial-gradient(1px 1px at 48% 22%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 58%  5%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 68% 15%, #ffd 0%, transparent 100%),
    radial-gradient(1px 1px at 78%  9%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 88% 20%, #ddf 0%, transparent 100%),
    radial-gradient(1px 1px at 93%  7%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 12% 35%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 32% 42%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 52% 38%, #ffd 0%, transparent 100%),
    radial-gradient(1px 1px at 72% 45%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 85% 32%, #ddf 0%, transparent 100%),
    radial-gradient(1px 1px at  3% 70%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 23% 68%, #ffd 0%, transparent 100%),
    radial-gradient(1px 1px at 43% 75%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 63% 62%, #ddf 0%, transparent 100%),
    radial-gradient(1px 1px at 83% 78%, #fff 0%, transparent 100%),
    radial-gradient(2px 2px at 22% 14%, #fff 0%, transparent 100%),
    radial-gradient(2px 2px at 62% 25%, #ffd 0%, transparent 100%),
    radial-gradient(2px 2px at 42% 52%, #fff 0%, transparent 100%),
    radial-gradient(2px 2px at  5% 55%, #fff 0%, transparent 100%),
    radial-gradient(2px 2px at 95% 48%, #ddf 0%, transparent 100%);
  animation: titleTwinkle 4s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes titleTwinkle {
  0%   { opacity: 0.55; }
  100% { opacity: 1.0; }
}

#title-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  padding: 24px;
}

#title-stars-decor {
  font-size: 20px;
  color: #ffdd88;
  text-shadow: 0 0 12px #ffdd00;
  letter-spacing: 8px;
  animation: titleStarPulse 2.5s ease-in-out infinite;
}

@keyframes titleStarPulse {
  0%, 100% { opacity: 0.6; text-shadow: 0 0 8px #ffdd00; }
  50%       { opacity: 1.0; text-shadow: 0 0 22px #ffdd00, 0 0 44px #ff8800; }
}

#title-heading {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(18px, 4vw, 36px);
  color: #ffe866;
  text-shadow: 0 0 20px #ffdd00, 0 0 44px #ff8800;
  letter-spacing: 4px;
  line-height: 1.4;
  margin: 0;
}

#title-sub {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(6px, 1.2vw, 9px);
  color: #7788bb;
  letter-spacing: 4px;
}

#title-divider {
  width: min(300px, 65vw);
  height: 2px;
  background: linear-gradient(90deg, transparent, #4455aa, #ffdd00, #4455aa, transparent);
  margin: 4px 0;
}

#title-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
}

#btn-new-game,
#btn-continue {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(7px, 1.5vw, 10px);
  padding: 14px 32px;
  min-width: min(240px, 70vw);
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, border-color 0.15s, color 0.15s;
  letter-spacing: 2px;
}

#btn-new-game {
  border: 2px solid #ffdd00;
  background: #0a0a1a;
  color: #ffdd00;
}

#btn-new-game:hover {
  background: #1c1c38;
  box-shadow: 0 0 14px #ffdd0077;
}

#btn-continue {
  border: 2px solid #446688;
  background: #0a0a1a;
  color: #6688aa;
}

#btn-continue:not(:disabled):hover {
  background: #0a1828;
  border-color: #88aaff;
  color: #88aaff;
  box-shadow: 0 0 14px #4488cc55;
}

#btn-continue:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

#title-save-info {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(4px, 0.9vw, 6px);
  color: #445566;
  min-height: 12px;
  letter-spacing: 1px;
  max-width: min(420px, 80vw);
  line-height: 1.8;
}
