/* ===========================================================
   魔王を倒せ・3周目 — style.css (v1.1 RPG-style overhaul)
   - ドット絵ゲーム向け
   - 暗い背景 + パステルアクセント
   - レスポンシブ（スマホ用仮想パッド対応）
   - DotGothic16 で本格JRPG感
   =========================================================== */

/* ドット風日本語フォント */
@import url('https://fonts.googleapis.com/css2?family=DotGothic16&display=swap');

/* リセット */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0a14;
  color: #f5f5f5;
  font-family: 'DotGothic16',
    "Hiragino Maru Gothic ProN",
    "ヒラギノ丸ゴ ProN W4",
    "Noto Sans JP",
    "Yu Gothic",
    "Meiryo",
    monospace,
    sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ドット絵向け描画 */
canvas, img {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

button {
  font-family: inherit;
  color: inherit;
  background: transparent;
  border: none;
  cursor: pointer;
}

/* 長文や input は通常フォントを維持（可読性確保） */
input, textarea, select,
.long-text, .normal-font {
  font-family:
    "Hiragino Maru Gothic ProN",
    "ヒラギノ丸ゴ ProN W4",
    "Noto Sans JP",
    "Yu Gothic",
    "Meiryo",
    sans-serif;
}

/* =========================
   #app コンテナ
   ========================= */
#app {
  position: relative;
  width: 100%;
  max-width: 800px;
  aspect-ratio: 16 / 10;
  margin: 0 auto;
  background: #111122;
  border: 2px solid #3a3a55;
  box-shadow: 0 0 24px rgba(120, 140, 255, 0.15);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* =========================
   HUD（上部ステータスバー）
   ========================= */
#hud {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 4px 12px;
  padding: 6px 10px;
  background: linear-gradient(180deg, #1c1c30, #15152a);
  /* ドット風ボーダー（点線で擬似ドット） */
  border-top: 1px dotted #4a4a66;
  border-bottom: 1px dotted #6c7bdc;
  box-shadow: inset 0 -2px 0 #0a0a14;
  font-family: 'DotGothic16', monospace;
  font-size: 12px;
  z-index: 10;
}

#hud-left { grid-column: 1; grid-row: 1; }
#hud-right {
  grid-column: 2;
  grid-row: 1;
  text-align: right;
}
#hud-stats {
  grid-column: 1 / -1;
  grid-row: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  color: #cfd6ff;
}

#hud-title {
  color: #ffd9a8;
  font-weight: bold;
  letter-spacing: 0.05em;
}

#timer-display {
  color: #ffe681;
  font-family: 'DotGothic16', 'Courier New', monospace;
  font-variant-numeric: tabular-nums;
  font-weight: bold;
  font-size: 15px;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  background: rgba(10, 10, 25, 0.55);
  border: 1px solid #4a4a66;
  border-radius: 3px;
}

/* HUD 各 stat をボックス化（RPG ステータスウィンドウ風） */
#hud-stats > span,
#stat-hp, #stat-mp, #stat-lv, #stat-gold {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(10, 10, 25, 0.65);
  border: 1px solid #2c2c44;
  border-radius: 3px;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.4);
}

#stat-hp { color: #ff8e9c; border-color: #5a2c38; }
#stat-mp { color: #8ec8ff; border-color: #2c3a5a; }
#stat-lv { color: #cfffd1; border-color: #2c5a38; }
#stat-gold { color: #ffe17a; border-color: #5a4a2c; }

/* =========================
   画面切替（シーン）
   ========================= */
#screen {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #07070f;
  overflow: hidden;
}

.scene {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
}

.scene.active {
  display: flex;
}

.scene-placeholder {
  color: #6a7090;
  font-family: 'DotGothic16', monospace;
  font-size: 14px;
  text-align: center;
  padding: 16px;
}

#field-canvas {
  width: 100%;
  height: 100%;
  background: #0d0d1a;
}

/* =========================
   タイトル画面（star-field 風）
   ========================= */
