/* =========================================================
 * left-or-right（右か左か） スタイル
 * 左 = シアン、右 = オレンジ。赤は「逆」のしるし
 * ========================================================= */
: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-bg: #0f1226;
  --c-bg-deep: #090b18;
  --c-text: #f4f6ff;
  --c-dim: #a9afd0;
  --c-left: #1fc8e0;
  --c-left-deep: #0e8fa6;
  --c-right: #ff9a1f;
  --c-right-deep: #d86a00;
  --c-red: #ff3355;
  --c-pink: #ff7eb6;
  --c-gold: #ffd166;
  --c-green: #52e08f;
  --c-panel: rgba(18, 21, 44, 0.95);
  --c-line: rgba(255, 255, 255, 0.16);
  --zone-h: clamp(64px, 12.5vh, 92px);
  /* ランキング（sgr-*）は明るいパネルで出す */
  --c-sgr-text: #1b1f3b;
  --c-sgr-dim: #6b6f85;
  --c-sgr-line: rgba(27, 31, 59, 0.14);
}

* { 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: var(--c-bg);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ===== レイアウト =====
   共通ヘッダー(--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 に残すため、display:none ではなく
   スクリーンリーダー向けの不可視にする */
#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: 17px;
  font-weight: 900;
  letter-spacing: 0.14em;
  color: #fff;
  white-space: nowrap;
}

.logo-r { color: var(--c-right); }
.logo-l { color: var(--c-left); }

#topbar-buttons {
  display: flex;
  gap: 6px;
}

.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: var(--c-bg);
  touch-action: manipulation;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ===== 上部 UI（HUD・ゲージ・お題） ===== */
#top-ui {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 12px 0;
  padding-left: calc(12px + env(safe-area-inset-left, 0px));
  padding-right: calc(12px + env(safe-area-inset-right, 0px));
  pointer-events: none;
}

#hud {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  max-width: 720px;
}

/* タイトル画面ではレイアウトを保ったまま隠す（カードの位置がずれないように） */
body.is-title #hud,
body.is-title #gauge { visibility: hidden; }

