/* クォッカ◯✕バトルの画面スタイル。
   配色は cho-han / tank と揃えたクォッカ路線(やわらかいピンク + クリーム)。
   盤面はサイズが変わるので、CSS変数 --board-size を JS から書き換えてグリッドを組み替えている。 */

:root {
  --pink: #e85d84;
  --pink-soft: #ffe3ec;
  --pink-bg: #fff6fa;
  --cream: #fffdfb;
  --text: #5b4a4a;
  --text-muted: #9c8d8d;
  --maru: #4a9ad4;
  --batsu: #e85d84;
}

* {
  box-sizing: border-box;
}

/* iPhoneは連打(ダブルタップ)をズーム操作と解釈することがある。
   manipulationにすると、ピンチズームは残したままダブルタップズームだけ止められる。 */
html {
  touch-action: manipulation;
}

body {
  margin: 0;
  padding: 0;
  font-family: "M PLUS Rounded 1c", -apple-system, "Hiragino Sans", "Yu Gothic", sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, #fff6fa 0%, #fffdfb 55%, #fff9f2 100%);
  min-height: 100vh;
  line-height: 1.7;
}

.hidden {
  display: none !important;
}

/* --- 画面 ---------------------------------------------------------------- */

.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 16px 90px;
  min-height: 100vh;
}

.panel {
  width: 100%;
  max-width: 420px;
  background: #ffffff;
  border: 2px solid var(--pink-soft);
  border-radius: 22px;
  padding: 26px 22px 20px;
  box-shadow: 0 10px 30px rgba(232, 93, 132, 0.12);
  text-align: center;
}

h1 {
  font-size: 22px;
  font-weight: 800;
  color: var(--pink);
  margin: 0 0 8px;
}

.sparkle {
  font-size: 16px;
}

/* 参加画面のクォッカ。width/height属性で縦横比を伝えてあるので、
   読み込み前でも高さが確保されて他の要素がガタつかない。 */
.hero-quokka {
  display: block;
  width: 132px;
  height: auto;
  margin: 2px auto 4px;
}

.hint {
  color: var(--text-muted);
  font-size: 13px;
  margin: 6px 0 12px;
}

.hint.small {
  font-size: 12px;
  margin-top: 10px;
}

.link-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

/* シェアボタンと見た目をそろえたピルボタン。以前は文字リンクのままだったが、
   押せることが伝わりにくかったので同じ形にした。 */
.rules-link,
.link-row .home-link,
.share-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border: 2px solid var(--pink-soft);
  border-radius: 999px;
  background: #ffffff;
  color: var(--pink);
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  text-decoration: none;
}

.rules-link:hover,
.link-row .home-link:hover,
.share-button:hover {
  border-color: var(--pink);
  background: var(--pink-bg);
}

label {
  display: block;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin: 14px 0 6px;
}

input[type="text"] {
  width: 100%;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--cream);
  border: 2px solid var(--pink-soft);
  border-radius: 12px;
  outline: none;
}

input[type="text"]:focus {
  border-color: var(--pink);
}

button {
  font-family: inherit;
  cursor: pointer;
}

.primary {
  width: 100%;
  margin-top: 16px;
  padding: 13px 18px;
  font-size: 16px;
  font-weight: 800;
  color: #ffffff;
  background: var(--pink);
  border: none;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(232, 93, 132, 0.32);
  transition: transform 0.08s ease, box-shadow 0.15s ease;
}

.primary:hover {
  box-shadow: 0 6px 16px rgba(232, 93, 132, 0.4);
}

.primary:active {
  transform: translateY(1px);
}

/* マッチング待ち中に出す「今すぐCPU戦」ボタン。主導線（対戦をはじめる）より控えめにする。 */
.waiting-actions {
  margin-bottom: 14px;
}

.secondary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 700;
  color: var(--pink);
  background: #ffffff;
  border: 2px solid var(--pink-soft);
  border-radius: 999px;
  transition: background 0.12s ease, transform 0.08s ease;
}

.secondary:hover {
  background: var(--pink-bg);
}

