@charset "UTF-8";
/* =============================================================================
   MIDNIGHT DEPART — レイアウトと UI。
   ゲーム本体は Canvas に描かれるので、ここは「入れ物」と画面外 UI だけを扱う。
   ============================================================================= */

:root {
  --md-bg: #05050f;
  --md-neon-a: #43e8ff;
  --md-neon-b: #c264ff;
  --md-neon-c: #ff5c9e;
  --md-text: #dbe4ff;
  --md-dim: #7f8ec9;
  --md-panel: rgba(10, 10, 32, 0.96);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: var(--md-bg);
  color: var(--md-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  /* 操作中に文字が選択されたり、ダブルタップで拡大したりしないようにする。
     manipulation はスクロール（ポーズメニュー）は残したままダブルタップ拡大だけ止める */
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* 入力欄だけは選択・操作をふつうに行えるようにしておく */
input, textarea, select {
  -webkit-user-select: auto;
  user-select: auto;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.hidden { display: none !important; }

/* -------------------------------------------------------------- ゲーム枠 */

#game-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  /* 横持ちのノッチ（左右のセーフエリア）にゲーム画面がかからないようにする。
     ノッチが無い端末では 0px なので、見た目は従来どおり */
  width: auto;
  margin-left: env(safe-area-inset-left, 0px);
  margin-right: env(safe-area-inset-right, 0px);
  /* 共通ヘッダーとフッター広告のぶんだけ縮める。どちらも無ければ 0px */
  height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  min-height: 240px;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 0%, #16123a 0%, #08081a 55%, #04040c 100%);
}

/* dvh 未対応ブラウザ向け */
@supports not (height: 100dvh) {
  #game-container { height: calc(100vh - var(--sgh-top, 0px) - var(--ad-space, 0px)); }
}

#game-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #05050f;
  box-shadow: 0 0 0 1px rgba(67, 232, 255, 0.18), 0 0 44px rgba(90, 60, 190, 0.34);
  /* キャンバス上ではスクロール・拡大・長押しメニュー・ドラッグをすべて無効にする */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}

/* 横長でキャンバスが画面いっぱいまで広がっているときは、外周の光は出さない
   （is-fullbleed は Game._onResize が付け外しする） */
#game-container.is-fullbleed #game-canvas { box-shadow: none; }

/* ------------------------------------------------ 起動できなかったときの案内 */

#boot-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: var(--md-bg);
  z-index: 30;
}

.boot-title {
  margin: 0 0 14px;
  font-family: "Courier New", monospace;
  font-size: 26px;
  letter-spacing: 0.1em;
  color: var(--md-neon-a);
  text-shadow: 0 0 14px rgba(67, 232, 255, 0.6);
}

#boot-fallback p { margin: 0 0 10px; font-size: 15px; color: var(--md-text); }
.boot-note { font-size: 12.5px; line-height: 1.8; color: var(--md-dim); }

/* -------------------------------------------------------- 隠しボタン群 */

.hidden-controls {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

/* ------------------------------------------------------------ フッター */

#page-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 4px;
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  font-size: 11px;
  line-height: 1.5;
  color: #4a5288;
  pointer-events: none;
  z-index: 3;
}

#page-footer a {
  color: #7f8ec9;
  text-decoration: none;
  pointer-events: auto;
}

#page-footer a:hover,
#page-footer a:focus { color: var(--md-neon-a); text-decoration: underline; }

/* プレイ中はフッターを隠して画面を広く使う */
body.in-game #page-footer { display: none; }

/* -------------------------------------------------------- タッチ操作UI */

#touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;                 /* 既定は非表示。タッチ端末でだけ出す */
  align-items: flex-end;
  justify-content: space-between;
  /* 左右のセーフエリアは #game-container の margin で確保済み */
  padding: 0 12px calc(12px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
  z-index: 4;
}

/* --- 移動用ジョイスティック ---
   枠（stick-zone）内のどこを触ってもそこにスティックが現れる「フローティング方式」。
   決まった位置のボタンを狙わずに済むので、画面を見ながらでも操作できる。
   位置は JS がインラインの left / top で動かし、離すと CSS の待機位置へ戻る。 */

