/* --- テーマ：プレミアム＆セレブレーション --- */
:root {
    --bg-color: #ffffff;
    --primary-color: #f8f9fa;
    --secondary-color: #e9ecef;
    --accent-color: #007bff;
    --glow-color: rgba(0, 123, 255, 0.5);
    --hit-color: #28a745;
    --reach-color: #fd7e14;
    --winner-color: #ffc107;
    --font-color: #212529;
    --font-color-light: #6c757d;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans JP', sans-serif;
}

body {
    background-color: var(--bg-color); /* スマホのデフォルト背景は白 */
    color: var(--font-color);
    font-family: var(--font-family);
    margin: 0;
    text-align: center;
    -webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

#app-container {
    width: 100%;
    height: 100vh; /* スマホでは画面いっぱいに */
    background-color: var(--bg-color);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ★★★★★ ここからが修正箇所です ★★★★★ */
#background-reaction-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1; /* コンテンツより後ろ */
    pointer-events: none; /* クリックを透過させる */
    overflow: hidden;
}

.background-reaction {
    position: absolute;
    bottom: -100px; /* 画面下からスタート */
    font-size: clamp(2rem, 8vw, 4rem);
    animation: float-up-background linear;
    opacity: 0.7;
}

@keyframes float-up-background {
    from {
        transform: translateY(0);
        opacity: 0.7;
    }
    to {
        transform: translateY(-120vh); /* 画面上部を突き抜ける */
        opacity: 0;
    }
}
/* ★★★★★ 修正はここまでです ★★★★★ */


/* PC（画面幅が500pxより大きい場合）の時だけ、黒い枠と背景を表示 */
@media (min-width: 500px) {
    body {
        background-color: #e9ecef;
        padding: 20px 0;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        box-sizing: border-box;
    }
    #app-container {
        max-width: 420px;
        max-height: 900px;
        height: 100%;
        border-radius: 40px;
        box-shadow: 0 10px 30px rgba(0,0,0,0.1);
        border: 8px solid #343a40;
    }
}

.hidden { display: none !important; }

/* --- 参加画面 --- */
#join-screen {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    z-index: 2; /* 背景リアクションより手前 */
    background: var(--bg-color);
}
.title-container {
    margin-bottom: 20px;
}
#join-screen h1 {
    font-size: clamp(2.2rem, 10vw, 3.2rem);
    font-weight: 800;
    color: var(--accent-color);
    margin: 0;
    line-height: 1.25;
}
#join-screen h2 {
    font-size: clamp(1.4rem, 6vw, 1.8rem);
    font-weight: 700;
    color: var(--font-color);
    margin: 5px 0 0 0;
}
.avatar-wrapper {
    position: relative;
    margin: 15px 0;
    width: 100px;
    height: 100px;
}
#avatar-preview-container {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: var(--secondary-color);
    overflow: hidden;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    display: flex;
    justify-content: center;
    align-items: center;
}
#avatar-preview {
    width: 100%;
    height: 100%;
}
#randomize-avatar-button {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid white;
    background-color: var(--accent-color);
    color: white;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    transition: transform 0.2s ease-in-out;
}
#randomize-avatar-button:hover {
    transform: scale(1.1) rotate(180deg);
}
#join-screen p {
    font-size: clamp(1rem, 4vw, 1.25rem);
    color: var(--font-color-light);
    line-height: 1.5;
}
#name-input {
    font-family: var(--font-family);
    font-size: clamp(1.2rem, 5vw, 1.5rem);
    text-align: center;
    padding: 15px;
    margin: 20px;
    width: 80%;
    border: 2px solid var(--secondary-color);
    background: var(--bg-color);
    color: var(--font-color);
    border-radius: 10px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}
#join-button {
    font-family: var(--font-family);
    font-size: clamp(1.3rem, 6vw, 1.6rem);
    font-weight: bold;
    padding: 15px 40px;
    border: none;
    background: var(--accent-color);
    color: white;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 4px 15px var(--glow-color);
    transition: all 0.2s ease;
}
#join-button:hover { transform: translateY(-2px); box-shadow: 0 6px 20px var(--glow-color); }


