/* ========================================================
   上海（Mahjong Solitaire）Webアプリ スタイルシート
   オリエンタル×モダン プレミアム翡翠デザイン
   ======================================================== */

:root {
    --bg-wood-dark: #12181F;
    --felt-green: #0F3B2E;
    --felt-green-light: #185241;
    --gold-primary: #D4AF37;
    --gold-hover: #F3E5AB;
    --tile-bg: #FDFBF7;
    --tile-side: #E2D9C8;
    --tile-back: #0E7490; /* 伝統的な背板の青竹/翡翠色 */
    --text-light: #F8FAFC;
    --text-muted: #94A3B8;
    --danger-red: #EF4444;
    --warning-yellow: #F59E0B;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    font-family: 'Hiragino Kaku Gothic ProN', 'Yu Gothic', 'Meiryo', sans-serif;
    background: radial-gradient(circle at center, #1A4D3E 0%, #0A221A 100%);
    color: var(--text-light);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* ヘッダー・情報バー */
.app-header {
    background: rgba(10, 24, 18, 0.85);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid rgba(212, 175, 55, 0.4);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    z-index: 100;
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.brand h1 {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: 2px;
    color: var(--gold-primary);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

.brand .subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.game-stats {
    display: flex;
    align-items: center;
    gap: 24px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: #FFFFFF;
    font-family: 'Courier New', monospace;
}

/* タイマーバー（アーケード風） */
.timer-container {
    width: 180px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.timer-bar-bg {
    width: 100%;
    height: 12px;
    background: #0B1914;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    overflow: hidden;
}

.timer-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #10B981, #34D399);
    transition: width 0.3s ease, background 0.5s ease;
    border-radius: 5px;
}

.timer-bar-fill.warning {
    background: linear-gradient(90deg, #F59E0B, #FBBF24);
}

.timer-bar-fill.danger {
    background: linear-gradient(90deg, #EF4444, #F87171);
    animation: timerPulse 0.6s infinite alternate;
}

@keyframes timerPulse {
    from { opacity: 1; }
    to { opacity: 0.4; }
}

/* コントロールボタン群 */
.controls-bar {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn {
    background: linear-gradient(180deg, #2D3748, #1A202C);
    color: #E2E8F0;
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 7px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.btn:hover:not(:disabled) {
    background: linear-gradient(180deg, #4A5568, #2D3748);
    border-color: var(--gold-primary);
    color: #FFFFFF;
    transform: translateY(-1px);
}

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

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(180deg, #D4AF37, #AA820A);
    color: #0F172A;
    border-color: #F3E5AB;
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(180deg, #E6C655, #C59B1B);
    color: #000000;
}

.select-mode {
    background: #1E293B;
    color: #F8FAFC;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
}

/* メイン卓（ゲーム盤コンテナ） */
.game-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 20px;
    overflow: hidden;
}

#board-container {
    width: 100%;
    height: 100%;
    max-width: 1100px;
    max-height: 800px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* 麻雀卓ボード */
#board {
    width: 760px;
    height: 560px;
    position: relative;
    transform-origin: center center;
    transition: transform 0.2s ease-out;
}

/* 麻雀牌のデザイン（3D立体） */
.tile {
    position: absolute;
    width: 48px;
    height: 64px;
    cursor: pointer;
    transition: transform 0.15s ease, filter 0.15s ease;
    filter: drop-shadow(2px 4px 6px rgba(0, 0, 0, 0.45));
}

/* 牌の表面 */
.tile-face {
    position: absolute;
    top: 0;
    left: 0;
    width: 44px;
    height: 60px;
    background: linear-gradient(135deg, #FFFFFF 0%, #FAF8F2 50%, #EFE9DB 100%);
    border-radius: 5px;
    border-top: 1.5px solid #FFFFFF;
    border-left: 1.5px solid #FFFFFF;
    border-right: 1px solid #D6CEBE;
    border-bottom: 1px solid #C4BAA6;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 3px 2px;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

/* 牌の本格SVGグラフィック */
.tile-svg {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
}

/* 牌の右側面（厚み・竹背板） */
.tile-side-right {
    position: absolute;
    top: 2px;
    right: 0;
    width: 4px;
    height: 60px;
    background: linear-gradient(180deg, #E2D7C2 0%, #15803D 30%, #14532D 100%);
    border-radius: 0 3px 3px 0;
}

/* 牌の下側面（厚み・竹背板） */
.tile-side-bottom {
    position: absolute;
    bottom: 0;
    left: 2px;
    width: 44px;
    height: 4px;
    background: linear-gradient(90deg, #E2D7C2 0%, #15803D 30%, #14532D 100%);
    border-radius: 0 0 3px 3px;
}

/* 牌の文字（フォールバック用） */
.tile-char {
    font-size: 1.7rem;
    font-weight: 800;
    line-height: 1;
    font-family: 'Yu Mincho', 'HiraMinProN-W6', serif;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
}

.tile-sub {
    font-size: 0.65rem;
    font-weight: 700;
    color: #64748B;
    margin-top: 2px;
}

/* 選択可能（フリー）な牌のホバー */
.tile.selectable:hover {
    transform: translateY(-5px) scale(1.04);
    z-index: 1000 !important;
}

.tile.selectable:hover .tile-face {
    background: linear-gradient(135deg, #FFFFFF 0%, #FFFBEB 100%);
    border: 1px solid var(--gold-primary);
}

/* 選択された牌（ゴールドグロー） */
.tile.selected {
    transform: translateY(-8px) scale(1.06);
    z-index: 1500 !important;
}

.tile.selected .tile-face {
    background: #FEF9C3 !important;
    border: 2px solid #EAB308 !important;
    box-shadow: 0 0 16px rgba(234, 179, 8, 0.8), inset 0 0 6px rgba(234, 179, 8, 0.4);
}

/* 左右・上が塞がれている選択不可の牌 */
.tile.blocked {
    filter: drop-shadow(1px 2px 4px rgba(0, 0, 0, 0.5)) brightness(0.85);
}

/* ヒント時のパルスアニメーション */
.tile.hint {
    animation: hintPulse 0.5s ease-in-out infinite alternate;
    z-index: 1200 !important;
}

@keyframes hintPulse {
    from {
        transform: translateY(-3px) scale(1.02);
        filter: drop-shadow(0 0 8px #38BDF8);
    }
    to {
        transform: translateY(-9px) scale(1.08);
        filter: drop-shadow(0 0 18px #0284C7);
    }
}

/* 不正クリック時の振動（シェイク） */
.tile.shake {
    animation: shakeAnim 0.3s ease-in-out;
}

@keyframes shakeAnim {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-4px); }
    40%, 80% { transform: translateX(4px); }
}

/* ペア成立時の消滅アニメーション */
.tile.matched {
    animation: matchedAnim 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    z-index: 2000 !important;
    pointer-events: none;
}

@keyframes matchedAnim {
    0% {
        transform: translateY(-5px) scale(1.1);
        opacity: 1;
        filter: brightness(1.5);
    }
    100% {
        transform: translateY(-25px) scale(1.4);
        opacity: 0;
        filter: brightness(2);
    }
}

/* モーダルウィンドウ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 5000;
    transition: opacity 0.25s ease;
}

.modal.hidden {
    display: none;
    opacity: 0;
}

.modal-content {
    background: linear-gradient(180deg, #1E293B 0%, #0F172A 100%);
    border: 2px solid var(--gold-primary);
    border-radius: 12px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    color: #F8FAFC;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8), 0 0 20px rgba(212, 175, 55, 0.3);
    text-align: center;
    position: relative;
}

.modal-title {
    font-size: 1.6rem;
    color: var(--gold-primary);
    margin-bottom: 15px;
    font-weight: 800;
}

.modal-body {
    font-size: 0.95rem;
    line-height: 1.7;
    color: #CBD5E1;
    margin-bottom: 24px;
    text-align: left;
}

.modal-body ul {
    margin-left: 20px;
    margin-top: 8px;
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
}

/* ランキング登録フォーム */
.ranking-register-box {
    margin-top: 20px;
    padding: 16px;
    background: rgba(15, 23, 42, 0.7);
    border: 1px dashed var(--gold-primary);
    border-radius: 8px;
}

.ranking-form-title {
    font-size: 0.95rem;
    color: var(--gold-primary);
    font-weight: 700;
    margin-bottom: 10px;
}

.ranking-form-row {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
}

.input-name {
    background: #0F172A;
    border: 1px solid rgba(212, 175, 55, 0.5);
    color: #FFFFFF;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    outline: none;
    width: 60%;
    transition: border-color 0.2s;
}

.input-name:focus {
    border-color: var(--gold-hover);
    box-shadow: 0 0 8px rgba(212, 175, 55, 0.4);
}

.submit-feedback {
    font-size: 0.85rem;
    margin-top: 8px;
    min-height: 1.2em;
}

.submit-feedback.success {
    color: #10B981;
}

.submit-feedback.error {
    color: #EF4444;
}

/* ランキング表示モーダル */
.ranking-modal-content {
    max-width: 650px;
}

.ranking-tabs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 16px;
}

.ranking-tab {
    background: #1E293B;
    color: #94A3B8;
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.ranking-tab.active {
    background: linear-gradient(180deg, #D4AF37, #B8860B);
    color: #0F172A;
    border-color: #F3E5AB;
}

.ranking-table-wrapper {
    max-height: 380px;
    overflow-y: auto;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(15, 23, 42, 0.8);
}

.ranking-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    text-align: center;
}

.ranking-table th {
    background: #0B1320;
    color: var(--gold-primary);
    padding: 10px 8px;
    position: sticky;
    top: 0;
    border-bottom: 1px solid rgba(212, 175, 55, 0.3);
    font-size: 0.82rem;
}

.ranking-table td {
    padding: 10px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: #E2E8F0;
}

.ranking-table tr:hover {
    background: rgba(212, 175, 55, 0.08);
}

/* 順位メダルバッジ */
.badge-rank {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-weight: 800;
    font-size: 0.8rem;
}

.badge-rank-1 {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #000000;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
}

.badge-rank-2 {
    background: linear-gradient(135deg, #E0E0E0, #9E9E9E);
    color: #000000;
}

.badge-rank-3 {
    background: linear-gradient(135deg, #CD7F32, #8B4513);
    color: #FFFFFF;
}

.ranking-status-msg {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 10px;
}

/* フッター */
.app-footer {
    padding: 8px 20px;
    background: rgba(10, 24, 18, 0.9);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

/* スマホ・タブレット用レスポンシブ */
@media (max-width: 800px) {
    .app-header {
        flex-direction: column;
        gap: 10px;
        padding: 8px 12px;
    }
    .brand h1 {
        font-size: 1.3rem;
    }
    .game-stats {
        gap: 12px;
        width: 100%;
        justify-content: space-around;
    }
    .timer-container {
        width: 120px;
    }
    .controls-bar {
        flex-wrap: wrap;
        justify-content: center;
    }
    .btn {
        padding: 5px 10px;
        font-size: 0.8rem;
    }
}