.stick-zone {
  position: relative;
  pointer-events: auto;
  width: 46%;
  max-width: 340px;
  height: 176px;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.stick {
  position: absolute;
  left: 84px;                    /* 待機位置（JS が触った場所へ動かす） */
  top: 50%;
  width: 132px;
  height: 132px;
  transform: translate(-50%, -50%);
  opacity: 0.55;
  /* 指を離したときだけ待機位置へすべって戻る（触った瞬間は即その場に出す） */
  transition: opacity 120ms linear, left 150ms ease-out, top 150ms ease-out;
}

.stick.is-active {
  opacity: 1;
  transition: opacity 120ms linear;
}

.stick-base {
  position: absolute;
  inset: 0;
  border: 2px solid rgba(67, 232, 255, 0.5);
  border-radius: 50%;
  background: rgba(10, 12, 34, 0.34);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  box-sizing: border-box;
}

.stick-arrow {
  color: rgba(214, 246, 255, 0.5);
  font-size: 15px;
  line-height: 1;
  transition: color 60ms linear;
}

.stick.is-left  .stick-arrow--l,
.stick.is-right .stick-arrow--r { color: #d6f6ff; }

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border: 2px solid rgba(67, 232, 255, 0.8);
  border-radius: 50%;
  background: rgba(67, 232, 255, 0.24);
  box-shadow: 0 0 12px rgba(67, 232, 255, 0.35);
  transition: transform 90ms ease-out;
}

/* 指で動かしている最中は追従を遅らせない（戻すときだけアニメーションさせる） */
.stick.is-active .stick-knob { transition: none; }

.touch-btn {
  pointer-events: auto;
  width: 88px;
  height: 88px;
  border: 2px solid rgba(67, 232, 255, 0.55);
  border-radius: 14px;
  /* ゲーム画面の上に重ねるので、下の絵が透けるくらいの濃さにする */
  background: rgba(10, 12, 34, 0.42);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  color: #d6f6ff;
  font-size: 24px;
  font-weight: bold;
  font-family: inherit;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  transition: background-color 60ms linear, transform 60ms linear;
}

.touch-btn--act {
  border-color: rgba(255, 92, 158, 0.65);
  color: #ffd9ec;
  font-size: 15px;
  letter-spacing: 0.06em;
}

.touch-btn.is-pressed {
  background: rgba(67, 232, 255, 0.32);
  transform: scale(0.94);
}

.touch-btn--act.is-pressed { background: rgba(255, 92, 158, 0.34); }

/* タッチ端末（または狭い画面）のプレイ中だけ表示する。
   メニュー画面では出さないので、画面のどこを触っても「決定」として届く */
@media (pointer: coarse) {
  body.in-game #touch-controls { display: flex; }
}
@media (max-width: 900px) {
  body.in-game #touch-controls { display: flex; }
  .touch-btn--act { width: 74px; height: 74px; font-size: 13px; }
  .stick { width: 120px; height: 120px; }
  .stick-knob { width: 54px; height: 54px; margin: -27px 0 0 -27px; }
}
@media (pointer: fine) and (min-width: 901px) {
  #touch-controls { display: none; }
}

/* スマホの横持ち。画面が低いので操作系を詰めて、プレイ画面を隠す面積を減らす */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 460px) {
  #touch-controls { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  .touch-btn--act { width: 68px; height: 68px; font-size: 12px; }
  /* 待機位置は画面の下寄せ気味にして、プレイ画面を隠す面積を抑える */
  .stick-zone { height: 120px; }
  .stick { left: 70px; width: 112px; height: 112px; }
  .stick-knob { width: 52px; height: 52px; margin: -26px 0 0 -26px; }
}

/* ------------------------------------------- ゲーム内メニューボタン（横持ち用） */

/* 既定では出さない。共通ヘッダーを隠す横持ちのときだけ表示する */
.menu-fab {
  display: none;
  position: absolute;
  top: 4px;
  right: 8px;
  z-index: 5;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(159, 180, 255, 0.45);
  border-radius: 9px;
  background: rgba(10, 12, 34, 0.6);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  color: #cfe0ff;
  font-family: inherit;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.menu-fab:hover,
.menu-fab:focus-visible {
  border-color: var(--md-neon-a);
  color: #eaf9ff;
  outline: none;
}

.menu-fab:active { background: rgba(40, 46, 100, 0.75); }

/* -------------------------------------------------------- ポーズメニュー */

#pause-menu {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(4, 4, 14, 0.78);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  z-index: 10;
}

.pm-panel {
  width: min(440px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 20px 22px 24px;
  border: 2px solid rgba(67, 232, 255, 0.6);
  border-radius: 6px;
  background: var(--md-panel);
  box-shadow: 0 0 40px rgba(120, 70, 220, 0.4);
}

.pm-title {
  margin: 0 0 16px;
  font-family: "Courier New", monospace;
  font-size: 26px;
  letter-spacing: 0.16em;
  text-align: center;
  color: var(--md-neon-a);
  text-shadow: 0 0 12px rgba(67, 232, 255, 0.7);
}

.pm-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
}

.pm-btn {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid rgba(159, 180, 255, 0.4);
  border-radius: 4px;
  background: rgba(30, 30, 72, 0.8);
  color: var(--md-text);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 100ms linear, border-color 100ms linear;
}

.pm-btn:hover,
.pm-btn:focus-visible {
  background: rgba(60, 55, 128, 0.9);
  border-color: var(--md-neon-a);
  outline: none;
}