.secondary:active {
  transform: translateY(1px);
}

.btn-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.join-error {
  margin-top: 10px;
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 700;
  color: #b4453f;
  background: #ffeceb;
  border: 2px solid #ffd6d3;
  border-radius: 12px;
}

/* --- ランキング ---------------------------------------------------------- */

.ranking-groups {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 22px;
}

.ranking-group {
  background: var(--pink-bg);
  border: 2px solid var(--pink-soft);
  border-radius: 14px;
  padding: 12px 14px;
}

.ranking-group-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--pink);
  margin-bottom: 6px;
}

.ranking-note {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0 0 8px;
  line-height: 1.5;
}

.ranking-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 3px 0;
}

.ranking-rank {
  width: 26px;
  flex-shrink: 0;
  text-align: center;
}

.ranking-name {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-value {
  font-weight: 800;
  color: var(--pink);
  flex-shrink: 0;
}

.ranking-empty {
  font-size: 12px;
  color: var(--text-muted);
}

/* --- フッター ------------------------------------------------------------ */

/* どの画面でも下に固定して出す、フッター一式(その他リンク・規約類・バージョン・
   著作権・音源クレジット)。以前は参加画面(join-screen)だけに置いていたため、
   他の画面(対戦中など)からは一度タイトルに戻らないと開けなかった。
   z-indexは結果画面より上、音量パネル・規約モーダルより下にする。
   縦に積むと小さい画面で盤面やボタンに重なるため、2行に折りたたんでいる。 */
.site-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 55;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  background: rgba(255, 253, 251, 0.92);
  border-top: 1px solid var(--pink-soft);
  backdrop-filter: blur(2px);
}

.site-footer a { color: var(--pink); font-weight: 600; text-decoration: none; }

.footer-links,
.footer-meta {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 2px 6px;
}

.copyright {
  color: var(--text-muted);
  font-size: 11px;
}

/* 音声素材の提供元クレジット。効果音ラボ等の利用規約に基づく表示。 */
.sound-credit {
  color: var(--text-muted);
}

/* --- 対戦画面のHUD ------------------------------------------------------- */

.hud-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  /* 右上に固定表示している音量ボタン(.sound-controls)の下にピルが潜り込まないよう、
     左右に同じだけ余白を空ける(中央揃えを保つため左右セット)。 */
  padding-inline: 56px;
  width: 100%;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 13px;
  font-size: 12px;
  background: #ffffff;
  border: 2px solid var(--pink-soft);
  border-radius: 999px;
  white-space: nowrap;
}

.stat-pill strong {
  color: var(--pink);
  font-weight: 800;
  /* 長いニックネームでHUDが崩れないように省略する。 */
  max-width: 9em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* プレイヤーを表すクォッカのアイコン。相手が人間かCPUかで src を差し替える。 */
.player-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  vertical-align: middle;
}

/* 自分と相手がどちらの記号かを示すバッジ。盤面と同じ色を使う。 */
.mark-badge {
  font-weight: 800;
  font-size: 14px;
  line-height: 1;
}

.mark-badge.maru {
  color: var(--maru);
}

.mark-badge.batsu {
  color: var(--batsu);
}

.status-text {
  min-height: 26px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  margin-bottom: 10px;
}

.turn-bar {
  width: 100%;
  max-width: 420px;
  height: 8px;
  background: var(--pink-soft);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 18px;
}

.turn-bar-fill {
  height: 100%;
  width: 100%;
  background: var(--pink);
  border-radius: 999px;
  transition: width 0.1s linear;
}

.turn-bar-fill.urgent {
  background: #f0a13a;
}

/* --- 盤面 ---------------------------------------------------------------- */

/* --board-size は renderBoard() が毎回書き換える。盤面が広がっても
   全体の見た目の大きさは変えず、1マスが小さくなるようにしている。 */
