/* =========================================================
 * たこ焼き名人（takoyaki） スタイル
 * ========================================================= */
:root {
  --font-jp: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  --font-num: "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --c-text: #2b1d14;
  --c-dim: #7d6a5a;
  --c-accent: #e2502a;
  --c-accent-deep: #b4361a;
  --c-gold: #f7c444;
  --c-green: #49b85a;
  --c-red: #d64545;
  --c-panel: rgba(255, 250, 241, 0.97);
  --c-line: rgba(43, 29, 20, 0.14);
  --c-glass: rgba(26, 18, 12, 0.78);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-jp);
  color: var(--c-text);
  background: #1c1510;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }
button { font-family: var(--font-jp); }
button:focus-visible, a:focus-visible { outline: 3px solid #7fc4ff; outline-offset: 2px; }

/* ===== レイアウト =====
   共通ヘッダー(--sgh-top)とフッター広告(--ad-space)のぶんだけ内側に収める */
#app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  display: flex;
  flex-direction: column;
}

/* ===== 上部バー =====
   タイトルだけの帯は縦幅を圧迫するので隠す（画面には出さず、スクリーンリーダー向けにだけ残す）。
   h1（ゲームタイトル）と、共通ヘッダーのメニューが click() で押す元ボタンは DOM に残す。
   position: absolute でフローから外れるので、#stage（flex: 1）が共通ヘッダーの直下から全部を使う */
#topbar {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
#logo {
  margin: 0;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #ffe9b0;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
#topbar-buttons { display: flex; gap: 6px; flex: none; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

/* ===== ステージ ===== */
#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #1c1510;
}
#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
}
/* 周辺減光（屋台の灯りの下） */
#stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(14, 7, 3, 0.5) 100%);
  z-index: 1;
}