/* --- カード配布アニメーション --- */
#card-deal-animation {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; justify-content: center; align-items: center;
    background: rgba(255,255,255,0.9); backdrop-filter: blur(10px);
    z-index: 300;
}
.deck { position: relative; width: 100px; height: 140px; }
.card-back {
    position: absolute;
    width: 100%; height: 100%;
    background-color: var(--accent-color);
    background-image: linear-gradient(45deg, rgba(255,255,255,0.1) 25%, transparent 25%, transparent 50%, rgba(255,255,255,0.1) 50%, rgba(255,255,255,0.1) 75%, transparent 75%, transparent);
    background-size: 30px 30px;
    border: 5px solid white;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    transform-origin: center center;
}
.deck .card-back:nth-child(1) { transform: translate(0, 0); animation: deal-card-1 1.5s forwards ease-out; }
.deck .card-back:nth-child(2) { transform: translate(2px, -2px); animation: deal-card-2 1.5s 0.2s forwards ease-out; }
.deck .card-back:nth-child(3) { transform: translate(4px, -4px); animation: deal-card-3 1.5s 0.4s forwards ease-out; }
.deck .card-back:nth-child(4) { transform: translate(6px, -6px); animation: deal-card-4 1.5s 0.6s forwards ease-out; }
.deck .card-back:nth-child(5) { transform: translate(8px, -8px); animation: deal-card-5 1.5s 0.8s forwards ease-out; }

@keyframes deal-card-1 {
    0% { transform: translate(0, 0) rotate(0); }
    50% { transform: translate(-150px, -200px) rotate(-30deg) scale(1.2); }
    100% { transform: translate(-100vw, -100vh) rotate(-90deg) scale(0); opacity: 0; }
}
@keyframes deal-card-2 { 0% { transform: translate(2px,-2px) rotate(0); } 50% { transform: translate(150px, -150px) rotate(25deg) scale(1.2); } 100% { transform: translate(100vw, -100vh) rotate(80deg) scale(0); opacity: 0; } }
@keyframes deal-card-3 { 0% { transform: translate(4px,-4px) rotate(0); } 50% { transform: translate(-130px, 200px) rotate(40deg) scale(1.2); } 100% { transform: translate(-100vw, 100vh) rotate(120deg) scale(0); opacity: 0; } }
@keyframes deal-card-4 { 0% { transform: translate(6px,-6px) rotate(0); } 50% { transform: translate(180px, 150px) rotate(-35deg) scale(1.2); } 100% { transform: translate(100vw, 100vh) rotate(-90deg) scale(0); opacity: 0; } }
@keyframes deal-card-5 {
    0% { transform: translate(8px, -8px) rotate(0deg) scale(1); }
    40% { transform: translate(0, 0) rotate(0deg) scale(1.3); }
    100% { transform: translate(0, 0) rotate(360deg) scale(6); opacity: 0; }
}


/* --- ゲーム画面 --- */
#game-screen { display: flex; flex-direction: column; height: 100%; padding: 20px; box-sizing: border-box; }
header { display: flex; justify-content: space-between; gap: 10px; flex-shrink: 0; }
.next-prize, .new-number-container {
    background: var(--primary-color);
    padding: 8px 15px;
    border-radius: 12px;
}
.next-prize { width: 65%; text-align: left; }
.next-prize p, .new-number-container p { font-size: 0.8rem; color: var(--font-color-light); margin: 0; }
.next-prize h2 { font-size: 1.1rem; font-weight: bold; color: var(--accent-color); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 4px 0; }
.new-number-container { width: 30%; text-align: center; }
#current-number { font-size: 2.5rem; font-weight: 800; margin: 0; color: var(--hit-color); }

main { flex-grow: 1; display: flex; justify-content: center; align-items: center; padding: 15px 0; }