#screen-title {
  position: relative;
  background: radial-gradient(ellipse at center, #14143a 0%, #07071a 70%, #03030c 100%);
  overflow: hidden;
  font-family: 'DotGothic16', monospace;
}

/* 星々：複数の白い box-shadow を散らして twinkle */
#screen-title::before,
#screen-title::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  height: 2px;
  background: transparent;
  pointer-events: none;
  z-index: 0;
  /* たくさんの星を box-shadow で配置 */
  box-shadow:
    24px 38px #ffffff, 78px 120px #cfd6ff, 142px 60px #ffffff,
    200px 180px #ffe681, 260px 30px #ffffff, 310px 220px #cfd6ff,
    360px 110px #ffffff, 420px 200px #ffffff, 480px 70px #ffe681,
    540px 160px #cfd6ff, 600px 40px #ffffff, 660px 230px #ffffff,
    720px 120px #cfd6ff, 60px 250px #ffe681, 130px 330px #ffffff,
    220px 380px #cfd6ff, 300px 300px #ffffff, 380px 360px #ffffff,
    460px 320px #ffe681, 550px 380px #cfd6ff, 640px 300px #ffffff,
    720px 350px #ffffff, 90px 180px #ffffff, 170px 220px #cfd6ff,
    250px 100px #ffffff, 330px 160px #ffe681, 410px 250px #ffffff,
    500px 220px #cfd6ff, 580px 100px #ffffff, 670px 170px #ffe681;
  animation: twinkle 4s ease-in-out infinite;
}

#screen-title::after {
  /* 二層目はオフセット＆位相ずらし */
  box-shadow:
    44px 88px #ffffff, 108px 30px #cfd6ff, 172px 200px #ffffff,
    240px 60px #ffe681, 290px 280px #ffffff, 350px 50px #cfd6ff,
    400px 200px #ffffff, 460px 130px #ffffff, 520px 30px #ffe681,
    580px 280px #cfd6ff, 640px 100px #ffffff, 700px 170px #ffffff,
    40px 360px #cfd6ff, 100px 80px #ffe681, 160px 270px #ffffff,
    280px 340px #cfd6ff, 340px 240px #ffffff, 400px 380px #ffffff,
    500px 280px #ffe681, 600px 200px #cfd6ff, 680px 380px #ffffff;
  animation: twinkle 6s ease-in-out infinite reverse;
  opacity: 0.7;
}

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

/* タイトルロゴ（金色） */
.title-logo {
  position: relative;
  z-index: 2;
  font-family: 'DotGothic16', monospace;
  color: #ffd966;
  text-shadow:
    0 0 8px rgba(255, 217, 102, 0.55),
    2px 2px 0 #5a3a00,
    4px 4px 0 rgba(0, 0, 0, 0.6);
  letter-spacing: 0.1em;
}

