/* ==========================================================================
   ぐらぐらバーガー（guragura-burger）
   青空の下の木のテーブル。ケチャップの赤・マスタードの黄・バンズの茶
   ========================================================================== */
:root {
  --navy: #2a1407;
  --ink: #3a1c0c;
  --snow: #fff8ea;
  --snow-dim: #ecd9b8;
  --gold: #ffc93c;
  --red: #e8452c;
  --blue: #9fdcff;
  --cyan: #9fdcff;
  --green: #a8ef7c;
  --pink: #ff9cb0;
  --panel: rgba(58, 28, 12, 0.93);
  --line: rgba(255, 226, 170, 0.32);
  --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, 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: #7fd0ff;
}

/* ---------- HUD ---------- */
#hud {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 6px;
  padding: 6px calc(8px + env(safe-area-inset-right, 0px)) 6px calc(8px + env(safe-area-inset-left, 0px));
  background: linear-gradient(180deg, #4a2410, #3a1c0c);
  border-bottom: 3px solid var(--gold);
}
#hud.off > * { visibility: hidden; }
.hud-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.hud-chip b { font-size: 18px; font-weight: 900; }
.hud-chip small { font-size: 11px; font-weight: 700; color: var(--snow-dim); }
#hud-score { justify-self: start; }
#hud-score b { color: var(--gold); min-width: 2.4em; text-align: right; }
#hud-score.bump b, #hud-count.bump b { animation: bump 0.2s ease-out; display: inline-block; }
@keyframes bump {
  from { transform: scale(1.35); }
  to { transform: scale(1); }
}
#hud-lives { justify-self: center; display: flex; gap: 3px; }
#hud-lives i {
  display: block;
  width: 26px;
  height: 26px;
  font-style: normal;
  transition: transform 0.2s, filter 0.2s, opacity 0.2s;
}
#hud-lives i::before {
  content: "♥";
  display: block;
  font-size: 26px;
  line-height: 26px;
  text-align: center;
  color: #ff6a5a;
  text-shadow: 0 2px 0 #7c1a0c;
}
#hud-lives i.off { transform: scale(0.8); opacity: 0.9; }
#hud-lives i.off::before { color: #6b4a36; text-shadow: none; }
#hud-lives.hit { animation: shake 0.35s linear; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
#hud-right { justify-self: end; display: flex; align-items: center; gap: 6px; }
#hud-count b { color: #fff; min-width: 1.2em; text-align: right; }

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

/* ---------- ゲーム画面（キャンバス） ---------- */
#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  outline: none;
  touch-action: none;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#cv {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* 「とじる」ボタン（上のバンズをのせて完成させる） */
#btn-close {
  position: absolute;
  right: calc(10px + env(safe-area-inset-right, 0px));
  bottom: 10px;
  z-index: 2;
  min-width: 112px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 8px 14px 7px;
  border-radius: 16px;
  border: 2px solid #fff3bf;
  background: linear-gradient(180deg, #ffe27a, var(--gold));
  color: var(--ink);
  font-family: inherit;
  font-weight: 900;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 4px 0 #a86a00, 0 8px 16px rgba(40, 16, 0, 0.35);
  touch-action: manipulation;
  transition: transform 0.08s;
}
#btn-close span { font-size: 16px; white-space: nowrap; }
#btn-close small { font-size: 11px; font-weight: 800; color: #9a3a10; white-space: nowrap; }
#btn-close:active { transform: translateY(2px); box-shadow: 0 2px 0 #a86a00; }
#btn-close:disabled { background: #cbb898; border-color: #e6d7bb; color: #6b523a; box-shadow: 0 4px 0 #8a7556; cursor: default; }
#btn-close:disabled small { color: #6b523a; }
#btn-close.closing:disabled { background: linear-gradient(180deg, #ff8a6a, var(--red)); border-color: #ffd0c4; color: #fff; box-shadow: 0 4px 0 #8a1f0e; }
#btn-close.closing:disabled span { font-size: 13px; }
#btn-close.closing:disabled small { color: #ffe6de; }
#btn-close.hint { animation: hint 0.7s ease-in-out infinite; }
@keyframes hint {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); box-shadow: 0 4px 0 #a86a00, 0 0 0 6px rgba(255, 255, 255, 0.55); }
}

#banner {
  position: absolute;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%);
  max-width: 96%;
  text-align: center;
  font-size: 26px;
  font-weight: 900;
  font-style: italic;
  line-height: 1.3;
  letter-spacing: 0.03em;
  white-space: nowrap;
  pointer-events: none;
  color: #fff;
  text-shadow: 0 3px 0 var(--ink), 0 0 18px rgba(58, 28, 12, 0.8);
  animation: pop 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
}
#banner.ready { font-size: 46px; color: var(--gold); }
#banner.go { font-size: 54px; color: #fff; text-shadow: 0 4px 0 var(--red), 0 0 18px rgba(58, 28, 12, 0.8); }
#banner.mark { top: 22%; color: #fff; font-size: clamp(20px, 6.4vw, 32px); padding: 4px 18px; border-radius: 999px; background: rgba(58, 28, 12, 0.7); text-shadow: none; }
#banner.end { font-size: clamp(36px, 12vw, 62px); color: var(--red); text-shadow: 0 4px 0 #fff, 0 0 22px rgba(58, 28, 12, 0.9); }
#banner.done { top: 18%; font-size: clamp(24px, 8vw, 50px); color: var(--gold); text-shadow: 0 4px 0 var(--red), 0 0 22px rgba(58, 28, 12, 0.9); }
@keyframes pop {
  from { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
@keyframes pop-in {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ---------- オーバーレイ ---------- */
.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(42, 20, 7, 0.5);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#title-overlay { background: linear-gradient(180deg, rgba(42, 20, 7, 0.1), rgba(42, 20, 7, 0.45)); }
#pause-overlay { background: rgba(42, 20, 7, 0.88); }
#result-overlay { background: rgba(42, 20, 7, 0.4); }
.overlay-box {
  position: relative;
  width: min(400px, 100%);
  margin: auto;
  padding: 20px 18px 16px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 16px 44px rgba(30, 12, 0, 0.55);
  text-align: center;
}
#title-box { border-top: 6px solid var(--gold); }
.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: 8px; }
#logo-kicker {
  display: inline-block;
  margin: 0 0 6px;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(255, 201, 60, 0.2);
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}
#logo {
  margin: 0;
  font-size: clamp(27px, 9.4vw, 44px);
  white-space: nowrap;
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: 0.01em;
  color: var(--gold);
  text-shadow: 0 4px 0 var(--red), 0 0 22px rgba(255, 120, 40, 0.45);
  transform: rotate(-2deg);
}
#logo-en { margin: 8px 0 0; font-size: 12px; font-weight: 900; letter-spacing: 0.3em; color: #fff; padding-left: 0.3em; }
#tagline { margin: 8px 0 12px; font-size: 14px; line-height: 1.6; 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: 19px; color: var(--gold); font-variant-numeric: tabular-nums; }