/* ビンゴカード */
#bingo-card { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; width: 100%; max-width: 400px; margin: 0 auto; aspect-ratio: 1 / 1; }
.cell {
    display: flex; justify-content: center; align-items: center;
    font-size: clamp(1.2rem, 5vw, 1.8rem); font-weight: 700;
    background: var(--primary-color); color: var(--font-color-light);
    border-radius: 10px;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.cell.hit { background: var(--hit-color); color: white; transform: scale(1.1); box-shadow: 0 4px 15px rgba(40, 167, 69, 0.5); }
.cell.free { background: var(--secondary-color); color: var(--font-color); }
.cell.reach { background: var(--reach-color); color: white; animation: pulse-reach 1.5s infinite; }

/* フッターと情報表示エリア */
footer { padding-top: 15px; border-top: 1px solid var(--secondary-color); flex-shrink: 0; }
.info-tabs { display: flex; justify-content: center; gap: 10px; margin-bottom: 10px; }
.tab-button {
    font-family: var(--font-family); font-size: 0.9rem;
    background: var(--primary-color); border: 1px solid var(--secondary-color);
    color: var(--font-color-light); padding: 5px 15px; border-radius: 20px;
    cursor: pointer; transition: all 0.2s;
}
.tab-button.active { background: var(--accent-color); color: white; border-color: var(--accent-color); }
.info-content { background: var(--primary-color); border-radius: 10px; padding: 10px; height: 90px; overflow-y: auto; }
.tab-content { display: none; flex-wrap: wrap; gap: 8px; }
.tab-content.active { display: flex; }

/* 参加者リストのアバター表示対応 */
.participant-chip {
    display: flex;
    align-items: center;
    background: var(--secondary-color);
    padding: 2px 10px 2px 2px;
    border-radius: 15px;
    font-size: 0.9rem;
}
.participant-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    margin-right: 6px;
}
.drawn-chip { background: var(--secondary-color); padding: 4px 10px; border-radius: 15px; font-size: 0.9rem; }
.drawn-chip { width: 30px; height: 30px; justify-content: center; align-items: center; display: flex; box-sizing: border-box; }

#winners-content { display: none; flex-direction: column; gap: 8px; }
#winners-content.active { display: flex; }
.winner-card { display: flex; align-items: center; background: var(--secondary-color); border-radius: 8px; padding: 8px; text-align: left; }
.winner-card img { width: 40px; height: 40px; border-radius: 6px; margin-right: 10px; object-fit: cover; }
.winner-info .name { font-weight: bold; color: var(--winner-color); }
.winner-info .prize { font-size: 0.8rem; color: var(--font-color-light); }

/* 絵文字リアクションボタン */
#reaction-buttons {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 110;
    transition: opacity 0.3s;
}
#reaction-buttons button {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    font-size: 20px;
    background: rgba(255,255,255,0.8);
    backdrop-filter: blur(5px);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: transform 0.2s;
}
#reaction-buttons button:active { transform: scale(0.9); }

#reaction-buttons.disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* おめでとうボタン */
#congrats-button {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 15px 30px;
    font-size: 1.2rem;
    font-weight: bold;
    background: var(--winner-color);
    color: var(--font-color);
    border: none;
    border-radius: 30px;
    box-shadow: 0 4px 15px rgba(255, 193, 7, 0.5);
    cursor: pointer;
    animation: pulse-congrats 2s infinite;
    z-index: 10;
}
@keyframes pulse-congrats { 50% { transform: translateX(-50%) scale(1.05); } }

/* ビンゴ達成演出 */
#bingo-celebration {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}
#bingo-celebration .content { text-align: center; padding: 20px; }
#bingo-celebration h1 { font-size: clamp(4rem, 20vw, 7rem); color: var(--winner-color); }
#won-prize-image { max-width: 80%; max-height: 40vh; border-radius: 15px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); margin: 20px 0; }
#won-prize-name { font-size: clamp(1.5rem, 6vw, 2.2rem); }
#winner-name { color: var(--accent-color); }

/* 当選証明カードのスタイル */
.winner-card-template {
    width: 375px;
    padding: 20px;
    background: white;
    box-sizing: border-box;
    font-family: 'Noto Sans JP', sans-serif;
    text-align: center;
    border: 1px solid #ddd;
}
.winner-card-template h2 {
    font-size: 24px;
    font-weight: 900;
    color: var(--winner-color);
    margin: 0 0 5px 0;
}
.winner-card-template .prize-name {
    font-size: 20px;
    font-weight: bold;
    margin: 10px 0;
    color: #333;
}
.winner-card-template .prize-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
    border-radius: 10px;
    margin-bottom: 20px;
}
.winner-card-template .bingo-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    margin-top: 15px;
}
.winner-card-template .bingo-grid div {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    font-weight: bold;
    border-radius: 5px;
    background: var(--primary-color);
    color: var(--font-color-light);
}
.winner-card-template .bingo-grid div.hit {
    background: var(--hit-color);
    color: white;
}

@keyframes pulse-reach {
    50% { transform: scale(1.1); }
}

/* ★★★★★ ここからが新しく追加されたスタイルです ★★★★★ */
/* --- Fullscreen Overlay --- */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    display: flex; /* JSで .visible をトグルすることを想定 */
    justify-content: center;
    align-items: center;
    z-index: 200;
    
    /* ★★★ これが重要：デフォルトでは非表示にする ★★★ */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* JSで .visible クラスを追加したときに表示 */
