/* ==========================================================================
   もういいかい（mouiikai）
   真夜中の廃校。黒に近い紺・懐中電灯の黄ばんだ光・お面の白・血のような赤
   ========================================================================== */
:root {
  --navy: #07080d;
  --ink: #14151c;
  --snow: #ecebe4;
  --snow-dim: #a9a79c;
  --gold: #e8d9a0;
  --red: #c2262c;
  --cyan: #9fd8d2;
  --green: #8fd6a0;
  --panel: rgba(16, 17, 24, 0.94);
  --line: rgba(232, 217, 160, 0.26);
  --sgh-top: 0px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--navy);
  color: var(--snow);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

#app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--navy);
}

/* ---------- HUD ---------- */
#hud {
  flex: none;
  padding: 5px calc(8px + env(safe-area-inset-right, 0px)) 5px calc(8px + env(safe-area-inset-left, 0px));
  background: #0c0d13;
  border-bottom: 1px solid var(--line);
}
#hud.off > * { visibility: hidden; }
#hud-top { display: flex; align-items: center; gap: 6px; }
.hud-chip {
  flex: none;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#hud-room { color: var(--gold); min-width: 5.4em; text-align: center; }
#hud-time { min-width: 3.6em; text-align: center; }
#hud-items { flex: 1; min-width: 0; display: flex; gap: 4px; overflow: hidden; }
.item-chip {
  flex: none;
  padding: 4px 7px;
  border-radius: 8px;
  background: rgba(232, 217, 160, 0.14);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  animation: item-in 0.5s ease-out;
}
@keyframes item-in { from { transform: scale(1.5); background: rgba(232, 217, 160, 0.7); } }
#hud-goal {
  margin-top: 4px;
  min-height: 1.5em;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.5;
  color: var(--snow-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#hud-goal::before { content: "▶ "; color: var(--red); }

.icon-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--snow);
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
}
.icon-btn:focus-visible, .btn:focus-visible, .pad-btn:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

/* ---------- 校舎（キャンバス） ---------- */
#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #000;
  outline: none;
  touch-action: none;
  cursor: default;
}
/* 下から: 背景（要素ごと動かす）→ 人物とドア → 明かり（GPU で計算した暗やみの膜）→ 文字や印 → ふちの暗さ・赤み */
#world { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
#bgcv { position: absolute; left: 0; top: 0; display: block; transform-origin: 0 0; will-change: transform; }
#cv, #lt, #fx { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
#vig, #vig-red { position: absolute; inset: 0; pointer-events: none; }
#vig { background: radial-gradient(ellipse at 50% 50%, rgba(0, 0, 0, 0) 42%, rgba(0, 0, 0, 0.62) 100%); }
#vig-red { opacity: 0; background: radial-gradient(ellipse at 50% 50%, rgba(120, 0, 0, 0) 52%, rgba(140, 0, 0, 0.5) 100%); will-change: opacity; }

#msg {
  position: absolute;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(560px, calc(100% - 20px));
  min-height: 84px;
  padding: 14px 34px 14px 16px;
  border-radius: 6px;
  background: rgba(6, 7, 11, 0.94);
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 2px #000, 0 10px 30px rgba(0, 0, 0, 0.7);
  z-index: 4;
  cursor: pointer;
}
#msg-text { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.75; white-space: pre-line; }
#msg-text.scrawl { color: #ff8d86; letter-spacing: 0.12em; }
#msg-next { position: absolute; right: 12px; bottom: 8px; color: var(--gold); font-size: 13px; animation: bob 0.7s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(4px); } }