.board {
  --board-size: 3;
  display: grid;
  /* 行も必ず等分する。grid-template-rows を書かないと行の高さが中身依存になり、
     記号が入っている行だけ背が高く、空の行が潰れて盤面がゆがむ
     (align-content: stretch は余白を各行に同量足すだけなので差が残る)。 */
  grid-template-columns: repeat(var(--board-size), 1fr);
  grid-template-rows: repeat(var(--board-size), 1fr);
  /* マス数が増えるほど隙間を詰める。11x11でも隙間で面積を食われすぎないように。 */
  --gap: max(2px, calc(18px / var(--board-size)));
  gap: var(--gap);
  width: min(92vw, 460px);
  aspect-ratio: 1 / 1;
  padding: 10px;
  background: var(--pink-bg);
  border: 3px solid var(--pink-soft);
  border-radius: 20px;
  /* .cell の文字サイズを盤面の実寸から求めるためのコンテナ。 */
  container-type: size;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-family: inherit;
  /* マス数に応じて文字も縮める。盤面の実寸(コンテナ)を基準にしているので、
     .board 側の width を変えてもここを直す必要はない。 */
  font-size: calc(100cqmin / var(--board-size) * 0.58);
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  background: #ffffff;
  border: 2px solid var(--pink-soft);
  /* 小さいマスで角丸が目立ちすぎないように、マス数に応じて丸みも小さくする。 */
  border-radius: max(4px, calc(30px / var(--board-size)));
  transition: background 0.12s ease, transform 0.08s ease;
}

.cell:disabled {
  cursor: default;
}

.board.interactive .cell:not(.filled):hover {
  background: #fff0f5;
}

.board.interactive .cell:not(.filled):active {
  transform: scale(0.95);
}

.cell.maru {
  color: var(--maru);
}

.cell.batsu {
  color: var(--batsu);
}

/* 直前に置かれたマス。相手（CPU含む）がどこに打ったかを見失わないようにする。
   枠線の太さはマス数に応じて調整し、11x11でも見えるようにしている。
   勝ち筋(.winning)は背景を変えるのに対し、こちらは枠だけなので併用できる。 */
.cell.last-move {
  box-shadow: inset 0 0 0 max(2px, calc(14px / var(--board-size))) #f0a13a;
}

/* 勝ちが決まった並びを光らせる。findWinningLine() が返す座標に付く。
   決着の見せ場なので、背景・枠・拡大に加えて発光をゆっくり明滅させ続ける。
   決着後も消さずに残す（match-end でも line を渡している）。 */
.cell.winning {
  background: #ffe9a8;
  border-color: #f0a13a;
  color: #a15c00;
  z-index: 1;
  animation: winning-pop 0.5s ease, winning-glow 1.4s ease-in-out 0.5s infinite;
}

/* 勝ち筋のマスでは、直前の手の枠より勝ち筋の演出を優先する。 */
.cell.winning.last-move {
  box-shadow: none;
}

@keyframes winning-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@keyframes winning-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 161, 58, 0.55); }
  50% { box-shadow: 0 0 14px 4px rgba(240, 161, 58, 0.55); }
}

/* --- 拡張の告知 ---------------------------------------------------------- */

/* 盤面が広がったとき、変化したピル（盤面サイズと勝利条件）だけを点滅させる。
   盤面の上に大きな告知を出す案はプレイの邪魔になるのでやめた。 */
.stat-pill.just-changed {
  animation: pill-flash 1.6s ease 2;
}

@keyframes pill-flash {
  0%, 100% { background: #ffffff; border-color: var(--pink-soft); transform: scale(1); }
  30% { background: #ffe9a8; border-color: #f0a13a; transform: scale(1.14); }
}

/* --- 結果パネル ---------------------------------------------------------- */

/* 結果画面の「タイトルに戻る」。主導線(もう1戦)より控えめにする。 */
.result-panel .secondary {
  width: 100%;
  margin-top: 8px;
}

.result-panel {
  width: 100%;
  max-width: 420px;
  margin-top: 20px;
  padding: 18px 20px;
  text-align: center;
  background: #ffffff;
  border: 2px solid var(--pink-soft);
  border-radius: 18px;
  box-shadow: 0 8px 22px rgba(232, 93, 132, 0.14);
}

.result-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--pink);
  margin: 0 0 4px;
}

