/* ============================================================
   ジンラミー - Gin Rummy  style.css
   ============================================================ */

:root {
  --felt-1: #2c8a55;
  --felt-2: #16613a;
  --felt-3: #093a21;
  --gold: #e8c46a;
  --gold-dim: #b99a4e;
  --ink: #1e2430;
  --red: #d0342c;
  --card-radius: 8%;
  --cw: 68px;   /* カード幅（JSが上書き） */
  --ch: 96px;   /* カード高（JSが上書き） */
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
  --card-font: "Palatino", "Georgia", "Times New Roman", serif;
  --m0: #4aa3ff;
  --m1: #ffb648;
  --m2: #c98bff;
  --m3: #5fd6a2;
}

* { 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: #eef4ef;
  -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; }

/* 検証用（?noanim）: すべてのトランジションを無効化 */
.noanim * { transition: none !important; animation: 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;
}

#score-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 auto;
}

.score-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
  padding: 2px 10px;
  border-radius: 10px;
  background: rgba(0,0,0,0.18);
  border: 1px solid rgba(255,255,255,0.12);
}

.score-name {
  font-size: 9px;
  letter-spacing: 0.12em;
  color: rgba(255,255,255,0.6);
}

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

.score-chip.leading .score-value { color: var(--gold); }

#round-chip {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,255,255,0.55);
  letter-spacing: 0.08em;
}

#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: 2px 6px 0;
}

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

.pile-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;
  cursor: pointer;
}

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

.pile-slot.drawable, .card.drawable-top {
  cursor: pointer;
}

/* 発光は ::after の opacity だけを動かす（box-shadow を直接アニメーションすると、
   手番で考えている間ずっと毎フレーム再描画になる） */
.pile-glow::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--card-radius);
  box-shadow: 0 0 0 3px rgba(232,196,106,0.75), 0 0 16px rgba(232,196,106,0.55);
  opacity: 0;
  pointer-events: none;
  animation: pileGlow 1.6s ease-in-out infinite;
}
.pile-slot.pile-glow::after { inset: -2px; }

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

#stock-count {
  position: absolute;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,255,255,0.65);
  background: rgba(0,0,0,0.3);
  padding: 1px 8px;
  border-radius: 8px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

#cpu-label {
  position: absolute;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: rgba(255,255,255,0.55);
  pointer-events: none;
  white-space: nowrap;
}

#cpu-think {
  margin-left: 8px;
  color: var(--gold);
  animation: blink 1.1s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

#message {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  pointer-events: none;
  padding: 0 12px;
  line-height: 1.4;
}

#dw-chip {
  position: absolute;
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  background: rgba(0,0,0,0.28);
  border: 1px solid rgba(255,255,255,0.12);
  padding: 2px 10px;
  border-radius: 9px;
  pointer-events: none;
  white-space: nowrap;
}

#dw-chip b {
  color: #fff;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

#dw-chip.knockable { border-color: var(--gold); color: var(--gold); }
#dw-chip.knockable b { color: var(--gold); }

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

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

.card.no-anim { transition: none; }

/* 移動中カードの一時最前面化（JSのboostZが付与。インラインz-indexより優先させる） */
.card.z-boost { z-index: 1000 !important; }

.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.no-anim .card-inner { transition: none; }

.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: #8f2635;
  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%, #a33648 0%, #6e1f2c 100%);
  background-size: 8px 8px, 100% 100%;
  border: 1px solid #4e1620;
  box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 4px #d4909c, 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.05em;
  font-weight: 700;
  letter-spacing: -0.05em;
}

.corner .c-suit { font-size: 0.8em; margin-top: 0.06em; }

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

.center-suit {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.9em;
  opacity: 0.82;
}

/* メルド色分け（上端のリボン） */
.card.meld-0 .card-face { box-shadow: inset 0 4px 0 var(--m0), 0 1px 3px rgba(0,0,0,0.35); }
.card.meld-1 .card-face { box-shadow: inset 0 4px 0 var(--m1), 0 1px 3px rgba(0,0,0,0.35); }
.card.meld-2 .card-face { box-shadow: inset 0 4px 0 var(--m2), 0 1px 3px rgba(0,0,0,0.35); }
.card.meld-3 .card-face { box-shadow: inset 0 4px 0 var(--m3), 0 1px 3px rgba(0,0,0,0.35); }

.card.selectable { cursor: pointer; }

.card.selected .card-face {
  outline: 3px solid var(--gold);
  outline-offset: -1px;
}

.card.just-drawn .card-face::after {
  content: "";
  position: absolute;
  top: 7%;
  right: 9%;
  width: 0.42em;
  height: 0.42em;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 6px rgba(232,196,106,0.9);
}

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

/* ============ アクションバー ============ */

#actions {
  flex: 0 0 auto;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 10px;
  flex-wrap: wrap;
}

