/* ============================================================
   ババ抜き - Old Maid
   ============================================================ */

:root {
  --felt-1: #7a4a99;
  --felt-2: #4a2a66;
  --felt-3: #241238;
  --ink: #1d2129;
  --red: #d4453a;
  --gold: #e8c46a;
  --card-radius: 7.5%;
  --card-font: "Palatino", "Georgia", "Times New Roman", serif;
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
}

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

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

body {
  font-family: var(--ui-font);
  background: var(--felt-3);
  color: #f4f1f8;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

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

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

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(6px + env(safe-area-inset-top)) 12px 6px;
  background: rgba(0, 0, 0, 0.25);
  flex: none;
}

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

#logo {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #fff;
  white-space: nowrap;
}

#logo::before { content: "★"; color: var(--gold); margin-right: 5px; }

#round-info {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.icon-btn {
  width: 34px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  color: #fff;
  transition: background 0.15s ease;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.22); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn.off { opacity: 0.45; }

/* ============ テーブル ============ */

#table {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse 90% 75% at 50% 42%, var(--felt-1) 0%, var(--felt-2) 62%, var(--felt-3) 100%);
}

#table::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(45deg, transparent 0, transparent 3px, rgba(0, 0, 0, 0.025) 3px, rgba(0, 0, 0, 0.025) 4px);
  pointer-events: none;
}

#cards-layer {
  position: absolute;
  inset: 0;
}

#cards-layer.no-anim .card,
#cards-layer.no-anim .card-inner { transition: none !important; }

/* ============ ネームプレート ============ */

.plate {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px 4px 5px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.38);
  border: 2px solid transparent;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
  z-index: 50;
  white-space: nowrap;
}

.plate.turn {
  border-color: var(--gold);
  box-shadow: 0 0 12px rgba(232, 196, 106, 0.55);
}

.plate.target {
  border-color: #7ec8ff;
  box-shadow: 0 0 12px rgba(126, 200, 255, 0.55);
}

.plate.out { opacity: 0.55; }

