/* サウンドメモリー - Sound Memory */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg1: #0d1026;
  --bg2: #1a1f45;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #eef0ff;
  --text-dim: #9aa0c8;
  --accent: #6c7bff;
  --accent2: #b56cff;
  /* SGRanking 共通モジュール用 */
  --accent3: #ffe14d;
  --bg-mid: #171c40;
  --hit: #ff7d8a;
  --line: rgba(255, 255, 255, 0.12);
  --font-jp: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background: radial-gradient(120% 100% at 50% 0%, var(--bg2) 0%, var(--bg1) 65%);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

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

/* ---------- ヘッダー ---------- */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0 10px;
}

#logo-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#logo {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: linear-gradient(90deg, #8ea2ff, #d78bff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
}

#diff-badge {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

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

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  font-size: 17px;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--text);
}

.icon-btn:active { transform: scale(0.94); }

/* ---------- ステータスバー ---------- */

#status-bar {
  display: flex;
  gap: 8px;
}

.status-box {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 7px 10px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}

.status-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
}

.status-value {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ---------- ステージ ---------- */

#stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 0;
}

#message {
  font-size: 17px;
  font-weight: 800;
  min-height: 1.5em;
  letter-spacing: 0.04em;
}

.msg-watch { color: #ffd76c; }
.msg-input { color: #7dffb8; }
.msg-clear { color: #8ea2ff; }
.msg-over  { color: #ff7d8a; }

/* ---------- ボタン盤面 ---------- */

#board-wrap {
  position: relative;
  width: min(100%, 420px, 58dvh);
}

#board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), 1fr);
  gap: clamp(8px, 2.5vw, 14px);
}

.pad {
  aspect-ratio: 1;
  border: none;
  border-radius: 22%;
  cursor: pointer;
  background:
    radial-gradient(115% 115% at 30% 25%,
      hsl(var(--h) 72% 62% / 0.95) 0%,
      hsl(var(--h) 78% 42%) 55%,
      hsl(var(--h) 82% 30%) 100%);
  box-shadow:
    inset 0 2px 6px rgba(255, 255, 255, 0.35),
    inset 0 -4px 10px rgba(0, 0, 0, 0.45),
    0 4px 14px rgba(0, 0, 0, 0.45);
  filter: brightness(0.62) saturate(0.85);
  transition: filter 0.12s ease, transform 0.08s ease, box-shadow 0.12s ease;
}

.pad.lit {
  filter: brightness(1.25) saturate(1.15);
  transform: scale(0.97);
  box-shadow:
    inset 0 2px 6px rgba(255, 255, 255, 0.5),
    inset 0 -4px 10px rgba(0, 0, 0, 0.3),
    0 0 26px hsl(var(--h) 90% 60% / 0.85),
    0 0 60px hsl(var(--h) 90% 55% / 0.45);
}

.pad.wrong {
  animation: shake 0.4s ease;
  filter: brightness(0.9) saturate(0.2);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

#board.locked .pad { cursor: default; }

#board:not(.locked) .pad:active { transform: scale(0.95); }

/* ---------- スタート画面 ---------- */

#start-overlay {
  position: absolute;
  inset: -6px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 16, 38, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 20px;
  z-index: 5;
}

#start-overlay.hidden { display: none; }

#start-box {
  width: 100%;
  max-width: 340px;
  padding: 12px;
  text-align: center;
}

#start-lead {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 14px;
}

.diff-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.diff-btn {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 6px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
}

.diff-btn small {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
}

.diff-btn.selected {
  border-color: var(--accent);
  background: rgba(108, 123, 255, 0.18);
  box-shadow: 0 0 0 1px var(--accent);
}

.diff-btn.selected small { color: #aab4ff; }

/* ---------- 汎用ボタン ---------- */

.btn {
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 800;
  padding: 12px 18px;
  cursor: pointer;
  color: #fff;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 4px 16px rgba(108, 123, 255, 0.4);
  width: 100%;
}

.btn-sub {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
}

/* ---------- 結果オーバーレイ ---------- */

#result-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 7, 20, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 20;
  padding: 16px;
}

#result-overlay.hidden { display: none; }

#result-box {
  width: 100%;
  max-width: 360px;
  background: linear-gradient(180deg, #232a5c, #171c40);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 22px 18px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

#result-title {
  font-size: 22px;
  font-weight: 900;
  margin-bottom: 6px;
}

#result-sub {
  color: #ffd76c;
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 4px;
}

#result-sub.hidden { display: none; }

#result-main {
  font-size: 18px;
  font-weight: 800;
  margin: 10px 0 14px;
}

