/* =========================================================
 * style.css — モバイルファーストUI
 * ========================================================= */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  /* ダブルタップでの拡大を止める。iOS Safariはmetaのuser-scalable=noを無視するため、
     全要素に指定して確実に効かせる(通常のタップ・スクロールは今まで通り使える) */
  touch-action: manipulation;
}

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none; /* 引っ張り更新の誤発動防止 */
}

body {
  font-family: 'Hiragino Maru Gothic ProN', 'BIZ UDGothic', system-ui, sans-serif;
  background: linear-gradient(180deg, #1e272e 0%, #2d3436 100%);
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100dvh; /* スマホのアドレスバーを考慮した高さ */
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ===== HUD ===== */

#hud {
  width: 100%;
  padding: 8px 14px 6px;
  flex-shrink: 0;
}

.hud-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-row.gauges {
  margin-top: 6px;
  gap: 12px;
}

.score-box {
  display: flex;
  flex-direction: column;
  min-width: 105px;
}

.score-box.small { min-width: 82px; opacity: 0.85; }

.score-label {
  font-size: 12px;
  color: #b2bec3;
  letter-spacing: 0.1em;
}

.score-value {
  font-size: 28px;
  font-weight: bold;
  line-height: 1.1;
  color: #ffeaa7;
}

.score-box.small .score-value { font-size: 19px; color: #dfe6e9; }

#next-box {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#next-face {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.next-face-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#btn-mute,
#btn-bgm {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 10px;
  width: 48px;
  height: 48px;
  cursor: pointer;
}

#btn-mute { font-size: 22px; }

#btn-bgm {
  color: #74b9ff;
  font-size: 9px;
  font-weight: bold;
  line-height: 1.1;
}

#btn-bgm[aria-pressed="false"],
#btn-vs-bgm[aria-pressed="false"] {
  color: #b2bec3;
  opacity: 0.72;
}

/* ゲージ共通 */
.gauge {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.gauge-label {
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 0.08em;
  color: #b2bec3;
  white-space: nowrap;
}

.gauge-track {
  flex: 1;
  height: 12px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 5px;
  overflow: hidden;
}

.gauge-fill {
  height: 100%;
  width: 0%;
  border-radius: 5px;
  transition: width 0.25s ease-out;
}

/* フィーバーゲージ */
.fever-gauge .gauge-fill {
  background: linear-gradient(90deg, #ff9f43, #ff6b81, #a55eea);
}

body.fever #fever-label {
  color: #ff6b81;
  animation: blink 0.5s infinite alternate;
}

/* 機嫌ゲージ */
.mood-gauge .gauge-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.gauge-face {
  font-size: 27px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  overflow: hidden;
}

.mood-face-img, .cutin-face-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.mood-gauge .gauge-fill { background: #74b9ff; }
.mood-gauge .gauge-fill[data-state="happy"] { background: linear-gradient(90deg, #ffeaa7, #ff9ff3); }
.mood-gauge .gauge-fill[data-state="angry"] { background: linear-gradient(90deg, #d63031, #ff7675); }

/* ===== キャラクター進化順 ===== */

.character-order {
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: calc(100% - 12px);
  min-height: 50px;
  margin: 0 auto 4px;
  padding: 4px 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.24);
  flex-shrink: 0;
}

.character-order-title {
  width: 36px;
  color: #ffeaa7;
  font-size: 11px;
  font-weight: bold;
  line-height: 1.15;
  text-align: center;
  flex-shrink: 0;
}

.character-order-track {
  display: flex;
  align-items: center;
  gap: 1px;
  min-width: 0;
  padding: 1px 2px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.character-order-track::-webkit-scrollbar { display: none; }

.character-order-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.09);
  flex: 0 0 34px;
}

.character-order-item img {
  width: 33px;
  height: 33px;
  object-fit: contain;
}

.character-order-fallback { font-size: 20px; }

.character-order-number {
  position: absolute;
  left: 1px;
  bottom: 0;
  min-width: 13px;
  height: 13px;
  padding: 0 2px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 9px;
  line-height: 13px;
  text-align: center;
}

.character-order-arrow {
  color: #ff9f43;
  width: 7px;
  font-size: 8px;
  text-align: center;
  line-height: 1;
  flex-shrink: 0;
}

/* ===== ゲーム画面 ===== */

#game-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 0; /* flexで縮められるように */
  display: flex;
  justify-content: center;
}

.hitbox-toggle {
  position: absolute;
  top: 8px;
  right: 32px;
  z-index: 12;
  min-width: 68px;
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid rgba(116, 255, 107, 0.6);
  border-radius: 10px;
  background: rgba(20, 30, 32, 0.82);
  color: #b8ffb2;
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
}

.hitbox-toggle.is-active,
[data-hitbox-toggle].is-active {
  color: #1e272e;
  background: #74ff6b;
  border-color: #74ff6b;
}

#game-canvas {
  height: 100%;
  max-width: 100%;
  aspect-ratio: 420 / 700;
  object-fit: contain;
  touch-action: none; /* スワイプでのスクロールを止める */
  cursor: pointer;
}

/* ロマ子様をゲームオーバーライン上に常駐させる */
.drop-animation-layer {
  --actor-x: 50%;
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 4;
}

.drop-animation-actor {
  position: absolute;
  bottom: 77.6%; /* 画像下部の透明余白を含め、見える足先をDEADLINE_Yへ合わせる */
  left: var(--actor-x);
  z-index: 1;
  width: min(20%, 100px);
  height: auto;
  transform: translateX(-50%);
  filter: drop-shadow(0 4px 5px rgba(0, 0, 0, 0.4));
  transition: left 0.12s linear, opacity 0.12s;
}

.drop-animation-held-pig {
  position: absolute;
  top: 12%;
  left: var(--actor-x);
  z-index: 2;
  width: var(--pig-size, 10%);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.48));
  transition: left 0.12s linear;
}

