/* グミドロップス - Gummy Drops */

:root {
  --color-bg: #fff6fa;
  --color-text: #5c4457;
  --color-text-light: #fff;
  --color-accent: #ff7fa8;
  --color-accent-hover: #f96d9a;
  --color-cell: #ffe4ef;
  --color-board: #ffd1e3;
  --color-panel: #ffffff;
}

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

html {
  height: 100%;
}

body {
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  background: linear-gradient(160deg, #ffeef6 0%, #fff6ee 55%, #e9f4ff 100%);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

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

/* ---------- ヘッダー ---------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 2px 8px;
}

.title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: linear-gradient(120deg, #ff7fa8, #ffa03c 45%, #6ec8ff 90%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: #ff7fa8; /* フォールバック */
}

.scores {
  display: flex;
  gap: 8px;
}

.score-box {
  background: var(--color-panel);
  border: 2px solid var(--color-board);
  border-radius: 12px;
  padding: 4px 12px;
  min-width: 72px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(255, 127, 168, 0.12);
}

.score-label {
  font-size: 10px;
  font-weight: bold;
  color: #b78aa0;
}

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

/* ---------- サブヘッダー ---------- */
.sub-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 0 10px;
}

.description {
  font-size: 13px;
  text-align: center;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: bold;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
  touch-action: manipulation;
}

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

.btn-primary {
  background: var(--color-accent);
  color: var(--color-text-light);
  box-shadow: 0 3px 10px rgba(255, 127, 168, 0.4);
}

.btn-primary:hover {
  background: var(--color-accent-hover);
}

.btn-secondary {
  background: var(--color-panel);
  color: var(--color-text);
  border: 2px solid var(--color-board);
}

.btn-secondary:hover {
  background: var(--color-cell);
}

.btn-icon {
  padding: 9px 12px;
}

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

/* ---------- ゲーム盤 ---------- */
.board-wrapper {
  position: relative;
  /* 高さに合わせて縮むが、最低でも 420px（画面が狭ければ左右いっぱい）は確保する */
  width: min(100%, calc(((100vh - var(--sgh-top, 0px) - var(--ad-space, 0px)) - 340px) * 0.644));
  width: clamp(min(420px, 100%), calc(((100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px)) - 340px) * 0.644), 100%);
  min-width: 240px;
  margin: 0 auto;
}

/* スマホでは左右の余白を詰めて画面いっぱいに近づける */
@media (max-width: 600px) {
  .app {
    padding-left: calc(6px + env(safe-area-inset-left, 0px));
    padding-right: calc(6px + env(safe-area-inset-right, 0px));
  }
}

#game-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 560 / 870;
  border-radius: 18px;
  box-shadow: 0 8px 28px rgba(214, 120, 160, 0.22);
  touch-action: none;
  cursor: pointer;
}

/* ---------- ゲームオーバーオーバーレイ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(255, 244, 250, 0.88);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  border-radius: 18px;
  animation: overlay-in 0.35s ease;
}

.overlay[hidden] {
  display: none;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-content {
  width: 100%;
  max-width: 320px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.overlay-title {
  font-size: 26px;
  font-weight: 800;
}

.overlay-message {
  font-size: 15px;
  font-weight: bold;
}

.overlay-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.overlay-buttons .btn {
  font-size: 15px;
  padding: 11px 22px;
}

.overlay-credits {
  margin-top: 8px;
  font-size: 11px;
  color: #a5798f;
}

.overlay-credits a {
  color: inherit;
}

/* ---------- 進化ストリップ ---------- */
.evo-wrap {
  padding: 10px 0 4px;
}

.evo-label {
  font-size: 11px;
  font-weight: bold;
  color: #b78aa0;
  text-align: center;
  margin-bottom: 2px;
}

#evo-canvas {
  display: block;
  width: 100%;
  height: 52px;
}

/* ---------- フッター ---------- */
.footer {
  margin-top: auto;
  padding-top: 12px;
  font-size: 11px;
  color: #9c7488;
  text-align: center;
  line-height: 1.7;
}

.footer a {
  color: inherit;
}

.footer-credits {
  margin-top: 6px;
}

/* ---------- 遊び方モーダル ---------- */
.howto-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(80, 60, 75, 0.5);
}

.howto-overlay[hidden] {
  display: none;
}

.howto-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 620px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--color-bg);
  border-radius: 16px;
  padding: 22px 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.howto-title {
  font-size: 20px;
  text-align: center;
}

.howto-list {
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.7;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.howto-controls {
  font-size: 13px;
  line-height: 1.8;
  background: var(--color-cell);
  border-radius: 10px;
  padding: 10px 12px;
}

/* ---------- 全国ランキング（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(80, 60, 75, 0.55);
}

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--color-bg);
  color: var(--color-text);
  border-radius: 12px;
  padding: 20px 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

.sgr-title {
  margin: 0;
  font-size: 20px;
  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: var(--color-cell);
  color: var(--color-text);
  cursor: pointer;
}

.sgr-tab-active {
  background: var(--color-accent);
  color: var(--color-text-light);
}

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

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

.sgr-name {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  padding: 8px 10px;
  border: 2px solid var(--color-board);
  border-radius: 8px;
  background: #fff;
  color: var(--color-text);
  font-family: inherit;
}

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

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: bold;
  font-family: inherit;
  background: var(--color-accent);
  color: var(--color-text-light);
  cursor: pointer;
}

.sgr-submit:hover {
  background: var(--color-accent-hover);
}

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

.sgr-error {
  margin: 4px 0 0;
  font-size: 12px;
  color: #c0392b;
}

.sgr-status {
  margin: 0;
  font-size: 13px;
  text-align: center;
}

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

.sgr-row:nth-child(even) {
  background: var(--color-cell);
}

.sgr-row.sgr-row-me {
  background: var(--color-accent);
  color: var(--color-text-light);
}

.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: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  font-family: inherit;
  background: var(--color-cell);
  color: var(--color-text);
  cursor: pointer;
}

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

.sgr-cta-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
}

.sgr-cta-btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: bold;
  font-family: inherit;
  background: var(--color-accent);
  color: var(--color-text-light);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(255, 127, 168, 0.5);
}

.sgr-cta-link {
  border: none;
  background: none;
  padding: 6px;
  font-size: 13px;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- モーション低減設定 ---------- */
@media (prefers-reduced-motion: reduce) {
  .overlay {
    animation-duration: 1ms;
  }
  .btn {
    transition: none;
  }
}

/* ---------- 狭い画面の微調整 ---------- */
@media (max-width: 360px) {
  .title {
    font-size: 20px;
  }
  .btn {
    padding: 8px 11px;
    font-size: 12px;
  }
}

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