/* ==========================================================================
   蜘蛛男（kumo-otoko）
   夕暮れの摩天楼。壁の茶・夜空の紺・糸と手袋の琥珀色
   ========================================================================== */
:root {
  --navy: #0e1730;
  --navy-2: #172447;
  --ink: #0a1022;
  --snow: #f4f7ff;
  --snow-dim: #c0cae6;
  --gold: #ffb52e;
  --red: #ff4d3d;
  --cyan: #7fd4ff;
  --green: #6fe39a;
  --panel: rgba(12, 20, 44, 0.84);
  --line: rgba(190, 210, 255, 0.28);
  --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, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, 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);
  overflow: hidden;
  background: linear-gradient(#2a5fc0, #cfe0f5);
}

/* ---------- コース（キャンバス） ---------- */
#stage {
  position: absolute;
  inset: 0;
  outline: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#cv { display: block; width: 100%; height: 100%; touch-action: none; }


/* ---------- HUD ---------- */
#hud {
  position: absolute;
  left: 0; right: 0;
  top: calc(8px + env(safe-area-inset-top, 0px));
  padding: 0 calc(10px + env(safe-area-inset-right, 0px)) 0 calc(10px + env(safe-area-inset-left, 0px));
  display: flex;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }
#hearts { display: flex; gap: 3px; padding: 7px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 17px; line-height: 1; }
#hearts i { font-style: normal; color: #ff4d6a; transition: transform 0.2s, color 0.2s; }
#hearts i.off { color: rgba(255, 255, 255, 0.2); transform: scale(0.8); }
#hud-height {
  flex: 1;
  text-align: center;
  font-weight: 900;
  font-style: italic;
  font-size: clamp(36px, 11vw, 52px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 3px 0 var(--ink), 0 0 18px rgba(10, 16, 34, 0.9);
  pointer-events: none !important;
}
#hud-height small { font-size: 0.45em; margin-left: 3px; color: var(--gold); }
#hud-right { display: flex; align-items: center; gap: 6px; }
#hud-best b { font-size: 15px; }
#warns { position: absolute; left: 0; top: calc(64px + env(safe-area-inset-top, 0px)); width: 0; height: 0; pointer-events: none; }
#warns i {
  position: absolute; left: -17px; top: 0;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: #ff3b30; color: #fff;
  border: 2px solid #fff;
  font-style: normal; font-weight: 900; font-size: 22px;
  box-shadow: 0 0 14px rgba(255, 59, 48, 0.9);
  transition: opacity 0.12s;
  animation: warnBlink 0.32s steps(2) infinite;
  will-change: transform, opacity;
}
#warns i.wide { width: 86px; left: -43px; border-radius: 17px; }
#warns i::after { content: ""; position: absolute; left: 50%; top: 100%; margin-left: -7px; border: 7px solid transparent; border-top-color: #fff; }
@keyframes warnBlink { from { background: #ff3b30; } to { background: #ffb52e; } }
#btn-zip {
  position: absolute;
  right: calc(14px + env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: 78px; height: 78px;
  border-radius: 50%;
  border: 3px solid #fff3bf;
  background: radial-gradient(circle at 35% 30%, #ffe27a, var(--gold));
  color: var(--ink);
  font-family: inherit; font-size: 13px; font-weight: 900; line-height: 1.15;
  box-shadow: 0 5px 0 #b87400, 0 8px 18px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  touch-action: none;
  transition: opacity 0.1s, transform 0.08s;
}
#btn-zip b { display: block; font-size: 24px; }
#btn-zip:active { transform: translateY(3px); box-shadow: 0 2px 0 #b87400; }
#btn-zip.cd { opacity: 0.45; }
#flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.35s; box-shadow: inset 0 0 90px 30px rgba(255, 40, 30, 0.75); }
#flash.on { opacity: 1; transition: none; }

.hud-chip {
  display: flex;
  align-items: baseline;
  gap: 3px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-weight: 800;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.hud-chip b { font-size: 20px; font-weight: 900; }
.hud-chip small { font-size: 11px; font-weight: 700; color: var(--snow-dim); }
.icon-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--snow);
  font-family: inherit;
  font-size: 16px;
  cursor: pointer;
}
.icon-btn:focus-visible, .btn:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

#banner {
  position: absolute;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-size: clamp(34px, 10vw, 56px);
  font-weight: 900;
  font-style: italic;
  white-space: nowrap;
  color: #fff;
  text-shadow: 0 3px 0 var(--ink), 0 0 22px rgba(10, 23, 48, 0.9);
}
#banner.show { animation: bannerPop 0.35s cubic-bezier(0.2, 1.6, 0.4, 1); }
#banner.gold { color: var(--gold); }
#banner.green { color: var(--green); }
#banner.red { color: #ff7466; }
@keyframes bannerPop {
  from { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
@keyframes pop {
  from { transform: translateX(-50%) scale(0.6); opacity: 0; }
  to { transform: translateX(-50%) scale(1); opacity: 1; }
}
#prompt {
  position: absolute;
  left: calc(12px + env(safe-area-inset-left, 0px));
  bottom: calc(26px + env(safe-area-inset-bottom, 0px));
  max-width: calc(100% - 120px);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 900;
  pointer-events: none;
}
#nogl {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: #7a1a16;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  z-index: 5;
}

/* ---------- オーバーレイ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  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(6, 18, 46, 0.45);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#title-overlay { background: linear-gradient(180deg, rgba(6, 18, 46, 0.1), rgba(6, 18, 46, 0.5)); }
.overlay-box {
  position: relative;
  width: min(400px, 100%);
  margin: auto;
  padding: 18px 16px 14px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 16px 44px rgba(3, 10, 30, 0.5);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  text-align: center;
}
.overlay-title { margin: 0 0 10px; font-size: 22px; font-weight: 900; }
.overlay-text { margin: 0 0 14px; font-size: 14px; color: var(--snow-dim); }
#title-head { margin-bottom: 6px; }
#logo-kicker { margin: 0 0 2px; font-size: 12px; font-weight: 900; letter-spacing: 0.2em; color: var(--gold); }
#logo {
  margin: 0;
  font-size: clamp(46px, 15vw, 64px);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: 0.08em;
  color: #fff;
  text-shadow: 0 4px 0 #b87400, 0 0 26px rgba(255, 181, 46, 0.55);
}
#logo-en { margin: 4px 0 0; font-size: 13px; font-weight: 900; letter-spacing: 0.42em; color: var(--cyan); padding-left: 0.42em; }
#tagline { margin: 6px 0 10px; font-size: 14px; line-height: 1.55; color: var(--snow-dim); }
#tagline b { color: #fff; }
#title-best { margin: 0 0 10px; font-size: 14px; font-weight: 800; color: var(--snow-dim); }
#title-best b { font-size: 20px; color: var(--gold); margin: 0 2px; }

.btn {
  display: block;
  width: 100%;
  margin: 0 0 8px;
  padding: 13px 14px;
  border-radius: 14px;
  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:disabled { opacity: 0.5; }
.btn-primary {
  background: linear-gradient(180deg, #ffe27a, var(--gold));
  color: var(--ink);
  border-color: #fff3bf;
  box-shadow: 0 4px 0 #b87400;
}
.btn-primary:active { box-shadow: 0 2px 0 #b87400; }
.btn-sub { background: rgba(255, 255, 255, 0.09); 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.6;
  color: var(--snow-dim);
}
.howto li { margin-bottom: 5px; }
.howto b { color: #fff; }
.howto .c-green { color: var(--green); }
.howto .c-red { color: #ff8a7d; }
.howto-short { margin-top: 2px; padding: 8px 12px 4px 2.1em; border-radius: 12px; background: rgba(255, 255, 255, 0.06); font-size: 12.5px; }

#footer { margin-top: 4px; font-size: 11px; line-height: 1.6; color: rgba(195, 212, 242, 0.8); }
#footer a { color: inherit; }
#howto-box .howto { font-size: 13.5px; }

/* ---------- 結果 ---------- */
#result-rank-name { display: inline-block; padding: 4px 14px; border-radius: 999px; background: rgba(255, 181, 46, 0.16); border: 1px solid rgba(255, 181, 46, 0.5); font-size: 14px; font-weight: 900; color: var(--gold); }
#result-score small { font-size: 0.4em; margin-left: 4px; }
#result-why { margin: 0 0 8px; font-size: 13px; color: var(--snow-dim); }
#result-score {
  margin: 2px 0 4px;
  font-size: clamp(46px, 14vw, 60px);
  font-weight: 900;
  font-style: italic;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  text-shadow: 0 3px 0 rgba(10, 23, 48, 0.8);
}
#result-new { margin-bottom: 4px; font-size: 15px; font-weight: 900; color: var(--green); animation: blink 0.9s ease-in-out infinite alternate; }
@keyframes blink { from { opacity: 0.55; } to { opacity: 1; } }
#result-list { list-style: none; margin: 0 0 12px; padding: 4px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.06); font-size: 13.5px; }
#result-list li { display: flex; align-items: baseline; gap: 8px; padding: 5px 0; border-bottom: 1px solid rgba(190, 220, 255, 0.14); }
#result-list li:last-child { border-bottom: 0; }
#result-list span { color: var(--snow-dim); }
#result-list b { margin-left: auto; font-variant-numeric: tabular-nums; }
#result-list em { min-width: 52px; text-align: right; font-style: normal; font-weight: 800; font-size: 12.5px; font-variant-numeric: tabular-nums; }

/* 横向きのスマホ: 高さが足りないので詰める */
@media (max-height: 520px) {
  #logo-kicker, #tagline, .howto-short { display: none; }
  #logo { font-size: 34px; }
  .overlay-box { width: min(560px, 100%); padding: 12px 14px 10px; }
  #hud-height { font-size: 32px; }
  #warns { top: calc(48px + env(safe-area-inset-top, 0px)); }
  #btn-zip { width: 66px; height: 66px; }
  #result-list { display: grid; grid-template-columns: 1fr 1fr; column-gap: 16px; }
}

/* ---------- 全国ランキング（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(6, 14, 38, 0.72);
}
.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #101f4d;
  color: var(--snow);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px 16px;
  box-shadow: 0 16px 44px rgba(3, 8, 24, 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);
}
.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: #ff9a8f; }
.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.05); }
.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.09);
  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 #b87400;
}
.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; }
}