.drop-animation-held-pig img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.drop-animation-layer[data-drop-phase="taking"] .drop-animation-held-pig {
  animation: take-pig-from-back 0.36s ease-out both;
}

.drop-animation-layer[data-drop-phase="releasing"] .drop-animation-held-pig {
  z-index: 3;
  animation: release-held-pig 0.45s ease-in both;
}

@keyframes take-pig-from-back {
  0% {
    opacity: 0;
    z-index: 0;
    left: calc(var(--actor-x) + 7%);
    top: 12%;
    transform: translate(-50%, -50%) scale(0.55);
  }
  32% {
    opacity: 1;
    z-index: 0;
    left: calc(var(--actor-x) + 6%);
    top: 11.5%;
    transform: translate(-50%, -50%) scale(0.7);
  }
  100% {
    opacity: 1;
    z-index: 2;
    left: var(--actor-x);
    top: 12%;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes release-held-pig {
  0% {
    opacity: 1;
    left: var(--actor-x);
    top: 12%;
    transform: translate(-50%, -50%) scale(1);
  }
  72% {
    opacity: 1;
    z-index: 3;
    left: var(--actor-x);
    top: 15%;
    transform: translate(-50%, -50%) scale(1);
  }
  88% {
    opacity: 1;
    z-index: 3;
    left: var(--actor-x);
    top: 20%;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    z-index: 3;
    left: var(--actor-x);
    top: 22%;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* フリーズ中の演出 */
body.frozen #game-canvas {
  filter: hue-rotate(140deg) saturate(0.8) brightness(1.1);
}

/* フィーバー中の背景演出 */
body.fever #app {
  animation: fever-bg 1.2s infinite alternate;
}

@keyframes fever-bg {
  from { background: rgba(255, 107, 129, 0.06); }
  to   { background: rgba(165, 94, 234, 0.12); }
}

/* コンボ表示 */
#combo-badge {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%) scale(0.8);
  background: rgba(255, 107, 129, 0.9);
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: bold;
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
  white-space: nowrap;
}

#combo-badge.show {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* ロマ子様の吹き出し */
#romako-bubble {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  max-width: 88%;
  background: #fff;
  color: #2d3436;
  padding: 8px 14px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: bold;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

#romako-bubble::after { /* 吹き出しのしっぽ */
  content: '';
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: #fff;
  border-bottom: none;
}

#romako-bubble.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* カットイン */
#romako-cutin {
  position: absolute;
  top: 34%;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 16px;
  background: linear-gradient(90deg, transparent, rgba(214, 48, 49, 0.85) 15%, rgba(214, 48, 49, 0.85) 85%, transparent);
  font-size: 16px;
  font-weight: bold;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
}

#romako-cutin.show {
  animation: cutin 2s ease forwards;
}

#romako-cutin-face {
  font-size: 30px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}

@keyframes cutin {
  0%   { opacity: 0; transform: translateX(-40px); }
  12%  { opacity: 1; transform: translateX(0); }
  85%  { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(30px); }
}

@keyframes blink {
  from { opacity: 1; }
  to   { opacity: 0.6; }
}

/* ===== タイトル・リザルト画面 ===== */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 25, 30, 0.92);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 200;
}

.screen[hidden] { display: none; }

.screen.show {
  opacity: 1;
  pointer-events: auto;
}

.screen-inner {
  text-align: center;
  padding: 24px;
  max-width: 400px;
  width: 100%;
  max-height: 100dvh;
  overflow-y: auto;
}

.screen-inner.title-screen-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 560px;
  height: 100dvh;
  padding: 0;
  overflow: hidden;
  background: #11181d;
}

.title-art {
  position: relative;
  width: min(100%, 46.914dvh);
  aspect-ratio: 859 / 1831;
  flex: 0 0 auto;
}

.title-art > img {
  display: block;
  width: 100%;
  height: 100%;
}

.title-art-button {
  position: absolute;
  left: 8%;
  width: 84%;
  height: 6.2%;
  border: 0;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
}

.title-art-button:active {
  background: rgba(255, 255, 255, 0.12);
}