.result-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}

/* --- サウンドパネル ------------------------------------------------------ */

.sound-controls {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.mute-btn {
  /* 【2026-08-18】絵文字を字として置くとベースラインに沿ってしまい、丸ボタンの
     真ん中からズレる(🔊と⚙️で字形の高さが違うので特に目立つ)。中身を中央に置く。 */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  width: 40px;
  height: 40px;
  font-size: 17px;
  background: #ffffff;
  border: 2px solid var(--pink-soft);
  border-radius: 50%;
  box-shadow: 0 3px 10px rgba(91, 74, 74, 0.12);
}

.settings-btn { width: 32px; height: 32px; font-size: 14px; }

.sound-panel {
  margin-top: 8px;
  padding: 12px 14px;
  background: #ffffff;
  border: 2px solid var(--pink-soft);
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(91, 74, 74, 0.14);
}

.sound-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
}

.sound-mute-btn {
  width: 30px;
  height: 30px;
  font-size: 14px;
  background: var(--pink-bg);
  border: 2px solid var(--pink-soft);
  border-radius: 50%;
}

.sound-row-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  width: 46px;
  text-align: left;
}

.sound-volume {
  width: 92px;
  accent-color: var(--pink);
}

/* --- 規約モーダル -------------------------------------------------------- */

.legal-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.legal-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(91, 74, 74, 0.45);
}

.legal-modal-box {
  position: relative;
  width: min(100%, 640px);
  height: min(84vh, 720px);
  background: #ffffff;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(91, 74, 74, 0.3);
}

.legal-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  width: 34px;
  height: 34px;
  font-size: 15px;
  color: var(--pink);
  background: #ffffff;
  border: 2px solid var(--pink-soft);
  border-radius: 50%;
}

.legal-modal-frame {
  width: 100%;
  height: 100%;
  border: none;
}

/* --- 切断バナー ---------------------------------------------------------- */

.disconnect-banner {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(91, 74, 74, 0.45);
}

.disconnect-box {
  width: min(100%, 360px);
  padding: 22px;
  text-align: center;
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 16px 40px rgba(91, 74, 74, 0.3);
}

.disconnect-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--pink);
  margin: 0 0 6px;
}

/* --- 狭い画面 ------------------------------------------------------------ */

@media (max-width: 420px) {
  .screen {
    padding: 20px 12px 40px;
  }

  .panel {
    padding: 22px 16px 16px;
  }

  h1 {
    font-size: 19px;
  }
}

/* --- 起死回生（盤面シフト） ------------------------------------------------ */

/* 盤面全体を1マスずらす技。1試合に1回だけなので、押しやすさより
   「まだ持っている／もう使った」が分かることを優先する。 */
.shift-controls {
  margin-top: 14px;
  padding: 10px 16px;
  text-align: center;
  background: #ffffff;
  border: 2px solid var(--pink-soft);
  border-radius: 16px;
}

.shift-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 800;
  color: var(--pink);
}

.shift-note {
  font-weight: 400;
  color: var(--text-muted);
}

/* 十字に並べる。中央は空けて方向が直感的にわかるようにする。 */
.shift-pad {
  display: grid;
  grid-template-columns: repeat(3, 38px);
  grid-template-rows: repeat(3, 34px);
  gap: 5px;
  justify-content: center;
}

/* 十字に並べる。矢印の位置と向きが揃っていないと、どちら側が空くのか読み取れない。 */
.shift-pad .shift-btn:nth-child(1) { grid-column: 2; grid-row: 1; }
.shift-pad .shift-btn:nth-child(2) { grid-column: 1; grid-row: 2; }
.shift-pad .shift-btn:nth-child(3) { grid-column: 3; grid-row: 2; }
.shift-pad .shift-btn:nth-child(4) { grid-column: 2; grid-row: 3; }

.shift-btn {
  font-size: 15px;
  font-weight: 800;
  color: var(--pink);
  background: #ffffff;
  border: 2px solid var(--pink-soft);
  border-radius: 10px;
  transition: background 0.12s ease, transform 0.08s ease;
}

