/* ========================================
   common.css
   全画面共通のデザインと基本レイアウト
======================================== */

:root {
  color-scheme: dark;

  --bg: #10121a;
  --panel: #191d29;
  --text: #f0f2fa;
  --muted: #8c94a8;
  --accent: #83f0d0;
  --border: #303748;
  --danger: #ff647c;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Helvetica Neue",
    sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  color: var(--text);
  background: var(--panel);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

button:active {
  transform: scale(0.98);
}

#game {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

.screen {
  position: relative;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}

.screen[hidden],
.overlay[hidden] {
  display: none !important;
}

/* ========================================
   タイトル画面
======================================== */

#title-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
  background:
    radial-gradient(
      ellipse at 50% 38%,
      #252e3d 0%,
      var(--bg) 65%
    );
}

.title-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 60px;
  margin-bottom: 28px;
}

.title-mark span {
  display: block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--accent);
  transform: rotate(45deg);
}

.title-mark span:nth-child(2) {
  width: 36px;
  height: 36px;
  background: var(--accent);
}

.eyebrow,
.label,
.version {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.2em;
}

h1 {
  margin: 14px 0;
  font-size: clamp(32px, 8vw, 54px);
  line-height: 1.08;
  letter-spacing: -0.04em;
}

.subtitle {
  margin: 8px 0 42px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.16em;
}

/* START・RESUME共通の主要ボタン */
.primary-button {
  width: min(100%, 300px);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #101b20;
  font-weight: 800;
  text-shadow: none;
  box-shadow: none;
  -webkit-text-fill-color: #101b20;
  transition:
    background-color 0.18s ease,
    border-color 0.18s ease,
    filter 0.18s ease;
}

.primary-button:hover {
  background: #a0f5df;
  border-color: #a0f5df;
}

.primary-button:active {
  background: #70d9bb;
  border-color: #70d9bb;
}

.primary-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.secondary-button {
  width: min(100%, 300px);
  margin-top: 12px;
  background: transparent;
}

.version {
  position: absolute;
  bottom: 20px;
}

/* ========================================
   戦闘画面
======================================== */

#battle-screen {
  display: flex;
  flex-direction: column;
  padding:
    max(12px, env(safe-area-inset-top))
    16px
    max(16px, env(safe-area-inset-bottom));
}

.battle-header {
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 60px;
  padding: 8px 0 14px;
}

.battle-header > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.battle-header strong {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.battle-header .icon-button {
  width: 48px;
  margin-left: auto;
  font-size: 20px;
}

#battle-field {
  position: relative;
  flex: 1;
  min-height: 300px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #131722;
  isolation: isolate;
}

.field-grid {
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(#ffffff08 1px, transparent 1px),
    linear-gradient(90deg, #ffffff08 1px, transparent 1px);
  background-size: 28px 28px;
}

.placeholder-player {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 2px solid var(--accent);
  background: #83f0d022;
  transform: translate(-50%, -50%) rotate(45deg);
}

.placeholder-player span {
  width: 7px;
  height: 7px;
  background: var(--accent);
}

.field-message {
  position: absolute;
  right: 12px;
  bottom: 12px;
  margin: 0;
  color: #697287;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.8;
  letter-spacing: 0.12em;
  text-align: right;
}

.field-message span {
  color: #51596c;
}

.battle-footer {
  padding-top: 16px;
}

.hp-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.hp-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 8px;
  background: #343848;
}

#hp-fill {
  width: 100%;
  height: 100%;
  background: var(--accent);
}

.battle-footer > p {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
  letter-spacing: 0.12em;
}

/* ========================================
   一時停止メニュー
======================================== */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #080a10dd;
}

.dialog {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(100%, 340px);
  padding: 28px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
}

.dialog h2 {
  margin: 10px 0 28px;
  font-size: 30px;
}

/* ========================================
   PC向けレイアウト
======================================== */

@media (min-width: 700px) {
  #battle-screen {
    width: min(100%, 900px);
    min-height: 100vh;
    margin: 0 auto;
  }
}

/* ========================================
   プレイヤー操作用
   タッチ操作によるスクロールを防ぐ。
======================================== */

#battle-field {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.placeholder-player {
  pointer-events: none;
  will-change: left, top;
}

/* ========================================
   ゲームオーバー画面
   main.jsからbattle-field内に動的生成する。
======================================== */

.game-over-overlay {
  position: absolute;
  inset: 0;
  z-index: 100;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 20px;
  overflow-y: auto;

  background: rgba(5, 8, 15, 0.88);

  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

/* hidden属性が他のdisplay指定に上書きされないようにする。 */
.game-over-overlay[hidden] {
  display: none !important;
}

/* ゲームオーバー画面の中央パネル */
.game-over-dialog {
  width: 100%;
  max-width: 340px;

  padding: 32px 22px;

  border: 1px solid rgba(255, 100, 124, 0.45);
  border-radius: 16px;

  background: #111722;

  box-shadow:
    0 0 30px rgba(255, 100, 124, 0.08),
    inset 0 0 24px rgba(255, 100, 124, 0.025);

  text-align: center;
}

/* ゲームタイトルの小見出し */
.game-over-eyebrow {
  margin: 0 0 14px;

  color: var(--accent);

  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.22em;
}

/* GAME OVERの見出し */
.game-over-dialog h2 {
  margin: 0;

  color: var(--danger);

  font-size: clamp(28px, 8vw, 40px);
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.2;
}

/* ゲームオーバー時の説明 */
.game-over-description {
  margin: 16px 0 28px;

  color: #9ba8bd;

  font-size: 11px;
  line-height: 1.8;
  letter-spacing: 0.12em;
}

/* ボタンを縦に並べる */
.game-over-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ゲームオーバー画面専用ボタン */
.game-over-button {
  width: 100%;
  min-height: 48px;

  padding: 12px 18px;

  border-radius: 8px;

  font: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;

  cursor: pointer;

  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.15s ease;
}

/* 押したときの反応 */
.game-over-button:active {
  transform: scale(0.98);
}

/* RETRY：目立つ主要ボタン */
.game-over-primary {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #101722;
}

.game-over-primary:hover {
  background: #a4ffe4;
  border-color: #a4ffe4;
}

/* TITLE：控えめな副ボタン */
.game-over-secondary {
  border: 1px solid #394456;
  background: transparent;
  color: #c8d1df;
}

.game-over-secondary:hover {
  border-color: #718097;
  background: rgba(255, 255, 255, 0.04);
}

/* キーボード操作時のフォーカス表示 */
.game-over-button:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 3px;
}

/* 動きを減らす設定を使用している場合 */
@media (prefers-reduced-motion: reduce) {
  .game-over-button {
    transition: none;
  }
}