* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #ddd;
  font-family: "Noto Sans JP", sans-serif;
}

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.hidden {
  display: none !important;
}

/* --- 共通スクリーン --- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  z-index: 10;
  gap: 24px;
}

/* --- タイトル画面 --- */
.title-screen {
  background: #000;
  overflow: hidden;
}

/* 背景：ゆっくり呼吸する赤い光（タイトルの奥で明滅） */
.title-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 55% 40% at 50% 40%,
    rgba(130, 0, 0, 0.22), rgba(60, 0, 0, 0.06) 45%, transparent 72%);
  animation: bg-breathe 6.5s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}
/* 文字・ボタンは背景光より前面に */
.title-screen > * {
  position: relative;
  z-index: 1;
}

.title-text {
  font-family: "Shippori Mincho", serif;
  font-size: 64px;
  font-weight: 700;
  color: #b60000;
  letter-spacing: 8px;
  text-shadow: 0 0 20px rgba(255, 0, 0, 0.4);
  animation: title-glow 4.5s ease-in-out infinite;
}

/* 各字を個別に、蛍光灯が切れかけるように不規則に明滅させる */
.tc {
  display: inline-block;
  animation: title-flicker 7s steps(1, end) infinite;
}
.title-text .tc:nth-child(1) { animation-delay: 0s; }
.title-text .tc:nth-child(2) { animation-delay: -2.7s; }
.title-text .tc:nth-child(3) { animation-delay: -4.9s; }

/* 中央の「に」＝別フォント(Yuji Syuku)に化けながらちかちかする */
.tc-ni {
  animation: ni-glitch 5.5s steps(1, end) infinite;
}

.title-sub {
  font-size: 14px;
  color: #666;
  letter-spacing: 6px;
  animation: title-flicker 9s steps(1, end) infinite;
  animation-delay: -3.5s;
}

@keyframes bg-breathe {
  0%, 100% { opacity: 0.45; transform: scale(1); }
  50%      { opacity: 1;    transform: scale(1.08); }
}

@keyframes title-glow {
  0%, 100% { text-shadow: 0 0 18px rgba(255, 0, 0, 0.35); }
  50%      { text-shadow: 0 0 34px rgba(255, 0, 0, 0.6), 0 0 10px rgba(255, 70, 45, 0.5); }
}

/* 大半は点灯、時々一瞬だけ暗転 */
@keyframes title-flicker {
  0%, 100% { opacity: 1; }
  7%  { opacity: 0.25; }
  8%  { opacity: 1; }
  41% { opacity: 1; }
  42% { opacity: 0.45; }
  43% { opacity: 1; }
  44% { opacity: 0.15; }
  45% { opacity: 1; }
  73% { opacity: 1; }
  74% { opacity: 0.55; }
  75% { opacity: 1; }
}

/* 「に」の字化け：明朝⇔崩し字を行き来しつつ位置・色が揺れる */
@keyframes ni-glitch {
  0%, 47%, 100% {
    font-family: "Shippori Mincho", serif;
    color: #b60000; opacity: 1; transform: translate(0, 0);
  }
  48% { font-family: "Yuji Syuku", serif; color: #ff3a2a; opacity: 0.85; transform: translate(1px, -1px) skewX(-6deg); }
  49% { opacity: 0.2; }
  50% { font-family: "Yuji Syuku", serif; color: #d10000; opacity: 1; transform: translate(-1px, 1px); }
  51% { font-family: "Shippori Mincho", serif; opacity: 1; transform: translate(0, 0); }
  52% { opacity: 0.4; }
  53% { opacity: 1; }
  80% { font-family: "Shippori Mincho", serif; }
  81% { font-family: "Yuji Syuku", serif; color: #ff3a2a; opacity: 0.6; transform: translate(0, -1px); }
  82% { font-family: "Shippori Mincho", serif; color: #b60000; opacity: 1; transform: translate(0, 0); }
}

/* 崩し字フォント先読み用（不可視・レイアウトに影響させない） */
.font-preload {
  position: absolute;
  left: -9999px;
  top: -9999px;
  font-family: "Yuji Syuku", serif;
  opacity: 0;
  pointer-events: none;
}

/* モーション過敏設定では静止させる */
@media (prefers-reduced-motion: reduce) {
  .title-screen::before,
  .title-text, .tc, .tc-ni, .title-sub {
    animation: none !important;
  }
  .tc-ni { font-family: "Shippori Mincho", serif; color: #b60000; opacity: 1; transform: none; }
}

.btn {
  padding: 14px 40px;
  background: transparent;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 4px;
  font-family: inherit;
  font-size: 16px;
  cursor: pointer;
  letter-spacing: 4px;
  transition: all 0.2s;
}

.btn:hover, .btn:active {
  background: #b60000;
  color: #fff;
  border-color: #b60000;
}

.btn-sub {
  padding: 10px 30px;
  font-size: 14px;
  border-color: #333;
  color: #888;
  letter-spacing: 3px;
}
.btn-sub:hover, .btn-sub:active {
  background: #2a2a2a;
  color: #ddd;
  border-color: #555;
}

/* --- 設定画面 --- */
.settings-title {
  font-family: "Shippori Mincho", serif;
  font-size: 22px;
  color: #ccc;
  letter-spacing: 6px;
  margin-bottom: 8px;
}
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 320px;
  max-width: 90vw;
}
.settings-row {
  display: grid;
  grid-template-columns: 80px 1fr 40px;
  align-items: center;
  gap: 12px;
  color: #bbb;
  font-size: 13px;
}
.settings-label {
  letter-spacing: 2px;
}
.settings-row input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: #333;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.settings-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: #b60000;
  border-radius: 50%;
  cursor: pointer;
}
.settings-row input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: #b60000;
  border-radius: 50%;
  border: none;
  cursor: pointer;
}
.settings-value {
  text-align: right;
  color: #888;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.hint {
  color: #666;
  font-size: 12px;
  text-align: center;
  line-height: 1.8;
  margin-top: 24px;
}

/* --- ゲームオーバー --- */
.gameover-text {
  font-family: "Shippori Mincho", serif;
  font-size: 48px;
  color: #b60000;
  letter-spacing: 12px;
}

.clear-text {
  font-family: "Shippori Mincho", serif;
  font-size: 48px;
  color: #ddd;
  letter-spacing: 12px;
}

/* --- 導入・エピローグの語り --- */
.narrative-screen {
  background: #000;
  cursor: pointer;
  opacity: 1;
  transition: opacity 0.9s ease;
}
.narrative-screen.fading-out {
  opacity: 0;
}
.narrative {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 680px;
  padding: 0 32px;
  text-align: center;
}
.narrative-line {
  font-family: "Shippori Mincho", serif;
  font-size: 20px;
  line-height: 2;
  color: #cfcfcf;
  letter-spacing: 3px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 1.6s ease, transform 1.6s ease;
}
.narrative-line.show {
  opacity: 1;
  transform: translateY(0);
}
.narrative-gap {
  height: 6px;
  margin: 0;
}
.narrative-skip {
  position: absolute;
  bottom: 28px;
  right: 28px;
  font-size: 11px;
  color: #555;
  letter-spacing: 2px;
}
@media (max-width: 640px) {
  .narrative-line { font-size: 16px; letter-spacing: 2px; }
}

/* --- HUD --- */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.key-counter {
  position: absolute;
  top: 16px;
  right: 16px;
  color: #d9b25a;
  font-family: "Shippori Mincho", serif;
  font-size: 20px;
  letter-spacing: 2px;
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.9);
}

.parking-tag {
  color: #ffd050;
  font-size: 16px;
}

.key-dot {
  margin: 0 1px;
  text-shadow: 0 0 6px currentColor;
}

.hud-pause-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 44px;
  height: 44px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #ddd;
  font-size: 14px;
  letter-spacing: 1px;
  border-radius: 6px;
  cursor: pointer;
  pointer-events: auto;
  font-family: inherit;
}
.hud-pause-btn:active {
  background: rgba(182, 0, 0, 0.35);
}

