/* ============================================================
   フリーセル - FreeCell  style.css
   ============================================================ */

:root {
  --felt-1: #1c6a8a;
  --felt-2: #0e4a63;
  --felt-3: #082f40;
  --gold: #e8c46a;
  --gold-dim: #b99a4e;
  --ink: #1e2430;
  --red: #d0342c;
  --card-radius: 7.5%;
  --cw: 80px;   /* カード幅（JSが上書き） */
  --ch: 112px;  /* カード高（JSが上書き） */
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Sans", sans-serif;
  --card-font: "Palatino", "Georgia", "Times New Roman", serif;
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--ui-font);
  background:
    radial-gradient(ellipse 120% 90% at 50% -10%, var(--felt-1) 0%, var(--felt-2) 55%, var(--felt-3) 100%);
  background-color: var(--felt-3);
  background-attachment: fixed;
  color: #eef2f4;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

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

.hidden { display: none !important; }

/* ============ ヘッダー ============ */

#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 4px;
  flex: 0 0 auto;
}

#logo {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--gold);
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
  white-space: nowrap;
}

#stats-bar {
  display: flex;
  gap: 14px;
  margin: 0 auto;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 52px;
}

.stat-label {
  font-size: 9px;
  letter-spacing: 0.15em;
  color: rgba(255,255,255,0.55);
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
}

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

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 10px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s;
}
.icon-btn:active { background: rgba(255,255,255,0.2); }

/* ============ 盤面 ============ */

#board-wrap {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
  padding: 4px 6px 0;
  /* カードの z-index（勝利演出 2000+・ドラッグ 1000+）を盤面の中に閉じ込め、モーダル・トーストより上に出さない */
  isolation: isolate;
}

#board {
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* --- 置き場（スロット） --- */

.slot {
  position: absolute;
  width: var(--cw);
  height: var(--ch);
  border-radius: var(--card-radius);
  border: 2px solid rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.12);
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
}

.slot .slot-mark {
  font-size: calc(var(--cw) * 0.42);
  color: rgba(255,255,255,0.22);
  line-height: 1;
}

/* フリーセルは枠色を変えて区別 */
.slot.slot-cell {
  border-style: dashed;
  border-color: rgba(140, 220, 255, 0.3);
  background: rgba(140, 220, 255, 0.05);
}
.slot.slot-cell .slot-mark {
  font-size: calc(var(--cw) * 0.3);
  color: rgba(140, 220, 255, 0.32);
}

.slot.drop-ok {
  border-color: var(--gold);
  background: rgba(232, 196, 106, 0.14);
  box-shadow: 0 0 12px rgba(232, 196, 106, 0.45), inset 0 2px 8px rgba(0,0,0,0.18);
}

.slot.hint-glow, .card.hint-glow {
  animation: hintPulse 0.75s ease-in-out 2;
}

@keyframes hintPulse {
  0%, 100% { box-shadow: 0 1px 3px rgba(0,0,0,0.35); }
  50% { box-shadow: 0 0 0 3px var(--gold), 0 0 18px rgba(232,196,106,0.8); }
}

/* ============ カード ============ */

.card {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cw);
  height: var(--ch);
  will-change: transform;
  transition: transform 0.22s ease;
  cursor: pointer;
  font-size: calc(var(--cw) * 0.2);
  perspective: 600px;
}

.card.no-anim { transition: none; }
.card.slow-anim { transition: transform 0.45s cubic-bezier(0.22, 0.8, 0.3, 1); }

.card.shake { animation: shake 0.3s ease; }
@keyframes shake {
  0%, 100% { margin-left: 0; }
  25% { margin-left: -4px; }
  75% { margin-left: 4px; }
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.3s ease;
}

.card.face-down .card-inner { transform: rotateY(180deg); }

