/* ==========================================================================
   ハリネズミの庭 - Hedgehog Garden
   盤面は js/game.js が SVG（1マス = 100 単位）で組み立てる。盤面の部品のクラスは b- / mk- / hint- で始まる
   ========================================================================== */
:root {
  --bg: #eef3df;
  --bg-deep: #dbe6c1;
  --panel: #fffdf6;
  --panel-2: #f5efdf;
  --ink: #3a2c20;
  --ink-sub: #7a6a58;
  --line: #e4d9c0;
  --accent: #d0652a;
  --accent-deep: #a24a16;
  --accent-ink: #ffffff;
  --leaf: #4f8f35;
  --leaf-deep: #3b6f26;
  --danger: #dc3f3f;
  --hint: #ffae1a;
  --wood: #4a3322;
  --shadow: 0 6px 18px rgba(70, 55, 25, 0.13);
  --d0: #4f9a3a;
  --d1: #d9861e;
  --d2: #c43c55;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", "Noto Sans JP", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body {
  min-height: 100dvh;
  overscroll-behavior: none;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, .55) 0 3px, transparent 4px),
    radial-gradient(circle at 78% 64%, rgba(255, 255, 255, .45) 0 2px, transparent 3px),
    radial-gradient(120% 70% at 50% 0%, var(--bg) 40%, var(--bg-deep) 100%);
  background-size: 140px 140px, 110px 110px, auto;
  background-attachment: fixed;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
button:focus-visible, #board:focus-visible, .switch:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
#board:focus { outline: none; }
#board:focus-visible { outline-offset: -2px; border-radius: 14px; }

.hidden { display: none !important; }
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------- 全体の配置 ---------- */
#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
}

/* タイトルだけの帯は縦幅を圧迫するので隠す（ボタンは共通ヘッダーのメニューへ集約済み）。
   h1 と、共通ヘッダーが click() で押す元ボタンは DOM に残すため、display:none ではなく
   スクリーンリーダー向けの不可視にする */
#topbar {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
#logo {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: .04em;
  color: var(--wood);
  white-space: nowrap;
}
.logo-mark { width: 30px; height: 30px; flex: none; }
#topbar-buttons { display: flex; gap: 6px; }
.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 19px;
  line-height: 1;
}
.icon-btn:active { transform: scale(.94); }

/* ---------- ステータス ---------- */
#status-bar {
  flex: none;
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-top: 8px; /* タイトル帯を隠したので、共通ヘッダーとの間を少し空ける */
}
.status-box {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 46px;
  padding: 6px 12px;
  border: 0;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.stage-box {
  flex: 1 1 auto;
  min-width: 0;
  text-align: left;
}
.stage-box:active { transform: scale(.98); }
.diff-badge {
  flex: none;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--d0);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}
.diff-badge[data-d="1"] { background: var(--d1); }
.diff-badge[data-d="2"] { background: var(--d2); }
.stage-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 800;
}
.caret { flex: none; color: var(--ink-sub); font-size: 12px; }
.count-box { flex: none; }
.count-icon { width: 24px; height: 24px; flex: none; }
.time-box { flex: none; flex-direction: column; justify-content: center; gap: 0; min-width: 72px; }
.status-label { font-size: 10px; font-weight: 700; color: var(--ink-sub); line-height: 1.2; }
.status-value {
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  white-space: nowrap;
}
#hog-count.is-full { color: var(--leaf-deep); }
.time-box.is-off #time-count { color: var(--ink-sub); }
.time-flash { animation: time-flash .9s ease; }
@keyframes time-flash {
  0%, 60% { color: var(--danger); transform: scale(1.12); }
  100% { color: inherit; transform: none; }
}

/* ---------- 盤面 ---------- */
#board-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0 8px;
}
#board {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  transition: filter .25s ease;
}
#board-wrap.is-paused #board { filter: blur(14px) saturate(.6); }
.pause-cover {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.pause-cover span {
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255, 253, 246, .92);
  box-shadow: var(--shadow);
  font-weight: 800;
}

