/* ===== Datadog Quest - レトロNES風スタイル ===== */

:root {
  --nes-bg: #0b0d2c;
  --nes-bg-dark: #06081c;
  --nes-fg: #f5f5f7;
  --nes-accent: #f6c453;
  --nes-accent2: #ff5b6b;
  --nes-blue: #4a90e2;
  --nes-green: #6ad36a;
  --nes-purple: #8e44ad;
  --nes-border: #f5f5f7;
  --dd-purple: #632ca6;
  --dd-purple-light: #7c3aed;
  --window-bg: #1a1d3d;
  --window-border: #f5f5f7;
}

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

html, body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: #000;
  color: var(--nes-fg);
  font-family: 'DotGothic16', 'Press Start 2P', monospace;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.02) 0px,
      rgba(255, 255, 255, 0.02) 2px,
      transparent 2px,
      transparent 4px
    ),
    radial-gradient(ellipse at center, #1a1d3d 0%, #06081c 100%);
}

.screen {
  display: none;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 20px 16px;
  box-sizing: border-box;
}

.screen.active {
  display: flex;
}

/* ===== ボタン (NES風) ===== */
.nes-btn {
  font-family: inherit;
  font-size: 18px;
  padding: 12px 24px;
  background: var(--window-bg);
  color: var(--nes-fg);
  border: 4px solid var(--nes-border);
  cursor: pointer;
  position: relative;
  letter-spacing: 1px;
  transition: transform 0.05s ease;
  box-shadow: 4px 4px 0 #000;
}

.nes-btn:hover:not(:disabled) {
  background: #2a2d5d;
}

.nes-btn:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 #000;
}

.nes-btn:disabled {
  background: #3a3a3a;
  color: #7a7a7a;
  border-color: #555;
  box-shadow: 4px 4px 0 #1a1a1a;
  cursor: not-allowed;
  opacity: 0.6;
}

.nes-btn.primary {
  background: var(--dd-purple);
  border-color: var(--nes-accent);
  color: #fff;
}

.nes-btn.primary:hover {
  background: var(--dd-purple-light);
}

.nes-btn.small {
  font-size: 14px;
  padding: 6px 14px;
  border-width: 3px;
}

/* ===== 言語トグル ===== */
.lang-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 4px;
  z-index: 5;
}
.title-frame { position: relative; }

.hud-lang-toggle {
  position: absolute;
  top: 4px;
  right: 8px;
  display: flex;
  gap: 4px;
}

#screen-field {
  position: relative;
  height: 100vh;
  height: 100dvh;
  justify-content: flex-start;
  padding: 8px;
  gap: 8px;
  overflow: hidden;
}

.lang-btn {
  font-family: inherit;
  font-size: 12px;
  padding: 3px 10px;
  background: #0d1133;
  color: var(--nes-fg);
  border: 2px solid var(--nes-border);
  cursor: pointer;
  letter-spacing: 1px;
}

.lang-btn.small {
  font-size: 10px;
  padding: 2px 6px;
  border-width: 1px;
}

.lang-btn.active {
  background: var(--nes-accent);
  color: #000;
  border-color: var(--nes-accent);
}

.sound-btn {
  font-size: 14px;
  letter-spacing: 0;
  min-width: 32px;
}

.sound-btn.small {
  font-size: 12px;
  min-width: 24px;
}

.sound-btn.muted {
  opacity: 0.5;
}

/* ===== タイトル画面 ===== */
.title-frame {
  text-align: center;
  padding: 40px;
  border: 6px double var(--nes-border);
  background: rgba(11, 13, 44, 0.85);
  box-shadow: 0 0 0 4px #000, 0 0 60px rgba(124, 58, 237, 0.4);
  max-width: 720px;
  width: 90%;
}

.title-logo {
  font-family: 'Press Start 2P', monospace;
  font-size: 56px;
  line-height: 1.1;
  margin-bottom: 24px;
  text-shadow:
    4px 4px 0 var(--dd-purple),
    8px 8px 0 #000;
}

.title-line1 {
  color: var(--nes-accent);
  display: block;
}

.title-line2 {
  color: var(--nes-fg);
  display: block;
}

.title-subtitle {
  font-size: 18px;
  color: var(--nes-fg);
  margin-bottom: 32px;
  letter-spacing: 2px;
}

