/* ==========================================================================
   線路つなぎ - Rail Puzzle
   テーマ（body[data-theme]）: rail = 線路 / pipe = 水道管 / circuit = 電子回路
   盤面そのものは js/game.js が canvas に描く（色は JS 側の THEMES と揃える）
   ========================================================================== */
:root {
  --bg: #f4efe3;
  --bg-deep: #e9e0cc;
  --panel: #fffdf8;
  --panel-2: #f7f1e4;
  --ink: #2f3540;
  --ink-sub: #6f6a5e;
  --line: #e2d8c3;
  --accent: #e0573a;
  --accent-deep: #b73f25;
  --accent-ink: #ffffff;
  --ok: #23a35a;
  --heart: #ec4a55;
  --star: #ffc531;
  --star-off: #d9d1bf;
  --shadow: 0 6px 18px rgba(80, 60, 30, 0.12);
  --tile-bg: #fbe9d6;
  --tile-ink: #7a4a22;
  color-scheme: light;
}
body[data-theme="pipe"] {
  --bg: #e6f1f5;
  --bg-deep: #d2e5ec;
  --panel: #fbfeff;
  --panel-2: #eef7fa;
  --ink: #23384a;
  --ink-sub: #5d7383;
  --line: #cfe0e8;
  --accent: #1f8fc0;
  --accent-deep: #146b92;
  --star-off: #c8d8df;
  --shadow: 0 6px 18px rgba(20, 70, 100, 0.12);
}
body[data-theme="circuit"] {
  --bg: #0f231c;
  --bg-deep: #0a1914;
  --panel: #173329;
  --panel-2: #1d3d31;
  --ink: #e4f6ec;
  --ink-sub: #92b9a7;
  --line: #2a4d40;
  --accent: #e8b53c;
  --accent-deep: #b78a1f;
  --accent-ink: #1b1305;
  --ok: #6ee69d;
  --star-off: #3c5b4f;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

*, *::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;
  transition: background-color .35s ease, color .35s ease;
  background-image: radial-gradient(120% 70% at 50% 0%, var(--bg) 40%, var(--bg-deep) 100%);
  background-attachment: fixed;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
button:focus-visible, canvas:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

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

#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 640px;
  height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  min-height: 300px;
  margin: 0 auto;
  padding: 0 max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px));
}

/* ---------- ヘッダー ---------- */
/* タイトルだけの帯は縦幅を圧迫するので隠す（ボタンは共通ヘッダーのメニューへ集約済み）。
   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 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: .04em;
}
.logo-mark {
  display: inline-block;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 26 26'%3E%3Cg fill='none' stroke='%23fff' stroke-linecap='round'%3E%3Cpath d='M9 26V17a8 8 0 0 1 8-8h9' stroke-width='2.4'/%3E%3Cpath d='M4 26V17a13 13 0 0 1 13-13h9' stroke-width='2.4'/%3E%3C/g%3E%3C/svg%3E") center / 100% no-repeat;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .18);
}
#topbar-buttons { display: flex; gap: 6px; }
.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 18px;
  line-height: 1;
}
.icon-btn:active { transform: scale(.94); }

/* ---------- ステータスバー ---------- */
#status-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: stretch;
  gap: 8px;
  margin: 6px 0 2px;
}
.status-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 4px 12px;
  border: 0;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: left;
}
.status-label {
  display: block;
  font-size: 11px;
  color: var(--ink-sub);
  line-height: 1.2;
}
.status-value {
  display: block;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stage-box { min-width: 0; padding-right: 8px; gap: 7px; }
.stage-box .status-value, .stage-box .status-label { overflow: hidden; text-overflow: ellipsis; }
.stage-box:active { transform: scale(.97); }
.theme-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--panel-2);
  font-size: 18px;
}
.stage-text { min-width: 0; flex: 1; }
.stage-caret { color: var(--ink-sub); font-size: 12px; }
.time-box { flex-direction: column; align-items: center; justify-content: center; gap: 0; min-width: 76px; text-align: center; }