.p-avatar {
  font-size: 20px;
  line-height: 1;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.p-info {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.p-name { font-size: 11px; font-weight: 700; }
.p-cards { font-size: 11px; color: rgba(255, 255, 255, 0.78); }

.p-rank {
  font-size: 10px;
  font-weight: 700;
  border-radius: 9px;
  padding: 2px 6px;
  color: #4a3400;
  background: var(--gold);
}

.p-rank.r2 { color: #2c2c2c; background: #d9dde2; }
.p-rank.r3 { color: #f0e6d8; background: rgba(120, 95, 70, 0.9); }
.p-rank.baba { color: #ffe3e0; background: rgba(180, 40, 30, 0.92); }

/* ============ 表情バブル ============ */

.bubble {
  position: absolute;
  z-index: 420;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  color: #2b2b33;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  animation: popIn 0.2s cubic-bezier(0.3, 1.4, 0.5, 1);
}

.bubble .b-face { font-size: 16px; }
.bubble.push { background: #ffe9a8; }
.bubble.worry { background: #cfe3ff; }

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

.card {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cw, 70px);
  height: var(--ch, 98px);
  will-change: transform;
  transition: transform var(--anim, 0.3s) cubic-bezier(0.25, 0.8, 0.35, 1), opacity var(--anim, 0.3s) ease;
  font-size: calc(var(--cw, 70px) * 0.2);
  perspective: 600px;
  cursor: default;
}

.card.pickable { cursor: pointer; }

.card.gone { opacity: 0; pointer-events: none; }

.card.sel .card-back {
  box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 4px var(--gold), 0 0 0 3px var(--gold), 0 6px 16px rgba(0, 0, 0, 0.5);
}

.card.sel .card-face {
  box-shadow: 0 0 0 3px var(--gold), 0 6px 16px rgba(0, 0, 0, 0.5);
}

.card.taken .card-face {
  box-shadow: 0 0 0 3px #7ec8ff, 0 0 16px rgba(126, 200, 255, 0.85);
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform var(--anim, 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: #4a2a66;
  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%, #6b3f8c 0%, #2c1642 100%);
  background-size: 8px 8px, 100% 100%;
  border: 1px solid #1c0f2a;
  box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 4px #b493cd, 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; }

/* --- ジョーカー --- */

.joker {
  position: absolute;
  inset: 10% 12%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.15em;
  border: 1px solid currentColor;
  border-radius: 6%;
  background:
    repeating-linear-gradient(45deg, rgba(212, 69, 58, 0.07) 0, rgba(212, 69, 58, 0.07) 4px, transparent 4px, transparent 8px);
}

.joker .j-face { font-size: 2.1em; line-height: 1; }
.joker .j-text { font-size: 0.72em; font-weight: 700; letter-spacing: 0.1em; }

/* ============ アクションバー・メッセージ ============ */

#actionbar {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  z-index: 400;
  pointer-events: none;
}

#msg {
  font-size: 13px;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.42);
  padding: 5px 14px;
  border-radius: 15px;
  max-width: 92%;
  text-align: center;
}

#msg:empty { display: none; }

#buttons { display: flex; gap: 8px; align-items: center; }

.primary-btn, .ghost-btn {
  border: none;
  border-radius: 10px;
  padding: 9px 20px;
  font-size: 14px;
  font-weight: 700;
  font-family: var(--ui-font);
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.12s ease, opacity 0.15s ease, background 0.15s ease;
}

.primary-btn {
  background: linear-gradient(160deg, #f3d488 0%, var(--gold) 55%, #cfa64e 100%);
  color: #3d2c07;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.primary-btn:disabled, .ghost-btn:disabled { opacity: 0.4; cursor: default; }
.primary-btn:not(:disabled):hover { transform: translateY(-1px); }
.primary-btn:not(:disabled):active { transform: translateY(1px); }

.ghost-btn {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.ghost-btn:not(:disabled):hover { background: rgba(255, 255, 255, 0.28); }
.ghost-btn:not(:disabled):active { transform: translateY(1px); }

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

#toast {
  position: absolute;
  top: 15%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 18px;
  z-index: 500;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

/* .hidden の display:none !important に勝たせ、opacity でフェードさせる */
#toast.hidden { opacity: 0; display: block !important; }

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

.hidden { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: linear-gradient(170deg, #fdfdfb 0%, #f0edf3 100%);
  color: var(--ink);
  border-radius: 16px;
  padding: 22px 24px;
  width: min(440px, 100%);
  max-height: min(82dvh, 660px);
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  animation: popIn 0.25s cubic-bezier(0.3, 1.3, 0.5, 1);
}

@keyframes popIn {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-box h2 {
  font-size: 19px;
  margin-bottom: 14px;
  text-align: center;
}

.help-box { text-align: left; }

.help-box h3 {
  font-size: 14px;
  margin: 14px 0 6px;
  color: #4a2a66;
}

.help-box p, .help-box li {
  font-size: 13px;
  line-height: 1.7;
  color: #333;
}

.help-box ul { padding-left: 18px; }

/* ============ 設定 ============ */

.settings-box { text-align: left; }

.settings-note {
  font-size: 12px;
  color: #777;
  margin-bottom: 10px;
  text-align: center;
}

.rule-name { font-size: 14px; font-weight: 700; color: #222; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 2px;
  border-bottom: 1px solid #e3dee9;
}

.seg {
  display: flex;
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid #c8bcd4;
}

.seg button {
  border: none;
  background: #fff;
  color: #555;
  font-family: var(--ui-font);
  font-size: 12.5px;
  font-weight: 700;
  padding: 7px 12px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg button + button { border-left: 1px solid #ded6e6; }
.seg button:hover { background: #f2eef6; }
.seg button.on { background: #4a2a66; color: #fff; }

#stats-box {
  margin-top: 12px;
  text-align: center;
  font-size: 12px;
  line-height: 1.7;
  color: #888;
}

/* ============ 結果モーダル ============ */

#result-banner {
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  color: #4b2a00;
  background: linear-gradient(160deg, #fff3cd, #ffe08a);
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 12px;
  animation: popIn 0.4s cubic-bezier(0.3, 1.5, 0.5, 1);
}

#result-banner.lose {
  color: #6d1f18;
  background: linear-gradient(160deg, #ffdcd8, #ffb3ab);
}

#score-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
}

#score-table th, #score-table td {
  padding: 7px 6px;
  font-size: 14px;
  text-align: center;
  border-bottom: 1px solid #e3dee9;
}

#score-table th {
  font-size: 12px;
  color: #777;
  font-weight: 600;
}

#score-table td:first-child { text-align: left; }

#score-table tr.me td { font-weight: 700; }
#score-table .rank-1 { color: #a67c00; font-weight: 700; }
#score-table .rank-last { color: #b8342a; font-weight: 700; }

#stats-line {
  text-align: center;
  font-size: 12px;
  color: #888;
  margin-bottom: 4px;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
}

#modal-confirm p {
  font-size: 13px;
  line-height: 1.7;
  text-align: center;
  color: #444;
}

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

#footer {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 12px calc(5px + env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.3);
  font-size: 10px;
  color: rgba(255, 255, 255, 0.55);
}

/* 右の著作表記（もう一方のサイトへのリンクつき）が 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.75);
  text-decoration: none;
}

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

/* ============ その他 ============ */

@media (hover: hover) {
  .card.pickable:hover { transform: var(--tf) translateY(-10px) !important; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .card-inner, .modal, .modal-box, .bubble { transition: none !important; animation: none !important; }
}

@media (max-width: 400px) {
  .primary-btn, .ghost-btn { padding: 8px 14px; font-size: 13px; }
  #msg { font-size: 12px; }
  .bubble { font-size: 11px; padding: 4px 9px; }
}

@media (min-width: 700px) {
  #logo { font-size: 21px; }
  #round-info { font-size: 13px; }
  #msg { font-size: 14px; }
  .p-name, .p-cards { 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; }
}
