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

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

body {
  /* Fallback background */
  background: #0b1021;
  min-height: 100vh;
  font-family: 'MS Gothic', 'MS UI Gothic', 'Press Start 2P', monospace;
  color: #fff;
  overflow-x: hidden;
  padding-top: calc(env(safe-area-inset-top) + 90px);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* 背景レイヤー */
#game-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -2;
  background-size: cover;
  background-position: center center; /* Default */
  background-repeat: no-repeat;
  transition: background-image 0.8s ease, background-position 0.8s ease;
}

/* 背景を少し暗くするオーバーレイ */
#game-background-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  background: rgba(0, 0, 20, 0.4); /* 40% dark blue tint */
  pointer-events: none;
}

.hidden { display: none !important; }

/* ステータスバー */
#status-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 90px;
  background: rgba(26, 35, 94, 0.95);
  backdrop-filter: blur(10px);
  z-index: 200;
  padding: 10px 20px;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 3px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  display: none;
}

#status-bar.show { display: block; }

.status-stage-info {
  font-size: 0.85rem;
  color: #ffeb3b;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-progress-bar {
  width: 100%;
  height: 16px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid #fff;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 6px;
}

.status-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4caf50, #8bc34a);
  width: 0%;
  transition: width 0.5s ease;
  box-shadow: 0 0 10px rgba(76, 175, 80, 0.6);
}

.status-details {
  font-size: 0.75rem;
  color: #fff;
  display: flex;
  justify-content: space-between;
}

/* タイトル画面 */
#title-screen {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.title-logo {
  font-family: 'Press Start 2P', monospace;
  font-size: 2rem;
  color: #ffeb3b;
  text-align: center;
  margin-bottom: 60px;
  line-height: 1.6;
}

.start-button {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.2rem;
  padding: 20px 40px;
  background: #2a2a9a;
  color: #fff;
  border: 3px solid #fff;
  cursor: pointer;
  animation: blink 1.5s infinite;
}

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

/* Title Buttons */
.title-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
}

#continue-btn {
    background: #006400; /* Dark Green */
    animation: none;
}

/* Intro Screen */
#intro-screen {
    position: fixed;
    inset: 0;
    z-index: 150;
    /* Allow scrolling */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: rgba(0,0,0,0.85);
    
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 40px 20px;
}

/* Vertical centering spacers */
#intro-screen::before {
    content: '';
    flex: 1;
    min-height: 20px;
}
#intro-screen::after {
    content: '';
    flex: 1;
    min-height: 20px;
}

.intro-character-container {
    width: 240px;
    height: 240px;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.character-large {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    filter: drop-shadow(0 0 20px rgba(255, 235, 59, 0.4));
    animation: float 3s ease-in-out infinite;
}

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

.intro-window {
    width: 90%;
    max-width: 800px;
    min-height: 200px;
    flex-shrink: 0;
}

/* Ending Screen */
#ending-screen {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: 40px;
}

.ending-characters {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    width: 100%;
    max-width: 900px;
}

.ending-char-img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    image-rendering: pixelated;
    opacity: 0;
    animation: fadeIn 1s forwards;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* キャラクター */
#character-container {
  position: fixed;
  top: 110px;
  left: 50%;
  transform: translateX(-50%);
  width: 160px;
  height: 160px;
  z-index: 100;
  background: transparent;
  pointer-events: none; /* クリックを邪魔しないように */
}

.character {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
  opacity: 0;
  transition: opacity 0.5s ease;
}

.character.show { opacity: 1; }

/* DQウィンドウ */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  /* キャラクター画像と重ならないようにパディング調整 */
  padding-top: 240px; 
}

.dq-window {
  background: rgba(26, 35, 126, 0.95);
  border: 4px solid #fff;
  box-shadow: inset 0 0 0 2px #000, 0 4px 0 rgba(0,0,0,0.5), 0 0 30px rgba(255,255,255,0.3);
  border-radius: 0;
  padding: 22px 28px;
  margin: 0 auto 20px;
  font-size: 1rem;
  line-height: 1.8;
  letter-spacing: 0.05em;
  position: relative;
  min-height: 160px;
}

.dq-name {
  position: absolute;
  top: -24px;
  left: 10px;
  background: #0a0a5a;
  border: 2px solid #fff;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* 選択肢 */
.choice-btn {
  display: block;
  width: 100%;
  padding: 12px 20px;
  margin: 10px 0;
  background: rgba(0, 0, 80, 0.9);
  color: #fff;
  border: 2px solid #fff;
  border-radius: 4px;
  font-family: 'MS Gothic', monospace;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: left;
  position: relative;
}

.choice-btn:hover {
  background: linear-gradient(135deg, #1976d2, #1565c0);
  transform: translateX(10px);
  box-shadow: 0 0 20px rgba(255, 235, 59, 0.5), 0 4px 8px rgba(0, 0, 0, 0.3);
  border-color: #ffeb3b;
}

.choice-btn:active {
  transform: translateX(10px) scale(0.98);
}

/* 自由入力 */
#free-input-container { margin-top: 20px; }

.text-input-area {
  width: 100%;
  min-height: 120px;
  padding: 15px;
  background: rgba(0, 0, 40, 0.9);
  color: #fff;
  border: 2px solid #fff;
  border-radius: 4px;
  font-family: 'MS Gothic', monospace;
  font-size: 1rem;
  line-height: 1.6;
  resize: vertical;
}

.text-input-area::placeholder { color: rgba(255, 255, 255, 0.5); }

/* XP獲得通知 */
#xp-notification {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  background: linear-gradient(135deg, #ffeb3b, #ffc107);
  color: #000;
  padding: 20px 40px;
  border: 4px solid #fff;
  border-radius: 12px;
  font-family: 'Press Start 2P', monospace;
  font-size: 1.5rem;
  z-index: 1500;
  box-shadow: 0 8px 32px rgba(255, 235, 59, 0.6), 0 0 60px rgba(255, 193, 7, 0.4);
  opacity: 0;
  pointer-events: none;
}

#xp-notification.show {
  animation: xpPopup 1.5s ease forwards;
}

@keyframes xpPopup {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
}

/* Result Screen */
.result-container {
    text-align: center;
    display: none;
}

.result-title {
    font-family: 'Press Start 2P', monospace;
    font-size: 1.5rem;
    color: #ffeb3b;
    margin-bottom: 30px;
}