/* ===== 注文票・火力 ===== */
#hud {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 10;
  padding: 6px 8px 0;
  padding-left: calc(8px + env(safe-area-inset-left, 0px));
  padding-right: calc(8px + env(safe-area-inset-right, 0px));
  pointer-events: none;
}
#hud > * { pointer-events: auto; }
#hud-row {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 760px;
  margin: 0 auto 6px;
  padding: 4px 6px 4px 10px;
  border-radius: 12px;
  background: var(--c-glass);
  color: #fff2dc;
  font-size: 13px;
  font-weight: 800;
}
#hud-count { white-space: nowrap; }
#hud-score-wrap { white-space: nowrap; color: rgba(255, 240, 215, 0.8); font-weight: 700; }
#hud-score { color: var(--c-gold); font-family: var(--font-num); font-size: 15px; }
#heat { margin-left: auto; display: flex; align-items: center; gap: 3px; }
.heat-lab { font-size: 15px; margin-right: 2px; }
.heat-btn {
  min-width: 38px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid rgba(255, 220, 170, 0.25);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  color: #ffe8c8;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}
.heat-btn.on { background: linear-gradient(180deg, #ff9a3c, #e2502a); border-color: #ffc27a; color: #fff; box-shadow: 0 0 10px rgba(255, 120, 40, 0.55); }

#tickets {
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: flex-start;
  max-width: 760px;
  margin: 0 auto;
  /* 注文票が出入りするたびにカメラが動かないよう、1 枚ぶんの高さをいつも空けておく */
  min-height: 112px;
}
.ticket {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  max-width: 300px;
  padding: 6px 8px 7px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: #fffaf0;
  color: var(--c-text);
  text-align: left;
  font-size: 11.5px;
  line-height: 1.35;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  animation: tk-in 0.35s ease-out;
  overflow: hidden;
}
@keyframes tk-in { from { transform: translateY(-110%); opacity: 0; } }
.ticket.sel { border-color: var(--c-accent); box-shadow: 0 0 0 2px rgba(226, 80, 42, 0.3), 0 4px 14px rgba(0, 0, 0, 0.45); }
.ticket.sel::before {
  content: "Cooking";
  position: absolute;
  right: 0;
  top: 0;
  padding: 1px 6px 2px;
  border-bottom-left-radius: 8px;
  background: var(--c-accent);
  color: #fff;
  font-size: 9.5px;
  font-weight: 900;
}
.ticket.done { opacity: 0.96; cursor: default; }
.tk-head { display: flex; align-items: center; gap: 5px; margin-bottom: 3px; font-weight: 900; }
.tk-face { font-size: 19px; line-height: 1; }
.tk-menu { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tk-n { margin-left: auto; padding: 0 6px; border-radius: 999px; background: #2b1d14; color: #ffe9b0; font-size: 11.5px; white-space: nowrap; }
.ticket.sel .tk-n { margin-right: 38px; }
.tk-row { display: flex; align-items: baseline; gap: 5px; margin-top: 2px; }
.tk-lab { flex: none; width: 5.6em; white-space: nowrap; color: var(--c-dim); font-size: 10px; font-weight: 800; }
.tk-val { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 5px; font-weight: 800; min-width: 0; }
.tk-chip { display: inline-flex; align-items: center; gap: 2px; white-space: nowrap; }
.tk-chip.no { color: var(--c-red); }
.tk-chip .c-mark { font-size: 12px; line-height: 1; }
.tk-chip .c-dot { width: 9px; height: 9px; }
.tk-sw { display: inline-block; width: 15px; height: 15px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.3); box-shadow: inset -2px -2px 3px rgba(0, 0, 0, 0.22), inset 2px 2px 2px rgba(255, 255, 255, 0.3); }
.tk-bar { height: 5px; margin-top: 5px; border-radius: 3px; background: rgba(43, 29, 20, 0.14); overflow: hidden; }
.tk-bar i { display: block; height: 100%; background: var(--c-green); transform-origin: left center; transition: transform 0.25s linear; }
.tk-bar i.mid { background: #e8a51c; }
.tk-bar i.low { background: var(--c-red); }
.tk-stamp {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px;
  background: rgba(255, 250, 240, 0.9);
  color: var(--c-accent-deep);
  text-align: center;
  animation: stamp-in 0.3s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes stamp-in { from { transform: scale(1.6); opacity: 0; } }
.tk-stamp b { font-size: 26px; font-family: var(--font-num); line-height: 1; }
.tk-stamp small { font-size: 11.5px; font-weight: 800; color: var(--c-text); }
.tk-stamp.great b { color: #d98a00; }
.tk-stamp.low b, .tk-stamp.left b { color: #777; }

.c-dot { display: inline-block; width: 13px; height: 13px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.28); flex: none; }
.c-mark { line-height: 1; }

/* ===== 操作パネル ===== */
#controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  padding: 6px 8px 8px;
  padding-left: calc(8px + env(safe-area-inset-left, 0px));
  padding-right: calc(8px + env(safe-area-inset-right, 0px));
  background: linear-gradient(180deg, rgba(20, 13, 8, 0) 0, rgba(20, 13, 8, 0.86) 26px);
}
#ctl-head, #tools, #tops { max-width: 760px; margin-left: auto; margin-right: auto; }
#ctl-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
#instr {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--c-glass);
  color: #fff2dc;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.4;
  min-height: 34px;
  display: flex;
  align-items: center;
}
#btn-serve {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 78px;
  height: 44px;
  padding: 0 12px;
  border: 2px solid rgba(255, 230, 190, 0.3);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: #ffe8c8;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.1;
  cursor: pointer;
}
#btn-serve small { font-size: 10.5px; font-family: var(--font-num); opacity: 0.85; }
#btn-serve.ready { background: linear-gradient(135deg, #f0702e, #c63b16); border-color: #ffc27a; color: #fff; box-shadow: 0 4px 14px rgba(198, 59, 22, 0.55); animation: serve-pulse 1.1s ease-in-out infinite; }
@keyframes serve-pulse { 50% { transform: scale(1.05); } }
#tools { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
#tops { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(255, 225, 180, 0.16); }
.chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  height: 44px;
  padding: 2px;
  border: 2px solid rgba(255, 230, 190, 0.16);
  border-radius: 10px;
  background: rgba(255, 250, 240, 0.1);
  color: #fff1de;
  cursor: pointer;
}
.chip .c-mark { font-size: 17px; }
.chip .c-dot { width: 15px; height: 15px; border-color: rgba(255, 255, 255, 0.4); }
.chip .c-name { font-size: 10.5px; font-weight: 800; white-space: nowrap; letter-spacing: -0.02em; }
.chip:hover { background: rgba(255, 250, 240, 0.17); }
.chip.on { background: #fff5df; border-color: var(--c-gold); color: var(--c-text); box-shadow: 0 0 10px rgba(247, 196, 68, 0.5); }
.chip.top { height: 42px; }
.chip.top .c-name { font-size: 10px; letter-spacing: -0.03em; }
.chip.top.want { border-color: rgba(247, 196, 68, 0.85); }
.chip.top.on { background: rgba(73, 184, 90, 0.3); border-color: var(--c-green); color: #eaffea; box-shadow: none; }
.chip.top.on .c-name::after { content: "✓"; margin-left: 1px; }
.chip.top.dim { opacity: 0.55; }

/* ===== 文字の演出 ===== */
#floats { position: absolute; inset: 0; pointer-events: none; z-index: 11; overflow: hidden; }
.float {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(26, 18, 12, 0.82);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
  opacity: 0;
}
.float.show { animation: float-up 1.1s ease-out forwards; }
.float.bad { color: #ffb0a0; }
.float.good { color: #fff; font-size: 20px; }
.float.great { color: var(--c-gold); font-size: 26px; }
@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.08); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(1); }
}
#banner {
  position: absolute;
  left: 50%;
  bottom: 200px;
  z-index: 13;
  max-width: min(92%, 460px);
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(26, 18, 12, 0.88);
  border: 1px solid rgba(255, 220, 170, 0.22);
  color: #fff3dd;
  font-size: 13.5px;
  font-weight: 800;
  line-height: 1.5;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 8px) scale(0.94);
  transition: opacity 0.25s, transform 0.25s;
}
#banner.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* ===== 画面オーバーレイ共通 ===== */
.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ===== 読み込み中 ===== */
#screen-loading { background: #1c1510; }
.loading-panel { text-align: center; color: #f5e6d3; font-size: 14px; }
.loading-ball {
  width: 46px;
  height: 46px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f3c06a, #b96a22 62%, #7a3f12);
  animation: ball-turn 1s ease-in-out infinite;
}
@keyframes ball-turn { 50% { transform: translateY(-8px) rotate(180deg); } }

/* ===== タイトル画面（鉄板が見えるように、上に寄せる） ===== */
#screen-title { align-items: flex-start; background: linear-gradient(180deg, rgba(16, 9, 5, 0.86) 0, rgba(16, 9, 5, 0.6) 46%, rgba(16, 9, 5, 0) 74%); }
.title-panel { width: min(430px, 100%); margin-top: 1vh; text-align: center; color: #fff; }
.title-en { margin: 0; font-size: 11px; font-weight: 800; letter-spacing: 0.34em; color: #ffcf7a; }
.title-ja { margin: 4px 0 2px; font-weight: 900; line-height: 1.05; text-shadow: 0 3px 0 #7a2410, 0 6px 16px rgba(0, 0, 0, 0.6); }
.title-ja .t1 { font-size: clamp(40px, 12vw, 60px); color: #ffe9b0; }
.title-ja .t2 { font-size: clamp(40px, 12vw, 60px); color: #ff8a3c; margin-left: 0.08em; }
.title-catch { margin: 6px 0 4px; font-size: 15px; font-weight: 900; color: #fff3dd; }
.title-desc { margin: 0 auto 8px; max-width: 360px; font-size: 12.5px; line-height: 1.6; color: rgba(255, 240, 220, 0.85); }
#title-best { margin: 0 0 8px; min-height: 1.3em; font-size: 13px; font-weight: 800; color: var(--c-gold); }
.title-buttons { display: flex; flex-direction: column; gap: 8px; align-items: stretch; max-width: 320px; margin: 0 auto; }
.title-sub-buttons { display: flex; gap: 8px; }
.title-sub-buttons .btn { flex: 1; }

/* ===== ボタン ===== */
.btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  font-family: var(--font-jp);
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  line-height: 1.25;
}
.btn small { font-size: 11px; font-weight: 700; opacity: 0.88; }
.btn:active { transform: scale(0.97); }
.btn-primary {
  color: #fff;
  font-size: 19px;
  background: linear-gradient(135deg, #f0702e, #c63b16);
  box-shadow: 0 6px 18px rgba(198, 59, 22, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-sub { color: #fff1de; font-size: 14px; padding: 10px 12px; background: rgba(40, 26, 16, 0.72); border: 1px solid rgba(255, 230, 190, 0.26); }
.btn-sub:hover { background: rgba(70, 46, 28, 0.8); }

/* ===== 結果 ===== */
#screen-result { background: rgba(12, 7, 4, 0.72); }
.result-panel {
  width: min(430px, 100%);
  margin: auto;
  padding: 16px 16px 14px;
  border-radius: 18px;
  background: var(--c-panel);
  color: var(--c-text);
  text-align: center;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.55);
}
.result-eyebrow { margin: 0; font-size: 12px; font-weight: 800; color: var(--c-dim); letter-spacing: 0.1em; }
.result-rank { margin: 4px 0 0; font-size: 30px; font-weight: 900; color: var(--c-accent-deep); }
.result-rank.rank-4 { color: #d98a00; text-shadow: 0 0 14px rgba(247, 196, 68, 0.6); }
.result-rank.rank-0 { color: #777; }
.result-score-row { margin: 0; font-family: var(--font-num); }
#result-score { font-size: 48px; font-weight: 900; line-height: 1.1; }
.result-unit { margin-left: 4px; font-size: 14px; font-weight: 800; color: var(--c-dim); }
#result-new { margin: 2px 0 0; font-size: 13px; font-weight: 900; color: #d98a00; }
.result-msg { margin: 4px 0 10px; font-size: 13px; font-weight: 700; color: var(--c-dim); }
#result-rows { list-style: none; margin: 0 0 12px; padding: 0; text-align: left; }
#result-rows li { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-top: 1px solid var(--c-line); }
.rr-face { font-size: 22px; line-height: 1; }
.rr-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rr-mid b { font-size: 13.5px; }
.rr-mid small { font-size: 11.5px; color: var(--c-dim); }
.rr-pt { font-family: var(--font-num); font-size: 17px; font-weight: 900; }
.rr-pt.hi { color: #d98a00; }
.rr-pt.lo { color: #8a8078; }
.result-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.result-buttons .btn-primary { flex: 1 1 100%; }
.result-buttons .btn-sub { flex: 1; color: var(--c-text); background: rgba(43, 29, 20, 0.07); border-color: var(--c-line); }
#share-msg { margin: 6px 0 0; min-height: 1em; font-size: 12px; color: var(--c-dim); }

/* ===== 一時停止・エラー ===== */
#screen-paused, #gl-error { background: rgba(10, 7, 5, 0.6); }
#screen-paused { cursor: pointer; }
.paused-panel { padding: 22px 26px; border-radius: 16px; text-align: center; color: #fff; background: rgba(30, 20, 13, 0.88); border: 1px solid rgba(255, 220, 170, 0.15); }
.paused-title { margin: 0 0 6px; font-size: 22px; font-weight: 900; }
.paused-hint { margin: 0; font-size: 13px; line-height: 1.6; color: rgba(255, 235, 210, 0.75); }

/* ===== モーダル（遊び方）。広告より上に出すため body 直下に置く ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2147482800;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-top: calc(16px + var(--sgh-top, 0px));
  padding-bottom: calc(16px + var(--ad-space, 0px));
  background: rgba(8, 6, 4, 0.66);
}
.modal-box {
  width: min(520px, 100%);
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 18px 16px;
  border-radius: 16px;
  background: var(--c-panel);
  color: var(--c-text);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5);
  -webkit-user-select: text;
  user-select: text;
}
.modal-title { margin: 0 0 10px; font-size: 19px; text-align: center; }
.howto { margin: 0 0 14px; padding-left: 1.4em; font-size: 13.5px; line-height: 1.7; }
.howto li { margin-bottom: 6px; }
.howto b { color: var(--c-accent-deep); }
.modal-box > .btn { width: 100%; }

/* ===== フッター ===== */
#footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  text-align: center;
  font-size: 11px;
  line-height: 1.6;
  color: rgba(255, 240, 225, 0.75);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  z-index: 40;
  display: none;
}
#footer a { color: #ffd04a; pointer-events: auto; }
body.on-title #footer { display: block; }

/* ===== PC・タブレット: 道具を 1 列に ===== */
@media (min-width: 700px) {
  #tools { grid-template-columns: repeat(10, 1fr); }
  .chip { height: 50px; }
  .chip .c-name { font-size: 11.5px; }
  .ticket { font-size: 12.5px; }
  #instr { font-size: 13.5px; }
}

/* ===== 小さいスマホ ===== */
@media (max-width: 360px) {
  .chip .c-name { font-size: 9.5px; }
  .chip.top .c-name { font-size: 9px; }
  .ticket { font-size: 10.5px; padding: 5px 6px 6px; }
  .tk-menu { font-size: 12.5px; }
}
/* 背の低いスマホ: 注文票をつめて、鉄板の見える高さをかせぐ */
@media (max-height: 720px) and (orientation: portrait) {
  #tickets { min-height: 78px; }
  .tk-lab { display: none; }
  .ticket { font-size: 10.5px; padding: 4px 6px 5px; line-height: 1.25; }
  .tk-head { margin-bottom: 1px; }
  .tk-face { font-size: 16px; }
  .tk-menu { font-size: 12.5px; }
  .tk-row { margin-top: 1px; }
  .tk-sw { width: 12px; height: 12px; }
  .tk-bar { margin-top: 3px; height: 4px; }
  #hud-row { margin-bottom: 4px; padding-top: 2px; padding-bottom: 2px; }
  .heat-btn { height: 28px; }
  #tops { margin-top: 4px; padding-top: 4px; }
  #ctl-head { margin-bottom: 4px; }
}
@media (max-height: 640px) and (orientation: portrait) {
  .chip { height: 38px; }
  .chip.top { height: 38px; }
  .chip .c-mark { font-size: 15px; }
  #instr { min-height: 30px; padding: 4px 8px; font-size: 11.5px; }
  #btn-serve { height: 38px; }
  .tk-row { margin-top: 1px; }
}

/* ===== 横向きのスマホ（背が低い）: 注文票を左、操作を右に寄せて、まん中に鉄板 ===== */
@media (max-height: 520px) and (orientation: landscape) {
  #hud { right: auto; bottom: 0; width: 196px; padding-bottom: 6px; overflow-y: auto; }
  #hud-row { flex-wrap: wrap; gap: 4px 8px; }
  #heat { margin-left: 0; width: 100%; }
  .heat-btn { flex: 1; height: 28px; }
  #tickets { flex-direction: column; min-height: 0; }
  .ticket { flex: none; width: 100%; max-width: none; }
  #controls { left: auto; top: 0; width: 236px; overflow-y: auto; background: rgba(20, 13, 8, 0.8); display: flex; flex-direction: column; justify-content: center; }
  #ctl-head { flex-direction: column-reverse; align-items: stretch; gap: 5px; width: 100%; }
  #btn-serve { flex-direction: row; gap: 6px; height: 36px; }
  #instr { font-size: 11px; min-height: 0; }
  #tools { width: 100%; grid-template-columns: repeat(5, 1fr); gap: 4px; }
  #tops { width: 100%; grid-template-columns: repeat(4, 1fr); }
  .chip, .chip.top { height: 36px; }
  .chip .c-mark { font-size: 14px; }
  .chip .c-dot { width: 12px; height: 12px; }
  .chip .c-name { font-size: 9.5px; }
  #screen-title { align-items: center; justify-content: flex-end; background: linear-gradient(270deg, rgba(16, 9, 5, 0.9) 0, rgba(16, 9, 5, 0.6) 46%, rgba(16, 9, 5, 0) 70%); }
  .title-panel { width: 330px; margin-top: 0; }
  .title-ja .t1, .title-ja .t2 { font-size: 34px; }
  .title-desc { display: none; }
  body.on-title #footer { text-align: left; left: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  #btn-serve.ready, .loading-ball { animation: none; }
}

/* ===== 全国ランキング（共通モジュール 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; }
}