.card-face, .card-back {
  position: absolute;
  inset: 0;
  border-radius: var(--card-radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
}

.card-face {
  background: linear-gradient(150deg, #ffffff 0%, #fbfaf6 60%, #f2efe6 100%);
  border: 1px solid #c9c4b4;
  color: var(--ink);
  font-family: var(--card-font);
  overflow: hidden;
}

.card.red .card-face { color: var(--red); }

.card-back {
  transform: rotateY(180deg);
  background-color: #26418f;
  background-image:
    linear-gradient(135deg, rgba(255,255,255,0.09) 25%, transparent 25%, transparent 50%, rgba(255,255,255,0.09) 50%, rgba(255,255,255,0.09) 75%, transparent 75%),
    radial-gradient(circle at 50% 50%, #35509e 0%, #1f3574 100%);
  background-size: 8px 8px, 100% 100%;
  border: 1px solid #16265a;
  box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 4px #90a4d4, 0 1px 3px rgba(0,0,0,0.35);
}

/* --- コーナー表記 --- */

.corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.corner .c-rank {
  font-size: 1.15em;
  font-weight: 700;
  letter-spacing: -0.05em;
}

.corner .c-suit { font-size: 0.85em; margin-top: 0.08em; }

.corner.tl { top: 4%; left: 5%; }
.corner.br { bottom: 4%; right: 5%; transform: rotate(180deg); }

/* --- 中央ピップ --- */

.pips {
  position: absolute;
  inset: 12% 18%;
}

.pip {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 1.1em;
  line-height: 1;
}
.pip.pip-flip { transform: translate(-50%, -50%) rotate(180deg); }

.pip.pip-ace {
  font-size: 2.6em;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.18));
}

/* --- 絵札 --- */

.court {
  position: absolute;
  inset: 14% 16%;
  border: 1px solid currentColor;
  border-radius: 6%;
  opacity: 0.92;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.1em;
  background:
    repeating-linear-gradient(45deg, transparent 0, transparent 5px, rgba(0,0,0,0.035) 5px, rgba(0,0,0,0.035) 6px);
}

.court::before, .court::after {
  content: "";
  position: absolute;
  inset: 5%;
  border: 1px solid currentColor;
  border-radius: 5%;
  opacity: 0.4;
  pointer-events: none;
}
.court::after { inset: 9%; opacity: 0.2; }

.court .court-letter {
  font-size: 1.7em;
  font-weight: 700;
  line-height: 1;
}

.court .court-suit { font-size: 1.3em; line-height: 1; }

/* ============ 自動完成ボタン ============ */

#btn-autocomplete {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 12px 26px;
  border: none;
  border-radius: 30px;
  background: linear-gradient(180deg, #f4d98c, var(--gold-dim));
  color: #4a3a10;
  font-family: var(--ui-font);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.45), 0 0 24px rgba(232,196,106,0.5);
  animation: acPulse 1.4s ease-in-out infinite;
  z-index: 500;
}

@keyframes acPulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.06); }
}

/* ============ ツールバー ============ */

#toolbar {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 8px 12px 4px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 12px;
  background: rgba(255,255,255,0.09);
  color: #fff;
  font-family: var(--ui-font);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.tool-btn:active { background: rgba(255,255,255,0.22); transform: scale(0.96); }
.tool-btn:disabled { opacity: 0.4; cursor: default; }

.tool-icon { font-size: 15px; }

/* ============ トースト ============ */

#toast {
  position: fixed;
  left: 50%;
  /* フッター固定バナー広告に隠れないよう持ち上げる（広告なしのときは 0px） */
  bottom: calc(110px + var(--ad-space, 0px));
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 22px;
  background: rgba(6, 20, 28, 0.88);
  border: 1px solid rgba(232,196,106,0.5);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  /* メニューを開いたまま出すエラー（ゲーム番号の入力ミス）も見えるよう、モーダルより上に出す */
  z-index: 1100;
  animation: toastIn 0.25s ease;
  pointer-events: none;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============ モーダル ============ */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 12, 18, 0.65);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

/* 手詰まり・クリア画面の表示中に共通ヘッダーから開いたメニュー・確認は、それらより手前に出す */
#modal-menu, #modal-confirm { z-index: 1001; }