.title-art-button:focus-visible {
  outline: 4px solid #fff;
  outline-offset: -5px;
}

.title-art-button-solo { top: 63%; }
.title-art-button-cpu { top: 70.2%; }
.title-art-button-online { top: 76.8%; }

.game-title {
  font-size: 40px;
  line-height: 1.3;
  margin-bottom: 8px;
  background: linear-gradient(180deg, #ffeaa7, #ff9f43);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.title-emoji {
  font-size: 52px;
  -webkit-text-fill-color: initial;
}

.title-copy {
  color: #b2bec3;
  font-size: 16px;
  margin-bottom: 24px;
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(90deg, #ff6b81, #ff9f43);
  color: #fff;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(255, 107, 129, 0.4);
  transition: transform 0.1s;
}

.btn-primary:active { transform: scale(0.97); }

.btn-secondary {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 14px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 14px;
  background: transparent;
  color: #dfe6e9;
  font-size: 17px;
  cursor: pointer;
}

.title-mode-button { margin-top: 10px; }

.btn-link {
  margin-top: 14px;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: #b2bec3;
  font-size: 14px;
  text-decoration: underline;
  cursor: pointer;
}

.mode-title { color: #ffeaa7; font-size: 30px; margin-bottom: 10px; }
.mode-copy { color: #b2bec3; font-size: 16px; margin-bottom: 22px; }
.cpu-level-copy { margin: 14px 0 8px; }

#screen-cpu .screen-inner,
#screen-online .screen-inner {
  max-width: 880px;
  padding: 20px;
}

#screen-cpu .mode-title,
#screen-online .mode-title {
  margin-bottom: 3px;
  font-size: 25px;
}

#screen-cpu > .screen-inner > .mode-copy,
#screen-online > .screen-inner > .mode-copy {
  margin-bottom: 8px;
  font-size: 13px;
}

#screen-cpu .cpu-level-copy { margin: 7px 0 5px; }
#screen-cpu .btn-link { margin-top: 5px; padding-block: 4px; }

/* 「戻る」は指で押しやすいよう高さ44pxを確保する(詰めすぎると押し間違えるため) */
#screen-cpu .btn-link,
#screen-online .btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}

.cpu-level-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.cpu-level-actions .btn-primary,
.cpu-level-actions .btn-secondary {
  margin-top: 0;
  padding: 12px 8px;
  font-size: 16px;
}

.online-selection-layout {
  display: grid;
  grid-template-columns: minmax(0, 2.5fr) minmax(220px, 1fr);
  align-items: center;
  gap: 12px;
}

.online-selection-layout .vs-rule-settings { margin-bottom: 0; }

.online-room-actions {
  min-width: 0;
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
}

.online-room-actions .btn-link { margin-top: 7px; }

/* ===== 対戦ルール選択 ===== */

.vs-rule-settings {
  margin-bottom: 8px;
  padding: 10px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
}

.vs-rule-tabs { display: flex; gap: 8px; }

.vs-rule-btn {
  flex: 1;
  min-height: 44px;
  padding: 8px 10px;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  background: transparent;
  color: #b2bec3;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
}

.vs-rule-btn.is-active {
  border-color: #ff9f43;
  background: rgba(255, 159, 67, 0.16);
  color: #fff;
}

.vs-rule-option {
  display: flex;
  align-items: center;
  /* ラベルと選択欄をまとめて右寄せにする(画面が広い時にラベルだけ遠く離れないように) */
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
  color: #dfe6e9;
  font-size: 15px;
  font-weight: bold;
}

.vs-rule-option[hidden] { display: none; }
.vs-rule-option select {
  min-width: 120px;
  /* 指で押しやすい高さを確保する */
  min-height: 44px;
  padding: 8px 12px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 11px;
  background: #2d3436;
  color: #fff;
  font-size: 15px;
}

.vs-rule-help { margin-top: 7px; color: #74b9ff; font-size: 12px; line-height: 1.35; }

.vs-score-rules {
  margin-top: 6px;
  padding: 7px;
  border: 1px solid rgba(255, 234, 167, 0.22);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.16);
  text-align: left;
}

.vs-score-rules[hidden] { display: none; }

.vs-score-rules h3 {
  margin: 0 0 7px;
  color: #ffeaa7;
  font-size: 14px;
  text-align: center;
}

/* 中身の文字数に合わせて自動で折り返す(4列固定にすると、スマホの幅では
   「相手へ+34」のような長い文字がセルからはみ出して隣と重なるため) */
.vs-score-rule-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 5px;
}

.vs-score-rule {
  display: grid;
  grid-template-columns: 25px minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  min-width: 0;
  padding: 4px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
}

.vs-score-rule-face {
  grid-row: 1 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  overflow: hidden;
  font-size: 17px;
}

.vs-score-rule-face img {
  display: block;
  width: 24px;
  height: 24px;
  object-fit: contain;
}