.overlay.visible {
    opacity: 1;
    visibility: visible;
}

.overlay-card {
    background: var(--bg-color);
    padding: 25px;
    border-radius: 16px; /* 既存の変数を利用 */
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    width: 90%;
    max-width: 400px; /* アプリの幅に合わせる */
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

.overlay.visible .overlay-card {
     transform: scale(1);
}

.overlay-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--font-color);
    margin: 0 0 15px 0;
}

.overlay-body {
    font-size: 1rem;
    color: var(--font-color-light);
    line-height: 1.6;
    margin-bottom: 25px;
}

.overlay-close {
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: bold;
    padding: 12px 25px;
    width: 100%;
    border: none;
    background: var(--accent-color);
    color: white;
    border-radius: 10px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.overlay-close:hover {
    background-color: #0069d9;
}
/* === Reaction bubble (avatar + emoji + name) === */
.reaction-bubble{
  position:absolute;
  display:inline-flex;
  align-items:center;
  gap:6px;
  pointer-events:none;
  z-index:150;                /* overlay(=200)より下、UIより上 */
  opacity:0;
  transform: translateY(18px) scale(.96);
  animation: reaction-fly 2.6s ease-out forwards;
}

.reaction-avatar{
  width:26px; height:26px;
  border-radius:50%;
  object-fit:cover;
  box-shadow:0 1px 6px rgba(0,0,0,.2);
}

.reaction-emoji-inline{       /* バブル内の絵文字（既存の .reaction-emoji とは別物） */
  font-size:24px;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.2));
}

.reaction-name{
  font-size:12px; font-weight:700; line-height:1;
  color:#fff; padding:4px 8px; border-radius:9999px;
  background:rgba(0,0,0,.35);
  backdrop-filter: blur(6px);
  white-space:nowrap;
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
}

/* ふわっと上に流れて消える */
@keyframes reaction-fly{
  0%   { opacity:0; transform: translateY(18px) scale(.96); }
  12%  { opacity:1; }
  100% { opacity:0; transform: translateY(-80px) scale(1.05); }
}

/* ★★★★★ 参加者タブのステータス表示用スタイル ★★★★★ */

.participant-chip {
    position: relative;
    padding-right: 8px; /* バッジ用のスペース */
}

/* リーチ・ビンゴバッジの共通スタイル */
.status-badge {
    position: absolute;
    top: -8px;
    right: -5px;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    color: white;
    border: 1px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* リーチ（オレンジ） */
.status-badge.reach {
    background-color: var(--reach-color);
}
.participant-chip.on-reach {
    background-color: #fff3e0; /* リーチの人の背景色 */
}

/* ビンゴ（黄色） */
.status-badge.bingo {
    background-color: var(--winner-color);
    color: var(--font-color);
    animation: pulse-congrats 1.5s infinite; /* おめでとうボタンのアニメーションを流用 */
}
.participant-chip.on-bingo {
    background-color: #fff9e0; /* ビンゴの人の背景色 */
}

/* ★★★★★ 王冠（当選済み）バッジ用のスタイル ★★★★★ */

/* 王冠（当選済み） */
.status-badge.winner {
    background-color: var(--winner-color);
    color: var(--font-color);
    font-size: 0.9rem; /* 王冠は少し大きめ */
    top: -10px;
    padding: 1px 5px;
}
.participant-chip.on-winner {
    background-color: #fff9e0; /* ビンゴと同じ背景色 */
    opacity: 0.6; /* 当選済みなので少し薄く */
}

/* セル全体を使うための土台 */
#bingo-card .cell { 
  position: relative; 
  overflow: hidden;   /* はみ出し防止 */
}

/* FREEセルは余白なしでベタ貼り */
#bingo-card .cell.free {
  padding: 0;
  background: #fff;          /* お好みで */
  border: 2px solid #ffd700; /* お好みで */
}

/* 画像をセルいっぱいにフィット */
#bingo-card .cell.free .free-icon {
  position: absolute;
  inset: 0;             /* top/right/bottom/left: 0 の省略 */
  width: 100%;
  height: 100%;
  object-fit: cover;     /* セルをはみ出さず全面表示 */
  border-radius: inherit;/* セルの角丸に合わせる（角丸を活かす） */
  box-shadow: none;
}
#bingo-card .cell.free .free-icon {
  transition: opacity 0.5s ease-in-out;
}