/* クォッカおちものライフ。
   配色・書体は他のクォッカ作品と揃えている。「〜ライフ」シリーズなので基調はピンク。
   盤面だけは食べ物が映えるよう、あたたかいクリーム色にしている。 */

:root {
  --pink: #e85d84;
  --pink-soft: #ffe3ec;
  --pink-bg: #fff6fa;
  --pink-strong: #d94c74;
  --cream: #fffdfb;
  --text: #5b4a4a;
  --text-muted: #9c8d8d;
  --board: #fdf3e4;
  --board-line: rgba(232, 131, 58, 0.09);
  --board-edge: #ffd9b8;
  --good: #3fa06b;
  --bad: #d9534f;
}

* { 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: 24px 16px 110px;
  min-height: 100vh;
}

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

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

/* タイトルの絵。食べ物がぽろぽろ落ちてくる感じに、少しずつずらして揺らす。 */
.hero-foods {
  display: flex;
  justify-content: center;
  gap: 6px;
  font-size: 40px;
  line-height: 1;
  margin: 4px 0 8px;
}
.hero-foods span { display: inline-block; animation: hero-bob 2.4s ease-in-out infinite; }
.hero-foods span:nth-child(2) { animation-delay: 0.3s; }
.hero-foods span:nth-child(3) { animation-delay: 0.6s; }
.hero-foods span:nth-child(4) { animation-delay: 0.9s; }
@keyframes hero-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(6px); }
}

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

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

/* シェアボタンと見た目をそろえたピルボタン */
.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;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-align: left;
}

input[type="text"] {
  width: 100%;
  padding: 11px 14px;
  font-size: 16px; /* 16px未満だとiPhoneが入力時に勝手にズームする */
  font-family: inherit;
  color: var(--text);
  border: 2px solid var(--pink-soft);
  border-radius: 12px;
  background: var(--pink-bg);
  margin-bottom: 12px;
}
input[type="text"]:focus { outline: none; border-color: var(--pink); }

button {
  font-family: inherit;
  cursor: pointer;
  /* 連打で文字が範囲選択されて青くハイライトされるのを防ぐ */
  user-select: none;
  -webkit-user-select: none;
}

.primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 999px;
  background: var(--pink);
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
  box-shadow: 0 5px 12px rgba(91, 74, 74, 0.20);
}
.primary:hover { background: var(--pink-strong); }
.primary:disabled { opacity: 0.5; cursor: default; }

.ghost {
  padding: 9px 20px;
  border: 2px solid var(--pink-soft);
  border-radius: 999px;
  background: #ffffff;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}
.ghost:hover { border-color: var(--pink); }
.ghost:disabled { opacity: 0.45; cursor: default; }

.join-error {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #ffeaea;
  color: var(--bad);
  font-size: 12px;
  font-weight: 700;
}

/* --- よみこみ画面 ------------------------------------------------------------- */
.loading-panel { text-align: center; }
.loading-title { font-weight: 700; color: var(--pink); margin: 8px 0 18px; }
.loading-bar { width: 100%; height: 14px; border-radius: 999px; background: var(--pink-soft); overflow: hidden; }
.loading-bar-fill { height: 100%; width: 0%; border-radius: 999px; background: var(--pink); transition: width 0.2s ease; }
.loading-percent { margin: 10px 0 0; font-size: 13px; color: var(--pink); }
.loading-panel .join-error { margin-top: 16px; text-align: center; }
.loading-panel .join-error button { margin-top: 8px; }

/* --- ゲーム画面 --------------------------------------------------------------- */
.game-screen { padding-top: 10px; }

.hud {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}
.hud-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.pill {
  padding: 3px 11px;
  border-radius: 999px;
  background: #ffffff;
  border: 2px solid var(--pink-soft);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  /* 数字の幅を等幅にして、桁が変わっても隣のpillが動かないようにする */
  font-variant-numeric: tabular-nums;
}
.pill strong { color: var(--pink); }
.num { font-variant-numeric: tabular-nums; }
#v-score { display: inline-block; min-width: 4.2em; text-align: right; }
#v-chain, #v-level { display: inline-block; min-width: 1.3em; text-align: center; }
.name-pill { max-width: 60vw; overflow: hidden; text-overflow: ellipsis; }

.pill-button {
  padding: 3px 12px;
  border-radius: 999px;
  border: 2px solid var(--pink-soft);
  background: #ffffff;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}
.pill-button:hover { border-color: var(--pink); }

.next-box {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  background: #ffffff;
  border: 2px solid var(--pink-soft);
}
.next-label { font-size: 10px; color: var(--text-muted); align-self: center; }
.next2 { opacity: 0.75; }

.board-wrap { position: relative; }
#board {
  display: block;
  background: var(--board);
  border: 3px solid var(--board-edge);
  border-radius: 12px;
}

/* れんさの表示。盤の真ん中に出して、すぐ消える。 */
.chain-pop {
  position: absolute;
  left: 50%;
  top: 36%;
  transform: translate(-50%, -50%) scale(0.9);
  font-size: 28px;
  font-weight: 800;
  color: var(--pink);
  text-shadow: 0 2px 0 #fff, 0 0 10px #fff;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
}
.chain-pop.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }

.pause-cover {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 12px;
  background: rgba(255, 253, 251, 0.88);
}
.pause-cover p { margin: 0; font-weight: 800; color: var(--pink); }
.pause-cover .primary { width: auto; padding: 10px 28px; }

.pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 340px;
  margin-top: 10px;
}
.pad button,
.drop-button {
  padding: 10px 0;
  border: 2px solid var(--pink-soft);
  border-radius: 14px;
  background: #ffffff;
  color: var(--text);
  font-size: 20px;
  font-weight: 800;
  touch-action: none; /* 長押しの連続移動中に画面がスクロールしないように */
}
.pad button:active,
.drop-button:active { background: var(--pink-bg); border-color: var(--pink); }
.drop-button {
  width: 100%;
  max-width: 340px;
  margin-top: 6px;
  padding: 8px 0;
  font-size: 14px;
}
.keys-hint {
  margin: 8px 0 0;
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
}
/* タッチだけの端末ではキーボードの説明は要らない */
@media (hover: none) { .keys-hint { display: none; } }

/* --- ランキング --------------------------------------------------------------- */
.ranking-groups {
  width: 100%;
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}
.ranking-group {
  background: #ffffff;
  border: 2px solid var(--pink-soft);
  border-radius: 18px;
  padding: 12px 14px;
}
.ranking-group-title { font-size: 14px; font-weight: 800; color: var(--pink); }
.ranking-empty { margin: 6px 0; font-size: 12px; color: var(--text-muted); }
.ranking-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 8px;
  font-size: 13px;
}
.ranking-row.you { background: var(--pink-bg); font-weight: 700; }
.ranking-rank { width: 26px; flex-shrink: 0; }
.ranking-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-value { flex-shrink: 0; color: var(--pink); font-weight: 700; font-size: 12px; font-variant-numeric: tabular-nums; }
.ranking-sub { flex-shrink: 0; color: var(--text-muted); font-size: 11px; }

/* --- 結果 ---------------------------------------------------------------------
   中身が画面より高くなっても上端まで届くよう、center ではなく flex-start + スクロール
   (pokapon-game-rules 画面まわりチェックリスト2) */
.result-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 16px 90px;
  background: rgba(91, 74, 74, 0.45);
  overflow-y: auto;
}
.result-box {
  width: 100%;
  max-width: 380px;
  margin: auto 0;
  background: var(--cream);
  border-radius: 20px;
  padding: 20px 18px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(91, 74, 74, 0.3);
}
.result-title { font-size: 20px; font-weight: 800; color: var(--pink); }
.result-foods { font-size: 30px; margin: 2px 0; }
.result-lines { margin: 8px 0; }
.result-line {
  display: flex;
  justify-content: space-between;
  padding: 4px 8px;
  font-size: 14px;
}
.result-line strong { color: var(--pink); }
.result-note { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.result-note.good { color: var(--good); font-weight: 700; }
.result-note.bad { color: var(--bad); }
.result-box .ranking { text-align: left; margin-bottom: 12px; }
.result-actions { display: flex; flex-direction: column; gap: 8px; align-items: center; }

/* --- フッター・規約ポップアップ -------------------------------------------------- */
/* どの画面でも下に固定して出す。z-indexは結果画面(50)より上、規約モーダル(100)より下。 */
.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(--text-muted); text-decoration: none; }
.site-footer a:hover { color: var(--pink); }
.footer-links,
.footer-meta {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 2px 6px;
}
.version-link {
  font-size: 10px;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}
.version-link:hover { color: var(--pink); }

.legal-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  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: 100%;
  max-width: 560px;
  height: min(80vh, 640px);
  background: var(--cream);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(91, 74, 74, 0.3);
}
.legal-modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  font-size: 14px;
}
.legal-modal-frame { width: 100%; height: 100%; border: none; background: var(--cream); }
