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

* {
  font-family: 'Press Start 2P', monospace !important;
}

html {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Press Start 2P', monospace;
  background: #111;
  color: white;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  width: 100%;
  height: 100%;
}

.hidden {
  display: none !important;
}

#game-container {
  width: 100vw;
  height: 100vh;
  position: relative;
  transform: none;
  transform-origin: top left;
}

#game-area {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url('./images/fi-rudo.png');
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center center;
  background-attachment: fixed;
  overflow: hidden;
  box-sizing: border-box;
}

#game-area::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}

#player {
  position: absolute;
  width: 115px;
  height: 115px;
  background-image: url('./images/hero.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 10;
  transition: all 0.1s ease;
  box-sizing: border-box;
}

.enemy {
  position: absolute;
  width: 72px;
  height: 72px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 5;
  box-sizing: border-box;
  /* ウェーブごとの色味（JSから --enemy-filter を上書き） */
  filter: var(--enemy-filter, none);
}

/* 新ウェーブ登場：敵だけが色変わりしつつ出現（景色は反転しない） */
.enemy.wave-spawn {
  animation: enemyWaveSpawn 0.55s ease-out;
}

@keyframes enemyWaveSpawn {
  0% {
    transform: scale(0.35);
    opacity: 0.2;
    filter: brightness(2.2) saturate(0.2);
  }
  45% {
    transform: scale(1.12);
    opacity: 1;
    filter: brightness(1.35) saturate(1.6) hue-rotate(40deg);
  }
  100% {
    transform: scale(1);
    opacity: 1;
    filter: var(--enemy-filter, none);
  }
}

/* アイテムスタイル */
.item {
  position: absolute;
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.9);
  border: 3px solid #ffcc00;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 20px;
  z-index: 8;
  animation: itemFloat 2s ease-in-out infinite;
  box-shadow: 0 0 15px rgba(255, 204, 0, 0.6);
}

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

/* アイテムエフェクト */
.item-effect {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(135deg, #ffcc00, #ff6600);
  color: white;
  padding: 15px 25px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: bold;
  z-index: 3000;
  animation: effectPop 2s ease-out forwards;
  box-shadow: 0 0 20px rgba(255, 204, 0, 0.8);
}

@keyframes effectPop {
  0% { transform: translate(-50%, -50%) scale(0.5); 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; }
}

#status-bar {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.8);
  border: 2px solid white;
  border-radius: 10px;
  padding: 8px 12px;
  color: white;
  font-weight: bold;
  z-index: 100;
  display: flex;
  gap: 15px;
  align-items: center;
  font-size: 14px;
  flex-wrap: wrap;
  max-width: 80%;
  box-sizing: border-box;
}

#hp-container {
  display: flex;
  gap: 5px;
  align-items: center;
}

#combo-container {
  display: flex;
  gap: 5px;
  align-items: center;
  background: rgba(255, 200, 0, 0.2);
  padding: 4px 8px;
  border-radius: 5px;
  border: 1px solid #ffcc00;
}

#combo-count {
  color: #ffcc00;
  font-weight: bold;
  min-width: 30px;
  text-align: center;
}

#exp-container {
  display: flex;
  gap: 8px;
  align-items: center;
}
#hp-hearts {
  display: flex;
  gap: 2px;
  color: #ff3333;
  letter-spacing: 1px;
}

#exp-bar {
  width: 120px;
  height: 16px;
  background: #333;
  border: 2px solid white;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}

#exp-fill {
  height: 100%;
  width: 0%;
  background: lime;
  transition: width 0.3s ease;
}

  #exp-text {
    font-size: 12px;
    margin-left: 8px;
  }

  #level-display {
    font-size: 12px;
    color: yellow;
  }

#score-display, #combo-display {
  font-size: 10px;
  color: #ffcc00;
  background: rgba(255, 204, 0, 0.2);
  padding: 4px 8px;
  border-radius: 5px;
  border: 1px solid #ffcc00;
}

#combo-display {
  color: #ff6600;
  background: rgba(255, 102, 0, 0.2);
  border-color: #ff6600;
  animation: comboPulse 0.5s ease-in-out;
}

@keyframes comboPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

