:root {
    --mj-green-light: #16562c;
    --mj-green-dark: #092713;
    --mj-gold: #f39c12;
    --mj-tile-bg: #fcfcfc;
    --mj-tile-shadow: #c7c7c7;
    --font-family-modern: 'Outfit', 'Noto Sans JP', sans-serif;
}

body {
    font-family: var(--font-family-modern);
    background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
}

/* 麻雀卓をイメージしたリッチなマットセクション */
.table-mat {
    background: radial-gradient(circle, var(--mj-green-light) 0%, var(--mj-green-dark) 100%);
    border-radius: 20px;
    padding: 2rem 1.5rem;
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.6), 0 10px 25px rgba(0,0,0,0.15);
    color: white;
    margin-bottom: 2rem;
    border: 4px solid #4a3728; /* 木製の枠をイメージ */
    position: relative;
}

.table-mat::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(rgba(255,255,255,0.03), transparent);
    pointer-events: none;
}

.section-title {
    font-family: var(--font-family-modern);
    font-weight: 800;
    letter-spacing: -0.5px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* 手牌エリア */
.hand-container {
    min-height: 100px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 12px;
    border: 2px dashed rgba(255, 255, 255, 0.2);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    gap: 6px;
    margin-bottom: 1.5rem;
    transition: all 0.3s ease;
}

.hand-container.full {
    border-color: var(--mj-gold);
    background: rgba(243, 156, 18, 0.05);
}

/* 麻雀牌のデザイン */
.mj-tile {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    width: 44px;
    height: 64px;
    background: var(--mj-tile-bg);
    border: 1px solid #ddd;
    border-radius: 6px;
    box-shadow: 0 4px 0 var(--mj-tile-shadow), 0 6px 10px rgba(0,0,0,0.3);
    padding: 6px 2px;
    cursor: pointer;
    user-select: none;
    transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.15s, filter 0.15s;
    position: relative;
    font-family: var(--font-family-modern);
    border-bottom: 3px solid #e2e2e2;
    touch-action: manipulation;
}

/* 牌の裏面を表現するグリーンの層 */
.mj-tile::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    right: 0;
    height: 4px;
    background: #1e7e34;
    border-radius: 0 0 6px 6px;
    z-index: -1;
}

.mj-tile:hover {
    transform: translateY(-6px);
    box-shadow: 0 10px 0 var(--mj-tile-shadow), 0 12px 16px rgba(0,0,0,0.4);
    filter: brightness(1.05);
}

.mj-tile:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--mj-tile-shadow), 0 3px 5px rgba(0,0,0,0.2);
}

