/* クォッカ餅パッチンバトルの画面スタイル。
   配色は他のクォッカ作品と揃えたやわらかいピンク+クリーム。
   このゲーム固有の主役は「距離ptに応じて伸び縮みする餅」(.mochi-arena)で、
   JS(quokka-mochi.js)が --distance-ratio(0〜1)を書き換え、間隔・餅の太さをCSS側で計算する。 */

:root {
  --pink: #e85d84;
  --pink-soft: #ffe3ec;
  --pink-bg: #fff6fa;
  --cream: #fffdfb;
  --text: #5b4a4a;
  --text-muted: #9c8d8d;
  --good: #3fa06b;
  --good-soft: #e3f5ea;
  --danger: #d9534f;
  --danger-soft: #ffeceb;
  --mochi: #fff7ea;
  --mochi-edge: #e8c98a;
}

* {
  box-sizing: border-box;
}

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: 440px;
  background: #ffffff;
  border: 2px solid var(--pink-soft);
  border-radius: 22px;
  padding: 22px 22px 20px;
  box-shadow: 0 10px 30px rgba(232, 93, 132, 0.12);
  text-align: center;
}

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

.sparkle {
  font-size: 16px;
}

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

.waiting-actions {
  margin: 4px 0 14px;
  text-align: center;
}

.waiting-countdown {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--text-muted);
}

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

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

/* --- 餅アリーナ(主役の演出) ------------------------------------------------ */

/* --distance-ratio(0〜1)を JS から書き換えて、間隔と餅の太さを連動させる。
   離れるほど間隔が広がり、餅は細く(薄く)なっていく見た目にしている。 */
.mochi-arena {
  --distance-ratio: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin: 10px auto 4px;
  padding: 6px 0;
}

.distance-caption {
  margin: 0 0 14px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
}

.distance-caption strong,
.distance-caption span {
  color: var(--pink);
}

/* 参加画面の一枚絵。縦長の絵なので高さを抑えて中央に置く。 */
.title-art {
  display: block;
  width: auto;
  height: min(220px, 32vh);
  margin: 0 auto 4px;
}

.mochi-quokka {
  width: 78px;
  height: 62px;
  flex-shrink: 0;
}

.mochi-quokka svg {
  width: 100%;
  height: 100%;
  display: block;
}