/* タイトルボタン */
.title-btn {
  position: relative;
  z-index: 2;
  font-family: 'DotGothic16', monospace;
  padding: 10px 20px;
  background: linear-gradient(180deg, #2c2c4a, #1a1a30);
  border: 2px solid #6c7bdc;
  border-radius: 4px;
  color: #f5f5f5;
  font-size: 14px;
  letter-spacing: 0.05em;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.title-btn:hover {
  transform: translateY(-2px);
  background: linear-gradient(180deg, #3c3c66, #2a2a4a);
  box-shadow: 0 6px 12px rgba(108, 123, 220, 0.55), 0 2px 0 rgba(0, 0, 0, 0.5);
}
.title-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}

/* =========================
   戦闘画面
   ========================= */
#screen-battle,
.battle-root {
  position: relative;
  font-family: 'DotGothic16', monospace;
  /* デフォルトは暗い赤紫グラデーション（魔王感） */
  background: radial-gradient(
    ellipse at center,
    #1a0810 0%,
    #2a0a20 40%,
    #1a0014 80%,
    #050008 100%
  );
}

/* フィールド戦：暗緑グラデーション */
.battle-bg-field,
#screen-battle.battle-bg-field,
.battle-root.battle-bg-field {
  background: radial-gradient(
    ellipse at center,
    #061a10 0%,
    #0a2a18 40%,
    #04140a 80%,
    #020805 100%
  );
}

/* ボス戦：濃い赤系グラデーション */
.battle-bg-boss,
#screen-battle.battle-bg-boss,
.battle-root.battle-bg-boss {
  background: radial-gradient(
    ellipse at center,
    #2a0408 0%,
    #4a0a18 35%,
    #20040a 75%,
    #080003 100%
  );
}

/* 戦闘コマンドボタン */
.cmd-btn {
  font-family: 'DotGothic16', monospace;
  padding: 8px 14px;
  background: linear-gradient(180deg, #2a2a44, #1a1a30);
  border: 2px solid #6c7bdc;
  border-radius: 4px;
  color: #f5f5f5;
  font-size: 14px;
  letter-spacing: 0.05em;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.cmd-btn:hover {
  transform: translateY(-2px);
  background: linear-gradient(180deg, #3c3c66, #2a2a4a);
  box-shadow: 0 6px 12px rgba(108, 123, 220, 0.5), 0 2px 0 rgba(0, 0, 0, 0.5);
}
.cmd-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}

/* 職業選択カード */
.class-card {
  font-family: 'DotGothic16', monospace;
  padding: 14px 18px;
  background: linear-gradient(180deg, #1c1c34, #12122a);
  border: 2px solid #4a4a66;
  border-radius: 6px;
  color: #f5f5f5;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.class-card:hover {
  transform: translateY(-2px);
  border-color: #ffd966;
  box-shadow:
    0 8px 18px rgba(255, 217, 102, 0.35),
    0 2px 0 rgba(0, 0, 0, 0.5);
}
.class-card:active {
  transform: translateY(0);
}

/* =========================
   メッセージウィンドウ（下中央・RPG風）
   ========================= */
#message-window {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 720px;
  min-height: 80px;
  padding: 12px 16px 14px;
  background: rgba(10, 10, 30, 0.92);
  border: 2px solid #6c7bdc;
  border-radius: 6px;
  /* 内側に細い border-bottom（RPGメッセボックス感） */
  box-shadow:
    0 0 0 2px #0a0a14 inset,
    0 -1px 0 rgba(140, 160, 255, 0.25) inset,
    0 2px 8px rgba(0, 0, 0, 0.6);
  color: #f5f5f5;
  font-family: 'DotGothic16', monospace;
  font-size: 14px;
  letter-spacing: 0.03em;
  line-height: 1.6;
  z-index: 20;
  display: none;
}

/* メッセボックス内側の追加横ライン */
#message-window::after {
  content: '';
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 4px;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(140, 160, 255, 0.4) 20%,
    rgba(140, 160, 255, 0.4) 80%,
    transparent 100%);
  pointer-events: none;
}

#message-window.visible {
  display: block;
}

#message-text {
  white-space: pre-wrap;
  word-break: break-word;
}

#message-cursor {
  position: absolute;
  right: 12px;
  bottom: 6px;
  color: #ffe681;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  to { visibility: hidden; }
}

/* =========================
   選択カーソル（戦闘ハイライト）
   ========================= */
