/* ぐるぐるペイント - Ring Paint */

:root {
  --bg: #15122b;
  --bg-deep: #0d0b1c;
  --card: #221d45;
  --card-line: #3a3366;
  --ink: #1a1433;
  --text: #ffffff;
  --text-dim: #bdb6e0;
  --paper: #fffaf3;
  --pink: #ff4f8b;
  --pink-hi: #ffb0cb;
  --cyan: #22d3ee;
  --yellow: #ffd23f;
  --lime: #7ee05a;
  --red: #ff4b5c;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg-deep);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(ellipse at 50% 0%, #2a1f55 0%, var(--bg) 45%, var(--bg-deep) 100%) fixed;
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font-family: inherit; }
.hidden { display: none !important; }

#app {
  min-height: calc(100vh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  min-height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--card-line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
.icon-btn:hover { border-color: var(--pink); }
.icon-btn:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

/* ===================== ホーム ===================== */

#screen-home {
  max-width: 560px;
  margin: 0 auto;
  padding: 14px max(16px, env(safe-area-inset-right)) calc(18px + var(--ad-space, 0px)) max(16px, env(safe-area-inset-left));
}

#home-head { position: relative; text-align: center; padding-top: 6px; }
#home-head-btns {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  min-height: 0;
}

#logo-kicker {
  display: inline-block;
  margin: 6px 0 0;
  padding: 3px 14px;
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.04em;
  transform: rotate(-2deg);
}

#logo {
  margin: 8px 0 4px;
  font-size: clamp(40px, 12vw, 64px);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: 0.02em;
}
#logo span { display: inline-block; }
.logo-a {
  color: var(--cyan);
  text-shadow: 3px 3px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink), 5px 6px 0 rgba(34, 211, 238, 0.25);
  transform: rotate(-3deg);
}
.logo-b {
  color: var(--pink);
  text-shadow: 3px 3px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink), 5px 6px 0 rgba(255, 79, 139, 0.3);
  transform: rotate(2deg);
}

#tagline { margin: 6px 0 0; font-size: 14px; color: var(--text-dim); }
#tagline b { color: var(--text); }

#home-main { margin-top: 10px; display: flex; flex-direction: column; gap: 14px; }

#demo-wrap {
  width: min(300px, 78vw);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border-radius: 50%;
  position: relative;
}
#demo {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.start-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: min(340px, 100%);
  margin: 0 auto;
  padding: 14px 18px 10px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: linear-gradient(180deg, #ff6a9e 0%, var(--pink) 60%, #e23674 100%);
  color: #fff;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-shadow: 2px 2px 0 rgba(26, 20, 51, 0.55);
  box-shadow: 0 5px 0 var(--ink), 0 10px 24px rgba(255, 79, 139, 0.35);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.start-btn:hover { transform: translateY(-1px); }
.start-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink), 0 4px 12px rgba(255, 79, 139, 0.3); }
.start-btn:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
.best-chip {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  padding: 1px 10px;
  border-radius: 999px;
  background: rgba(26, 20, 51, 0.35);
  text-shadow: none;
}

.card {
  background: var(--card);
  border: 2px solid var(--card-line);
  border-radius: 18px;
  padding: 14px 16px 16px;
}
.card-title { margin: 0 0 8px; font-size: 18px; font-weight: 900; color: var(--yellow); }

.howto { margin: 0; padding-left: 1.3em; font-size: 14px; color: var(--text-dim); }
.howto li { margin: 4px 0; }
.howto b { color: var(--text); }

.zukan { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.zukan-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
}
.zukan-icon {
  flex: 0 0 56px;
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: radial-gradient(circle at 50% 70%, #3a3366 0%, #1b1738 70%);
}
.zukan-text { display: flex; flex-direction: column; min-width: 0; }
.zukan-name { font-size: 14px; color: var(--text); }
.zukan-desc { font-size: 12.5px; color: var(--text-dim); line-height: 1.5; }

#footer {
  margin-top: 18px;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
}
#footer a { color: var(--text); }

/* ===================== ゲーム画面 ===================== */

#screen-game {
  position: relative;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px max(12px, env(safe-area-inset-right)) 4px max(12px, env(safe-area-inset-left));
}
#hud .icon-btn { width: 38px; height: 38px; font-size: 16px; }
#hud-stage {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  white-space: nowrap;
}
#hud-stage b { font-size: 18px; color: var(--text); }
#hud-score {
  flex: 1;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}
.hud-label { font-size: 11px; font-weight: 900; color: var(--text-dim); letter-spacing: 0.08em; }
#hud-score-val {
  font-size: 22px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--yellow);
  text-shadow: 2px 2px 0 var(--ink);
}
#hud-lives { display: flex; gap: 1px; font-size: 18px; line-height: 1; white-space: nowrap; }
.heart { color: var(--pink); text-shadow: 1px 1px 0 var(--ink); }
.heart.empty { color: rgba(255, 255, 255, 0.18); text-shadow: none; }

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  outline: none;
  touch-action: none;
  cursor: pointer;
}
#cv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#hint {
  flex: 0 0 auto;
  padding: 4px 12px 10px;
  text-align: center;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-dim);
}

/* ステージクリア（リングの中央に出す） */
#clear-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(250px, 62%);
  transform: translate(-50%, -50%);
  padding: 12px 12px 10px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 6px 0 var(--ink), 0 12px 30px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
