/* =========================================================
 * ドーナッツメーカー（donut-maker） スタイル
 * ========================================================= */
: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: #3a2218;
  --c-dim: #8a6f62;
  --c-accent: #ec5a93;
  --c-accent-deep: #c4326c;
  --c-gold: #ffca52;
  --c-green: #49b85a;
  --c-red: #d64545;
  --c-panel: rgba(255, 249, 243, 0.97);
  --c-line: rgba(58, 34, 24, 0.14);
  --c-glass: rgba(48, 27, 18, 0.8);
}

* { 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: #3a2218;
  -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 に残す */
#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; }
.icon-btn { width: 30px; height: 30px; padding: 0; }

/* ===== ステージ ===== */
#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #d9cbc0;
}
#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 60%, rgba(40, 20, 10, 0.3) 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-row, #ticket { max-width: 620px; margin: 0 auto 5px; }
#hud-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px 5px 10px;
  border-radius: 12px;
  background: var(--c-glass);
  color: #fff2e6;
  font-size: 13px;
  font-weight: 800;
}
#hud-count { white-space: nowrap; }
#hud-score-wrap { white-space: nowrap; color: rgba(255, 238, 222, 0.8); font-weight: 700; }
#hud-score { color: var(--c-gold); font-family: var(--font-num); font-size: 15px; }
#steps { display: flex; gap: 3px; margin: 0 0 0 auto; padding: 0; list-style: none; counter-reset: st; }
#steps li {
  counter-increment: st;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 238, 222, 0.6);
  font-size: 11.5px;
  white-space: nowrap;
}
#steps li::before { content: counter(st) " "; font-family: var(--font-num); }
#steps li.done { color: rgba(255, 238, 222, 0.85); }
#steps li.done::before { content: "✓ "; }
#steps li.on { background: linear-gradient(135deg, #f372a4, #d83b78); color: #fff; box-shadow: 0 0 10px rgba(240, 90, 150, 0.55); }
#ticket {
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: min(620px, 100%);
  padding: 5px 12px 5px 6px;
  border-radius: 999px;
  background: #fffaf3;
  box-shadow: 0 3px 10px rgba(40, 20, 10, 0.35);
  font-size: 13px;
}
.tk-lab { flex: none; padding: 2px 9px; border-radius: 999px; background: var(--c-text); color: #ffe9c9; font-size: 11px; font-weight: 900; }
#tk-items { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 5px; min-width: 0; }
.tk-chip { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.tk-plus { color: var(--c-dim); font-weight: 900; font-size: 11px; }

.c-dot { display: inline-block; width: 15px; height: 15px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.3); flex: none; box-shadow: inset -2px -2px 3px rgba(0, 0, 0, 0.18), inset 2px 2px 2px rgba(255, 255, 255, 0.35); }
.c-dot.line { width: 18px; height: 7px; border-radius: 4px; transform: rotate(-28deg); }

/* ===== 操作パネル ===== */
#controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  padding: 16px 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(48, 27, 18, 0) 0, rgba(48, 27, 18, 0.88) 30px);
}
#controls > * { max-width: 620px; margin-left: auto; margin-right: auto; }
#controls.busy .pane { opacity: 0.55; pointer-events: none; }
#instr {
  margin: 0 auto 6px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--c-glass);
  color: #fff2e6;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.45;
  min-height: 48px;
  display: flex;
  align-items: center;
}
.pane-btns { display: flex; gap: 6px; align-items: stretch; margin-top: 6px; }
.act {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 2px 10px;
  border: 2px solid rgba(255, 230, 200, 0.3);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff0e2;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.15;
  cursor: pointer;
}
.act small { font-size: 10px; font-weight: 700; opacity: 0.8; }
.act:disabled { opacity: 0.4; cursor: default; }
.act.go { flex: 1.5; background: linear-gradient(135deg, #f372a4, #d83b78); border-color: #ffc0d8; color: #fff; box-shadow: 0 4px 14px rgba(216, 59, 120, 0.5); }
.act.go:disabled { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 230, 200, 0.3); box-shadow: none; }
.act.go.ready { animation: go-pulse 1.1s ease-in-out infinite; }
.act:not(:disabled):active { transform: scale(0.97); }
@keyframes go-pulse { 50% { transform: scale(1.035); } }

/* メーター */
.gauge { display: flex; align-items: center; gap: 8px; color: #fff0e2; font-size: 11.5px; font-weight: 800; }
.gauge + .gauge { margin-top: 5px; }
.g-lab { flex: none; width: 6.4em; white-space: nowrap; }
.gauge.wide .g-lab { width: 3.4em; }
.gauge > b { flex: none; width: 4.2em; text-align: right; font-family: var(--font-num); font-size: 13px; }
.gauge > b.g-note { font-family: var(--font-jp); font-size: 9.5px; line-height: 1.2; font-weight: 700; opacity: 0.75; }
.gauge > b.hot { color: #ff8d7a; }
.gauge > b.cold { color: #8fd0ff; }
.bar { position: relative; flex: 1; height: 14px; border-radius: 7px; background: rgba(255, 255, 255, 0.16); box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4); }
.bar .fill { position: absolute; inset: 0; border-radius: 7px; background: linear-gradient(90deg, #f6d9a8, #f0b55c); transform-origin: left center; }
#g-core .fill { background: linear-gradient(90deg, #ffb37a, #ff7a59); }
#g-core.full .fill { background: linear-gradient(90deg, #7fdc8d, #49b85a); }
.bar .zone { position: absolute; top: -3px; bottom: -3px; border: 2px solid #fff; border-radius: 5px; box-shadow: 0 0 6px rgba(255, 255, 255, 0.7); }
#g-temp { background: linear-gradient(90deg, #5aa8e8 0%, #8fd0a0 36%, #f4d35e 58%, #f08a4b 76%, #d8412f 100%); }
#g-temp .zone { left: 42.9%; width: 21.4%; }
.bar .mark { position: absolute; top: -5px; bottom: -5px; width: 5px; margin-left: -2.5px; border-radius: 3px; background: #2a160d; border: 1px solid #fff; box-shadow: 0 0 4px rgba(0, 0, 0, 0.6); transition: left 0.12s linear; }
#heat { display: flex; align-items: center; gap: 3px; }
.heat-lab { font-size: 16px; margin-right: 1px; }
.heat-btn {
  min-width: 40px;
  height: 46px;
  padding: 0 8px;
  border: 2px solid rgba(255, 220, 190, 0.25);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffe8d2;
  font-size: 14px;
  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); }

/* トッピングの道具 */
.tools { display: grid; gap: 4px; }
#tools-ice { grid-template-columns: repeat(5, 1fr); }
#tools-ex { grid-template-columns: repeat(6, 1fr); margin-top: 5px; }
.chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  height: 44px;
  padding: 2px;
  border: 2px solid rgba(255, 230, 200, 0.16);
  border-radius: 10px;
  background: rgba(255, 250, 240, 0.1);
  color: #fff1e2;
  cursor: pointer;
}
.chip .c-dot { border-color: rgba(255, 255, 255, 0.45); }
.chip .c-name { font-size: 10.5px; font-weight: 800; white-space: nowrap; letter-spacing: -0.04em; }
.chip:hover { background: rgba(255, 250, 240, 0.17); }
.chip.on { background: #fff5e6; border-color: var(--c-gold); color: var(--c-text); box-shadow: 0 0 10px rgba(255, 202, 82, 0.55); }
.chip.on .c-dot { border-color: rgba(0, 0, 0, 0.3); }

/* ===== 1 個ごとの採点 ===== */
#card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 14;
  width: min(520px, 100%);
  margin: 0 auto;
  padding: 12px 14px 12px;
  border-radius: 18px 18px 0 0;
  background: var(--c-panel);
  box-shadow: 0 -8px 30px rgba(40, 20, 10, 0.4);
  animation: card-in 0.35s ease-out;
}
@keyframes card-in { from { transform: translateY(40%); opacity: 0; } }
#card-title { margin: 0 0 6px; font-size: 14px; font-weight: 900; text-align: center; }
.card-main { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-rows { flex: 1; min-width: 0; margin: 0; padding: 0; list-style: none; }
.card-row { display: flex; align-items: baseline; gap: 8px; padding: 4px 2px; border-top: 1px solid var(--c-line); font-size: 13px; font-weight: 800; }
.card-row:first-child { border-top: none; }
.card-row span { flex: none; width: 5.4em; }
.card-row small { flex: 1; min-width: 0; color: var(--c-dim); font-size: 11.5px; font-weight: 700; }
.card-row b { flex: none; font-family: var(--font-num); font-size: 14px; }
.card-row.hi b { color: #d98a00; }
.card-row.lo b { color: #8a8078; }
.card-total { flex: none; margin: 0; min-width: 84px; text-align: center; color: var(--c-accent-deep); }
.card-total b { font-family: var(--font-num); font-size: 36px; line-height: 1; font-variant-numeric: tabular-nums; }
.card-total span { margin-left: 2px; font-size: 13px; font-weight: 900; }
#card .btn { width: 100%; padding: 10px 18px; font-size: 17px; }

#banner {
  position: absolute;
  left: 50%;
  bottom: 200px;
  z-index: 13;
  max-width: min(92%, 460px);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(48, 27, 18, 0.9);
  border: 1px solid rgba(255, 220, 190, 0.25);
  color: #fff3e4;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.5;
  text-align: center;
  white-space: nowrap;
  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; }

/* ===== このゲームの上書き（色・結果の出し方） ===== */
#screen-loading { background: #3a2218; }
.loading-ball { background: radial-gradient(circle at 50% 50%, #3a2218 0 26%, #e9a54e 28% 62%, #b9702a 70%); box-shadow: inset 0 -4px 6px rgba(90, 40, 10, 0.5); }
#screen-title { background: linear-gradient(180deg, rgba(48, 24, 14, 0.9) 0, rgba(48, 24, 14, 0.62) 46%, rgba(48, 24, 14, 0) 76%); pointer-events: none; }
.title-panel { pointer-events: auto; }
.title-en { color: #ffc0d8; }
.title-ja { text-shadow: 0 3px 0 #8c2550, 0 6px 16px rgba(0, 0, 0, 0.5); }
.title-ja .t1, .title-ja .t2 { font-size: clamp(30px, 9.4vw, 50px); }
.title-ja .t1 { color: #fff0d8; }
.title-ja .t2 { color: #ff8fba; }
.btn-primary { background: linear-gradient(135deg, #f372a4, #d83b78); box-shadow: 0 6px 18px rgba(216, 59, 120, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
.btn-sub { background: rgba(58, 34, 24, 0.75); }
.btn-sub:hover { background: rgba(88, 54, 38, 0.82); }
/* 結果: 箱のドーナツが見えるよう、下（横長の画面では右）に寄せる */
#screen-result { background: none; align-items: flex-end; padding: 0; pointer-events: none; }
.result-panel { pointer-events: auto; width: min(520px, 100%); max-height: 62%; overflow-y: auto; -webkit-overflow-scrolling: touch; margin: 0 auto; padding: 12px 16px 12px; border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(40, 20, 10, 0.4); }
.result-rank { font-size: 24px; }
#result-score { font-size: 40px; }
.result-msg { margin-bottom: 6px; }
#result-rows { margin-bottom: 8px; }
#result-rows li { padding: 4px 4px; }
.rr-face { flex: none; padding: 2px 7px; border-radius: 999px; background: var(--c-text); color: #ffe9c9; font-size: 10.5px; font-weight: 900; }
#screen-paused, #gl-error { background: rgba(40, 20, 10, 0.6); }
.paused-panel { background: rgba(58, 34, 24, 0.92); }
#footer { color: rgba(60, 34, 24, 0.85); text-shadow: 0 1px 2px rgba(255, 255, 255, 0.6); }
#footer a { color: #b4285f; }

/* ===== PC・タブレット ===== */
@media (min-width: 700px) {
  .chip { height: 50px; }
  .chip .c-name { font-size: 12px; letter-spacing: 0; }
  #instr { font-size: 13.5px; min-height: 40px; }
  #ticket { font-size: 14px; }
}
/* ===== 小さいスマホ ===== */
@media (max-width: 360px) {
  .chip .c-name { font-size: 9.5px; }
  #steps li { padding: 3px 6px; font-size: 10.5px; }
  .g-lab { width: 5.8em; font-size: 10.5px; }
  .heat-btn { min-width: 34px; }
}
@media (max-height: 640px) and (orientation: portrait) {
  .chip { height: 38px; }
  .act, .heat-btn { min-height: 40px; height: 40px; }
  #instr { min-height: 44px; padding: 4px 8px; font-size: 11.5px; }
  .bar { height: 12px; }
}

/* ===== 横長の画面: 結果は右に ===== */
@media (min-aspect-ratio: 6/5) {
  #screen-result { align-items: center; justify-content: flex-end; padding: 12px; }
  .result-panel { width: 350px; max-height: 100%; margin: 0; border-radius: 18px; }
}
/* ===== 横向きのスマホ（背が低い）: お題を左、操作を右に寄せる ===== */
@media (max-height: 520px) and (orientation: landscape) {
  #hud { right: auto; width: 190px; }
  #hud-row { flex-wrap: wrap; gap: 4px 8px; }
  #steps { margin-left: 0; }
  #ticket { border-radius: 14px; }
  #controls { left: auto; top: 0; width: 290px; padding-top: 8px; overflow-y: auto; background: rgba(48, 27, 18, 0.84); display: flex; flex-direction: column; justify-content: center; }
  #controls > * { width: 100%; }
  #instr { font-size: 11px; min-height: 0; }
  .chip { height: 36px; }
  .act, .heat-btn { min-height: 38px; height: 38px; font-size: 13px; }
  .pane-btns { flex-wrap: wrap; }
  #heat { width: 100%; }
  .heat-btn { flex: 1; }
  #card { left: auto; right: 0; top: 0; width: 300px; margin: 0; border-radius: 0; display: flex; flex-direction: column; justify-content: center; }
  .card-main { flex-direction: column; align-items: stretch; }
  #screen-title { align-items: center; justify-content: flex-end; background: linear-gradient(270deg, rgba(48, 24, 14, 0.92) 0, rgba(48, 24, 14, 0.62) 46%, rgba(48, 24, 14, 0) 70%); }
  .title-panel { width: 330px; margin-top: 0; }
  .title-ja .t1, .title-ja .t2 { font-size: 30px; }
  .title-desc { display: none; }
  body.on-title #footer { text-align: left; left: 12px; }
  .result-panel { width: 320px; }
}
@media (prefers-reduced-motion: reduce) {
  .act.go.ready, .loading-ball, #card { 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; }
}