#pad {
  position: absolute;
  right: calc(14px + env(safe-area-inset-right, 0px));
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: flex-end;
  gap: 10px;
  z-index: 3;
}
.pad-btn {
  white-space: pre-line;
  width: 96px;
  height: 96px;
  padding: 4px;
  border-radius: 50%;
  border: 2px solid rgba(232, 217, 160, 0.75);
  background: rgba(20, 21, 28, 0.72);
  color: var(--snow);
  font-family: inherit;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.25;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.pad-btn.off { opacity: 0.28; border-color: rgba(255, 255, 255, 0.3); }
.pad-btn.hot { background: rgba(194, 38, 44, 0.78); border-color: #ffb3ae; }
.pad-btn.down { transform: scale(0.94); background: rgba(232, 217, 160, 0.32); }
.pad-sub { width: 66px; height: 66px; font-size: 14px; }

/* ---------- オーバーレイ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(3, 3, 6, 0.72);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#title-overlay { background: radial-gradient(ellipse at 50% 40%, rgba(3, 3, 6, 0.1), rgba(3, 3, 6, 0.7)); }
#pause-overlay { background: rgba(3, 3, 6, 0.93); }
#over-overlay { background: rgba(40, 2, 4, 0.82); }
.overlay-box {
  position: relative;
  width: min(400px, 100%);
  margin: auto;
  padding: 20px 18px 16px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.75);
  text-align: center;
}
#title-box { border-top: 4px solid var(--red); padding-top: 14px; }
.overlay-title { margin: 0 0 10px; font-size: 22px; font-weight: 900; letter-spacing: 0.08em; }
.overlay-text { margin: 0 0 14px; font-size: 14px; line-height: 1.7; color: var(--snow-dim); }

#title-head { margin-bottom: 8px; }
#logo-kicker { margin: 0 0 4px; color: var(--snow-dim); font-size: 13px; font-weight: 800; font-style: italic; letter-spacing: 0.12em; }
#logo {
  margin: 0;
  font-size: clamp(34px, 11vw, 50px);
  white-space: nowrap;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 0.04em;
  color: #f4f1e6;
  text-shadow: 0 0 18px rgba(194, 38, 44, 0.95), 3px 3px 0 #5d0b0f;
  animation: logo-flick 5.5s linear infinite;
}
@keyframes logo-flick { 0%, 91%, 94%, 97%, 100% { opacity: 1; } 92.5% { opacity: 0.35; } 95.5% { opacity: 0.6; } }
#logo span { display: block; font-size: 0.56em; letter-spacing: 0.1em; }
#logo-en { margin: 6px 0 0; font-size: 10.5px; font-weight: 900; letter-spacing: 0.2em; color: var(--red); }
#tagline { margin: 10px 0 12px; font-size: 14px; line-height: 1.7; color: var(--snow-dim); }
#tagline b { color: #fff; }
#title-best { margin: 0 0 10px; font-size: 13px; font-weight: 800; color: var(--snow-dim); }
#title-best b { font-size: 20px; color: var(--gold); font-variant-numeric: tabular-nums; }
#title-note { margin: 0 0 6px; font-size: 11.5px; color: var(--snow-dim); }

.btn {
  display: block;
  width: 100%;
  margin: 0 0 8px;
  padding: 13px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-family: inherit;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.08s;
}
.btn:active { transform: translateY(2px); }
.btn-primary { background: linear-gradient(180deg, #d5333a, #96151b); color: #fff; border-color: #f08a8a; box-shadow: 0 4px 0 #4d0a0d; letter-spacing: 0.1em; }
.btn-primary:active { box-shadow: 0 2px 0 #4d0a0d; }
.btn-sub { background: rgba(255, 255, 255, 0.08); color: var(--snow); font-size: 14px; padding: 11px 10px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

#title-box #btn-sound, #title-box #btn-restart { position: absolute; top: 10px; right: 10px; }

.howto { margin: 4px 0 12px; padding: 0 0 0 1.4em; text-align: left; font-size: 13px; line-height: 1.65; color: var(--snow-dim); }
.howto li { margin-bottom: 5px; }
.howto b { color: #fff; }
.howto .c-gold { color: var(--gold); }
.howto .c-red { color: #ff8d86; }
.howto-short { margin-top: 6px; padding: 10px 12px 6px 2.1em; border-radius: 8px; background: rgba(255, 255, 255, 0.05); }

#footer { margin-top: 4px; font-size: 11px; line-height: 1.6; color: rgba(169, 167, 156, 0.9); }
#footer a { color: inherit; }

#howto-box { width: min(480px, 100%); }
#howto-box .howto { font-size: 13.5px; }

/* ---------- 校内図 ---------- */
#map-box { width: min(560px, 100%); }
#map-cv { display: block; width: 100%; height: auto; border-radius: 6px; background: #d9d2b8; margin-bottom: 10px; }
#map-goal { margin-bottom: 10px; }

/* ---------- キーボックス ---------- */
#dial { display: flex; justify-content: center; gap: 10px; margin: 0 0 10px; }
.dial-col { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.dial-col button {
  width: 56px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.1);
  color: var(--gold);
  font-family: inherit;
  font-size: 16px;
  cursor: pointer;
}
.dial-num {
  width: 56px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: linear-gradient(180deg, #0a0a0d, #2a2b33 50%, #0a0a0d);
  border: 2px solid #55565f;
  font-size: 36px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #f4f1e6;
}
#dial-miss { margin: 0 0 4px; font-size: 14px; font-weight: 800; letter-spacing: 0.12em; color: #8f8c80; }
#dial-miss.warn { color: #ff8d86; }
#dial-msg { min-height: 1.6em; margin: 0 0 8px; font-size: 13px; font-weight: 800; color: #ff8d86; }
#dial-box.shake { animation: shake 0.35s; }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }

/* ---------- つかまった・結果 ---------- */
#over-box { border-top: 4px solid var(--red); }
#over-title { font-size: 30px; color: #ff8d86; letter-spacing: 0.12em; text-shadow: 0 0 14px rgba(194, 38, 44, 0.9); }
#over-tip { font-size: 12.5px; padding: 8px 10px; border-radius: 8px; background: rgba(255, 255, 255, 0.06); }
#result-rank-name { font-size: 15px; font-weight: 900; color: var(--cyan); letter-spacing: 0.06em; }
#result-score { font-size: 54px; font-weight: 900; line-height: 1.15; color: var(--gold); font-variant-numeric: tabular-nums; }
#result-new { margin: 2px 0 6px; font-size: 14px; font-weight: 900; color: var(--green); }
#result-list { list-style: none; margin: 8px 0 14px; padding: 0; border-top: 1px solid var(--line); }
#result-list li { display: flex; justify-content: space-between; padding: 7px 6px; border-bottom: 1px solid var(--line); font-size: 14px; }
#result-list li span { color: var(--snow-dim); }
#result-list li b { font-variant-numeric: tabular-nums; }

@media (max-height: 560px) {
  .pad-btn { width: 78px; height: 78px; font-size: 13px; }
  .pad-sub { width: 56px; height: 56px; }
  #msg { min-height: 64px; padding-top: 9px; padding-bottom: 9px; }
  #msg-text { font-size: 14.5px; }
  .howto-short, #title-note { display: none; }
}

/* ---------- 全国ランキング（SGRanking 共通モジュール） ---------- */
.sgr-hidden { display: none !important; }

.sgr-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(3, 3, 6, 0.85);
}
.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #14151c;
  color: var(--snow);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px 16px;
  box-shadow: 0 16px 44px rgba(6, 12, 36, 0.6);
}
.sgr-title { margin: 0; font-size: 20px; font-weight: 900; text-align: center; }
.sgr-tabs { display: flex; gap: 6px; justify-content: center; }
.sgr-tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.08);
  color: var(--snow);
  cursor: pointer;
}
.sgr-tab-active { background: var(--gold); color: var(--ink); }
.sgr-register-msg { margin: 0 0 6px; font-size: 14px; font-weight: 800; color: var(--gold); text-align: center; }
.sgr-form { display: flex; gap: 8px; }
.sgr-name {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 16px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  -webkit-user-select: text;
  user-select: text;
}
.sgr-name:focus { outline: 3px solid var(--cyan); outline-offset: 0; }
.sgr-submit {
  border: 1px solid #fff3bf;
  border-radius: 10px;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 900;
  background: var(--gold);
  color: var(--ink);
  cursor: pointer;
}
.sgr-submit:disabled { opacity: 0.5; cursor: default; }
.sgr-error { margin: 4px 0 0; font-size: 12px; font-weight: 700; color: #ff9aa2; }
.sgr-status { margin: 0; font-size: 13px; color: var(--snow-dim); text-align: center; }
.sgr-list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  border-top: 1px solid var(--line);
}
.sgr-row { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; font-size: 14px; }
.sgr-row:nth-child(even) { background: rgba(255, 255, 255, 0.06); }
.sgr-row.sgr-row-me { background: var(--gold); color: var(--ink); font-weight: 800; }
.sgr-rank { width: 2em; text-align: right; font-weight: 900; flex-shrink: 0; }
.sgr-row-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sgr-row-score { font-weight: 900; color: var(--gold); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.sgr-row.sgr-row-me .sgr-row-score { color: var(--ink); }
.sgr-close {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.1);
  color: var(--snow);
  cursor: pointer;
}
.sgr-cta { margin: 0 0 12px; text-align: center; }
.sgr-cta-msg { margin: 0 0 6px; font-size: 14px; font-weight: 900; color: var(--green); }
.sgr-cta-btn {
  border: 1px solid #fff3bf;
  border-radius: 12px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 900;
  background: var(--gold);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 0 #b78a12;
}
.sgr-cta-link {
  border: none;
  background: none;
  color: var(--cyan);
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  text-decoration: underline;
  cursor: pointer;
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / 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;
}

@media print {
  .ad-banner { display: none; }
}