.title-menu {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 320px;
  margin: 0 auto 24px;
}

.title-version {
  font-size: 13px;
  color: #b1b3d9;
  margin-top: 16px;
  animation: blink 1.4s infinite;
}

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

/* ===== フィールド画面 ===== */
.field-hud {
  width: min(900px, 100%);
  flex: 0 0 auto;
  background: var(--window-bg);
  border: 4px solid var(--nes-border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 10px 14px;
  font-size: 14px;
  box-shadow: 4px 4px 0 #000;
}

.hud-cell { min-width: 0; }

.hud-label {
  display: block;
  color: var(--nes-accent);
  font-size: 11px;
}

.hud-name, .hud-hp, .hud-defeated, .hud-time {
  display: block;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-time {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  color: var(--nes-green);
}

.hud-center { text-align: center; }
.hud-right { text-align: right; }

.field-wrap {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 900px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 4px solid var(--nes-border);
  background: #0a3812;
  box-shadow: 4px 4px 0 #000;
  position: relative;
  overflow: hidden;
}

#field-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  /* 内部解像度を表示サイズ(×DPR)に合わせて描画するため、拡大時もぼやけない。
     DPRダウンサンプルを滑らかにするため auto を指定 */
  image-rendering: auto;
  background: #1d6b2a;
  touch-action: none;
}

.field-message {
  width: min(900px, 100%);
  flex: 0 0 auto;
  background: var(--window-bg);
  border: 4px solid var(--nes-border);
  padding: 10px 14px;
  font-size: 15px;
  box-shadow: 4px 4px 0 #000;
  min-height: 56px;
}

.field-controls {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
}

/* ===== タッチ操作用 十字キー ===== */
.touch-dpad {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 500;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 54px);
  gap: 5px;
  opacity: 0.9;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.dpad-btn {
  font-family: inherit;
  font-size: 22px;
  color: var(--nes-fg);
  background: rgba(26, 29, 61, 0.92);
  border: 3px solid var(--nes-border);
  box-shadow: 2px 2px 0 #000;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.dpad-btn:active {
  background: var(--dd-purple);
  transform: translate(1px, 1px);
}

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

/* タッチデバイス、または狭い画面で十字キーを表示 */
@media (hover: none) and (pointer: coarse) {
  .touch-dpad { display: grid; }
}

@media (max-width: 820px) {
  .touch-dpad { display: grid; }
}

/* ===== バトル画面 ===== */
#screen-battle {
  background:
    repeating-linear-gradient(
      45deg,
      #1a1d3d 0px,
      #1a1d3d 8px,
      #14163a 8px,
      #14163a 16px
    );
}

.battle-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(720px, 95%);
  gap: 10px;
}