.hud-cell {
  display: flex;
  flex-direction: column;
  min-width: 84px;
  padding: 4px 10px 5px;
  border-radius: 10px;
  background: rgba(6, 8, 20, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.hud-left { align-items: flex-start; }
.hud-center { align-items: center; min-width: 64px; }
.hud-right { align-items: flex-end; }

.hud-label {
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 0.16em;
  color: var(--c-dim);
}

.hud-value {
  display: inline-block;
  font-family: var(--font-num);
  font-size: 20px;
  font-weight: bold;
  line-height: 1.15;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

#hud-score { color: var(--c-gold); }

.hud-combo {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.hud-mult {
  font-family: var(--font-num);
  font-size: 13px;
  font-weight: bold;
  color: var(--c-dim);
}

.hud-mult.hot { color: var(--c-gold); }

.hud-value.bump { animation: bump 0.3s ease-out; }

@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* 時間ゲージ */
#gauge {
  position: relative;
  width: 100%;
  max-width: 720px;
  height: 12px;
  margin-top: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

#gauge-fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--c-left), #7be3c0 50%, var(--c-right));
  transform-origin: left center;
  will-change: transform;
}

#gauge.warn #gauge-fill { background: linear-gradient(90deg, #ffb02e, #ffd166); }
#gauge.danger #gauge-fill {
  background: linear-gradient(90deg, #ff3355, #ff7a5c);
  animation: gauge-blink 0.5s ease-in-out infinite alternate;
}
#gauge.frozen #gauge-fill { filter: saturate(0.4) brightness(1.15); }

@keyframes gauge-blink {
  from { opacity: 1; }
  to { opacity: 0.55; }
}

/* お題 */
.prompt {
  margin: 8px 0 0;
  min-height: 1.4em;
  padding: 3px 18px;
  border-radius: 999px;
  background: rgba(6, 8, 20, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: clamp(17px, 5vw, 26px);
  font-weight: 900;
  line-height: 1.4;
  letter-spacing: 0.04em;
  color: #fff;
  white-space: nowrap;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

.prompt:empty { visibility: hidden; }
.prompt .red { color: var(--c-red); }
.prompt .pink { color: var(--c-pink); }
.prompt .gold { color: var(--c-gold); }

/* 新しいルールの紹介中 */
.prompt.new {
  border-color: rgba(255, 209, 102, 0.85);
  box-shadow: 0 0 18px rgba(255, 209, 102, 0.35);
}

.prompt .badge {
  display: inline-block;
  margin-right: 8px;
  padding: 1px 7px 2px;
  border-radius: 6px;
  background: var(--c-gold);
  color: #2a1a00;
  font-family: var(--font-num);
  font-size: 0.55em;
  letter-spacing: 0.1em;
  vertical-align: 0.25em;
  text-shadow: none;
}

.prompt.switch { animation: prompt-switch 0.32s cubic-bezier(0.2, 1.4, 0.4, 1); }

@keyframes prompt-switch {
  0% { transform: scale(0.7); opacity: 0.2; }
  100% { transform: scale(1); opacity: 1; }
}

/* ===== 振り分け先 ===== */
#zones {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  z-index: 9;
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 0 12px;
  padding-left: calc(12px + env(safe-area-inset-left, 0px));
  padding-right: calc(12px + env(safe-area-inset-right, 0px));
  transition: opacity 0.3s ease;
}

/* タイトル・リザルトではフッターと重ならないように隠す（レイアウトは保つ） */
body:not(.playing) #zones {
  opacity: 0;
  pointer-events: none;
}

.zone {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  max-width: 340px;
  height: var(--zone-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0;
  padding: 0 10px;
  border-radius: 18px;
  border: 2px solid;
  color: #fff;
  font-family: var(--font-jp);
  cursor: pointer;
  overflow: hidden;
  touch-action: manipulation;
  outline: none;
}

.zone-left {
  border-color: rgba(31, 200, 224, 0.75);
  background: linear-gradient(180deg, rgba(31, 200, 224, 0.28), rgba(14, 143, 166, 0.2));
  box-shadow: 0 0 18px rgba(31, 200, 224, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.zone-right {
  border-color: rgba(255, 154, 31, 0.8);
  background: linear-gradient(180deg, rgba(255, 154, 31, 0.28), rgba(216, 106, 0, 0.2));
  box-shadow: 0 0 18px rgba(255, 154, 31, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.zone:focus-visible { box-shadow: 0 0 0 3px #fff; }

.zone__arrow {
  flex: none;
  font-size: clamp(16px, 4.4vw, 22px);
  line-height: 1;
}

.zone-left .zone__arrow { color: var(--c-left); }
.zone-right .zone__arrow { color: var(--c-right); }

.zone__text {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.zone__main {
  max-width: 100%;
  font-size: clamp(18px, 5.4vw, 28px);
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

.zone__sub {
  font-size: 11px;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.72);
  white-space: nowrap;
}

.zone__sub:empty { display: none; }

.zone__key {
  position: absolute;
  bottom: 3px;
  font-family: var(--font-num);
  font-size: 10px;
  color: rgba(255, 255, 255, 0.5);
}

.zone-left .zone__key { left: 12px; }
.zone-right .zone__key { right: 12px; }

/* タッチ端末ではキーの案内を出さない */
@media (hover: none) {
  .zone__key { display: none; }
}

.zone.swap .zone__text { animation: zone-swap 0.32s ease-out; }

@keyframes zone-swap {
  0% { transform: rotateX(90deg); opacity: 0; }
  100% { transform: rotateX(0); opacity: 1; }
}

.zone::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.zone.ok::after { animation: zone-ok 0.26s ease-out; }
.zone.bad::after { background: var(--c-red); animation: zone-bad 0.42s ease-out; }
.zone.hint { animation: zone-hint 0.42s ease-in-out; }

@keyframes zone-ok {
  0% { opacity: 0.55; }
  100% { opacity: 0; }
}

@keyframes zone-bad {
  0% { opacity: 0.7; }
  100% { opacity: 0; }
}

@keyframes zone-hint {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* ===== 案内の帯（READY / NEW RULE / LEVEL UP） ===== */
.banner {
  position: absolute;
  left: 50%;
  top: 46%;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  max-width: calc(100% - 24px);
  padding: 10px 26px 12px;
  border-radius: 18px;
  transform: translate(-50%, -50%) scale(0.85);
  background: rgba(8, 10, 24, 0.86);
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  color: #fff;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.2s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.banner__head {
  font-family: var(--font-num);
  font-size: clamp(22px, 7vw, 38px);
  font-weight: 900;
  letter-spacing: 0.12em;
  line-height: 1.1;
}

.banner__head:empty,
.banner__text:empty { display: none; }

.banner__text {
  font-size: clamp(16px, 4.8vw, 24px);
  font-weight: 900;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.banner__text .red { color: var(--c-red); }
.banner__text .pink { color: var(--c-pink); }

.banner.new { border-color: rgba(255, 209, 102, 0.75); }
.banner.new .banner__head { color: var(--c-gold); font-size: clamp(15px, 4.4vw, 20px); letter-spacing: 0.3em; }
.banner.go .banner__head { color: var(--c-green); }
.banner.level .banner__head { color: var(--c-gold); }
.banner.over { border-color: rgba(255, 51, 85, 0.75); }
.banner.over .banner__head { color: #ff6b80; }

/* 新しいルールの紹介中は、カードの上に重ねずに少し上へずらす */
.banner.new { top: 30%; }

/* ===== 得点のポップ ===== */
#floats {
  position: absolute;
  inset: 0;
  z-index: 13;
  pointer-events: none;
  overflow: hidden;
}

.float {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--font-num);
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
  animation: float-up 0.75s ease-out forwards;
}

.float.l { color: var(--c-left); }
.float.r { color: var(--c-right); }
.float.bad { color: #ff5a70; font-size: 28px; }
.float.combo { color: var(--c-gold); font-size: 22px; animation-duration: 1.1s; }

@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -170%) scale(1); }
}

/* ===== 画面（タイトル・リザルト・一時停止） ===== */
.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
  background: radial-gradient(ellipse at 50% 45%, rgba(10, 12, 28, 0.3), rgba(6, 7, 18, 0.8));
  overflow-y: auto;
}

/* タイトル・リザルトは下のフッター（2行）と重ならないように、そのぶん上へ寄せる */
#screen-title,
#screen-result { padding-bottom: 50px; }

.screen-dim { background: rgba(6, 7, 18, 0.94); }

.panel {
  width: min(400px, 100%);
  margin: auto;
  padding: 22px 20px 20px;
  border-radius: 18px;
  background: var(--c-panel);
  border: 1px solid var(--c-line);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  text-align: center;
}

.title-panel {
  position: relative;
  padding-top: 24px;
  overflow: hidden;
}

/* パネルの左右の縁を、左＝シアン・右＝オレンジに光らせる */
.title-panel::before,
.title-panel::after {
  content: "";
  position: absolute;
  top: 12%;
  bottom: 12%;
  width: 4px;
  border-radius: 4px;
}

.title-panel::before { left: 0; background: var(--c-left); box-shadow: 0 0 16px var(--c-left); }
.title-panel::after { right: 0; background: var(--c-right); box-shadow: 0 0 16px var(--c-right); }

.title-en {
  margin: 0;
  font-family: var(--font-num);
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 0.32em;
  color: var(--c-dim);
}

.t-l { color: var(--c-left); }
.t-r { color: var(--c-right); }

.title-ja {
  margin: 4px 0 0;
  font-size: clamp(40px, 13vw, 58px);
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1.15;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.4));
}

.tj-r { color: var(--c-right); }
.tj-l { color: var(--c-left); }
.tj-k { color: #fff; font-size: 0.62em; margin: 0 0.04em; }

.title-catch {
  margin: 10px 0 0;
  font-size: 14px;
  line-height: 1.7;
  color: var(--c-text);
}

.title-best {
  display: inline-block;
  margin: 14px 0 0;
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(255, 209, 102, 0.12);
  border: 1px solid rgba(255, 209, 102, 0.32);
  font-size: 13px;
  font-weight: bold;
  color: var(--c-gold);
}

.title-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.title-sub-buttons {
  display: flex;
  gap: 8px;
}

.title-sub-buttons .btn {
  flex: 1;
  padding: 10px 8px;
  font-size: 14px;
  white-space: nowrap;
}

.title-hint {
  margin: 14px 0 0;
  font-size: 11px;
  color: var(--c-dim);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 12px;
  font-family: var(--font-jp);
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:active { transform: scale(0.97); }

.btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.btn-primary {
  border: 0;
  background: linear-gradient(90deg, #13a9c2, #ff8a12);
  color: #fff;
  font-size: 17px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  box-shadow: 0 4px 0 #6b3c0e, 0 8px 18px rgba(255, 138, 18, 0.28);
}

.btn-primary:active { box-shadow: 0 2px 0 #6b3c0e; transform: translateY(2px); }

.btn-sub {
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.06);
  color: var(--c-text);
}

/* リザルト */
.result-title {
  margin: 0;
  font-family: var(--font-num);
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.2em;
  color: #ff6b80;
}

.result-new {
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: bold;
  color: var(--c-gold);
  animation: glow 1.2s ease-in-out infinite alternate;
}

@keyframes glow {
  from { text-shadow: 0 0 4px rgba(255, 209, 102, 0.3); }
  to { text-shadow: 0 0 14px rgba(255, 209, 102, 0.9); }
}

.result-score-row {
  margin: 8px 0 0;
  font-family: var(--font-num);
  color: var(--c-gold);
}

#result-score {
  font-size: 46px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.result-unit {
  margin-left: 4px;
  font-family: var(--font-jp);
  font-size: 16px;
  font-weight: bold;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 12px 0 16px;
}

.rstat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.rstat-label {
  font-size: 11px;
  color: var(--c-dim);
  white-space: nowrap;
}

.rstat span:last-child {
  font-size: 16px;
  font-weight: bold;
}

.result-buttons {
  display: flex;
  gap: 8px;
}

.result-buttons .btn { flex: 1; }

/* 一時停止 */
.paused-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--c-text);
  font-family: var(--font-jp);
  cursor: pointer;
}

.paused-panel:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.paused-title {
  font-size: 22px;
  font-weight: 900;
  color: var(--c-gold);
}

.paused-note {
  font-size: 13px;
  line-height: 1.6;
  color: var(--c-dim);
}

.paused-hint {
  font-size: 13px;
  color: var(--c-dim);
}

/* ===== 遊び方モーダル ===== */
.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(6, 7, 18, 0.72);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.modal-box {
  width: min(470px, 100%);
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 18px 18px;
  border-radius: 16px;
  background: var(--c-panel);
  border: 1px solid var(--c-line);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.modal-title {
  margin: 0 0 10px;
  font-size: 19px;
  color: var(--c-gold);
}

.howto {
  margin: 0 0 16px;
  padding: 0 0 0 1.2em;
  text-align: left;
  font-size: 14px;
  line-height: 1.7;
}

.howto li + li { margin-top: 6px; }
.howto b { color: var(--c-gold); }
.howto b.c-red { color: #ff6b80; }

.howto-rules {
  margin: 4px 0 0;
  padding: 6px 10px 6px 1.6em;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 13px;
}

.howto-rules li + li { margin-top: 2px; }

.modal-box .btn { min-width: 160px; }

/* ===== フッター ===== */
#footer {
  position: absolute;
  left: 0;
  right: 0;
  /* #app 自体が広告の上で終わっているので、ここで --ad-space を足さない */
  bottom: 6px;
  text-align: center;
  font-size: 11px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.78);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 31;
}

#footer a {
  color: var(--c-gold);
  pointer-events: auto;
}

body.playing #footer { display: none; }

/* ===== 高さの小さいスマホ（iPhone SE など） ===== */
@media (max-height: 700px) {
  .title-panel { padding: 18px 16px 16px; }
  .title-ja { font-size: clamp(36px, 11vw, 48px); }
  .title-catch { margin-top: 8px; font-size: 13px; line-height: 1.6; }
  .title-best { margin-top: 10px; }
  .title-buttons { margin-top: 12px; gap: 8px; }
  .title-hint { display: none; }
  .result-panel { padding: 16px 14px 14px; }
  #result-score { font-size: 38px; }
  .result-stats { margin: 8px 0 12px; }
}

/* ===== 低い画面（横向きのスマホなど） ===== */
@media (max-height: 520px) {
  :root { --zone-h: 52px; }
  #logo { font-size: 15px; }
  .icon-btn { width: 28px; height: 28px; font-size: 14px; }
  #top-ui { padding-top: 4px; }
  /* HUD とゲージとお題を1行にまとめるほどの高さは無いので、詰めて並べる */
  .hud-cell { min-width: 64px; padding: 2px 8px 3px; }
  .hud-label { font-size: 9px; }
  .hud-value { font-size: 15px; }
  .hud-mult { font-size: 11px; }
  #gauge { height: 8px; margin-top: 4px; }
  .prompt { margin-top: 4px; padding: 1px 14px; font-size: 16px; }
  #zones { bottom: 6px; }
  .zone__main { font-size: 18px; }
  .zone__sub { display: none; }
  .title-catch, .title-hint { display: none; }
  .panel, .result-panel, .title-panel { padding: 12px 16px; }
  .title-ja { font-size: 36px; }
  .rstat span:last-child { font-size: 14px; }
  .banner { padding: 6px 18px 8px; }
  .banner.new { top: 36%; }
  /* フッターは1行にまとめ、パネルはその上に収める */
  #footer { display: flex; justify-content: center; gap: 10px; bottom: 3px; font-size: 10px; line-height: 1.4; }
  #screen-title, #screen-result { padding-top: 8px; padding-bottom: 24px; }
  .result-title { font-size: 18px; }
  .result-new { margin-top: 2px; font-size: 12px; }
  .result-score-row { margin-top: 2px; }
  #result-score { font-size: 30px; }
  .result-stats { margin: 6px 0 8px; gap: 4px; }
  .rstat { padding: 3px 4px; gap: 0; }
  .rstat-label { font-size: 10px; }
  .result-buttons .btn { min-height: 38px; padding: 6px 12px; }
  .title-buttons .btn { min-height: 38px; }
}

/* ===== 全国ランキング（共通モジュール 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, 7, 18, 0.7);
  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: #f7f8fc;
  color: var(--c-sgr-text);
  border-radius: 14px;
  padding: 20px 18px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5);
  -webkit-user-select: text;
  user-select: text;
}

.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-sgr-line);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(19, 169, 194, 0.06);
  color: var(--c-sgr-text);
  cursor: pointer;
}

.sgr-tab-active {
  background: linear-gradient(90deg, #13a9c2, #ff8a12);
  border-color: transparent;
  color: #fff;
}

.sgr-register-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  color: #c4620c;
}

.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-sgr-line);
  border-radius: 8px;
  background: #fff;
  color: var(--c-sgr-text);
  -webkit-user-select: text;
  user-select: text;
}

.sgr-name::placeholder { color: var(--c-sgr-dim); }

.sgr-name:focus {
  outline: none;
  border-color: #13a9c2;
  box-shadow: 0 0 8px rgba(19, 169, 194, 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(90deg, #13a9c2, #ff8a12);
  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: #c9252e;
}

.sgr-status {
  margin: 0;
  font-size: 13px;
  text-align: center;
  color: var(--c-sgr-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(19, 169, 194, 0.07); }

.sgr-row.sgr-row-me {
  background: linear-gradient(90deg, #13a9c2, #ff8a12);
  color: #fff;
}

.sgr-rank {
  width: 2em;
  text-align: right;
  font-weight: bold;
  flex-shrink: 0;
}

.sgr-rank-top1 { color: #c98d1c; }
.sgr-rank-top2 { color: #8a93a6; }
.sgr-rank-top3 { color: #b0703a; }
.sgr-row-me .sgr-rank { color: #fff; }

.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-sgr-line);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(19, 169, 194, 0.06);
  color: var(--c-sgr-text);
  cursor: pointer;
}

.sgr-close:hover { border-color: #13a9c2; }

.sgr-cta {
  margin: 0 0 12px;
  text-align: center;
}

.sgr-cta-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  color: var(--c-gold);
}

.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, #ffd166, #ff9a1f);
  color: #2a1a00;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(255, 154, 31, 0.4);
}

.sgr-cta-btn:hover { filter: brightness(1.08); }

.sgr-cta-link {
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.2);
  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; }
}