#clear-panel.pop { animation: clear-pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
@keyframes clear-pop {
  from { transform: translate(-50%, -50%) scale(0.4); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
#clear-stage { font-size: 19px; font-weight: 900; color: var(--pink); letter-spacing: 0.02em; }
#clear-list { list-style: none; margin: 6px 0 4px; padding: 0; font-size: 13px; }
#clear-list li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 4px; border-bottom: 1px dashed rgba(26, 20, 51, 0.15); }
#clear-list li b { font-variant-numeric: tabular-nums; }
#clear-list li.good b { color: #1f9d55; }
#clear-next { font-size: 11px; font-weight: 800; color: rgba(26, 20, 51, 0.55); margin-top: 4px; }

/* 一時停止 */
#pause-ov {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 8, 24, 0.66);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  cursor: default;
}
#pause-box {
  width: min(280px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 16px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 6px 0 var(--ink);
}
#pause-title { margin: 0 0 2px; font-size: 20px; font-weight: 900; }

.btn {
  display: block;
  width: 100%;
  padding: 11px 14px;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 3px 0 var(--ink);
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.btn-primary { background: var(--pink); color: #fff; }
.btn-sub { background: #fff; color: var(--ink); }

/* ===================== 結果・遊び方 ===================== */

#result-overlay,
#howto-overlay {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 8, 24, 0.72);
  overflow-y: auto;
}
#result-box,
#howto-box {
  width: min(380px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 18px 16px 16px;
  border: 3px solid var(--ink);
  border-radius: 20px;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 6px 0 var(--ink);
  animation: box-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes box-in {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
#result-kicker { font-size: 13px; font-weight: 900; letter-spacing: 0.16em; color: rgba(26, 20, 51, 0.55); }
#result-title { font-size: 22px; font-weight: 900; color: var(--pink); }
#result-score { margin: 2px 0; }
#result-value { font-size: 44px; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.1; }
.result-unit { font-size: 16px; font-weight: 900; margin-left: 4px; }
#result-best {
  display: inline-block;
  margin: 2px 0 4px;
  padding: 2px 12px;
  border-radius: 999px;
  background: var(--yellow);
  font-size: 13px;
  font-weight: 900;
  animation: best-blink 1s ease-in-out infinite;
}
@keyframes best-blink { 50% { transform: scale(1.06); } }
#result-list { list-style: none; margin: 8px 0 12px; padding: 0; font-size: 14px; text-align: left; }
#result-list li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 6px; border-bottom: 1px dashed rgba(26, 20, 51, 0.18); }
#result-list li b { font-variant-numeric: tabular-nums; }
#result-buttons { display: flex; gap: 10px; }
#result-buttons .btn { flex: 1; }

#howto-box { text-align: left; }
#howto-box h2 { margin: 0 0 8px; text-align: center; font-size: 20px; }
#howto-box .howto { color: rgba(26, 20, 51, 0.8); margin-bottom: 14px; }
#howto-box .howto b { color: var(--ink); }

/* 低い画面（横向きのスマホ） */
@media (max-height: 460px) {
  #hud { padding-top: 4px; }
  #hint { display: none; }
  #clear-panel { padding: 8px; }
  #clear-list { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  #clear-panel.pop, #result-box, #howto-box, #result-best { animation: none; }
}

/* ---------- 全国ランキング（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(10, 8, 24, 0.7);
}
.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 18px 16px;
  box-shadow: 0 6px 0 var(--ink);
}
.sgr-title { margin: 0; font-size: 20px; font-weight: 900; text-align: center; }
.sgr-tabs { display: flex; gap: 6px; justify-content: center; }
.sgr-tab {
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 5px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.sgr-tab-active { background: var(--yellow); }
.sgr-register-msg { margin: 0 0 6px; font-size: 14px; font-weight: 800; color: var(--pink); text-align: center; }
.sgr-form { display: flex; gap: 8px; }
.sgr-name {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 16px;
  padding: 8px 10px;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
.sgr-name:focus { outline: 3px solid var(--yellow); outline-offset: 0; }
.sgr-submit {
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 900;
  background: var(--pink);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--ink);
}
.sgr-submit:disabled { opacity: 0.5; cursor: default; }
.sgr-error { margin: 4px 0 0; font-size: 12px; font-weight: 700; color: var(--red); }
.sgr-status { margin: 0; font-size: 13px; color: rgba(26, 20, 51, 0.6); text-align: center; }
.sgr-list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  border-top: 2px dashed rgba(26, 20, 51, 0.25);
}
.sgr-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; font-size: 14px; }
.sgr-row:nth-child(even) { background: rgba(255, 79, 139, 0.08); }
.sgr-row.sgr-row-me { background: var(--yellow); font-weight: 800; }
.sgr-rank { width: 2em; text-align: right; font-weight: 900; flex-shrink: 0; }
.sgr-row-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sgr-row-score { font-weight: 900; color: var(--pink); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.sgr-row.sgr-row-me .sgr-row-score { color: var(--ink); }
.sgr-close {
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  padding: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 900;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 2px 0 var(--ink);
}
.sgr-close:active, .sgr-cta-btn:active { transform: translateY(2px); box-shadow: 0 0 0 var(--ink); }
.sgr-cta { margin: 0 0 12px; text-align: center; }
.sgr-cta-msg { margin: 0 0 6px; font-size: 14px; font-weight: 900; color: var(--pink); }
.sgr-cta-btn {
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 900;
  background: var(--yellow);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
}
.sgr-cta-link {
  border: none;
  background: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  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; }
}