.enemy-stage {
  width: 100%;
  background: linear-gradient(180deg, #2c4a7b 0%, #1a3050 100%);
  border: 4px solid var(--nes-border);
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 4px 4px 0 #000;
  min-height: 220px;
  position: relative;
}

.enemy-card {
  text-align: center;
}

.enemy-sprite {
  font-size: 96px;
  filter: drop-shadow(4px 4px 0 #000);
  animation: bob 2s ease-in-out infinite;
}

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

.enemy-sprite.hit {
  animation: shake 0.4s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-12px); filter: drop-shadow(4px 4px 0 #000) brightness(2); }
  50% { transform: translateX(12px); filter: drop-shadow(4px 4px 0 #000) hue-rotate(90deg); }
  75% { transform: translateX(-8px); }
}

.enemy-sprite.defeated {
  animation: fadeout 0.8s forwards;
}

@keyframes fadeout {
  0% { opacity: 1; transform: scale(1) rotate(0); }
  100% { opacity: 0; transform: scale(0.5) rotate(360deg); }
}

.enemy-info {
  margin-top: 8px;
}

.enemy-name {
  font-size: 22px;
  color: var(--nes-accent);
  letter-spacing: 2px;
}

.enemy-level {
  font-size: 16px;
  color: var(--nes-accent2);
  margin: 4px 0;
}

.enemy-category {
  font-size: 13px;
  color: var(--nes-fg);
  background: var(--dd-purple);
  display: inline-block;
  padding: 2px 8px;
  border: 2px solid #fff;
}

.battle-status {
  width: 100%;
  background: var(--window-bg);
  border: 4px solid var(--nes-border);
  padding: 10px 14px;
  box-shadow: 4px 4px 0 #000;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  margin: 4px 0;
}

.status-label {
  width: 110px;
  color: var(--nes-accent);
}

.hp-bar {
  flex: 1;
  height: 14px;
  background: #000;
  border: 2px solid var(--nes-border);
  position: relative;
  overflow: hidden;
}

.hp-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--nes-green) 0%, #2c8a2c 100%);
  transition: width 0.4s ease;
}

.hp-bar-fill.low {
  background: linear-gradient(90deg, var(--nes-accent2) 0%, #8a2c2c 100%);
}

.battle-question {
  width: min(720px, 95%);
  margin-top: 12px;
}

.msg-window, .question-window {
  background: var(--window-bg);
  border: 4px solid var(--nes-border);
  padding: 14px 18px;
  box-shadow: 4px 4px 0 #000;
  margin-bottom: 10px;
}

.msg-window {
  font-size: 16px;
  min-height: 56px;
}

.question-text {
  font-size: 18px;
  line-height: 1.6;
  margin-bottom: 14px;
  color: var(--nes-fg);
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.choice-btn {
  font-family: inherit;
  font-size: 16px;
  text-align: left;
  padding: 10px 14px;
  background: #0d1133;
  color: var(--nes-fg);
  border: 3px solid var(--nes-border);
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  line-height: 1.4;
}

.choice-btn:hover:not(:disabled) {
  background: var(--dd-purple);
  border-color: var(--nes-accent);
}

.choice-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.choice-btn.correct {
  background: #1e5a1e;
  border-color: var(--nes-green);
  color: var(--nes-fg);
}

.choice-btn.wrong {
  background: #5a1e1e;
  border-color: var(--nes-accent2);
}

.choice-num {
  color: var(--nes-accent);
  font-weight: bold;
  flex-shrink: 0;
}

/* ===== モーダル ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.modal.hidden {
  display: none;
}

.modal-frame {
  background: var(--window-bg);
  border: 4px solid var(--nes-border);
  padding: 24px;
  max-width: 520px;
  width: 90%;
  box-shadow: 6px 6px 0 #000;
  text-align: center;
}

.modal-header {
  font-size: 22px;
  color: var(--nes-accent);
  margin-bottom: 12px;
  letter-spacing: 2px;
}

.modal-header.correct { color: var(--nes-green); }
.modal-header.wrong { color: var(--nes-accent2); }

.modal-body {
  font-size: 16px;
  line-height: 1.6;
  margin-bottom: 20px;
  text-align: left;
  background: #0d1133;
  border: 2px solid #444;
  padding: 12px;
  white-space: pre-wrap;
}

/* ===== 名前入力 ===== */
.nes-input {
  width: 100%;
  font-family: inherit;
  font-size: 18px;
  padding: 10px;
  background: #0d1133;
  color: var(--nes-fg);
  border: 3px solid var(--nes-border);
  outline: none;
}

.nes-input:focus {
  border-color: var(--nes-accent);
}

/* ===== ランキング ===== */
.ranking-frame {
  max-width: 640px;
}

.ranking-help {
  font-size: 12px;
  color: #b1b3d9;
  text-align: center;
  margin-bottom: 10px;
}

.ranking-list {
  background: #0d1133;
  border: 2px solid #444;
  padding: 8px;
  margin-bottom: 16px;
  font-size: 13px;
  max-height: 320px;
  overflow-y: auto;
}

.ranking-row {
  display: grid;
  grid-template-columns: 32px 1fr 70px 70px 60px;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px dashed #444;
  align-items: center;
}

.ranking-row:last-child { border-bottom: none; }

.ranking-row.self {
  background: rgba(246, 196, 83, 0.15);
  border: 2px solid var(--nes-accent);
  border-left: 6px solid var(--nes-accent);
}

.rank-rank { color: var(--nes-accent); font-weight: bold; text-align: center; }
.rank-name { color: var(--nes-fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-score { color: var(--nes-green); text-align: right; font-family: 'Press Start 2P', monospace; font-size: 12px; }
.rank-time { color: #b1b3d9; text-align: right; font-family: 'Press Start 2P', monospace; font-size: 11px; }
.rank-acc { color: var(--nes-accent2); text-align: right; font-size: 12px; }

.ranking-row.header {
  font-size: 11px;
  color: var(--nes-accent);
  border-bottom: 2px solid #555;
  padding-bottom: 4px;
}

.ranking-empty {
  text-align: center;
  padding: 24px;
  color: #b1b3d9;
}

.ending-ranking {
  margin: 20px 0;
}

.ending-ranking-title {
  font-size: 16px;
  color: var(--nes-accent);
  margin-bottom: 8px;
  letter-spacing: 2px;
}

/* ===== エンディング / ゲームオーバー ===== */
/* ===== イントロ ===== */
.intro-frame {
  max-width: 960px;
  width: 94%;
  padding: 24px 32px;
  border: 6px double var(--nes-border);
  background: rgba(11, 13, 44, 0.95);
  box-shadow: 0 0 0 4px #000, 0 0 60px rgba(255, 91, 107, 0.3);
  margin: 12px auto;
}

.intro-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 20px;
  color: var(--nes-accent);
  text-align: center;
  margin-bottom: 18px;
  letter-spacing: 4px;
}

.intro-text {
  font-size: 16px;
  line-height: 1.7;
  min-height: 240px;
  white-space: pre-wrap;
  color: var(--nes-fg);
  text-shadow: 2px 2px 0 #000;
}

.intro-text .typing-cursor {
  display: inline-block;
  width: 10px;
  background: var(--nes-accent);
  margin-left: 4px;
  animation: blink 0.8s infinite;
}

.intro-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
}

.ending-frame {
  text-align: center;
  padding: 28px 32px;
  border: 6px double var(--nes-border);
  background: rgba(11, 13, 44, 0.9);
  max-width: 960px;
  width: 94%;
  box-shadow: 0 0 0 4px #000, 0 0 60px rgba(246, 196, 83, 0.3);
  margin: 12px auto;
}

.ending-title {
  font-size: 24px;
  color: var(--nes-accent);
  margin-bottom: 12px;
  letter-spacing: 2px;
  line-height: 1.4;
}

.ending-title.gameover {
  color: var(--nes-accent2);
}

.ending-art {
  font-size: 44px;
  margin: 12px 0;
  animation: bob 2s ease-in-out infinite;
}

.ending-text {
  font-size: 15px;
  line-height: 1.7;
  margin: 12px 0;
}

.ending-stats {
  font-size: 14px;
  background: #0d1133;
  border: 2px solid #444;
  padding: 12px;
  margin: 16px 0;
  text-align: left;
}

.rescue-scene {
  font-size: 13px;
  line-height: 1.7;
  background: rgba(246, 196, 83, 0.12);
  border: 3px double var(--nes-accent);
  padding: 12px 16px;
  margin: 10px 0;
  text-align: left;
  white-space: pre-wrap;
}

.rescue-scene .narrator {
  color: var(--nes-accent);
  font-weight: bold;
}

.rescue-scene .bits-line {
  color: var(--nes-green);
}

.bits-icon {
  display: inline-block;
  vertical-align: middle;
  image-rendering: pixelated;
}

.rescue-scene .bits-icon {
  width: 24px;
  height: 24px;
}

.ending-art .bits-icon {
  width: 48px;
  height: 48px;
}

/* ===== レスポンシブ ===== */
@media (max-width: 640px) {
  .title-logo { font-size: 36px; }
  .title-subtitle { font-size: 14px; }
  .nes-btn { font-size: 15px; padding: 10px 18px; }
  .choices { grid-template-columns: 1fr; }
  .enemy-sprite { font-size: 72px; }
  .question-text { font-size: 16px; }

  /* フィールドHUDを縦に詰めて省スペース化 */
  .field-hud { font-size: 12px; padding: 6px 8px; gap: 4px; }
  .hud-label { font-size: 9px; }
  .hud-name, .hud-hp, .hud-defeated { font-size: 13px; }
  .hud-time { font-size: 12px; }
  .field-message { font-size: 13px; min-height: 44px; padding: 8px 10px; }
  .hud-lang-toggle { top: 2px; right: 4px; }

  /* 小さめの十字キー */
  .touch-dpad {
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(3, 48px);
    bottom: 12px;
    right: 12px;
  }
}