.shift-btn:hover:not(:disabled) {
  background: var(--pink-bg);
}

.shift-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.shift-btn:disabled {
  color: var(--text-muted);
  border-color: #f0eae6;
  cursor: default;
}

/* --- 起死回生の演出 -------------------------------------------------------- */

/* 盤面が一瞬で切り替わると何が起きたか目で追えないので、
   ①石が実際にスライドする ②新しく空いた列を光らせる の2つで見せる。
   動くのは石だけ（マス目の枠は動かない）なので .filled にだけ付ける。 */
.cell.slide-right { animation: slide-from-left 0.42s cubic-bezier(0.2, 0.9, 0.3, 1); }
.cell.slide-left { animation: slide-from-right 0.42s cubic-bezier(0.2, 0.9, 0.3, 1); }
.cell.slide-down { animation: slide-from-top 0.42s cubic-bezier(0.2, 0.9, 0.3, 1); }
.cell.slide-up { animation: slide-from-bottom 0.42s cubic-bezier(0.2, 0.9, 0.3, 1); }

@keyframes slide-from-left {
  from { transform: translateX(calc(-100% - var(--gap))); }
  to { transform: translateX(0); }
}
@keyframes slide-from-right {
  from { transform: translateX(calc(100% + var(--gap))); }
  to { transform: translateX(0); }
}
@keyframes slide-from-top {
  from { transform: translateY(calc(-100% - var(--gap))); }
  to { transform: translateY(0); }
}
@keyframes slide-from-bottom {
  from { transform: translateY(calc(100% + var(--gap))); }
  to { transform: translateY(0); }
}

/* 押し出されて消える石。シフトの直前に一瞬だけ見せる。 */
.cell.vanishing {
  animation: vanish 0.34s ease forwards;
}

@keyframes vanish {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.55); }
}

/* 起死回生のキー操作ヒント。素の矢印キーはページのスクロールに使われるので、
   Shiftとの同時押しにしている（うっかり押しで技を失わないためでもある）。 */
.shift-keyhint {
  margin: -4px 0 8px;
  font-size: 10px;
  color: var(--text-muted);
}

/* 起死回生の確定前プレビュー ------------------------------------------------ */

/* 選んでいる向きのボタン。どれを下見中なのか分かるようにする。 */
.shift-btn.chosen {
  background: var(--pink);
  border-color: var(--pink);
  color: #ffffff;
}

/* まだ確定していない盤面であることを示す。少し淡くして「仮」に見せる。 */
.board.previewing {
  opacity: 0.92;
  outline: 3px dashed var(--pink);
  outline-offset: 4px;
}

/* ずらすと新しく空くマス。起死回生で狙いたいのはここ。 */
.cell.opened {
  background: #fff6d8;
  border-color: #f2d16b;
}

/* ずらすと相手に取られて負けるマス。 */
.cell.danger {
  background: #ffecec;
  border-color: #d9534f;
  color: #d9534f;
  font-weight: 800;
}

.shift-confirm {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff6fa;
  border: 2px solid var(--pink);
}

/* 負けが見えている向きは色を変えて、うっかり確定しないようにする。 */
.shift-confirm.danger {
  background: #ffecec;
  border-color: #d9534f;
}

.shift-confirm-text {
  margin: 0 0 8px;
  font-size: 12px;
  line-height: 1.6;
}

.shift-confirm-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.shift-commit,
.shift-cancel {
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  border: 2px solid transparent;
}

.shift-commit {
  background: var(--pink);
  color: #ffffff;
}

.shift-confirm.danger .shift-commit {
  background: #d9534f;
}

.shift-cancel {
  background: #ffffff;
  border-color: var(--pink-soft);
  color: var(--text-muted);
}

/* --- バージョン表記 ------------------------------------------------------- */

/* フッターに出す。クリックするとリリースノートがポップアップで開く。
   主導線ではないので、著作権表示と同じくらい控えめにする。 */
.version-link {
  font-size: 10px;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}

.version-link:hover {
  color: var(--pink);
}