/* 盤面の部品（SVG） */
.b-frame { fill: #6b4a30; }
.b-grid { fill: none; stroke: rgba(74, 51, 34, .2); stroke-width: 2; }
.b-border { fill: none; stroke: var(--wood); stroke-width: 6; stroke-linecap: round; }
.b-edge { fill: none; stroke: var(--wood); stroke-width: 7; }
.b-cell { transition: fill .3s ease; }
.b-tex { fill: none; stroke: rgba(255, 255, 255, .5); stroke-width: 3; stroke-linecap: round; pointer-events: none; }
.b-given { fill: none; stroke: rgba(255, 255, 255, .85); stroke-width: 5; stroke-dasharray: 10 8; }
.b-bad { fill: rgba(232, 58, 58, .38); }
.mk-x { fill: none; stroke: #6d4b33; stroke-width: 9; stroke-linecap: round; }
.mk-dot { fill: rgba(90, 60, 35, .34); }
.mk-pop { transform-box: fill-box; transform-origin: 50% 60%; animation: hog-pop .32s cubic-bezier(.2, 1.6, .4, 1); }
.mk-xpop { transform-box: fill-box; transform-origin: 50% 50%; animation: x-pop .18s ease-out; }
.mk-ouch { transform-box: fill-box; transform-origin: 50% 80%; animation: hog-ouch .45s ease; }
.mk-nope { transform-box: fill-box; transform-origin: 50% 80%; animation: hog-nope .35s ease; }
@keyframes hog-pop {
  0% { transform: scale(.3) translateY(18%); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
@keyframes x-pop {
  0% { transform: scale(.4); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
@keyframes hog-ouch {
  0%, 100% { transform: none; }
  20% { transform: translateX(-7%) rotate(-8deg); }
  45% { transform: translateX(6%) rotate(7deg); }
  70% { transform: translateX(-3%) rotate(-3deg); }
}
@keyframes hog-nope {
  0%, 100% { transform: none; }
  30% { transform: rotate(-10deg); }
  65% { transform: rotate(8deg); }
}

.hint-area { fill: rgba(255, 216, 92, .5); pointer-events: none; }
.hint-focus {
  fill: rgba(255, 176, 32, .28);
  stroke: var(--hint);
  stroke-width: 8;
  pointer-events: none;
  animation: hint-pulse 1.1s ease-in-out infinite;
}
@keyframes hint-pulse {
  0%, 100% { stroke-opacity: 1; fill-opacity: 1; }
  50% { stroke-opacity: .35; fill-opacity: .45; }
}
.b-cursor { fill: none; stroke: #2f6fd6; stroke-width: 7; stroke-dasharray: 18 10; pointer-events: none; }

/* クリアの演出 */
.bloom { transform-box: fill-box; transform-origin: 50% 50%; animation: bloom .55s cubic-bezier(.2, 1.5, .4, 1) both; animation-delay: var(--d, 0s); }
@keyframes bloom {
  0% { transform: scale(0) rotate(-60deg); opacity: 0; }
  100% { transform: none; opacity: .95; }
}
.is-win .mk-hog { transform-box: fill-box; transform-origin: 50% 100%; animation: hog-hop .7s ease both; animation-delay: var(--d, 0s); }
@keyframes hog-hop {
  0%, 100% { transform: none; }
  35% { transform: translateY(-22%) scale(1.05, .96); }
  60% { transform: translateY(0) scale(1.08, .9); }
  80% { transform: translateY(-5%); }
}

/* ---------- メッセージ（案内・ヒント） ---------- */
.message {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 54px;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.msg-text {
  flex: 1;
  margin: 0;
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.5;
  color: var(--ink);
}
.message.is-hint { background: #fff5d6; box-shadow: 0 0 0 2px var(--hint) inset, var(--shadow); }
.message.is-error { background: #ffe9e6; box-shadow: 0 0 0 2px var(--danger) inset, var(--shadow); }
.message.is-clear { background: #eaf6dd; box-shadow: 0 0 0 2px var(--leaf) inset, var(--shadow); }
.msg-action {
  flex: none;
  max-width: 44%;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12.5px;
  font-weight: 800;
  line-height: 1.3;
  box-shadow: inset 0 -3px 0 var(--accent-deep);
}
.msg-action:active { transform: scale(.96); }

/* ---------- ツールバー ---------- */
#toolbar {
  flex: none;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}
.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 50px;
  padding: 6px 8px;
  border: 0;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: inset 0 -3px 0 var(--line), var(--shadow);
  font-size: 14px;
  font-weight: 800;
}
.tool-btn:active { transform: translateY(1px) scale(.98); }
.tool-btn:disabled { background: #f3efe4; color: #b3a893; box-shadow: inset 0 -3px 0 #e6dfcd; cursor: default; transform: none; }
.tool-btn:disabled .tool-ico { opacity: .45; }
.tool-ico { font-size: 19px; line-height: 1; }
.tool-txt { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.tool-txt small { font-size: 10px; font-weight: 700; color: var(--ink-sub); }
.tool-txt small:empty { display: none; }
.tool-btn--hint { background: #fff4cf; box-shadow: inset 0 -3px 0 #f1d27c, var(--shadow); }

#footer {
  flex: none;
  padding: 8px 0 6px;
  font-size: 11px;
  line-height: 1.6;
  text-align: center;
  color: var(--ink-sub);
}
#footer a { color: inherit; }

/* ---------- トースト ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--ad-space, 0px) + 96px);
  z-index: 1100;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(58, 44, 32, .92);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
  animation: toast-in .2s ease;
}
@keyframes toast-in {
  0% { opacity: 0; transform: translate(-50%, 8px); }
  100% { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- ダイアログ ---------- */
.overlay {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(40, 32, 18, .45);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade-in .2s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.dialog {
  width: 100%;
  max-width: 400px;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 20px 18px 18px;
  border-radius: 22px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
  animation: pop-in .28s cubic-bezier(.2, 1.3, .4, 1);
}
.dialog:focus { outline: none; }
.dialog--wide { max-width: 540px; }
@keyframes pop-in {
  0% { opacity: 0; transform: scale(.9) translateY(10px); }
  100% { opacity: 1; transform: none; }
}
.dialog-title {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 900;
  text-align: center;
  color: var(--wood);
}
.btn {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 12px;
  padding: 10px 14px;
  border: 0;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 800;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: inset 0 -4px 0 var(--accent-deep); }
.btn-sub { background: var(--panel-2); color: var(--ink); box-shadow: inset 0 -3px 0 var(--line); }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { margin-top: 8px; }

/* ステージ選択 */
.diff-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.diff-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 8px 4px;
  border: 0;
  border-radius: 12px;
  background: var(--panel-2);
  font-size: 14px;
  font-weight: 800;
}
.diff-tab small { font-size: 11px; font-weight: 700; color: var(--ink-sub); }
.diff-tab[aria-selected="true"] { background: var(--d0); color: #fff; }
.diff-tab[data-d="1"][aria-selected="true"] { background: var(--d1); }
.diff-tab[data-d="2"][aria-selected="true"] { background: var(--d2); }
.diff-tab[aria-selected="true"] small { color: rgba(255, 255, 255, .9); }
.diff-desc { margin: 10px 2px 4px; font-size: 12.5px; line-height: 1.6; color: var(--ink-sub); }
.stage-grid { margin-top: 4px; }
.stage-group-title {
  margin: 12px 0 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink-sub);
}
.stage-group-title:first-child { margin-top: 6px; }
.stage-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.stage-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 4px 2px;
  border: 0;
  border-radius: 12px;
  background: var(--panel-2);
  box-shadow: inset 0 -3px 0 var(--line);
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.stage-btn small { font-size: 9.5px; font-weight: 700; color: var(--ink-sub); }
.stage-btn.is-clear { background: #e6f3d6; box-shadow: inset 0 -3px 0 #bcdca0; }
.stage-btn.is-current { outline: 3px solid var(--accent); outline-offset: -1px; }
.stage-btn .st-mark { position: absolute; top: 2px; right: 4px; font-size: 11px; line-height: 1; }
.stage-legend { margin: 12px 0 0; font-size: 12px; color: var(--ink-sub); text-align: center; }

/* クリア */
.result { text-align: center; }
.result-kicker { margin: 0; font-size: 13px; font-weight: 800; color: var(--ink-sub); }
.result-title {
  margin: 2px 0 4px;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: .08em;
  color: var(--leaf-deep);
}
.result-hogs { display: flex; justify-content: center; gap: 4px; margin: 2px 0 8px; }
.result-hogs svg { width: 54px; height: 54px; animation: hog-hop .9s ease infinite; }
.result-hogs svg:nth-child(2) { animation-delay: .15s; width: 62px; height: 62px; }
.result-hogs svg:nth-child(3) { animation-delay: .3s; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.rstat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 4px;
  border-radius: 12px;
  background: var(--panel-2);
}
.rstat-label { font-size: 11px; font-weight: 700; color: var(--ink-sub); }
.rstat-value { font-size: 18px; font-weight: 900; font-variant-numeric: tabular-nums; }
.res-badge { margin: 10px 0 0; font-size: 15px; font-weight: 800; color: #c24474; }
.res-new { margin: 6px 0 0; font-size: 14px; font-weight: 800; color: var(--accent); animation: hint-pulse 1.2s ease-in-out infinite; }

/* 設定 */
.set-list { display: flex; flex-direction: column; gap: 6px; }
.set-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--panel-2);
  cursor: pointer;
}
.set-row--select { flex-wrap: wrap; cursor: default; }
.set-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.set-text b { font-size: 14px; }
.set-text small { font-size: 11.5px; line-height: 1.45; color: var(--ink-sub); }
.switch {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  position: relative;
  width: 50px;
  height: 30px;
  margin: 0;
  border-radius: 999px;
  background: #cfc6b3;
  cursor: pointer;
  transition: background .2s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .2s ease;
}
.switch:checked { background: var(--leaf); }
.switch:checked::after { transform: translateX(20px); }
.seg { display: flex; gap: 4px; padding: 3px; border-radius: 12px; background: #e7dfcb; }
.seg-btn {
  padding: 7px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}
.seg-btn[aria-checked="true"] { background: var(--panel); box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }

/* 遊び方 */
.howto-body { display: flex; gap: 14px; align-items: flex-start; }
.howto-example { flex: none; width: 150px; text-align: center; }
.howto-board { display: block; width: 150px; height: 150px; }
.howto-cap { margin: 4px 0 0; font-size: 11px; color: var(--ink-sub); }
.howto-rules, .howto-ops {
  margin: 0;
  padding-left: 1.2em;
  font-size: 13.5px;
  line-height: 1.65;
}
.howto-rules li, .howto-ops li { margin-bottom: 4px; }
.howto-sub { margin: 14px 0 6px; font-size: 15px; font-weight: 900; color: var(--wood); }
.mini-hog { display: inline-block; width: 22px; height: 22px; margin-right: 3px; vertical-align: -5px; }
.mini-hog svg { width: 100%; height: 100%; }
@media (max-width: 460px) {
  .howto-body { flex-direction: column; align-items: center; }
}

/* ---------- 横向きで背の低い画面（スマホ横持ち）: 盤面を左、操作を右に ---------- */
@media (orientation: landscape) and (max-height: 560px) {
  #app {
    display: grid;
    max-width: 960px;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 330px);
    /* #topbar は隠してあり行を取らないので、ステータス・メッセージ・操作・フッターの4行 */
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    column-gap: 14px;
  }
  #board-wrap { grid-column: 1; grid-row: 1 / -1; padding: 6px 0; }
  #status-bar, #message, #toolbar, #footer { grid-column: 2; }
  #logo { font-size: 17px; }
  .logo-mark { width: 24px; height: 24px; }
  #status-bar { flex-wrap: wrap; gap: 6px; }
  .stage-box { flex-basis: 100%; }
  .status-box { min-height: 40px; }
  .count-box, .time-box { flex: 1 1 0; }
  #message { align-self: center; margin-top: 8px; }
  #toolbar { margin-top: 6px; }
  .tool-btn { min-height: 44px; }
  #footer { padding: 4px 0; font-size: 10px; }
}

/* ---------- 小さな画面 ---------- */
@media (max-height: 640px) and (orientation: portrait) {
  #logo { font-size: 17px; }
  .logo-mark { width: 24px; height: 24px; }
  .status-box { min-height: 40px; padding: 4px 10px; }
  .message { min-height: 46px; padding: 6px 10px; }
  .msg-text { font-size: 12.5px; }
  .tool-btn { min-height: 44px; }
  #board-wrap { padding: 6px 0 4px; }
  #footer { padding: 4px 0; }
}
@media (max-width: 380px) {
  #status-bar { gap: 6px; }
  .status-box { padding-left: 9px; padding-right: 9px; }
  .sl-word { display: none; }
  .stage-label { font-size: 15px; }
  .time-box { min-width: 58px; }
  .count-icon { width: 20px; height: 20px; }
  .tool-btn { font-size: 13px; gap: 4px; padding: 6px 4px; }
  .tool-ico { font-size: 16px; }
  .tool-txt { white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ==========================================================================
   全国ランキング（共通モジュール js/ranking.js の sgr-*）
   ranking.js は見た目を持たないので、各ゲームの CSS で描く
   ========================================================================== */
.sgr-hidden { display: none !important; }

.sgr-overlay {
  position: fixed;
  inset: 0;
  /* 広告枠（2147482000）・共通ヘッダー（2147482500）より上 */
  z-index: 2147483000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-top: calc(16px + var(--sgh-top, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(40, 32, 18, .5);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.sgr-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(420px, 100%);
  max-height: min(82vh, 660px);
  padding: 20px 18px 18px;
  border-radius: 22px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
  animation: pop-in .28s cubic-bezier(.2, 1.3, .4, 1);
}
.sgr-title {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  text-align: center;
  color: var(--wood);
}
.sgr-tabs { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.sgr-tab {
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
}
.sgr-tab-active { background: var(--accent); color: var(--accent-ink); }

.sgr-register {
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--panel-2);
}
.sgr-register-msg {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  color: var(--accent);
}
.sgr-form { display: flex; gap: 8px; }
.sgr-name {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* iOS がフォーカス時に拡大しない大きさ */
}
.sgr-name:focus { outline: none; border-color: var(--accent); }
.sgr-submit {
  flex: none;
  padding: 9px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  box-shadow: inset 0 -3px 0 var(--accent-deep);
}
.sgr-submit:disabled { opacity: .5; cursor: default; }
.sgr-error { margin: 6px 0 0; font-size: 12px; font-weight: 700; color: var(--danger); }

.sgr-status { margin: 0; font-size: 13px; text-align: center; color: var(--ink-sub); }
.sgr-list {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.sgr-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 14px;
}
.sgr-row:nth-child(even) { background: var(--panel-2); }
.sgr-row.sgr-row-me { background: var(--accent); color: var(--accent-ink); }
.sgr-rank {
  flex: none;
  width: 2em;
  font-weight: 800;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
/* 1〜3位はメダルの絵文字（ranking.js が入れる）を中央に大きめに */
.sgr-rank-top1, .sgr-rank-top2, .sgr-rank-top3 { text-align: center; font-size: 17px; }
.sgr-row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sgr-row-score {
  flex: none;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.sgr-row.sgr-row-me .sgr-row-score { color: inherit; }
.sgr-close {
  min-height: 46px;
  padding: 10px;
  border: 0;
  border-radius: 14px;
  background: var(--panel-2);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 800;
}
.sgr-close:active, .sgr-submit:active, .sgr-cta-btn:active { transform: scale(.97); }

/* 結果ダイアログに差し込まれる「ランキングに登録」 */
.sgr-cta {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--panel-2);
  text-align: center;
}
.sgr-cta-msg { margin: 0 0 8px; font-size: 14px; font-weight: 800; color: var(--accent); }
.sgr-cta-btn {
  min-height: 42px;
  padding: 9px 18px;
  border: 0;
  border-radius: 12px;
  background: #ffc531;
  color: #4a3200;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  box-shadow: inset 0 -3px 0 #d89b0c;
}
.sgr-cta-link {
  padding: 6px;
  border: 0;
  background: none;
  color: var(--ink-sub);
  font: inherit;
  font-size: 13px;
  text-decoration: underline;
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / 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; }
}