.hearts { gap: 3px; padding: 4px 9px; justify-content: center; }
.heart {
  display: inline-block;
  width: 21px;
  height: 19px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 22'%3E%3Cpath d='M12 21.2 2.6 12.3A5.9 5.9 0 0 1 12 4.2a5.9 5.9 0 0 1 9.4 8.1Z' fill='%23ec4a55' stroke='%23b8323c' stroke-width='1.4'/%3E%3Cpath d='M6.8 6.4a3.3 3.3 0 0 0-2.2 3' fill='none' stroke='%23fff' stroke-width='1.6' stroke-linecap='round' opacity='.75'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform .2s ease, opacity .2s ease, filter .2s ease;
}
.heart.lost {
  filter: grayscale(1);
  opacity: .28;
}
.heart.breaking { animation: heart-break .55s ease; }
@keyframes heart-break {
  0% { transform: scale(1); filter: none; opacity: 1; }
  30% { transform: scale(1.35) rotate(-10deg); }
  60% { transform: scale(.8) rotate(8deg); }
  100% { transform: scale(1); }
}
.hearts.shake { animation: shake .35s ease; }
@keyframes shake {
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

/* ---------- 盤面 ---------- */
#board-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 0;
}
#board {
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  border-radius: 12px;
}
#coach {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(92%, 420px);
  padding: 9px 14px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
  box-shadow: var(--shadow);
  pointer-events: none;
  animation: coach-in .35s ease;
}
@keyframes coach-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- 操作ツール ---------- */
#tools {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 2px 0 4px;
}
.tool-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 54px;
  padding: 6px 8px;
  border: 0;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-weight: 700;
  font-size: 14px;
}
.tool-btn:active { transform: scale(.96); }
.tool-btn:disabled { opacity: .45; cursor: default; transform: none; }
.tool-icon { font-size: 19px; line-height: 1; }
.tool-label { font-size: 12px; line-height: 1.2; white-space: nowrap; }
.tool-icon--x { font-weight: 900; color: var(--ink-sub); }
.tool-state {
  position: absolute;
  top: 6px;
  right: 8px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 10px;
  color: var(--ink-sub);
}
#btn-xmode[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}
#btn-xmode[aria-pressed="true"] .tool-icon--x { color: var(--accent-ink); }
#btn-xmode[aria-pressed="true"] .tool-state { background: rgba(255, 255, 255, .25); color: var(--accent-ink); }

/* ---------- フッター ---------- */
#footer {
  padding: 4px 0 6px;
  font-size: 11px;
  line-height: 1.6;
  text-align: center;
  color: var(--ink-sub);
}
#footer a { color: inherit; }

/* ---------- オーバーレイ・ダイアログ ---------- */
.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: 16px;
  background: rgba(20, 18, 14, .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;
  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--wide { max-width: 560px; }
@keyframes pop-in {
  from { opacity: 0; transform: scale(.9) translateY(10px); }
  to { opacity: 1; transform: none; }
}
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.dialog-title {
  margin: 0 0 12px;
  font-size: 19px;
  font-weight: 800;
}
.dialog-head .dialog-title { margin: 0; }

.btn {
  display: block;
  min-height: 46px;
  padding: 10px 16px;
  border: 0;
  border-radius: 14px;
  font-weight: 800;
  font-size: 15px;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: inset 0 -3px 0 var(--accent-deep);
}
.btn-sub {
  background: var(--panel-2);
  color: var(--ink);
}
.btn-wide { width: 100%; margin-top: 8px; }
.dialog-buttons { display: grid; gap: 8px; margin-top: 16px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.dialog--small { max-width: 340px; text-align: center; }
.confirm-text { margin: 0 0 16px; font-size: 14px; line-height: 1.7; color: var(--ink-sub); }
#btn-hint.armed { background: #ffe9a8; color: #6b4a00; }
#btn-hint.next { background: var(--accent); color: var(--accent-ink); }

/* ---------- 結果 ---------- */
#result-box, #over-box { text-align: center; }
.result-stage { font-size: 13px; font-weight: 700; color: var(--ink-sub); }
.result-title {
  margin: 2px 0 8px;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: .06em;
  color: var(--accent);
}
.result-title--sad { font-size: 22px; color: var(--ink); }
.result-stars { display: flex; justify-content: center; gap: 6px; margin: 4px 0 2px; }
.rstar {
  width: 52px;
  height: 50px;
  background: var(--star-off);
  clip-path: polygon(50% 0%, 61.8% 35%, 98% 35.4%, 68.9% 57.2%, 79.4% 91.5%, 50% 70.6%, 20.6% 91.5%, 31.1% 57.2%, 2% 35.4%, 38.2% 35%);
}
.rstar:nth-child(2) { transform: translateY(-8px) scale(1.08); }
.rstar.on { background: var(--star); }
.rstar.pop { animation: star-pop .45s cubic-bezier(.2, 1.6, .4, 1) both; }
.rstar:nth-child(2).pop { animation-name: star-pop-mid; }
@keyframes star-pop {
  from { transform: scale(0) rotate(-40deg); }
  to { transform: scale(1) rotate(0); }
}
@keyframes star-pop-mid {
  from { transform: translateY(-8px) scale(0) rotate(-40deg); }
  to { transform: translateY(-8px) scale(1.08) rotate(0); }
}
.result-reason { min-height: 18px; font-size: 12px; color: var(--ink-sub); }
.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 12px;
}
.rstat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 4px;
  border-radius: 12px;
  background: var(--panel-2);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.rstat-label { font-size: 11px; font-weight: 600; color: var(--ink-sub); }
.result-note {
  margin: 12px 0 0;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--panel-2);
  font-size: 13px;
  font-weight: 700;
}
.over-hearts { display: flex; justify-content: center; gap: 6px; margin-bottom: 6px; }
.over-hearts .heart { width: 30px; height: 28px; filter: grayscale(1); opacity: .35; }
.over-text { margin: 4px 0 0; font-size: 13px; line-height: 1.7; color: var(--ink-sub); }