#result-main span {
  font-size: 34px;
  color: #8ea2ff;
  font-variant-numeric: tabular-nums;
}

#result-stats {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.rstat {
  flex: 1;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rstat-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
}

.rstat span:last-child {
  font-size: 14px;
  font-weight: 800;
}

#result-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---------- メニューモーダル ---------- */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 7, 20, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 30;
  padding: 16px;
}

.modal.hidden { display: none; }

.modal-box {
  width: 100%;
  max-width: 400px;
  max-height: min(86dvh, 640px);
  overflow-y: auto;
  background: linear-gradient(180deg, #232a5c, #171c40);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 20px 18px;
  -webkit-overflow-scrolling: touch;
}

.modal-title {
  font-size: 18px;
  font-weight: 900;
  text-align: center;
  margin-bottom: 14px;
}

.menu-section { margin-bottom: 18px; }

.menu-caption {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.menu-note {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
}

#best-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.best-row {
  display: flex;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 700;
}

.best-row span:last-child { color: #8ea2ff; }

.howto {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 12.5px;
  line-height: 1.6;
  color: #c9cdea;
}

.howto li {
  padding-left: 16px;
  position: relative;
}

.howto li::before {
  content: "●";
  position: absolute;
  left: 0;
  top: 0;
  font-size: 8px;
  line-height: 2.4;
  color: var(--accent);
}

.howto b { color: var(--text); }

#btn-close-menu { width: 100%; }

/* ---------- フッター ---------- */

#footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.7;
  padding-top: 12px;
}

#footer a {
  color: #8ea2ff;
  text-decoration: none;
}

#footer a:hover { text-decoration: underline; }

/* ---------- 小さい画面 ---------- */

@media (max-height: 640px) {
  #logo { font-size: 17px; }
  #board-wrap { width: min(100%, 420px, 52dvh); }
  #message { font-size: 15px; }
}
/* ---------- 全国ランキング（SGRanking 共通モジュール） ---------- */

.sgr-hidden { display: none !important; }

.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(9, 12, 34, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, #1c2158 0%, var(--bg-mid) 100%);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 30px rgba(62, 201, 255, 0.12);
}

.sgr-title {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  text-align: center;
}

.sgr-tabs {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.sgr-tab {
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  background: rgba(154, 163, 208, 0.16);
  color: var(--text);
  cursor: pointer;
}

.sgr-tab-active {
  background: var(--accent);
  color: #06122a;
}

.sgr-register-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  color: var(--accent3);
}

.sgr-form {
  display: flex;
  gap: 8px;
}

.sgr-name {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-family: var(--font-jp);
  padding: 8px 10px;
  border: 2px solid rgba(154, 163, 208, 0.45);
  border-radius: 8px;
  background: rgba(13, 16, 48, 0.65);
  color: var(--text);
}

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

.sgr-name:focus {
  outline: none;
  border-color: var(--accent);
}

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: linear-gradient(180deg, #8fe0ff 0%, var(--accent) 60%, #1fa8e6 100%);
  color: #06122a;
  cursor: pointer;
}

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

.sgr-submit:disabled {
  opacity: 0.5;
  cursor: default;
}

.sgr-error {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--hit);
}

.sgr-status {
  margin: 0;
  font-size: 13px;
  text-align: center;
  color: var(--text-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(154, 163, 208, 0.1); }

.sgr-row.sgr-row-me {
  background: var(--accent);
  color: #06122a;
}

.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;
  flex-shrink: 0;
}

.sgr-close {
  border: 1px solid rgba(154, 163, 208, 0.4);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(154, 163, 208, 0.16);
  color: var(--text);
  cursor: pointer;
}

.sgr-close:hover { background: rgba(154, 163, 208, 0.28); }

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

.sgr-cta-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  color: var(--accent3);
  text-shadow: 0 0 12px rgba(255, 225, 77, 0.4);
}

.sgr-cta-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 15px;
  font-weight: 800;
  font-family: var(--font-jp);
  background: linear-gradient(180deg, #fff0a0 0%, var(--accent3) 55%, #ffc93e 100%);
  color: #3a2c00;
  cursor: pointer;
  box-shadow: 0 4px 0 #b8892a, 0 8px 22px rgba(255, 225, 77, 0.35);
  transition: transform 0.15s, box-shadow 0.15s;
}

.sgr-cta-btn:active {
  transform: scale(0.94);
  box-shadow: 0 2px 0 #b8892a, 0 4px 12px rgba(255, 225, 77, 0.35);
}

.sgr-cta-link {
  border: none;
  background: none;
  padding: 6px;
  font-size: 13px;
  color: var(--text-dim);
  text-decoration: underline;
  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; }
}