#controller {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: calc(12px + env(safe-area-inset-left, 0px));
  z-index: 200;
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(3, 64px);
  gap: 6px;
  opacity: 0.85;
}

#btn-up { grid-column: 2; grid-row: 1; }
#btn-left { grid-column: 1; grid-row: 2; }
#btn-down { grid-column: 2; grid-row: 3; }
#btn-right { grid-column: 3; grid-row: 2; }

#controller button {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 3px solid rgba(255, 255, 255, 0.85);
  border-radius: 14px;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease, background 0.08s ease, border-color 0.08s ease;
}

#controller button:active {
  background: rgba(255, 255, 255, 0.4);
  border-color: white;
  transform: scale(0.92);
}

#controller button:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* 十字キー矢印（上下左右を同じ三角形スタイルで統一） */
.pad-arrow {
  display: block;
  width: 0;
  height: 0;
  border-style: solid;
}

.pad-up {
  border-width: 0 11px 16px 11px;
  border-color: transparent transparent #fff transparent;
}

.pad-down {
  border-width: 16px 11px 0 11px;
  border-color: #fff transparent transparent transparent;
}

.pad-left {
  border-width: 11px 16px 11px 0;
  border-color: transparent #fff transparent transparent;
}

.pad-right {
  border-width: 11px 0 11px 16px;
  border-color: transparent transparent transparent #fff;
}

/* むずかしい問題のジャンル表示 */
#quiz-genre.quiz-hard {
  color: #ffb347;
}

/* 特殊能力ボタン */
.ability-buttons {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ability-button {
  width: 50px;
  height: 50px;
  font-size: 16px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  opacity: 0.5;
}

.ability-button.active {
  opacity: 1;
  background: rgba(255, 255, 255, 0.3);
  border-color: #ffcc00;
  box-shadow: 0 0 10px rgba(255, 204, 0, 0.5);
}

.ability-button:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* クイズ画面（iPhone縦持ち向け） */
#quiz-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.88);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding:
    calc(12px + env(safe-area-inset-top, 0px))
    calc(12px + env(safe-area-inset-right, 0px))
    calc(16px + env(safe-area-inset-bottom, 0px))
    calc(12px + env(safe-area-inset-left, 0px));
  box-sizing: border-box;
}

#quiz-box {
  width: min(100%, 420px);
  max-height: min(78vh, 720px);
  background: #1a1a1a;
  border: 3px solid #fff;
  border-radius: 16px;
  padding: 14px 14px 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-sizing: border-box;
}

#quiz-genre {
  margin: 0;
  font-size: 11px;
  color: #ffcc00;
  text-align: center;
  letter-spacing: 1px;
}

#quiz-question {
  margin: 0;
  font-size: clamp(11px, 3.4vw, 14px);
  color: white;
  line-height: 1.7;
  padding: 12px 10px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  text-align: center;
  flex-shrink: 0;
}

#quiz-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0;
  flex: 1;
  min-height: 0;
}

#quiz-options button {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(9px, 2.6vw, 11px);
  line-height: 1.55;
  padding: 12px 8px;
  background: linear-gradient(180deg, #4a4a4a, #2a2a2a);
  color: white;
  border: 2px solid #aaa;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.08s ease, background 0.08s ease;
  text-align: center;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  word-break: break-word;
}

#quiz-options button:hover {
  background: linear-gradient(180deg, #5a5a5a, #3a3a3a);
  border-color: #ffcc00;
}

#quiz-options button:active {
  transform: scale(0.96);
  border-color: #ffcc00;
}

/* チュートリアル */
#tutorial-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1500;
  display: flex;
  justify-content: center;
  align-items: center;
}

#tutorial-box {
  background: #222;
  border: 3px solid #fff;
  border-radius: 12px;
  padding: 20px;
  max-width: 80%;
  text-align: center;
}

#tutorial-box h2 {
  font-size: 16px;
  margin: 10px 0;
}

#tutorial-box p {
  font-size: 12px;
  margin: 10px 0;
}

#tutorial-start {
  margin-top: 15px;
  padding: 10px 20px;
  font-size: 14px;
  cursor: pointer;
}

/* レベルアップ演出 */
#levelup-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.72);
  z-index: 1800;
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: none;
}