.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-primary {
  background: linear-gradient(180deg, #ffe27a, var(--gold));
  color: var(--ink);
  border-color: #fff3bf;
  box-shadow: 0 4px 0 #a86a00;
}
.btn-primary:active { box-shadow: 0 2px 0 #a86a00; }
.btn-sub { background: rgba(255, 255, 255, 0.12); 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-gold { color: var(--gold); }
.howto .c-red { color: #ff9a8a; }
.howto .c-blue { color: var(--blue); }
.howto .c-green { color: var(--green); }
.howto .c-pink { color: var(--pink); }
.howto-short { margin-top: 6px; padding: 10px 12px 6px 2.1em; border-radius: 12px; background: rgba(255, 255, 255, 0.08); }

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

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

/* ---------- 結果 ---------- */
#result-rank-name { font-size: 15px; font-weight: 900; color: var(--cyan); letter-spacing: 0.06em; }
#result-score { font-size: 60px; font-weight: 900; line-height: 1.1; color: var(--gold); font-variant-numeric: tabular-nums; }
#result-score small { font-size: 22px; margin-left: 4px; }
#result-new { margin: 2px 0 6px; font-size: 15px; font-weight: 900; color: var(--green); animation: pop-in 0.5s cubic-bezier(0.2, 1.6, 0.4, 1); }
#result-note { margin: 4px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--snow-dim); }
#result-note.good { color: var(--gold); font-weight: 800; }
#result-list { list-style: none; margin: 10px 0 14px; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
#result-list li { padding: 8px 4px; border-radius: 10px; background: rgba(255, 255, 255, 0.1); display: flex; flex-direction: column; gap: 2px; }
#result-list li > span { font-size: 11px; color: var(--snow-dim); font-weight: 700; }
#result-list b { font-size: 18px; font-weight: 900; font-variant-numeric: tabular-nums; }
#result-list b small { font-size: 11px; margin-left: 2px; font-weight: 700; color: var(--snow-dim); }

@media (max-width: 380px) {
  #hud { gap: 4px; padding-left: calc(6px + env(safe-area-inset-left, 0px)); padding-right: calc(6px + env(safe-area-inset-right, 0px)); }
  .hud-chip { padding: 4px 9px; font-size: 11.5px; }
  .hud-chip b { font-size: 15px; }
  .hud-chip small { font-size: 10px; }
  #hud-lives i { width: 22px; height: 22px; }
  #hud-lives i::before { font-size: 22px; line-height: 22px; }
  .icon-btn { width: 32px; height: 32px; font-size: 14px; }
  #btn-close { min-width: 100px; padding: 7px 10px 6px; }
  #btn-close span { font-size: 14.5px; }
}
@media (max-height: 620px) {
  .overlay-box { padding: 14px 14px 12px; }
  #tagline { margin: 4px 0 8px; font-size: 13px; }
  .howto-short { display: none; }
  #result-score { font-size: 46px; }
  #logo { font-size: 28px; }
}
@media (max-height: 440px) {
  #hud { padding-top: 3px; padding-bottom: 3px; }
  #logo-kicker, #logo-en, #tagline { display: none; }
  #logo { font-size: 24px; }
  .btn { padding: 9px 12px; margin-bottom: 6px; }
  .howto { font-size: 12px; line-height: 1.45; }
  #btn-close { bottom: 6px; padding: 5px 10px 4px; }
  #result-list { margin: 6px 0 8px; }
}
@media (min-width: 768px) {
  .hud-chip { font-size: 15px; padding: 7px 16px; }
  .hud-chip b { font-size: 22px; }
  #hud-lives i { width: 30px; height: 30px; }
  #hud-lives i::before { font-size: 30px; line-height: 30px; }
  #btn-close { min-width: 140px; padding: 10px 18px 9px; right: 16px; bottom: 16px; }
  #btn-close span { font-size: 19px; }
  #btn-close small { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  #banner, #result-new, #hud-lives.hit, #hud-score.bump b, #hud-count.bump b, #btn-close.hint { animation: 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(30, 12, 2, 0.78);
}
.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #4a2410;
  color: var(--snow);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px 16px;
  box-shadow: 0 16px 44px rgba(30, 12, 0, 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: #ffb0a2; }
.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 #a86a00;
}
.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; }
}