.pm-btn--primary {
  background: linear-gradient(180deg, #2b6fb0, #1d3f80);
  border-color: var(--md-neon-a);
  color: #eaf9ff;
}

.pm-btn--small {
  margin-top: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
}

.pm-settings {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 0;
  border-top: 1px solid rgba(159, 180, 255, 0.18);
  border-bottom: 1px solid rgba(159, 180, 255, 0.18);
}

.pm-row {
  display: grid;
  /* 3列目は「ON / OFF」が折り返さない幅にする */
  grid-template-columns: 84px 1fr 66px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  cursor: pointer;
}

.pm-label { color: var(--md-dim); }
.pm-val { text-align: right; color: var(--md-text); font-variant-numeric: tabular-nums; white-space: nowrap; }

.pm-row input[type="range"] {
  width: 100%;
  accent-color: var(--md-neon-a);
  cursor: pointer;
}

.pm-row--check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--md-neon-a);
  cursor: pointer;
  justify-self: start;
}

.pm-help {
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid rgba(159, 180, 255, 0.22);
  border-radius: 4px;
  background: rgba(16, 16, 44, 0.9);
  font-size: 12.5px;
  line-height: 1.7;
}

.pm-help dl {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 4px 10px;
  margin: 0 0 10px;
}

.pm-help dt { color: var(--md-neon-a); font-family: "Courier New", monospace; }
.pm-help dd { margin: 0; color: var(--md-text); }
.pm-help p { margin: 0; color: var(--md-dim); }

/* ------------------------------------------------------ 横画面推奨の案内 */

#rotate-notice {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(5, 5, 18, 0.94);
  text-align: center;
}

.rotate-icon {
  display: block;
  font-size: 46px;
  margin-bottom: 12px;
  animation: md-rotate-hint 2.2s ease-in-out infinite;
}

#rotate-notice p { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
#rotate-notice .rotate-sub { font-size: 13px; color: var(--md-dim); font-weight: 400; }

@keyframes md-rotate-hint {
  0%, 45%, 100% { transform: rotate(0deg); }
  60%, 85%      { transform: rotate(90deg); }
}

@media (max-width: 900px) and (orientation: portrait) {
  #rotate-notice { display: flex; }
  /* 案内を出しているあいだは仮想操作を隠す（案内の上に浮いて見えないように） */
  body.in-game #touch-controls { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .rotate-icon { animation: none; }
  .touch-btn { transition: none; }
  .stick,
  .stick-knob { transition: none; }
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / js/ad-banner.js が挿入する）
   --ad-h    : 広告そのものの高さ。広告なしのときは 0px
   --ad-space: レイアウトが空けるべき高さ（広告 + セーフエリア）
   ========================================================================== */
:root {
  --ad-h: 0px;
  --ad-space: 0px;
}
html.has-ad-banner {
  --ad-space: calc(var(--ad-h, 0px) + env(safe-area-inset-bottom, 0px));
}

.ad-banner {
  /* height は広告そのものの高さ。セーフエリアぶんの padding は外側に足す */
  box-sizing: content-box;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  /* ポーズ等の全画面オーバーレイ（2147483000）よりは下に置く */
  z-index: 2147482000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: var(--ad-h, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow: hidden;
  background: rgba(14, 16, 20, 0.86);
  /* border ではなく inset shadow にして、枠線ぶん高さがずれないようにする */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.ad-banner__frame {
  display: block;
  width: 100%;
  height: var(--ad-h, 0px);
  border: 0;
  color-scheme: light;
}

/* ==========================================================================
   スマホの横持ち。共通ヘッダーを隠して、そのぶんプレイ画面を高く使う。
   （ここで上書きする基本ルールより後に置くこと。共通ヘッダーの CSS は
     このファイルより後に読み込まれるので、そちらの上書きには !important が要る）
   ========================================================================== */
@media (orientation: landscape) and (max-height: 520px) {
  :root {
    /* ヘッダーぶんの余白をなくす（body の padding-top もこの値を見ている） */
    --sgh-top: env(safe-area-inset-top, 0px) !important;
  }
  .sgh-header { display: none !important; }

  /* 共通ヘッダーのメニューが使えなくなるので、代わりの入口を出す */
  .menu-fab { display: block; }

  /* 画面が低いぶんポーズメニューを詰める（横持ちではここが唯一のメニュー） */
  #pause-menu { padding: 8px; }
  .pm-panel { padding: 12px 16px 14px; }
  .pm-title { margin: 0 0 10px; font-size: 21px; }
  .pm-actions { gap: 6px; margin-bottom: 10px; }
  .pm-btn { padding: 8px 12px; font-size: 14px; }
  .pm-settings { gap: 7px; padding: 10px 0; }
  .pm-help { margin-top: 8px; padding: 10px 12px; }
}