#levelup-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  padding: 12px 20px;
}

#levelup-title {
  margin: 0;
  font-size: 14px;
  color: #ffcc00;
  letter-spacing: 2px;
  text-shadow: 0 0 10px rgba(255, 204, 0, 0.6);
}

#levelup-stage {
  position: relative;
  width: min(42vw, 200px);
  height: min(42vw, 200px);
}

#levelup-hero-from,
#levelup-hero-to {
  position: absolute;
  inset: 0;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

#levelup-hero-from {
  opacity: 1;
}

#levelup-hero-to {
  opacity: 0;
}

#levelup-container.playing #levelup-hero-from {
  animation: levelupFadeOut 0.8s ease forwards;
}

#levelup-container.playing #levelup-hero-to {
  animation: levelupFadeIn 0.8s ease forwards;
}

#levelup-container.playing #levelup-box {
  animation: levelupPop 0.35s ease-out;
}

#levelup-text {
  margin: 0;
  max-width: 90vw;
  font-size: 12px;
  line-height: 1.7;
  color: #ffffff;
  text-shadow: 0 2px 0 #000, 0 0 12px rgba(255, 255, 255, 0.35);
}

@keyframes levelupFadeOut {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.92); }
}

@keyframes levelupFadeIn {
  from { opacity: 0; transform: scale(1.08); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes levelupPop {
  from { transform: scale(0.86); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}

/* ゲームオーバー画面 */
#gameover-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.95);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.5s ease-out;
}

#gameover-box {
  background: #330000;
  border: 5px solid #ff0000;
  border-radius: 15px;
  padding: 40px 60px;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 0 30px rgba(255, 0, 0, 0.5);
  transform: scale(0.9);
  animation: popIn 0.5s ease-out forwards;
}

#gameover-text {
  font-family: 'Press Start 2P', monospace;
  font-size: 2em;
  color: #ffffff;
  text-shadow: 0 0 15px rgba(255, 255, 255, 0.7), 0 0 5px rgba(255, 255, 255, 0.9);
  margin-bottom: 30px;
  letter-spacing: 3px;
  animation: pulse 1.5s infinite alternate;
  line-height: 1.4;
}

#restart-button {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.2em;
  padding: 15px 30px;
  background: linear-gradient(135deg, #007bff, #0056b3);
  color: white;
  border: 3px solid #0056b3;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

#restart-button:hover {
  background: linear-gradient(135deg, #0056b3, #003a72);
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

#restart-button:active {
  transform: translateY(0);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

/* アニメーションキーフレーム */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popIn {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes pulse {
  from { transform: scale(1); opacity: 1; }
  to { transform: scale(1.05); opacity: 0.8; }
}

/* レスポンシブ */
@media (max-width: 600px) {
  #controller {
    grid-template-columns: repeat(3, 58px);
    grid-template-rows: repeat(3, 58px);
  }

  #controller button {
    width: 58px;
    height: 58px;
  }

  #quiz-options button {
    min-height: 68px;
  }
}

@media (min-width: 1025px) {
  #status-bar {
    font-size: 12px;
    padding: 6px 10px;
    gap: 10px;
    max-width: 95%;
  }

  #controller {
    grid-template-columns: repeat(3, 72px);
    grid-template-rows: repeat(3, 72px);
    gap: 8px;
  }

  #controller button {
    width: 72px;
    height: 72px;
  }

  .pad-up { border-width: 0 12px 18px 12px; }
  .pad-down { border-width: 18px 12px 0 12px; }
  .pad-left { border-width: 12px 18px 12px 0; }
  .pad-right { border-width: 12px 0 12px 18px; }

  #exp-bar {
    width: 80px;
    height: 12px;
  }

  #quiz-container {
    align-items: center;
  }

  #quiz-box {
    padding: 18px;
    width: min(100%, 480px);
  }

  #quiz-question {
    font-size: 13px;
  }

  #quiz-options {
    gap: 12px;
  }

  #quiz-options button {
    font-size: 11px;
    min-height: 80px;
    padding: 14px 10px;
  }

  #gameover-text {
    font-size: 1.5em;
  }

  #restart-button {
    font-size: 1em;
    padding: 12px 25px;
  }
}