.modal-box {
  width: 100%;
  max-width: 420px;
  max-height: calc((100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px)) - 40px);
  overflow-y: auto;
  background: linear-gradient(165deg, #0d3247, #081f2d);
  border: 1px solid rgba(232,196,106,0.45);
  border-radius: 18px;
  padding: 22px 20px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.6);
  animation: modalIn 0.22s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-box-small { max-width: 320px; text-align: center; }

.modal-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--gold);
  text-align: center;
  margin-bottom: 16px;
  letter-spacing: 0.08em;
}

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

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.menu-label { font-size: 14px; font-weight: 600; }

.menu-note {
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  margin: -4px 0 12px;
}

.game-no-input {
  display: flex;
  gap: 6px;
}

.game-no-input input {
  width: 110px;
  padding: 7px 10px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 10px;
  background: rgba(0,0,0,0.25);
  color: #fff;
  font-family: var(--ui-font);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.game-no-input input:focus {
  outline: none;
  border-color: var(--gold);
}
.game-no-input input::placeholder { color: rgba(255,255,255,0.35); font-weight: 400; }

.btn-mini {
  padding: 7px 14px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #f4d98c, var(--gold-dim));
  color: #4a3a10;
  font-family: var(--ui-font);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}
.btn-mini:active { transform: scale(0.96); }

.seg {
  display: flex;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 10px;
  overflow: hidden;
}

.seg-btn {
  padding: 7px 16px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.65);
  font-family: var(--ui-font);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--gold);
  color: #3a2d0a;
}

.menu-subtitle {
  font-size: 13px;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 10px;
  letter-spacing: 0.1em;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.sg-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 9px 4px;
  background: rgba(255,255,255,0.06);
  border-radius: 10px;
}

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

.sg-label {
  font-size: 10px;
  color: rgba(255,255,255,0.55);
  margin-top: 2px;
}

.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 6px;
}

.btn {
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  font-family: var(--ui-font);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: transform 0.1s, filter 0.15s;
}
.btn:active { transform: scale(0.97); filter: brightness(1.1); }

.btn-primary {
  background: linear-gradient(180deg, #f4d98c, var(--gold-dim));
  color: #4a3a10;
  box-shadow: 0 3px 10px rgba(0,0,0,0.35);
}

.btn-sub {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
}

.confirm-text {
  font-size: 14px;
  line-height: 1.7;
  margin-bottom: 16px;
}

.rules-hint {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.14);
}

.rules-hint p {
  font-size: 12px;
  line-height: 1.75;
  color: rgba(255,255,255,0.75);
}

/* ============ 勝利画面 ============ */

.modal-box-win { text-align: center; max-width: 340px; }

.win-title {
  font-size: 26px;
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 0.06em;
  margin-bottom: 8px;
  animation: winPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes winPop {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.win-record {
  font-size: 13px;
  font-weight: 800;
  color: #ffe9a8;
  margin-bottom: 8px;
  animation: recordBlink 0.9s ease-in-out infinite;
}

@keyframes recordBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.win-stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 14px 0 10px;
}

#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 990;
}

/* ============ フッター ============ */

#footer {
  flex: 0 0 auto;
  text-align: center;
  padding: 6px 10px 10px;
  font-size: 10px;
  line-height: 1.7;
  color: rgba(255,255,255,0.5);
}

#footer a {
  color: rgba(255,255,255,0.65);
  text-decoration: none;
}
#footer a:hover { text-decoration: underline; }

/* ============ レスポンシブ微調整 ============ */

@media (max-width: 420px) {
  #logo { font-size: 14px; }
  #stats-bar { gap: 8px; }
  .stat { min-width: 44px; }
  .stat-value { font-size: 14px; }
  .tool-btn { padding: 8px 14px; font-size: 12px; }
  #toast { bottom: calc(96px + var(--ad-space, 0px)); }
}

/* 幅 360px 未満では長いトーストが画面からはみ出すので折り返す */
@media (max-width: 359px) {
  #toast {
    width: max-content;
    max-width: calc(100vw - 16px);
    white-space: normal;
    text-align: center;
  }
}

@media (min-height: 800px) {
  #toolbar { padding-bottom: 8px; }
}

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