.selected {
  position: relative;
  border-color: #ffd966 !important;
  color: #fffbe6 !important;
  background: linear-gradient(180deg, #4a3a18, #2a200a) !important;
  box-shadow:
    0 0 0 2px rgba(255, 217, 102, 0.4),
    0 2px 0 rgba(0, 0, 0, 0.5) !important;
  animation: cursor-blink 1s ease-in-out infinite;
}

@keyframes cursor-blink {
  0%, 100% {
    box-shadow:
      0 0 0 2px rgba(255, 217, 102, 0.4),
      0 0 8px rgba(255, 217, 102, 0.3),
      0 2px 0 rgba(0, 0, 0, 0.5);
  }
  50% {
    box-shadow:
      0 0 0 3px rgba(255, 217, 102, 0.85),
      0 0 16px rgba(255, 217, 102, 0.7),
      0 2px 0 rgba(0, 0, 0, 0.5);
  }
}

/* =========================
   HP/MP バー（戦闘画面などで使う共通スタイル）
   ========================= */
.bar {
  position: relative;
  height: 10px;
  width: 160px;
  background: #2a2a3f;
  border: 1px solid #4a4a66;
  border-radius: 3px;
  overflow: hidden;
}
.bar > .fill {
  position: absolute;
  inset: 0;
  width: 100%;
  transform-origin: left center;
  transition: transform 0.25s ease;
}
.bar.hp .fill { background: linear-gradient(90deg, #ff5a72, #ff8e9c); }
.bar.mp .fill { background: linear-gradient(90deg, #4f7dff, #8ec8ff); }

/* =========================
   仮想パッド（スマホ用・PCでは非表示）
   ========================= */
#virtual-pad {
  display: none;
  position: absolute;
  inset: auto 0 0 0;
  padding: 8px 12px 12px;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 30;
}

#dpad {
  position: relative;
  width: 132px;
  height: 132px;
  pointer-events: auto;
}

#dpad .vbtn {
  position: absolute;
  width: 44px;
  height: 44px;
  background: rgba(40, 44, 70, 0.85);
  border: 1px solid #6c7bdc;
  border-radius: 8px;
  color: #f5f5f5;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dpad-up    { top: 0; left: 44px; }
.dpad-left  { top: 44px; left: 0; }
.dpad-right { top: 44px; left: 88px; }
.dpad-down  { top: 88px; left: 44px; }

#action-buttons {
  display: flex;
  gap: 12px;
  pointer-events: auto;
}

#action-buttons .vbtn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(50, 36, 70, 0.85);
  border: 1px solid #cfa6ff;
  font-weight: bold;
  font-size: 18px;
  color: #fff;
}
.btn-a { background: rgba(70, 36, 50, 0.9); border-color: #ff9eb1; }
.btn-b { background: rgba(36, 50, 70, 0.9); border-color: #9ebcff; }

/* =========================
   レスポンシブ（スマホ）
   ========================= */
@media (max-width: 480px) {
  html, body {
    font-size: 13px;
  }
  #hud {
    font-size: 11px;
    padding: 5px 8px;
  }
  #timer-display {
    font-size: 13px;
    padding: 1px 6px;
  }
  #hud-stats > span,
  #stat-hp, #stat-mp, #stat-lv, #stat-gold {
    padding: 1px 6px;
    font-size: 11px;
  }
  .title-logo {
    font-size: 28px;
  }
  .title-btn, .cmd-btn {
    font-size: 13px;
    padding: 8px 14px;
  }
  .class-card {
    padding: 10px 14px;
    font-size: 13px;
  }
  #message-window {
    font-size: 13px;
    bottom: 160px;
    padding: 10px 12px 12px;
  }
  #virtual-pad { display: flex; }
  #app {
    aspect-ratio: auto;
    height: 100vh;
    height: 100dvh;
    max-width: 100%;
    border: none;
    box-shadow: none;
  }
}

/* =========================
   モーダル（セーブ確認など）
   ========================= */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 15, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }

.modal-inner {
  background: #1a1a2e;
  border: 2px solid #6c7bdc;
  border-radius: 8px;
  padding: 24px 28px;
  text-align: center;
  max-width: 360px;
  width: calc(100% - 32px);
  color: #f5f5f5;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.modal-inner p {
  margin-bottom: 16px;
  font-size: 14px;
}

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.modal-buttons button {
  flex: 1;
  padding: 10px 12px;
  background: #2c2c4a;
  border: 1px solid #6c7bdc;
  border-radius: 4px;
  color: #f5f5f5;
  font-size: 14px;
  transition: background 0.15s ease, transform 0.12s ease;
}
.modal-buttons button:hover {
  background: #3c3c66;
  transform: translateY(-2px);
}
.modal-buttons button:active {
  background: #50509a;
  transform: translateY(0);
}