.mochi-strand {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  /* 20px(咥え合う至近距離)から最大でビューポート幅の62%まで、距離ptに応じて大胆に伸びる。
     vw分をmin()で足きりすることで、距離ptの上限が大きい設定でも狭い画面からはみ出さない。 */
  width: min(calc(20px + var(--distance-ratio) * 260px), 62vw);
  margin: 0 -6px;
  background: linear-gradient(180deg, var(--mochi) 0%, #fdecc9 100%);
  border: 2px solid var(--mochi-edge);
  border-radius: 999px;
  /* 伸びるほど薄く(細く)なる。伸びを大胆にした分、薄さも強めにして「限界まで伸びた」感を出す。 */
  transform: scaleY(calc(1 - var(--distance-ratio) * 0.62));
  transition: width 0.35s ease, transform 0.35s ease;
}

.mochi-blob {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fffaf0;
  opacity: 0.8;
}

/* 決着の瞬間、餅がはじけて戻る演出。両者が同時に口を開けた/伸びきって
   引きちぎれたときは、どちらにも寄らず左右対称にはじける。 */
@keyframes mochi-snap {
  0% { transform: scaleY(calc(1 - var(--distance-ratio) * 0.62)) scaleX(1.15); }
  40% { transform: scaleY(1.3) scaleX(0.6); }
  100% { transform: scaleY(calc(1 - var(--distance-ratio) * 0.62)) scaleX(1); }
}

.mochi-arena.snap .mochi-strand {
  animation: mochi-snap 0.42s ease;
}

/* 片方だけが口を開けたときは、**開けなかった側へ餅が縮んでいく**。
   transform-origin を当たる側に置くと、口を離した側の端だけが相手のところまで
   一気に走っていく見え方になる(クォッカ自体は動かないので、餅だけが飛ぶ)。
   途中で scaleY が膨らむのは、縮んだぶん餅が太くなって「ぶつかった」ように見せるため。
   62%で縮みきる ≒ quokka-mochi.js の MOCHI_HIT_DELAY_MS(260ms)。 */
@keyframes mochi-hit {
  0% { transform: scaleY(calc(1 - var(--distance-ratio) * 0.62)) scaleX(1); }
  20% { transform: scaleY(calc(1 - var(--distance-ratio) * 0.62)) scaleX(1.06); }
  62% { transform: scaleY(1.45) scaleX(0.04); }
  78% { transform: scaleY(1.2) scaleX(0.35); }
  100% { transform: scaleY(calc(1 - var(--distance-ratio) * 0.62)) scaleX(1); }
}

.mochi-arena.snap-to-a .mochi-strand,
.mochi-arena.snap-to-b .mochi-strand {
  animation: mochi-hit 0.42s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 左(自分)に当たるなら左端へ、右(相手)に当たるなら右端へ寄せる。 */
.mochi-arena.snap-to-a .mochi-strand { transform-origin: left center; }
.mochi-arena.snap-to-b .mochi-strand { transform-origin: right center; }

/* 当てられた側は、餅が届いた瞬間に小さくのけぞる。 */
@keyframes mochi-quokka-hit {
  0%, 55% { transform: translateX(0) rotate(0); }
  70% { transform: translateX(var(--hit-shift, 5px)) rotate(var(--hit-tilt, 6deg)); }
  85% { transform: translateX(calc(var(--hit-shift, 5px) * -0.4)) rotate(calc(var(--hit-tilt, 6deg) * -0.4)); }
  100% { transform: translateX(0) rotate(0); }
}

.mochi-arena.snap-to-a .mochi-quokka-a,
.mochi-arena.snap-to-b .mochi-quokka-b {
  animation: mochi-quokka-hit 0.42s ease;
}

/* のけぞる向きは、餅が飛んできた向きの逆(=外側)。 */
.mochi-arena.snap-to-a .mochi-quokka-a { --hit-shift: -5px; --hit-tilt: -6deg; }
.mochi-arena.snap-to-b .mochi-quokka-b { --hit-shift: 5px; --hit-tilt: 6deg; }

/* 動きを減らす設定にしている人には、往復する演出は出さない。 */
@media (prefers-reduced-motion: reduce) {
  .mochi-arena.snap .mochi-strand,
  .mochi-arena.snap-to-a .mochi-strand,
  .mochi-arena.snap-to-b .mochi-strand,
  .mochi-arena.snap-to-a .mochi-quokka-a,
  .mochi-arena.snap-to-b .mochi-quokka-b {
    animation: none;
  }
}

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

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

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

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

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

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

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

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

.hud-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
  /* 右上に固定表示している音量ボタン(.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;
}

.stat-pill strong {
  color: var(--pink);
}

.status-text {
  min-height: 20px;
  margin: 4px 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
}

/* --- HPバー -------------------------------------------------------------------- */

.hp-rows {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 4px;
}

.hp-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hp-label {
  width: 84px;
  flex-shrink: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 12px;
  font-weight: 700;
  text-align: left;
}

.hp-bar {
  flex: 1;
  height: 14px;
  background: var(--pink-bg);
  border: 2px solid var(--pink-soft);
  border-radius: 999px;
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  width: 100%;
  background: var(--good);
  border-radius: 999px;
  transition: width 0.3s ease, background 0.3s ease;
}

.hp-fill.low {
  background: var(--danger);
}

.hp-value {
  width: 52px;
  flex-shrink: 0;
  font-size: 12px;
  text-align: right;
}

/* --- ラウンド持ち時間バー -------------------------------------------------------- */

.round-bar {
  width: 100%;
  max-width: 420px;
  height: 5px;
  margin: 6px 0 14px;
  background: var(--pink-soft);
  border-radius: 999px;
  overflow: hidden;
}

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

/* --- 行動ボタン ----------------------------------------------------------------- */

.action-row {
  width: 100%;
  max-width: 420px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 6px;
}

.action-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 12px 6px;
  background: #ffffff;
  border: 2px solid var(--pink-soft);
  border-radius: 16px;
  text-align: center;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}

/* 「口を開ける」のクールダウン残りラウンド数。空文字のときは:emptyで自動的に隠れるので、
   JS側は表示/非表示を気にせずtextContentを書き換えるだけでよい。画面幅に関わらず常に
   見えるようにしたい(action-descはモバイルで非表示になるため、そちらには乗せない)。 */
.cooldown-badge {
  position: absolute;
  top: 4px;
  right: 6px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 800;
  color: #ffffff;
  background: var(--text-muted);
  border-radius: 999px;
  line-height: 1.5;
}

.cooldown-badge:empty {
  display: none;
}

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

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

.action-icon {
  font-size: 24px;
}

.action-name {
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
}

.action-desc {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.4;
}

.action-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.action-btn.chosen {
  border-color: var(--pink);
  background: var(--pink-bg);
  opacity: 1;
}

.action-btn.locked-out {
  opacity: 0.35;
}

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

.result-panel .secondary {
  width: 100%;
  margin-top: 8px;
}

.result-panel {
  width: 100%;
  max-width: 420px;
  margin-top: 16px;
  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;
}

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

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

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

.version-link {
  font-size: 10px;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}

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

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

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

  .mochi-quokka {
    width: 64px;
    height: 50px;
  }

  .mochi-strand {
    width: min(calc(14px + var(--distance-ratio) * 170px), 58vw);
  }

  .hud-top {
    gap: 6px;
  }

  .stat-pill {
    font-size: 11px;
    padding: 4px 10px;
  }

  .action-desc {
    display: none;
  }
}