.caption {
  position: absolute;
  left: 50%;
  bottom: 12%;
  transform: translateX(-50%);
  max-width: 82%;
  text-align: center;
  color: #e6e2da;
  font-family: "Shippori Mincho", serif;
  font-size: 20px;
  letter-spacing: 1px;
  line-height: 1.7;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.95), 0 0 3px rgba(0, 0, 0, 0.9);
  opacity: 0;
  transition: opacity 0.7s ease;
  pointer-events: none;
  white-space: pre-wrap;
}
.caption.show {
  opacity: 1;
}

/* 「開ける」プロンプト */
.interact-prompt {
  position: absolute;
  left: 50%;
  bottom: 30%;
  transform: translateX(-50%);
  color: #eae6de;
  font-family: "Noto Sans JP", sans-serif;
  font-size: 15px;
  letter-spacing: 2px;
  padding: 7px 16px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  white-space: nowrap;
}
.interact-prompt .ip-key {
  display: inline-block;
  padding: 1px 7px;
  margin-right: 6px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  font-size: 12px;
  letter-spacing: 1px;
}
@media (max-width: 640px) {
  .interact-prompt .ip-key { display: none; } /* スマホは「開」ボタンで操作 */
  .interact-prompt { bottom: 34%; }
}
@media (max-width: 640px) {
  .caption { font-size: 16px; bottom: 16%; }
}

.vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    transparent 40%,
    rgba(0, 0, 0, 0.5) 80%,
    rgba(0, 0, 0, 0.9) 100%
  );
  pointer-events: none;
}

/* --- バーチャル十字キー（スマホのみ表示） --- */
.dpad {
  position: absolute;
  bottom: 24px;
  left: 24px;
  width: 180px;
  height: 180px;
  z-index: 20;
  touch-action: none;
}

.dpad-btn {
  position: absolute;
  width: 56px;
  height: 56px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.6);
  font-size: 20px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.1s;
}

.dpad-btn:active,
.dpad-btn.pressed {
  background: rgba(182, 0, 0, 0.4);
  color: #fff;
}

.dpad-up    { top: 0;   left: 62px; }
.dpad-left  { top: 62px; left: 0; }
.dpad-right { top: 62px; left: 124px; }
.dpad-down  { top: 124px; left: 62px; }

/* 右側：旋回2ボタン ＋ 走るボタン
   dpadは position:absolute で bottom-left に配置。旋回ボタンは
   画面右端に別ブロックとして絶対配置する。 */
.dpad-turnL,
.dpad-turnR,
.dpad-run,
.dpad-torch,
.dpad-open {
  position: fixed;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  font-size: 26px;
}
.dpad-open {
  right: 60px;
  bottom: 200px;
  font-size: 22px;
  background: rgba(120, 170, 255, 0.16);
}
.dpad-turnL { right: 96px; bottom: 40px; }
.dpad-turnR { right: 24px; bottom: 40px; }
.dpad-run {
  right: 24px;
  bottom: 120px;
  font-size: 20px;
  background: rgba(182, 0, 0, 0.15);
}
.dpad-torch {
  right: 96px;
  bottom: 120px;
  font-size: 20px;
  background: rgba(255, 200, 100, 0.15);
}