/* はみ出さないよう、セル幅で切り詰める(nowrap のままだと隣の列に重なる) */
.vs-score-rule-source {
  min-width: 0;
  overflow: hidden;
  color: #b2bec3;
  font-size: 10px;
  line-height: 1.1;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.vs-score-rule-points {
  min-width: 0;
  overflow: hidden;
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  line-height: 1.15;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.vs-score-rules > p {
  margin: 7px 0 3px;
  color: #b2bec3;
  font-size: 11px;
  line-height: 1.4;
}

.vs-score-rules > strong {
  display: block;
  color: #ff7675;
  font-size: 12px;
  text-align: center;
}

.vs-king-rules {
  border-color: rgba(253, 203, 110, 0.34);
  background: linear-gradient(135deg, rgba(253, 203, 110, 0.08), rgba(255, 159, 67, 0.04));
}

.vs-king-rules .vs-score-rule {
  background: rgba(253, 203, 110, 0.09);
}

.vs-king-rules .vs-score-rule-points,
.vs-king-rules > strong {
  color: #ffeaa7;
}

.vs-king-rules-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.vs-king-gauge-rules,
.vs-king-special-rules {
  min-width: 0;
  padding: 8px;
  border: 1px solid rgba(253, 203, 110, 0.2);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.1);
}

.vs-king-gauge-rules > p,
.vs-king-special-rules > p {
  margin: 6px 0 0;
  color: #b2bec3;
  font-size: 10px;
  line-height: 1.3;
}

.vs-king-rules > .vs-combo-attack-rule {
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid rgba(116, 185, 255, 0.48);
  border-radius: 9px;
  background: rgba(9, 132, 227, 0.14);
  color: #74b9ff;
  font-size: 12px;
  font-weight: bold;
  line-height: 1.4;
  text-align: center;
}

.vs-king-traits {
  margin: 0;
  padding: 0;
}

.vs-king-traits h3 { margin-bottom: 6px; }

.vs-king-trait-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.vs-king-trait {
  display: flex;
  align-items: flex-start;
  min-width: 0;
  gap: 5px;
  padding: 6px;
  border: 1px solid rgba(116, 220, 255, 0.2);
  border-radius: 8px;
  background: rgba(20, 63, 84, 0.28);
}

.vs-king-trait-icon {
  flex: 0 0 auto;
  font-size: 17px;
  line-height: 1.15;
}

.vs-king-trait > span:last-child { min-width: 0; }

.vs-king-trait strong,
.vs-king-trait small {
  display: block;
  line-height: 1.25;
}

.vs-king-trait strong {
  color: #dff8ff;
  font-size: 10px;
}

.vs-king-trait small {
  margin-top: 2px;
  color: #b2bec3;
  font-size: 9px;
}

@media (max-width: 640px) {
  #screen-cpu .screen-inner,
  #screen-online .screen-inner { max-width: 620px; }
  .online-selection-layout { grid-template-columns: 1fr; }
  .vs-king-rules-layout { grid-template-columns: 1fr; }
}

.room-divider { margin: 15px 0 10px; color: #636e72; font-size: 12px; }
.room-label { display: block; text-align: left; color: #dfe6e9; font-size: 12px; }
.room-input {
  width: 100%;
  margin: 6px 0 0;
  padding: 13px;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 22px;
  font-weight: bold;
  letter-spacing: 0.18em;
  text-align: center;
  text-transform: uppercase;
  user-select: text;
  -webkit-user-select: text;
}
.room-input:focus { outline: none; border-color: #ff9f43; }
.room-created {
  margin-top: 16px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255,211,42,0.1);
}
.room-created span { display: block; color: #b2bec3; font-size: 12px; }
.room-created strong { display: block; margin-top: 4px; color: #ffd32a; font-size: 28px; letter-spacing: 0.16em; }
.online-status { min-height: 20px; margin-top: 12px; color: #74b9ff; font-size: 13px; }
.online-status.error { color: #ff7675; }
.online-status[data-state="connecting"] { color: #ffeaa7; }
.online-status[data-state="connected"] { color: #74b9ff; }
.online-status[data-state="waiting"] { color: #a29bfe; }
.online-status[data-state="ready"] { color: #55efc4; font-weight: bold; }
.online-status[data-state="delayed"] { color: #fdcb6e; }
.online-status[data-state="error"] { color: #ff7675; font-weight: bold; }

.online-ready-panel {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(116, 185, 255, 0.35);
  border-radius: 14px;
  background: rgba(9, 132, 227, 0.09);
}
.online-ready-panel[hidden] { display: none; }
.online-rule-summary { color: #ffeaa7; font-size: 15px; font-weight: bold; }
.online-rule-notes { margin: 6px 0 10px; color: #dfe6e9; font-size: 11px; line-height: 1.5; }
.ready-state { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 10px; font-size: 12px; color: #b2bec3; }
.ready-state .is-ready { color: #55efc4; font-weight: bold; }
.online-ready-panel .btn-primary { padding: 12px; font-size: 16px; }
.online-ready-panel .btn-primary:disabled { opacity: 0.55; cursor: default; }
.vs-rule-btn:disabled, .vs-rule-option select:disabled { opacity: 0.5; cursor: default; }

/* ===== 対戦画面 ===== */

#versus-view {
  display: none;
  flex-direction: column;
  width: 100%;
  max-width: 1000px;
  height: 100dvh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

body.versus-mode #app { display: none; }
#versus-view.active { display: flex; }

.vs-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  column-gap: 8px;
  row-gap: 5px;
  align-items: center;
  padding: 9px 12px;
  flex-shrink: 0;
}
.vs-player-hud { display: flex; flex-direction: column; font-size: 12px; color: #b2bec3; }
.vs-player-hud.opponent { align-items: flex-end; text-align: right; }
.vs-player-hud strong { color: #ffeaa7; font-size: 24px; line-height: 1.05; }
.vs-name { color: #fff; font-weight: bold; font-size: 14px; }
.vs-center-hud {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 96px;
  text-align: center;
  font-size: 12px;
  color: #b2bec3;
}
/* 「CPU ふつう・ラ／イフバトル」のように語の途中で折れないようにする */
.vs-center-hud strong { color: #ff9f43; font-size: 15px; word-break: keep-all; overflow-wrap: anywhere; }
.vs-round-info:not(.is-timer) { word-break: keep-all; overflow-wrap: anywhere; }
.vs-center-hud #vs-status[data-state="ready"] { color: #55efc4; }
.vs-center-hud #vs-status[data-state="playing"] { color: #74b9ff; font-weight: bold; }
.vs-center-hud #vs-status[data-state="waiting"] { color: #ffeaa7; }
.vs-center-hud #vs-status[data-state="delayed"] { color: #fdcb6e; font-weight: bold; }
.vs-center-hud #vs-status[data-state="error"] { color: #ff7675; font-weight: bold; }
.vs-round-info { color: #ffeaa7; font-size: 13px; font-weight: bold; }

/* 残り時間は勝負を左右する情報なので、大きく等幅で目立たせる
   (等幅にしないと数字が変わるたびに幅が動いてチラつく) */
.vs-round-info.is-timer {
  display: inline-block;
  margin-top: 2px;
  padding: 3px 12px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.42);
  color: #fff;
  font-size: 25px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}

/* 残りわずかになったら赤く点滅させて気づかせる */
.vs-round-info.is-timer.is-urgent {
  color: #ff7675;
  background: rgba(255, 118, 117, 0.16);
  animation: timer-pulse 1s ease-in-out infinite;
}

@keyframes timer-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}

/* 動きが苦手な人のために、点滅を止める設定なら色だけで知らせる */
@media (prefers-reduced-motion: reduce) {
  .vs-round-info.is-timer.is-urgent { animation: none; }
}
.vs-lives { color: #ff7675; font-size: 13px; font-weight: bold; white-space: nowrap; }
.vs-next {
  display: flex;
  align-items: center;
  width: max-content;
  margin-top: 4px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.32);
  color: #b2bec3;
  font-size: 9px;
  font-weight: bold;
  line-height: 1;
  pointer-events: none;
}
.vs-player-hud.opponent .vs-next { align-self: flex-end; }
.vs-next span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  margin-left: 3px;
  font-size: 42px;
}
.vs-next-img {
  display: block;
  width: 56px;
  height: 56px;
  object-fit: contain;
}
.vs-king-tug-gauge {
  grid-column: 1 / -1;
  grid-row: 2;
  justify-self: center;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 11px;
  align-items: center;
  width: min(calc(100vw - 32px), 860px);
  margin: 4px 0 3px;
  color: #ffeaa7;
  font-size: 14px;
  font-weight: bold;
}
.vs-king-tug-gauge[hidden] { display: none; }
.vs-king-tug-label { white-space: nowrap; }
.vs-king-tug-label.self { color: #74b9ff; }
.vs-king-tug-label.rival { color: #ff7675; }
.vs-king-tug-track {
  position: relative;
  display: block;
  width: 100%;
  height: 28px;
  border: 4px solid rgba(255, 234, 167, 0.82);
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(116,185,255,0.4), rgba(255,255,255,0.1) 50%, rgba(255,118,117,0.4));
  box-shadow: 0 0 12px rgba(255, 234, 167, 0.15);
}
.vs-king-tug-fill {
  position: absolute;
  top: 3px;
  left: 50%;
  width: 0;
  height: 14px;
  border-radius: 999px;
  background: #ffd32a;
  box-shadow: 0 0 9px rgba(255, 211, 42, 0.92);
  transition: left 0.15s linear, width 0.15s linear, background 0.15s linear;
}
.vs-king-tug-center {
  position: absolute;
  top: -7px;
  bottom: -7px;
  left: 50%;
  width: 3px;
  transform: translateX(-1.5px);
  background: rgba(255,255,255,0.9);
}
.vs-king-tug-marker {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  transform: translate(-50%, -52%);
  font-size: 38px;
  line-height: 1;
  filter: drop-shadow(0 2px 3px #000);
  transition: left 0.15s linear;
}
.vs-king-tug-gauge.near-max .vs-king-tug-track,
.vs-king-tug-gauge.near-max .vs-king-tug-marker {
  animation: king-gauge-alert 0.55s ease-in-out infinite alternate;
}
@keyframes king-gauge-alert {
  from { filter: brightness(1); }
  to { filter: brightness(1.7) drop-shadow(0 0 5px #ffd32a); }
}
.versus-order { max-width: 620px; margin-bottom: 2px; }

/* 進化順バーの表示/非表示(display 指定に [hidden] が負けるため明示) */
.versus-order[hidden] { display: none; }

.vs-boards {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  overflow: hidden;
}
.vs-board-wrap { position: relative; }

/* 自分の盤面: 高さ・幅の両方に収まる最大サイズを JS(_fitLocalBoard)が
   ピクセルで指定する。CSSの aspect-ratio + max-width だけでは縦横比が崩れるため */
.vs-board-wrap.local {
  flex: 0 0 auto;
  z-index: 1;
}
.vs-board-wrap.local canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}

/* 相手の盤面: 自分の盤面の右上に重ねる小窓
   盤面上部(点線ラインより上)は普段フルーツが来ないので邪魔になりにくい */
.vs-board-wrap.opponent-mini {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  width: 24%;
  max-width: 130px;
  aspect-ratio: 420 / 700;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 7px;
  overflow: hidden;
  opacity: 0.93;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45);
  pointer-events: none;   /* 自分の操作を邪魔しない */
}
.vs-board-wrap.opponent-mini canvas {
  display: block;
  width: 100%;
  height: 100%;
}
/* 相手小窓は狭いので、ロマ子様の落下演出は出さない(はみ出し防止の保険) */
.vs-board-wrap.opponent-mini .drop-animation-layer { display: none; }
.vs-countdown {
  position: absolute;
  inset: 0;
  z-index: 100; /* 盤面・壁・相手小窓より必ず手前に表示する */
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffd32a;
  font-size: clamp(50px, 20vw, 120px);
  font-weight: bold;
  text-shadow: 0 4px 14px #000;
  pointer-events: none;
}
.vs-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-height: 42px;
  padding: 2px 12px calc(2px + env(safe-area-inset-bottom));
  color: #b2bec3;
  font-size: 13px;
  flex-shrink: 0;
}
.vs-footer .btn-link { margin: 0; font-size: 13px; }
/* 狭い画面ではボタンが左へはみ出して押せなくなるため、収まらない分は折り返す */
.vs-footer-links {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 4px 10px;
  min-width: 0;
}

/* ===== 対戦コンボ表示 ===== */

.vs-combo-badge {
  position: absolute;
  top: 22%;
  left: 50%;
  z-index: 4;
  max-width: 92%;
  transform: translateX(-50%) scale(0.72);
  color: #ffd32a;
  font-size: clamp(20px, 6vw, 38px);
  font-weight: 900;
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
  text-shadow: 0 3px 0 #d35400, 0 5px 12px #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s, transform 0.18s;
}

.vs-combo-badge.show {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.vs-attack-flight {
  position: absolute;
  left: 46%;
  top: 45%;
  z-index: 90;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  box-shadow: 0 0 18px rgba(217, 154, 82, 0.9);
  opacity: 0;
  pointer-events: none;
}
.vs-attack-flight img { width: 100%; height: 100%; object-fit: contain; }
.vs-attack-flight[data-kind="king"] {
  width: 66px;
  height: 66px;
  filter: drop-shadow(0 0 10px #ffd32a);
}
.vs-attack-flight.show { animation: garbage-flight 0.85s ease-in forwards; }
@keyframes garbage-flight {
  0% { opacity: 1; transform: translate(-50%, 20px) scale(0.75) rotate(-20deg); }
  65% { opacity: 1; transform: translate(105px, -125px) scale(1.05) rotate(250deg); }
  100% { opacity: 0; transform: translate(145px, -165px) scale(0.5) rotate(420deg); }
}

.vs-board-wrap.local.garbage-impact { animation: garbage-impact 0.62s ease-out; }
@keyframes garbage-impact {
  0%, 100% { filter: none; transform: translate(0, 0); }
  18% { filter: drop-shadow(0 0 18px #ff4757); transform: translate(-5px, 2px); }
  36% { transform: translate(5px, -2px); }
  54% { transform: translate(-3px, 1px); }
}

/* 盤面の一番上に細い帯で出す。中央に出すと落とす場所が隠れて操作の邪魔になるため、
   ブタを積み上げる領域にはかからない高さに収める */
.vs-king-cutin {
  position: absolute;
  inset: 0 0 auto;
  z-index: 95;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 0;
  padding: 6px 14px;
  color: #4a2600;
  background: linear-gradient(90deg, transparent, rgba(255,211,42,0.97) 18%, #fff3a3 50%, rgba(255,211,42,0.97) 82%, transparent);
  font-size: clamp(15px, 3.6vw, 24px);
  font-weight: 900;
  text-align: center;
  text-shadow: 0 1px 0 #fff;
  opacity: 0;
  transform: translateX(-110%) skewX(-8deg);
  pointer-events: none;
}
.vs-king-cutin.incoming {
  color: #fff;
  background: linear-gradient(90deg, transparent, rgba(214,48,49,0.96) 18%, #ff7675 50%, rgba(214,48,49,0.96) 82%, transparent);
  text-shadow: 0 2px 5px #6b0000;
}
.vs-king-cutin.show { animation: king-cutin 1.2s ease-out forwards; }
.vs-king-cutin-crown { font-size: 1.15em; }
@keyframes king-cutin {
  0% { opacity: 0; transform: translateX(-110%) skewX(-8deg); }
  18%, 72% { opacity: 1; transform: translateX(0) skewX(-8deg); }
  100% { opacity: 0; transform: translateX(110%) skewX(-8deg); }
}

/* ===== 攻撃を受けた時のお知らせ ===== */

/* ブタを持つ位置のすぐ上に出す。中央に出すと落下・積み上げの視界をふさぐため。
   --vs-drop-top は versus.js の _fitBoards() が実寸から計算して渡す
   (画面幅で盤面の高さが変わるので、固定pxだとどこかの端末でズレる)。
   下端を基準にしているので、文字が折り返しても上へ伸びて落下エリアに入らない */
.vs-effect-banner {
  position: absolute;
  bottom: calc(100% - var(--vs-drop-top, 44px) + 6px);
  left: 50%;
  transform: translateX(-50%) scale(0.85);
  z-index: 5;
  max-width: calc(100% - 16px);
  padding: 6px 16px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: bold;
  /* 狭い画面では「…」で切れて内容が分からなくなるので折り返す */
  text-align: center;
  line-height: 1.25;
  word-break: keep-all;
  overflow-wrap: anywhere;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}

.vs-effect-banner.show { opacity: 1; transform: translateX(-50%) scale(1); }
/* 受けた時は赤、撃った時は青で区別する */
.vs-effect-banner[data-kind="hit"] { background: rgba(214, 48, 49, 0.92); color: #fff; }
.vs-effect-banner[data-kind="sent"] { background: rgba(9, 132, 227, 0.92); color: #fff; }
.vs-effect-banner[data-kind="delivered"] { background: rgba(0, 184, 148, 0.94); color: #fff; }
.vs-effect-banner[data-kind="defend"] { background: rgba(108, 92, 231, 0.94); color: #fff; }
.vs-effect-banner[data-kind="king"] { background: rgba(253, 203, 110, 0.96); color: #4a2600; }
.vs-effect-banner[data-kind="king-hit"] { background: rgba(108, 16, 16, 0.96); color: #ffd32a; }
.vs-effect-banner[data-kind="life-barrier"] { background: rgba(9, 132, 227, 0.96); color: #e8fbff; }
.vs-effect-banner[data-kind="absorb"] { background: rgba(245, 190, 45, 0.97); color: #3d2500; }

/* 時間停止中は盤面を暗くして操作できないと分かるように */
.vs-board-wrap.local.stunned canvas { filter: grayscale(0.7) brightness(0.55); }
.vs-result-scores { display: flex; justify-content: space-around; align-items: baseline; }
.vs-result-scores p:last-child { color: #b2bec3; }
.vs-result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin: -8px 0 16px;
}
.vs-result-stats div { padding: 7px; border-radius: 9px; background: rgba(255,255,255,0.07); }
.vs-result-stats dt { color: #b2bec3; font-size: 11px; }
.vs-result-stats dd { color: #ffeaa7; font-size: 18px; font-weight: bold; }

/* 画面が広い時(タブレット・PC・横向き)は2つ並べたほうが見やすいので横並びに戻す */
@media (min-width: 720px) {
  .vs-boards { gap: 16px; }
  /* 小窓をやめて通常の盤面に戻す(大きさは _fitBoards が指定する) */
  .vs-board-wrap.opponent-mini {
    position: static;
    max-width: none;
    aspect-ratio: auto;
    opacity: 1;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }
  @keyframes garbage-flight {
    0% { opacity: 1; transform: translate(-120px, 20px) scale(0.75) rotate(-20deg); }
    65% { opacity: 1; transform: translate(150px, -40px) scale(1.05) rotate(250deg); }
    100% { opacity: 0; transform: translate(260px, 0) scale(0.5) rotate(420deg); }
  }
}

@media (max-width: 520px) {
  #app { max-width: 100%; }
  #hud { padding: 7px 10px 5px; }
  .hud-row { gap: 8px; }
  .score-box { min-width: 90px; }
  .score-box.small { min-width: 70px; }
  .score-label { font-size: 11px; }
  .score-value { font-size: 25px; }
  .score-box.small .score-value { font-size: 17px; }
  #next-face { width: 54px; height: 54px; font-size: 30px; }
  #btn-mute, #btn-bgm { width: 45px; height: 45px; }
  #btn-mute { font-size: 20px; }
  .gauge-label { font-size: 11px; }
  .gauge-track { height: 11px; }
  .gauge-face { width: 33px; height: 33px; font-size: 25px; }
  .character-order { min-height: 46px; gap: 6px; padding: 3px 6px; }
  .character-order-title { width: 30px; font-size: 10px; }
  .character-order-item { width: 28px; height: 28px; flex-basis: 28px; }
  .character-order-item img { width: 27px; height: 27px; }
}

@media (max-width: 420px) {
  #hud { padding-inline: 8px; }
  .hud-row { gap: 6px; }
  .score-box { min-width: 72px; }
  .score-box.small { min-width: 58px; }
  .score-label { font-size: 10px; }
  .score-value { font-size: 24px; }
  #next-face { width: 50px; height: 50px; font-size: 28px; }
  #btn-mute, #btn-bgm { width: 42px; height: 42px; }
  .character-order { gap: 4px; }
  .character-order-title { width: 26px; font-size: 9px; }
  .character-order-track { gap: 2px; }
  .character-order-item { width: 26px; height: 26px; flex-basis: 26px; }
  .character-order-item img { width: 25px; height: 25px; }
  .character-order-arrow { display: none; }
  .vs-header { column-gap: 3px; row-gap: 4px; padding-inline: 6px; }
  .vs-player-hud strong { font-size: 17px; }
  .vs-center-hud { min-width: 88px; }
  .vs-center-hud strong { font-size: 11px; }
  .vs-round-info { max-width: 88px; font-size: 10px; line-height: 1.15; text-align: center; }
  /* 残り時間だけは狭い画面でも縮めない(見えないと意味がないため) */
  .vs-round-info.is-timer { max-width: none; font-size: 21px; padding-inline: 8px; }
  .vs-next { margin-top: 3px; padding: 1px 4px; font-size: 8px; }
  .vs-next span { width: 46px; height: 46px; font-size: 34px; }
  .vs-next-img { width: 44px; height: 44px; }
  .vs-king-tug-gauge { width: calc(100vw - 12px); gap: 5px; font-size: 10px; }
  .vs-king-tug-track { height: 22px; border-width: 3px; }
  .vs-king-tug-fill { top: 3px; height: 10px; }
  .vs-king-tug-center { top: -6px; bottom: -6px; }
  .vs-king-tug-marker { font-size: 31px; }
  .vs-footer > span { display: none; }
  .vs-footer { justify-content: flex-end; }
}

@media (max-width: 360px) {
  .character-order { gap: 3px; }
  .character-order-title { width: 21px; font-size: 8px; }
  .character-order-track { gap: 2px; }
  .character-order-item { width: 21px; height: 21px; flex-basis: 21px; }
  .character-order-item img { width: 20px; height: 20px; }
  .character-order-arrow { display: none; }
  .character-order-number { font-size: 7px; transform: scale(0.85); transform-origin: left bottom; }
  .screen-inner { padding: 20px; }
  .game-title { font-size: 34px; }
  .title-emoji { font-size: 44px; }
  .btn-primary { padding: 14px; font-size: 18px; }
  .btn-secondary { padding: 12px; font-size: 15px; }
}

.title-best {
  margin-top: 16px;
  color: #ffeaa7;
  font-size: 14px;
}

.howto {
  margin-top: 20px;
  text-align: left;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  color: #dfe6e9;
}

.howto summary {
  cursor: pointer;
  font-weight: bold;
  color: #ffeaa7;
}

.howto ul {
  margin: 8px 0 4px;
  padding-left: 18px;
  line-height: 1.7;
}

/* リザルト */
.go-title {
  font-size: 26px;
  margin-bottom: 4px;
  color: #ff7675;
}

/* どちらのモードで遊んだかの表示 */
.go-mode-label {
  display: inline-block;
  margin-bottom: 10px;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(255, 159, 67, 0.2);
  color: #ffd32a;
  font-size: 12px;
  font-weight: bold;
}

.go-new {
  display: none;
  color: #ffd32a;
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 6px;
  animation: blink 0.6s infinite alternate;
}

.go-serifu {
  background: #fff;
  color: #2d3436;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 16px;
}

.go-scores { margin-bottom: 20px; }

.go-score-value {
  font-size: 34px;
  font-weight: bold;
  color: #ffeaa7;
}

.go-best-line {
  color: #b2bec3;
  font-size: 14px;
  margin-top: 4px;
}

/* 小さめ端末での微調整 */
@media (max-height: 640px) {
  .score-value { font-size: 18px; }
  .character-order { min-height: 36px; padding-block: 2px; }
  .character-order-item { width: 24px; height: 24px; flex-basis: 24px; }
  .character-order-item img { width: 23px; height: 23px; }
}

@media (max-width: 360px) and (max-height: 640px) {
  .character-order-item { width: 21px; height: 21px; flex-basis: 21px; }
  .character-order-item img { width: 20px; height: 20px; }
}