.act-btn {
  border: none;
  border-radius: 12px;
  padding: 10px 20px;
  font-family: var(--ui-font);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.act-btn:active { transform: translateY(1px); }
.act-btn:disabled { opacity: 0.45; cursor: default; }

.act-primary {
  background: linear-gradient(180deg, #f3d98a, var(--gold-dim));
  color: #4a3a10;
}

.act-danger {
  background: linear-gradient(180deg, #ff9d6b, #d0552c);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.25);
}

.act-special {
  background: linear-gradient(180deg, #8be0ff, #2c8ad0);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.25);
  animation: specialPulse 1.4s ease-in-out infinite;
}

@keyframes specialPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.18); }
}

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

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

#toast {
  position: fixed;
  /* フッター固定バナー広告に隠れないよう持ち上げる（広告なしのときは 0px） */
  bottom: calc(env(safe-area-inset-bottom) + 84px + var(--ad-space, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 26, 22, 0.92);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 12px;
  z-index: 2100;
  max-width: calc(100vw - 32px);
  text-align: center;
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  /* 表示中も下の手札をタップできるように */
  pointer-events: none;
}

/* ============ モーダル共通 ============ */

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

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

.modal-box {
  width: 100%;
  max-width: 420px;
  max-height: calc((100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px)) - 48px);
  overflow-y: auto;
  background: linear-gradient(165deg, #1d3527, #12241a);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}

.modal-box-small { max-width: 340px; }
.modal-box-round { max-width: 480px; }

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

.menu-section {
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

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

.menu-label { font-size: 13px; font-weight: 700; }

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

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

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

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

.menu-subtitle {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: rgba(255,255,255,0.6);
  margin-bottom: 8px;
}

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

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

.sg-value {
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  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: 8px;
  margin-top: 14px;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-family: var(--ui-font);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(180deg, #f3d98a, var(--gold-dim));
  color: #4a3a10;
}

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

.confirm-text {
  text-align: center;
  font-size: 13px;
  line-height: 1.7;
  color: rgba(255,255,255,0.85);
}

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

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

.rules-hint b { color: var(--gold); }

/* ============ ラウンド結果 ============ */

#round-verdict {
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 12px;
  color: #fff;
}

#round-verdict .verdict-badge {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 10px;
  background: rgba(232,196,106,0.15);
  border: 1px solid var(--gold);
  color: var(--gold);
}

.rh-panel {
  background: rgba(0,0,0,0.2);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.rh-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.rh-name { font-size: 13px; font-weight: 800; }
.rh-name .rh-role {
  font-size: 10px;
  font-weight: 700;
  color: var(--gold);
  margin-left: 6px;
  letter-spacing: 0.08em;
}
.rh-dw { font-size: 11px; color: rgba(255,255,255,0.65); }
.rh-dw b { color: #fff; font-size: 13px; }

.rh-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: flex-start;
}

.mgroup {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 7px;
  background: rgba(255,255,255,0.06);
  border-top: 3px solid rgba(255,255,255,0.2);
}

.mgroup.g0 { border-top-color: var(--m0); }
.mgroup.g1 { border-top-color: var(--m1); }
.mgroup.g2 { border-top-color: var(--m2); }
.mgroup.g3 { border-top-color: var(--m3); }
.mgroup.gdead { border-top-color: #e05a5a; background: rgba(224,90,90,0.1); }

.mcard {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 34px;
  padding: 0 3px;
  border-radius: 5px;
  background: linear-gradient(150deg, #ffffff, #f2efe6);
  border: 1px solid #c9c4b4;
  color: var(--ink);
  font-family: var(--card-font);
  font-size: 12px;
  font-weight: 700;
}

.mcard.red { color: var(--red); }

.mcard.laid {
  outline: 2px dashed var(--gold);
  outline-offset: -2px;
}

.rh-laidnote {
  width: 100%;
  font-size: 10px;
  color: var(--gold);
  margin-top: 2px;
}

#round-score-line {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: rgba(255,255,255,0.85);
  margin-top: 4px;
  line-height: 1.7;
}

#round-score-line .rs-total {
  font-size: 12px;
  color: rgba(255,255,255,0.6);
}

/* ============ マッチ結果 ============ */

.win-title {
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 14px;
  animation: winPop 0.5s ease;
}

.win-title.lose { color: #9fb8aa; }

@keyframes winPop {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

#match-tally {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

#match-tally th, #match-tally td {
  padding: 6px 8px;
  text-align: right;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-variant-numeric: tabular-nums;
}

#match-tally th { color: rgba(255,255,255,0.6); font-weight: 700; }
#match-tally td:first-child, #match-tally th:first-child { text-align: left; color: rgba(255,255,255,0.75); }
#match-tally tr.total td { font-weight: 800; font-size: 14px; color: var(--gold); border-bottom: none; }

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

#footer {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 6px;
  font-size: 10px;
  color: rgba(255,255,255,0.45);
}

/* 右の著作表記（もう一方のサイトへのリンクつき）が 1 行に収まらない幅では、右側だけを 2 行に折る（左のタイトルは折らない） */
#footer > div:first-child { flex: none; white-space: nowrap; }
#footer > div:last-child { text-align: right; }

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

#footer a:active, #footer a:hover { color: var(--gold); }

/* ============ 狭い画面調整 ============ */

@media (max-width: 380px) {
  #logo { font-size: 14px; }
  .score-chip { min-width: 46px; padding: 2px 6px; }
  .act-btn { padding: 9px 14px; font-size: 13px; }
}

@media (max-height: 480px) {
  #topbar { padding: 4px 12px 2px; }
  #actions { min-height: 44px; padding: 4px 10px; }
  #footer { display: none; }
}

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