/* =========================================================
 * 焼肉シミュレーター（namasyoku） スタイル
 * ========================================================= */
: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: #d8432a;
  --c-accent-deep: #a82c18;
  --c-gold: #f7c444;
  --c-gold-deep: #e89a1c;
  --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(22, 14, 10, 0.74);
}

* { 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: #17100c;
  -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: #ffe2b0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  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: 32px;
  height: 32px;
  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: 16px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.94); }

/* ===== ステージ ===== */
#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #17100c;
}
#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#game-canvas { touch-action: none; cursor: grab; }
#stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 48%, transparent 55%, rgba(14, 7, 3, 0.45) 100%);
  z-index: 1;
}

/* ===== 3D の上に重ねる札（タレの名前・点数） ===== */
#labels { position: absolute; inset: 0; z-index: 9; pointer-events: none; overflow: hidden; }
.tag {
  position: absolute;
  left: 0;
  top: 0;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(22, 14, 10, 0.78);
  border: 1px solid rgba(255, 230, 190, 0.35);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.4;
  white-space: nowrap;
  will-change: transform;
}
.tag-tare { border-color: #c98a4a; }
.tag-lemon { border-color: #f2df5a; color: #fff6b8; }
.tag-miso { border-color: #e8853a; color: #ffd9b0; }
.tag-hold { background: rgba(190, 50, 25, 0.92); border-color: rgba(255, 255, 255, 0.5); font-size: 13px; padding: 3px 11px; }
.sel-ring {
  position: absolute;
  left: 0;
  top: 0;
  width: 74px;
  height: 74px;
  border: 3px dashed #ffe27a;
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(255, 220, 100, 0.6);
  will-change: transform;
}
.pop {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 900;
  white-space: nowrap;
  color: #fff;
  background: rgba(22, 14, 10, 0.72);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  animation: pop-up 1.5s ease-out forwards;
}
.pop.perfect { font-size: 19px; color: #3a2408; background: linear-gradient(135deg, #ffe98a, #ffb23a); text-shadow: none; box-shadow: 0 0 16px rgba(255, 200, 80, 0.8); }
.pop.good { color: #d8ffd0; }
.pop.meh { color: #ffe3b0; }
.pop.bad { color: #fff; background: rgba(200, 40, 30, 0.92); }
.pop.match { font-size: 12px; color: #fff6b8; background: rgba(60, 40, 10, 0.8); animation-delay: 0.08s; }
@keyframes pop-up {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  12% { opacity: 1; transform: translate(-50%, -80%) scale(1.12); }
  22% { transform: translate(-50%, -90%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -130%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}

/* ===== 時間・点数 ===== */
#hud {
  position: absolute;
  top: 6px;
  left: calc(8px + env(safe-area-inset-left, 0px));
  right: calc(8px + env(safe-area-inset-right, 0px));
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  pointer-events: none;
}
#hud-row { display: flex; gap: 8px; justify-content: center; }
.hud-box {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 0;
  padding: 3px 12px;
  border-radius: 12px;
  background: var(--c-glass);
  border: 1px solid rgba(255, 220, 160, 0.16);
  color: #fff;
  white-space: nowrap;
}
.hud-label { font-size: 10.5px; font-weight: 800; color: rgba(255, 232, 196, 0.8); }
#hud-time, #hud-score { font-family: var(--font-num); font-size: 22px; font-weight: 900; font-variant-numeric: tabular-nums; }
#hud-time { color: #b8ffb0; }
#hud-time.warn { color: #ff8a70; animation: warn-blink 0.8s steps(2) infinite; }
@keyframes warn-blink { 50% { opacity: 0.45; } }
#hud-score { color: #ffd04a; }
.hud-unit { font-size: 11px; font-weight: 900; color: rgba(255, 232, 196, 0.8); }
#hud-wave { margin: 0; padding: 1px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 800; color: rgba(255, 240, 220, 0.92); background: rgba(22, 14, 10, 0.5); }
#hud-combo { margin: 0; min-height: 1.3em; font-size: 15px; font-weight: 900; color: #ffe27a; text-shadow: 0 2px 0 rgba(120, 40, 10, 0.9), 0 0 12px rgba(255, 180, 60, 0.7); }

/* ===== 操作パネル ===== */
#controls {
  position: absolute;
  left: calc(8px + env(safe-area-inset-left, 0px));
  right: calc(8px + env(safe-area-inset-right, 0px));
  bottom: 8px;
  z-index: 12;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
#ctl {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(600px, 100%);
  padding: 6px 6px 6px 12px;
  border-radius: 16px;
  background: var(--c-glass);
  border: 1px solid rgba(255, 220, 160, 0.14);
  pointer-events: auto;
}
#hint { flex: 1; margin: 0; font-size: 12px; font-weight: 800; line-height: 1.4; color: rgba(255, 240, 220, 0.95); }
.btn-ice {
  flex: none;
  flex-direction: row;
  gap: 4px;
  min-height: 44px;
  padding: 6px 12px;
  font-size: 13.5px;
  color: #eaf6ff;
  white-space: nowrap;
  background: linear-gradient(135deg, #4a8fd6, #235aa8);
  border: 1px solid rgba(255, 255, 255, 0.25);
}
.btn-ice:disabled { opacity: 0.45; filter: grayscale(0.6); cursor: default; }
.btn-ice.alert { animation: ice-alert 0.5s ease-in-out infinite alternate; }
@keyframes ice-alert { from { box-shadow: 0 0 0 rgba(120, 190, 255, 0); } to { box-shadow: 0 0 18px rgba(120, 200, 255, 0.95); transform: scale(1.05); } }
#ice-count { font-family: var(--font-num); font-weight: 900; }
@media (prefers-reduced-motion: reduce) { .btn-ice.alert, #hud-time.warn { animation: none; } }

#banner {
  position: absolute;
  left: 50%;
  top: 23%;
  z-index: 13;
  transform: translate(-50%, -50%);
  max-width: 94%;
  font-size: clamp(17px, 4.6vw, 28px);
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #fff;
  text-align: center;
  text-shadow: 0 3px 0 rgba(120, 40, 10, 0.9), 0 6px 18px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  opacity: 0;
}
#banner.show { animation: banner-pop 1.6s ease-out forwards; }
@keyframes banner-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  22% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%) 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: #17100c; }
.loading-panel { text-align: center; color: #f5e6d3; font-size: 14px; }
.loading-pan {
  width: 54px;
  height: 54px;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--c-gold);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== タイトル ===== */
#screen-title { align-items: flex-end; background: linear-gradient(180deg, rgba(15, 8, 4, 0.05) 20%, rgba(15, 8, 4, 0.82) 70%); }
.title-panel { width: min(460px, 100%); text-align: center; color: #fff; }
.title-en { margin: 0; font-size: 12px; font-weight: 900; letter-spacing: 0.42em; color: #ffcf8a; }
.title-ja { margin: 2px 0 6px; line-height: 1.05; text-shadow: 0 3px 0 #7a1e0c, 0 8px 22px rgba(0, 0, 0, 0.7); }
.title-ja .t1 { display: block; font-size: clamp(44px, 13vw, 66px); font-weight: 900; letter-spacing: 0.04em; color: #fff3da; }
.title-ja .t2 { display: block; font-size: clamp(22px, 6.4vw, 32px); font-weight: 900; letter-spacing: 0.14em; color: #ffd04a; }
.title-catch { margin: 0 0 6px; font-size: 15px; font-weight: 900; color: #ffe9c4; }
.title-desc { margin: 0 auto 8px; max-width: 400px; font-size: 12.5px; font-weight: 700; line-height: 1.6; color: rgba(255, 240, 220, 0.86); }
#title-best { margin: 0 0 10px; min-height: 1.3em; font-size: 13px; font-weight: 900; color: #ffd04a; }
.title-buttons { display: flex; flex-direction: column; gap: 8px; }
.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, #ee5a2e, #b82a14);
  box-shadow: 0 6px 18px rgba(184, 42, 20, 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(255, 255, 255, 0.1); border: 1px solid rgba(255, 230, 190, 0.22); }
.btn-sub:hover { background: rgba(255, 255, 255, 0.16); }

/* ===== 注文 ===== */
#screen-order { background: rgba(10, 6, 3, 0.62); }
.order-panel, .result-panel, .final-panel {
  width: min(440px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 14px 16px;
  border-radius: 18px;
  background: var(--c-panel);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.55);
}
.order-no { margin: 0 0 6px; font-size: 12px; font-weight: 900; letter-spacing: 0.2em; color: var(--c-accent-deep); text-align: center; }
.order-head { display: flex; align-items: flex-start; gap: 10px; }
.order-face { flex: none; width: 60px; height: 60px; border-radius: 50%; background: #ffe7c2; font-size: 40px; line-height: 60px; text-align: center; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.08); }
.order-speech { position: relative; flex: 1; margin: 0; padding: 10px 12px; border-radius: 14px; background: #fff; border: 1px solid var(--c-line); font-size: 14.5px; font-weight: 800; line-height: 1.6; }
.order-h { margin: 12px 0 4px; font-size: 12px; font-weight: 900; letter-spacing: 0.3em; color: var(--c-dim); text-align: center; }
.order-list { margin: 0 0 8px; padding: 0; list-style: none; border-top: 2px dashed var(--c-line); }
.order-list li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 4px; border-bottom: 1px dashed var(--c-line); font-size: 15px; font-weight: 900; }
.order-list li span:first-child { color: var(--c-dim); font-size: 12.5px; font-weight: 800; align-self: center; }
.order-tip { margin: 0 0 10px; padding: 6px 10px; border-radius: 10px; font-size: 12px; font-weight: 800; line-height: 1.55; color: #7a3a14; background: rgba(247, 196, 68, 0.22); }
.order-tip:empty { display: none; }
.order-panel > .btn { width: 100%; }

/* ===== 結果 ===== */
#screen-result { align-items: flex-end; background: linear-gradient(180deg, rgba(15, 8, 4, 0) 30%, rgba(15, 8, 4, 0.55)); pointer-events: none; }
#screen-result .result-panel { pointer-events: auto; padding: 10px 14px; }
#screen-final { background: rgba(10, 6, 3, 0.7); }
.result-top { display: flex; align-items: center; justify-content: center; gap: 14px; }
.result-rank {
  flex: none;
  width: 58px;
  height: 58px;
  margin: 0;
  border-radius: 50%;
  font-size: 34px;
  font-weight: 900;
  line-height: 58px;
  text-align: center;
  color: #fff;
  background: linear-gradient(135deg, #f7c444, #e2602a);
  box-shadow: 0 4px 12px rgba(226, 96, 42, 0.45);
}
.result-rank.rank-S { background: linear-gradient(135deg, #ffe27a, #ff9a1c); text-shadow: 0 2px 0 rgba(150, 70, 0, 0.6); }
.result-rank.rank-B { background: linear-gradient(135deg, #8cc7ff, #3d7be0); box-shadow: none; }
.result-rank.rank-C, .result-rank.rank-D { background: linear-gradient(135deg, #b9aea4, #7d7067); box-shadow: none; }
.result-title { margin: 0; font-size: 14px; font-weight: 900; }
.result-score-row { margin: 0; line-height: 1.1; }
#result-score, #final-score { font-family: var(--font-num); font-size: 40px; font-weight: 900; color: var(--c-accent-deep); font-variant-numeric: tabular-nums; }
.result-unit { margin-left: 4px; font-size: 14px; font-weight: 900; color: var(--c-dim); }
.result-panel.angry { border: 3px solid #d62f2f; background: #fff1ee; animation: angry-in 0.5s ease-out; }
.result-panel.angry .result-speech { background: #ffe1dc; border-color: #e89a90; color: #8a1410; font-size: 14px; }
.result-panel.angry .result-rank { background: linear-gradient(135deg, #e0483a, #8a1410); box-shadow: none; }
@keyframes angry-in { 0% { transform: translateX(0); } 15% { transform: translateX(-9px); } 30% { transform: translateX(8px); } 45% { transform: translateX(-6px); } 60% { transform: translateX(5px); } 80% { transform: translateX(-2px); } 100% { transform: translateX(0); } }
#stage.shake #game-canvas { animation: stage-shake 0.45s linear 2; }
@keyframes stage-shake { 0%, 100% { transform: translate(0, 0); } 20% { transform: translate(-6px, 3px); } 40% { transform: translate(6px, -3px); } 60% { transform: translate(-4px, -2px); } 80% { transform: translate(4px, 2px); } }
@media (prefers-reduced-motion: reduce) { .result-panel.angry, #stage.shake #game-canvas { animation: none; } }
.result-speech { margin: 6px 0; padding: 7px 10px; border-radius: 12px; background: #fff; border: 1px solid var(--c-line); font-size: 13px; font-weight: 800; line-height: 1.5; }
#result-rows, #final-rows { margin: 0 0 8px; padding: 0; list-style: none; }
#result-rows li { display: grid; grid-template-columns: 6.2em 1fr auto; align-items: baseline; gap: 6px; padding: 3px 2px; border-bottom: 1px dashed var(--c-line); font-size: 12.5px; font-weight: 800; }
#result-rows .r-name { font-weight: 900; }
#result-rows .r-note { color: var(--c-dim); font-size: 12px; min-width: 0; }
#result-rows .r-pt { font-family: var(--font-num); font-weight: 900; color: var(--c-accent-deep); white-space: nowrap; }
.result-buttons, .final-buttons, .modal-buttons { display: flex; gap: 8px; }
.result-buttons .btn, .final-buttons .btn, .modal-buttons .btn { flex: 1; }
.result-buttons .btn-primary { flex: 1.5; font-size: 17px; }
.result-panel .btn-sub, .final-panel .btn-sub, .modal-buttons .btn-sub { color: var(--c-text); background: rgba(43, 29, 20, 0.07); border-color: var(--c-line); }
#share-msg, #final-msg { margin: 6px 0 0; min-height: 1.2em; font-size: 12px; font-weight: 800; text-align: center; color: var(--c-dim); }
#share-msg:empty { display: none; }
.final-eyebrow { margin: 0 0 6px; font-size: 12px; font-weight: 900; letter-spacing: 0.3em; color: var(--c-accent-deep); text-align: center; }
#final-new { margin: 6px 0 0; font-size: 14px; font-weight: 900; text-align: center; color: #d8780c; }
#final-rows { margin-top: 10px; border-top: 2px dashed var(--c-line); }
#final-rows li { display: flex; align-items: center; gap: 8px; padding: 5px 2px; border-bottom: 1px dashed var(--c-line); font-size: 13px; font-weight: 800; }
#final-rows .r-name { flex: 1; min-width: 0; }
#final-rows .r-val { font-family: var(--font-num); font-weight: 900; color: var(--c-accent-deep); white-space: nowrap; }
#final-rows .f-face { font-size: 20px; }
#final-rows .f-name { flex: 1; min-width: 0; }
#final-rows .f-sub { display: block; font-size: 11.5px; color: var(--c-dim); }
#final-rows .f-pt { font-family: var(--font-num); font-size: 16px; font-weight: 900; color: var(--c-accent-deep); }
.final-buttons { flex-wrap: wrap; }
.final-buttons .btn-primary { flex: 1 1 100%; }

/* ===== 一時停止・エラー ===== */
#screen-paused, #gl-error { background: rgba(10, 6, 3, 0.72); cursor: pointer; }
.paused-panel { text-align: center; color: #fff; }
.paused-title { margin: 0 0 6px; font-size: 24px; font-weight: 900; }
.paused-hint { margin: 0; font-size: 13px; font-weight: 700; color: rgba(255, 240, 220, 0.8); }

/* ===== モーダル。広告より上に出すため 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(500px, 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%; }
.confirm-box { width: min(400px, 100%); }
.confirm-text { margin: 4px 0 12px; font-size: 15px; font-weight: 800; line-height: 1.6; text-align: center; white-space: pre-line; }

/* ===== フッター ===== */
#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.7);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  z-index: 40;
  display: none;
}
#footer a { color: #ffd04a; pointer-events: auto; }
body.on-title #footer { display: block; }
body.on-title #screen-title { padding-bottom: 48px; }

/* ===== 小さい画面・横向き ===== */
@media (max-height: 560px) {
  #hud { top: 3px; gap: 3px; }
  #ticket-face { font-size: 16px; }
  #instr { font-size: 12px; padding: 3px 10px; }
  #step-row { flex-direction: row; }
  .title-ja .t1 { font-size: 36px; }
  .title-ja .t2 { font-size: 18px; }
  .title-desc { display: none; }
  .ctl-row .btn { min-height: 38px; }
  .heat-btn { height: 32px; }
  #ctl { gap: 4px; padding: 5px; }
  #meters { padding: 4px 8px; gap: 2px; }
  .meter.big .m-num { font-size: 20px; }
  .order-face { width: 44px; height: 44px; font-size: 28px; line-height: 44px; }
}
@media (max-width: 380px) {
  .ctl-row .btn { font-size: 12.5px; }
  .ctl-row .btn-primary { font-size: 14px; }
  .ctl-row { gap: 4px; }
  #ticket-chips li { font-size: 11px; padding: 1px 5px; }
  #instr { font-size: 12px; padding: 3px 10px; }
  .result-buttons .btn-primary { font-size: 15px; }
}
@media (max-height: 700px) {
  #ticket-chips li { font-size: 11px; padding: 1px 5px; }
  #instr { font-size: 12px; padding: 3px 10px; }
  .meter.big .m-num { font-size: 20px; }
  #result-score { font-size: 30px; }
  .result-rank { width: 44px; height: 44px; font-size: 26px; line-height: 44px; }
}
@media (max-height: 560px) and (min-width: 640px) {
  .ctl-row .btn { font-size: 12.5px; }
  .ctl-row .btn-primary { font-size: 14px; }
  #screen-result { align-items: flex-start; padding: 6px; }
  #screen-result .result-panel { padding: 6px 10px; }
  .result-speech { margin: 3px 0; padding: 4px 8px; font-size: 12px; }
  #result-rows { margin-bottom: 4px; }
  #result-rows li { font-size: 11.5px; padding: 1px 2px; }
  .result-buttons .btn { padding: 6px 4px; min-height: 0; font-size: 13px; }
  .result-buttons .btn-primary { font-size: 14px; }
  /* 横向きスマホ: 操作と結果を右に寄せる */
  #controls { left: auto; width: 300px; }
  #hud { align-items: flex-start; right: 316px; }
  #meters { width: min(360px, 100%); }
  #screen-result { align-items: center; justify-content: flex-end; }
  #screen-result .result-panel { width: 320px; }
  #screen-title { align-items: center; justify-content: flex-end; background: linear-gradient(90deg, rgba(15, 8, 4, 0.05) 30%, rgba(15, 8, 4, 0.85) 75%); }
  .title-panel { width: 320px; }
}

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