/* 手牌の中の牌アニメーション */
.hand-tile {
    animation: popIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.7) translateY(15px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* 牌の種類による色分け */
.mj-man { color: #d90429; } /* 赤 */
.mj-pin { color: #0066cc; } /* 青 */
.mj-sou { color: #2a9d8f; } /* 緑 */
.mj-ji { color: #2b2d42; } /* 黒 */
.mj-ji.mj-chun { color: #d90429; } /* 中 */
.mj-ji.mj-hatsu { color: #2a9d8f; } /* 發 */
.mj-ji.mj-haku { color: #8d99ae; } /* 白 */

.mj-tile .tile-num {
    font-size: 1.4rem;
    font-weight: 800;
    line-height: 1;
    margin-top: 2px;
}

.mj-tile .tile-suit {
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 2px;
}

/* 白 (Haku) のデザイン調整 */
.mj-tile.tile-haku .tile-num {
    width: 20px;
    height: 28px;
    border: 2px solid #0066cc;
    border-radius: 3px;
    margin-top: 4px;
}

/* 牌選択キーパッド */
.keypad-section {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 1.2rem;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 1.5rem;
}

.keypad-title {
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.7);
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}

.tile-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-start;
    margin-bottom: 1.2rem;
}

/* 残り枚数制限で非活性 */
.mj-tile.disabled {
    opacity: 0.3;
    pointer-events: none;
    filter: grayscale(1);
    transform: none !important;
    box-shadow: 0 2px 0 var(--mj-tile-shadow), 0 2px 3px rgba(0,0,0,0.1) !important;
}

/* 結果カード */
.result-card {
    background: rgba(255, 255, 255, 0.95);
    color: #1f2937;
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 10px 20px rgba(0,0,0,0.15);
    border: 1px solid rgba(255, 255, 255, 0.8);
    transition: all 0.3s ease;
}

.result-card.tenpai {
    border-left: 6px solid var(--mj-gold);
    background: #fffdf5;
}

.result-card.noten {
    border-left: 6px solid #9ca3af;
}

.result-card.invalid {
    border-left: 6px solid #ef4444;
}

.waiting-tiles-display {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 1rem;
}

.waiting-tile {
    cursor: default;
    animation: popIn 0.3s ease forwards;
}

.waiting-tile:hover {
    transform: none;
    filter: none;
    box-shadow: 0 4px 0 var(--mj-tile-shadow), 0 6px 10px rgba(0,0,0,0.15);
}

.clear-btn {
    border-radius: 50px;
    font-weight: 700;
    padding: 0.5rem 1.5rem;
    transition: all 0.2s;
    touch-action: manipulation;
}

.clear-btn:hover {
    transform: translateY(-2px);
}

/* 説明アコーディオン */
.explanation-card {
    border-radius: 16px;
    border: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.badge-count {
    background-color: rgba(255,255,255,0.2);
    color: white;
    border-radius: 30px;
    padding: 0.25rem 0.75rem;
    font-size: 0.85rem;
    font-weight: bold;
}

/* 萬子 (Manzu) のスタイル */
.tile-num-man {
    font-size: 1.4rem;
    font-weight: 800;
    line-height: 1.1;
    margin-top: 4px;
    font-family: "Noto Sans JP", sans-serif;
}
.tile-suit-man {
    font-size: 0.75rem;
    font-weight: 800;
    color: #d90429;
    margin-bottom: 2px;
    font-family: "Noto Sans JP", sans-serif;
}

/* 字牌 (Jihai) のスタイル */
.tile-num-ji {
    font-size: 1.7rem;
    font-weight: 800;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 100%;
    margin-top: 4px;
    font-family: "Noto Sans JP", sans-serif;
}

/* 白 (Haku) の枠線スタイル */
.haku-frame {
    width: 24px;
    height: 36px;
    border: 3px double #0066cc;
    border-radius: 4px;
    margin: auto;
    margin-top: 8px;
}

/* 筒子のコンテナ */
.pin-container {
    position: relative;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
}

/* 共通のドットスタイル */
.pin-dot {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: radial-gradient(circle at 3px 3px, #4d607a 0%, #0d1f36 100%); /* 濃い紺色 */
    box-shadow: 1px 1px 1px rgba(0,0,0,0.3);
    transform: translate(-50%, -50%);
}

.pin-dot.red {
    background: radial-gradient(circle at 3px 3px, #ff7b7b 0%, #b3000f 100%); /* 赤 */
}

/* 1pは中央に巨大な1個の丸（同心円） */
.pin-dot.large {
    width: 22px;
    height: 22px;
    background: radial-gradient(circle, #ff8a8a 0%, #c30010 40%, #ff8a8a 50%, #c30010 80%, #900 100%);
    border: 1px dashed rgba(255,255,255,0.4);
    box-shadow: 1px 2px 4px rgba(0,0,0,0.4);
}

/* 索子のコンテナ */
.sou-container {
    position: relative;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
}

/* 竹の棒スタイル */
.sou-bar {
    position: absolute;
    width: 4px;
    height: 12px;
    background: linear-gradient(to right, #40c057, #2f9e44); /* 緑 */
    border-radius: 1px;
    box-shadow: 1px 1px 1px rgba(0,0,0,0.25);
    transform: translate(-50%, -50%);
}

.sou-bar.red {
    background: linear-gradient(to right, #ff8a8a, #c30010); /* 赤 */
}

/* 1s: Unicode絵文字（鳥） */
.sou-1 {
    font-size: 2.2rem;
    line-height: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(to bottom, #2a9d8f 0%, #2a9d8f 72%, #d90429 72%, #d90429 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    margin: 0;
}

/* 手牌エリア内の牌とプレースホルダーの配置 */
#hand-tiles {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    width: 100%;
    gap: 0 !important;
}

#hand-main-row {
    display: flex;
    flex-direction: row;
    justify-content: center;
    flex-wrap: nowrap;
    gap: 0 !important;
}

#hand-tsumo-row {
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 0 !important;
    margin-left: 14px; /* PCでの隙間 */
}

#hand-main-row .mj-tile,
#hand-main-row .mj-tile-placeholder,
#hand-tsumo-row .mj-tile {
    margin: 0 -1px 8px 0 !important;
    border-radius: 4px;
}

/* 未選択スロットのプレースホルダー */
.mj-tile-placeholder {
    display: inline-flex;
    width: 44px;
    height: 64px;
    border: 2px dashed rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
    box-sizing: border-box;
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.3);
}

/* 14枚目（ツモ牌）のスタイル */
#hand-tsumo-row .mj-tile.tsumo-tile {
    border-radius: 6px;
}

/* 切り候補牌（シミュレーション対象） */
.mj-tile.discard-candidate {
    opacity: 0.55;
    border: 2px solid #ef4444 !important;
    transform: translateY(6px);
    box-shadow: 0 1px 2px rgba(0,0,0,0.15) !important;
}

.mj-tile.discard-candidate::before {
    content: '切';
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: #ef4444;
    color: white;
    font-size: 0.65rem;
    font-weight: bold;
    padding: 1px 5px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    z-index: 10;
}

/* テンパイ可能（有効打牌）のハイライト */
.mj-tile.tenpai-possible {
    border: 2px solid var(--mj-gold) !important;
    box-shadow: 0 0 12px rgba(243, 156, 18, 0.7), 0 4px 0 var(--mj-tile-shadow) !important;
}

.mj-tile.tenpai-possible::before {
    content: '打';
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--mj-gold);
    color: #1f2937;
    font-size: 0.65rem;
    font-weight: bold;
    padding: 1px 5px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    z-index: 10;
}

/* モバイル画面用のレイアウト・スタイル調整 (画面幅 991px 以下) */
@media (max-width: 991px) {
    /* 手牌と判定結果を上部固定するラッパー */
    .sticky-hand-wrapper {
        position: sticky;
        top: 0 !important;
        z-index: 1020;
        background: radial-gradient(circle, var(--mj-green-light) 0%, var(--mj-green-dark) 100%);
        margin: -2rem -1.5rem 1.5rem -1.5rem !important;
        padding: 1.5rem 1.5rem 0.5rem 1.5rem !important;
        border-bottom: 4px solid #4a3728;
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
    }
}

/* スマートフォン表示用の超縮小フィット (画面幅 576px 以下) */
@media (max-width: 576px) {
    .hand-container {
        padding: 0.3rem 0.1rem !important;
    }

    #hand-tiles {
        flex-direction: column !important;
        align-items: center !important;
    }

    #hand-main-row {
        flex-wrap: nowrap !important;
        justify-content: center !important;
        width: 100% !important;
    }

    #hand-tsumo-row {
        justify-content: center !important;
        width: 100% !important;
        margin-left: 0 !important;
        margin-top: 8px !important; /* 下部に配置しマージンで少し離す */
    }

    /* 13枚の牌を小さくして1列に収める */
    #hand-main-row .mj-tile,
    #hand-tsumo-row .mj-tile {
        width: 25px !important;
        height: 38px !important;
        padding: 2px 0px !important;
        margin: 0 -1px 4px 0 !important;
        box-shadow: 0 2px 0 var(--mj-tile-shadow), 0 3px 5px rgba(0,0,0,0.2) !important;
        border-bottom: 1.5px solid #e2e2e2 !important;
    }

    #hand-main-row .mj-tile-placeholder {
        width: 25px !important;
        height: 38px !important;
        margin: 0 -1px 4px 0 !important;
        border: 1px dashed rgba(255, 255, 255, 0.25) !important;
        box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.3) !important;
    }

    #hand-main-row .mj-tile::after,
    #hand-tsumo-row .mj-tile::after {
        height: 2px !important;
        bottom: -2px !important;
    }

    /* 数牌・字牌などのフォント・枠線サイズ調整 (手牌エリア限定) */
    #hand-tiles .mj-tile .tile-num-man {
        font-size: 0.85rem !important;
        margin-top: 1px !important;
    }

    #hand-tiles .mj-tile .tile-suit-man {
        font-size: 0.5rem !important;
        margin-bottom: 0px !important;
        transform: scale(0.8);
    }

    #hand-tiles .mj-tile .tile-num-ji {
        font-size: 0.95rem !important;
        margin-top: 1px !important;
    }

    #hand-tiles .mj-tile .haku-frame {
        width: 14px !important;
        height: 20px !important;
        margin-top: 5px !important;
        border-width: 1.5px !important;
    }

    #hand-tiles .mj-tile .sou-1 {
        font-size: 1.4rem !important;
    }

    #hand-tiles .mj-tile .pin-dot {
        width: 5px !important;
        height: 5px !important;
    }

    #hand-tiles .mj-tile .pin-dot.large {
        width: 14px !important;
        height: 14px !important;
    }

    #hand-tiles .mj-tile .sou-bar {
        width: 1.5px !important;
        height: 7px !important;
    }

    #hand-tiles .mj-tile.tsumo-tile {
        margin-left: 8px !important;
    }

    #hand-tiles .mj-tile.discard-candidate {
        transform: translateY(4px) !important;
    }

    #hand-tiles .mj-tile.discard-candidate::before,
    #hand-tiles .mj-tile.tenpai-possible::before {
        font-size: 0.45rem !important;
        padding: 0px 2px !important;
        top: -9px !important;
        border-radius: 2px !important;
    }
}