/* ---------- ステージ選択 ---------- */
.stars-total {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.stars-total small { color: var(--ink-sub); font-weight: 600; }
.star-mini {
  display: inline-block;
  width: 14px;
  height: 13px;
  background: var(--star-off);
  clip-path: polygon(50% 0%, 61.8% 35%, 98% 35.4%, 68.9% 57.2%, 79.4% 91.5%, 50% 70.6%, 20.6% 91.5%, 31.1% 57.2%, 2% 35.4%, 38.2% 35%);
}
.star-mini.on { background: var(--star); }
.stage-list { display: grid; gap: 14px; }
.stage-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 2px 6px;
  font-size: 13px;
  font-weight: 800;
}
.stage-group-head small { font-weight: 600; color: var(--ink-sub); }
.stage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 6px;
}
.stage-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  aspect-ratio: 1;
  padding: 4px 2px;
  border: 0;
  border-radius: 14px;
  font-weight: 800;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .1);
}
.stage-tile .tile-stars { display: flex; gap: 1px; }
.stage-tile .star-mini { width: 11px; height: 10px; background: rgba(0, 0, 0, .14); }
.stage-tile .star-mini.on { background: var(--star); }
.stage-tile.t-rail { background: #fbe4cd; color: #7a421a; }
.stage-tile.t-pipe { background: #d5edf6; color: #15597a; }
.stage-tile.t-circuit { background: #1d4a3b; color: #d6f5e4; }
.stage-tile.t-circuit .star-mini { background: rgba(255, 255, 255, .18); }
.stage-tile.t-circuit .star-mini.on { background: var(--star); }
.stage-tile.current { outline: 3px solid var(--accent); outline-offset: 1px; }
.stage-tile.locked {
  background: var(--panel-2);
  color: var(--ink-sub);
  opacity: .55;
  cursor: default;
  box-shadow: none;
}
.stage-tile.locked .tile-lock { font-size: 12px; }
.stage-tile:not(.locked):active { transform: scale(.94); }

/* ---------- メニュー ---------- */
.menu-section {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.menu-section:first-of-type { border-top: 0; padding-top: 0; }
.menu-section .btn-wide:first-child { margin-top: 0; }
.menu-caption {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink-sub);
}
.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  font-size: 14px;
}
.toggle {
  position: relative;
  flex: none;
  width: 50px;
  height: 30px;
  border: 0;
  border-radius: 15px;
  background: var(--star-off);
  transition: background .2s ease;
}
.toggle .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .2s ease;
}
.toggle.on { background: var(--ok); }
.toggle.on .knob { transform: translateX(20px); }
.record-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.record {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 4px;
  border-radius: 12px;
  background: var(--panel-2);
  text-align: center;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.record-label { font-size: 11px; font-weight: 600; color: var(--ink-sub); }

.howto {
  margin: 0;
  padding-left: 1.2em;
  font-size: 14px;
  line-height: 1.75;
}
.howto li + li { margin-top: 2px; }
.howto-note { margin: 10px 0 0; font-size: 12px; line-height: 1.7; color: var(--ink-sub); }

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

/* 横長の画面（PC・横向きスマホ）では盤面を優先する */
@media (max-height: 560px) {
  #logo { font-size: 17px; }
  .icon-btn { width: 36px; height: 36px; }
  .status-box { min-height: 40px; }
  .tool-btn { min-height: 44px; flex-direction: row; gap: 6px; }
  .tool-state { position: static; }
  #footer { display: none; }
}

/* 横向きのスマホ: 盤面を左、ステータスと操作を右の列に並べる */
@media (orientation: landscape) and (max-height: 560px) {
  #app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(200px, 250px);
    /* #topbar は見えない形にして流れから外したので、行はステータス・余白・操作の3つ */
    grid-template-rows: auto minmax(0, 1fr) auto;
    column-gap: 14px;
    max-width: 980px;
  }
  #board-wrap { grid-column: 1; grid-row: 1 / span 3; overflow: hidden; }
  #status-bar { grid-column: 2; grid-row: 1; grid-template-columns: 1fr 1fr; }
  .stage-box { grid-column: 1 / -1; }
  .time-box { flex-direction: row; justify-content: center; align-items: center; gap: 8px; min-width: 0; min-height: 34px; padding: 4px 10px; }
  #tools { grid-column: 2; grid-row: 3; margin-bottom: 8px; }
  .tool-btn { flex-direction: column; gap: 2px; }
  .tool-state { position: absolute; }
}

@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(20, 18, 14, .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;
}
.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: #e23d47; }
body[data-theme="circuit"] .sgr-error { color: #ff8a92; }

.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; }
}
