/* =========================================================
   3D脱出ゲーム3 ファラオの墓（escape-room-3）
   ========================================================= */
:root {
  --font-jp: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  --font-num: "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --c-text: #2a1c12;
  --c-dim: #7c6a58;
  --c-accent: #b8791c;
  --c-accent-deep: #8a5610;
  --c-orange: #c9741a;
  --c-red: #c0392b;
  --c-gold: #f3c45a;
  --c-panel: rgba(250, 243, 228, 0.98);
  --c-line: rgba(42, 28, 18, 0.16);
  --c-glass: rgba(18, 13, 9, 0.72);
  --inv-h: 86px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #0b0806;
  color: #f4ead6;
  font-family: var(--font-jp);
}
button { font-family: inherit; }
.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;
  background: #0b0806;
}
#stage { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; outline: none; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: pointer; }
#vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 46%, rgba(0,0,0,0) 52%, rgba(0,0,0,0.5) 100%); }
#veil { position: absolute; inset: 0; pointer-events: none; background: #05060a; opacity: 0; transition: opacity 0.28s; }
#veil.on { opacity: 1; }
#veil.time { background: radial-gradient(circle at 50% 50%, #fffbe6 0%, #f3dc9a 45%, #b98a3a 100%); transition: opacity 0.42s; }
/* ===== 時をわたる ===== */
#btn-time { position: absolute; right: calc(10px + env(safe-area-inset-right, 0px)); bottom: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; width: 74px; height: 74px; padding: 0; border-radius: 50%; border: 2px solid #f3c45a; background: radial-gradient(circle at 35% 30%, #5a4520, #1c140a 75%); color: #ffe9b8; cursor: pointer; box-shadow: 0 0 14px rgba(243, 196, 90, 0.55), inset 0 0 10px rgba(0, 0, 0, 0.6); animation: time-pulse 2.4s ease-in-out infinite; }
#btn-time .tm-ico { font-size: 26px; line-height: 1.1; }
#btn-time b { max-width: 64px; font-size: 10px; font-weight: 800; letter-spacing: 0; line-height: 1.1; text-align: center; overflow-wrap: break-word; }
#btn-time.past { border-color: #9ec4ff; background: radial-gradient(circle at 35% 30%, #2a3c66, #0c1224 75%); color: #dbe8ff; box-shadow: 0 0 14px rgba(140, 180, 255, 0.6), inset 0 0 10px rgba(0, 0, 0, 0.6); }
#btn-time:active { transform: scale(0.94); }
@keyframes time-pulse { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.28); } }
@media (prefers-reduced-motion: reduce) { #btn-time { animation: none; } }
.hint-grid { display: inline-grid; grid-template-columns: repeat(3, 1.5em); gap: 2px; padding: 4px 6px; border-radius: 8px; background: #0e1638; color: #56608c; font-size: 1.1em; line-height: 1.4; text-align: center; }
.hint-grid b.on { color: #ffe27a; }
#fade { position: absolute; inset: 0; pointer-events: none; background: #060a16; opacity: 0; transition: opacity 0.4s; }
#fade.on { opacity: 1; transition: opacity 1.5s ease-in 1.1s; }
#nogl { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; line-height: 1.8; }

/* ===== HUD ===== */
#hud { position: absolute; left: 0; right: 0; top: 0; display: flex; justify-content: space-between; align-items: flex-start; padding: 10px calc(10px + env(safe-area-inset-right, 0px)) 0 calc(10px + env(safe-area-inset-left, 0px)); pointer-events: none; transition: opacity 0.3s; }
#hud.off { opacity: 0; visibility: hidden; }
#hud-time { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--c-glass); border: 1px solid rgba(243, 196, 90, 0.35); font-size: 13px; }
#timer { font-family: var(--font-num); font-size: 15px; letter-spacing: 0.04em; color: var(--c-gold); }
.hud-btn { pointer-events: auto; display: flex; align-items: center; gap: 4px; min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 1px solid rgba(243, 196, 90, 0.55); background: var(--c-glass); color: #fff3d6; font-size: 15px; font-weight: 700; cursor: pointer; }
.hud-btn span { font-size: 13px; }
.hud-btn:hover { background: rgba(60, 42, 20, 0.85); }

/* ===== 視点の切りかえ ===== */
.nav-btn { position: absolute; display: flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid rgba(243, 196, 90, 0.5); background: var(--c-glass); color: #ffe9b8; font-size: 20px; cursor: pointer; padding: 0; }
.nav-btn:hover { background: rgba(60, 42, 20, 0.85); }
.nav-btn:active { transform: scale(0.95); }
#btn-left, #btn-right { top: 50%; width: 46px; height: 76px; margin-top: -38px; }
#btn-left { left: calc(6px + env(safe-area-inset-left, 0px)); border-radius: 12px; }
#btn-right { right: calc(6px + env(safe-area-inset-right, 0px)); border-radius: 12px; }
#btn-back { left: 50%; bottom: 10px; width: 132px; height: 44px; margin-left: -66px; border-radius: 999px; font-size: 15px; }
#btn-back span { font-size: 14px; font-weight: 700; }
#btn-back:active { transform: scale(0.96); }

/* ===== ひとこと ===== */
#msg { position: absolute; left: 50%; bottom: 94px; transform: translateX(-50%); width: max-content; max-width: min(92%, 520px); padding: 10px 18px; border-radius: 12px; background: rgba(14, 10, 7, 0.88); border: 1px solid rgba(243, 196, 90, 0.4); color: #fff6e0; font-size: 14px; line-height: 1.6; text-align: center; pointer-events: none; animation: msg-in 0.2s ease-out; }
.msg-name { margin-top: 2px; color: var(--c-gold); font-size: 16px; font-weight: 800; }
@keyframes msg-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ===== 持ちもの ===== */
#inv { flex: 0 0 auto; height: var(--inv-h); padding: 4px calc(8px + env(safe-area-inset-right, 0px)) 6px calc(8px + env(safe-area-inset-left, 0px)); background: linear-gradient(#241a12, #130d09); border-top: 2px solid #6e5222; transition: opacity 0.3s; }
#inv.off { opacity: 0.25; pointer-events: none; }
#inv-name { height: 18px; font-size: 12px; line-height: 18px; text-align: center; color: var(--c-gold); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#inv-list .slot:first-child { margin-left: auto; }
#inv-list .slot:last-child { margin-right: auto; }
#inv-list { display: flex; justify-content: flex-start; gap: 6px; height: 56px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
#inv-list::-webkit-scrollbar { display: none; }
.slot { flex: 0 0 54px; width: 54px; height: 54px; padding: 3px; border-radius: 10px; border: 2px solid #5a4424; background: radial-gradient(circle at 50% 35%, #4a3a26, #261c12); cursor: pointer; }
.slot canvas { width: 100%; height: 100%; display: block; pointer-events: none; }
.slot.empty { background: rgba(255, 255, 255, 0.04); border-color: rgba(110, 82, 34, 0.45); cursor: default; }
.slot.sel { border-color: var(--c-gold); background: radial-gradient(circle at 50% 35%, #8a6a2c, #3a2a14); box-shadow: 0 0 10px rgba(243, 196, 90, 0.7); }
.slot:not(.empty):active { transform: scale(0.94); }
@media (min-width: 420px) { #inv-list.many { justify-content: center; } }

/* ===== 画面オーバーレイ共通 ===== */
.overlay { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 12px; overflow-y: auto; background: radial-gradient(ellipse at 50% 40%, rgba(20, 14, 9, 0.55), rgba(8, 5, 3, 0.9)); }
.overlay-dim { background: rgba(8, 5, 3, 0.72); z-index: 30; }
.overlay-box { width: min(100%, 440px); max-height: 100%; overflow-y: auto; margin: auto; padding: 22px 20px 16px; border-radius: 16px; background: var(--c-panel); color: var(--c-text); border: 2px solid #b8913c; box-shadow: 0 16px 50px rgba(0, 0, 0, 0.6), inset 0 0 0 4px rgba(184, 145, 60, 0.18); text-align: center; }
.small-box { width: min(100%, 360px); }
.overlay-title { margin: 0 0 10px; font-size: 20px; font-weight: 800; letter-spacing: 0.04em; }
.overlay-text { margin: 0 0 12px; font-size: 14px; line-height: 1.75; }
.overlay-note { margin: 0 0 12px; font-size: 12px; line-height: 1.6; color: var(--c-dim); }
.hint-line { margin: 0 0 10px; padding: 10px 12px; border-radius: 10px; background: rgba(184, 121, 28, 0.12); border: 1px solid rgba(184, 121, 28, 0.35); font-size: 14px; line-height: 1.75; text-align: left; }
.hint-strong { background: rgba(192, 57, 43, 0.09); border-color: rgba(192, 57, 43, 0.35); }
.hint-ans { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; margin: 0 0 12px; padding: 10px; border-radius: 10px; background: #fffaf0; border: 1px solid rgba(192, 57, 43, 0.35); }
.hint-dot { display: inline-block; width: 24px; height: 24px; border-radius: 50%; border: 2px solid rgba(0, 0, 0, 0.3); box-shadow: inset 0 2px 3px rgba(255, 255, 255, 0.5); }
.hint-ch { font-size: 24px; line-height: 1; font-family: var(--font-num); color: #3a2410; }
.hint-pair { display: inline-flex; align-items: center; gap: 4px; }
.hint-gly { width: 36px; height: 36px; border-radius: 8px; background: #f3e6c2; border: 1px solid rgba(90, 58, 26, 0.45); }
.hint-grid b { font-family: var(--font-num); }
#item-cv { width: 120px; height: 120px; margin: 0 auto 6px; display: block; border-radius: 16px; background: radial-gradient(circle at 50% 35%, #5a4630, #2a1e12); border: 2px solid #b8913c; }

/* ===== タイトル ===== */
#logo { margin: 0 0 10px; line-height: 0; }
#logo img { display: block; margin: 0 auto; width: auto; height: auto; max-width: min(100%, 380px); max-height: min(30vh, 210px); }
#tagline { margin: 0 0 12px; font-size: 14px; line-height: 1.75; }
#title-best { margin: 0 0 10px; font-size: 13px; color: var(--c-dim); }
#title-best b { font-family: var(--font-num); color: var(--c-accent-deep); font-size: 15px; }

/* ===== ボタン ===== */
.btn { display: block; width: 100%; min-height: 48px; margin: 0 0 8px; padding: 10px 14px; border-radius: 12px; border: 0; font-size: 16px; font-weight: 800; cursor: pointer; }
.btn-primary { background: linear-gradient(#d39a2c, #a86a12); color: #fff; box-shadow: 0 4px 0 #6e430a; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35); }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 1px 0 #6e430a; }
.btn-sub { background: #fffaf0; color: var(--c-text); border: 1.5px solid var(--c-line); font-size: 14px; min-height: 44px; }
.btn-sub:hover { background: #fff; }
.btn:focus-visible, .slot:focus-visible, .nav-btn:focus-visible, .hud-btn:focus-visible { outline: 3px solid #4aa3ff; outline-offset: 2px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1 1 0; padding: 8px 6px; }
.icon-btn { display: none; }
.howto { margin: 0 0 12px; padding-left: 22px; text-align: left; font-size: 13px; line-height: 1.75; }
.howto li { margin-bottom: 6px; }
.howto-short { margin-top: 6px; color: #4a382a; }

/* ===== 脱出成功 ===== */
#clear-kicker { margin: 0; font-size: 12px; letter-spacing: 0.4em; color: var(--c-accent); font-weight: 800; }
#clear-rank { display: inline-block; margin: 0 0 8px; padding: 3px 14px; border-radius: 999px; background: #3a2410; color: var(--c-gold); font-size: 13px; font-weight: 700; }
#clear-score small { display: block; font-size: 12px; color: var(--c-dim); }
#clear-time { font-family: var(--font-num); font-size: 44px; font-weight: 800; color: var(--c-accent-deep); line-height: 1.2; }
#clear-new { margin: 2px 0 6px; color: var(--c-red); font-weight: 800; font-size: 14px; }
#clear-list { list-style: none; margin: 8px 0 14px; padding: 0; border-top: 1px solid var(--c-line); }
#clear-list li { display: flex; justify-content: space-between; padding: 7px 4px; border-bottom: 1px solid var(--c-line); font-size: 13px; }
#clear-list b { font-family: var(--font-num); }

/* ===== フッター ===== */
#footer { margin-top: 10px; font-size: 11px; line-height: 1.7; color: var(--c-dim); }
#footer a { color: inherit; }

/* ===== 小さい画面・横向き ===== */
@media (max-height: 520px) {
  :root { --inv-h: 62px; }
  #inv-name { display: none; }
  #inv-list { height: 50px; }
  .slot { flex-basis: 48px; width: 48px; height: 48px; }
  .overlay-box { padding: 14px 16px 10px; }
  .howto-short { display: none; }
  #logo img { max-height: 92px; }
  #msg { bottom: 58px; }
}
@media (min-width: 900px) {
  .slot { flex-basis: 60px; width: 60px; height: 60px; }
  #inv-list { height: 62px; }
  :root { --inv-h: 94px; }
  #btn-left, #btn-right { width: 56px; height: 96px; margin-top: -48px; font-size: 24px; }
}

/* ===== 全国ランキング（共通モジュール sgr-*） ===== */
.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(6, 12, 18, 0.66);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.sgr-hidden { display: none !important; }

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--c-panel);
  color: var(--c-text);
  border-radius: 14px;
  padding: 20px 18px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.45);
}

.sgr-title {
  margin: 0;
  font-size: 20px;
  text-align: center;
}

.sgr-tabs {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.sgr-tab {
  border: 1px solid var(--c-line);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(226, 80, 42, 0.08);
  color: var(--c-text);
  cursor: pointer;
}

.sgr-tab-active {
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-deep));
  border-color: transparent;
  color: #fff;
}

.sgr-register-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  color: var(--c-orange);
}

.sgr-form { display: flex; gap: 8px; }

.sgr-name {
  flex: 1;
  min-width: 0;
  font-size: 16px; /* iOSズーム防止のため16px以上 */
  font-family: var(--font-jp);
  padding: 8px 10px;
  border: 2px solid var(--c-line);
  border-radius: 8px;
  background: #fff;
  color: var(--c-text);
  -webkit-user-select: text;
  user-select: text;
}

.sgr-name::placeholder { color: var(--c-dim); }

.sgr-name:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 8px rgba(226, 80, 42, 0.3);
}

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-deep));
  color: #fff;
  cursor: pointer;
}

.sgr-submit:hover { filter: brightness(1.1); }

.sgr-submit:disabled { opacity: 0.5; cursor: default; }

.sgr-error {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--c-red);
}

.sgr-status {
  margin: 0;
  font-size: 13px;
  text-align: center;
  color: var(--c-dim);
}

.sgr-list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.sgr-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.sgr-row:nth-child(even) { background: rgba(226, 80, 42, 0.07); }

.sgr-row.sgr-row-me {
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-deep));
  color: #fff;
}

.sgr-rank {
  width: 2em;
  text-align: right;
  font-weight: bold;
  flex-shrink: 0;
}

.sgr-row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sgr-row-score {
  font-weight: bold;
  font-family: var(--font-num);
  flex-shrink: 0;
}

.sgr-close {
  border: 1px solid var(--c-line);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(226, 80, 42, 0.08);
  color: var(--c-text);
  cursor: pointer;
}

.sgr-close:hover { border-color: var(--c-accent); }

.sgr-cta {
  margin: 2px 0 12px;
  text-align: center;
}

.sgr-cta-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  color: var(--c-orange);
}

.sgr-cta-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 15px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: linear-gradient(135deg, #f5a623, #f0741e);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(240, 116, 30, 0.4);
}

.sgr-cta-btn:hover { filter: brightness(1.08); }

.sgr-cta-link {
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(30, 43, 56, 0.08);
  border: 1px solid var(--c-line);
  color: var(--c-text);
  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; }
}
