/* =====================================================
   ゲームページ専用レイアウト
===================================================== */
body {
    font-family: 'Hiragino Kaku Gothic ProN', sans-serif;
    text-align: center;
    margin: 0;
    color: var(--text-main);
    position: relative;

}

h1 {
    font-size: 1.8rem;
    /* 少し視認性を上げました */
    text-align: left;
    margin-bottom: 15px;
    padding-left: 10px;
}

#custom-alert {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 9999;
    justify-content: center;
    align-items: center;
}

.alert-box {
    color: var(--text-main);
    padding: 40px;
    margin: auto;
    position: absolute;
    /* width: 100%; */
    right: 0;
    left: 0;
    display: inline-table;
    top: 325px;
    background: var(--bg-card);
}

.alert-message {
    font-size: 1.4rem;
    font-weight: bold;
    color: #f57c00;
}

.alert-subtext {
    font-size: 1rem;
    margin-top: 10px;
    color: #666;
}

.alert-xp {
    color: #4caf50;
    font-weight: bold;
}

.alert-btn {
    padding: 10px;
    width: 80%;
    border-radius: 50px;
    border: solid 3px;
    border-color: cornflowerblue;
    background: aliceblue;
    color: cornflowerblue;
    font-weight: bold;
    margin-top: 20px;
    cursor: pointer;
    transition: 0.1s;
}

/* 履歴全体の枠 */
#history-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: left;
}

.history-item {
    display: flex;
    align-items: center;
    margin: 4px 1%;
    padding: 8px 12px;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    position: relative;
    overflow: hidden;
    width: 48%;
}

.japanese .history-item,
.japanese .alert-box,
.japanese .game-info-main {
    background: var(--japanese-item-bg);
    color: var(--japanese-c);
}

.math .history-item,
.math .alert-box,
.math .game-info-main {
    background: var(--math-item-bg);
    color: var(--math-c);
}

.game-info-main {
    display: flex;
    align-items: center;
    justify-content: space-evenly;
}

.reload-btn {
    padding: 4px 10px;
    cursor: pointer;
    background: none;
    border: beige;
    font-size: 30px;
}

/* 不正解時の揺れるアニメーション */
@keyframes shake {
    0% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-10px);
    }

    50% {
        transform: translateX(10px);
    }

    75% {
        transform: translateX(-10px);
    }

    100% {
        transform: translateX(0);
    }
}

.error-shake {
    /* 強制的に色を変えて揺らす */
    color: #e53935 !important;
    border-color: #e53935 !important;
    background-color: #ffebee !important;
    animation: shake 0.12s 2;
    /* 0.12秒を2回繰り返して合計約0.25秒 */
}

/* 最新（NEW）のアイテムを強調 */
.history-item.is-latest {
    border-color: #ffeb3b;
    background-color: #fffde7;
    box-shadow: 0 4px 10px rgba(255, 235, 59, 0.3);
}

.history-medal {
    font-size: 1.4rem;
    margin-right: 12px;
}

.history-content {
    flex-grow: 1;
    text-align: left;
}

.history-meta {
    font-size: 0.7rem;
    color: var(--text-sub);
    margin-bottom: 2px;
}

.new-badge {
    background: #ff5252;
    color: white;
    padding: 1px 4px;
    border-radius: 4px;
    font-weight: bold;
    margin-left: 4px;
    font-size: 0.6rem;
}

.history-number {
    position: absolute;
    right: 10px;
    bottom: -5px;
    font-size: 2rem;
    opacity: 0.2;
    font-weight: 900;
    font-style: italic;
}

.history-value {
    font-size: 1.1rem;
    color: var(--text-main);
}

.history-index {
    font-size: 0.8rem;
    color: #ccc;
    font-weight: bold;
}






/* メインカード */
.game-card {
    background: var(--bg-card);
    border-radius: 24px;
    border: 4px solid var(--border-light);
    margin-bottom: 25px;
    overflow: hidden;
    transition: all 0.3s ease;
}

body.focus-mode .game-card {
    margin: 25px auto;
    max-width: 500px;
}

/* タイトル */
.game-title {
    display: block;
    font-size: 20px;
    font-weight: bold;
    color: var(--text-main);
    margin: 2px;
}

/* サブ */
.game-sub {
    font-size: 15px;
    margin-top: 4px;
    color: var(--text-sub);
}


.game-info-main {
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 2px dashed var(--border-soft);
}

.subject-tag {
    display: inline-block;
    padding: 2px 12px;
    border-radius: 50px;
    font-size: 12px;
    font-weight: bold;
    color: #fff;
    background: var(--accent-main);
    margin-bottom: 5px;
}

/* ユーザーダッシュボード */
.user-dashboard {
    padding: 20px;
}

.avatar-frame {
    position: relative;
    width: 64px;
    height: 64px;
    background: var(--bg-card);
    border-radius: 50%;
    border: 3px solid var(--accent-main);
    padding: 2px;
    margin: auto;
}

.avatar-frame img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.level-badge {
    position: absolute;
    bottom: -5px;
    right: -5px;
    background: var(--accent-danger);
    color: #fff;
    font-size: 11px;
    font-weight: 900;
    padding: 2px 8px;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* スタッツグリッド */
.stats-grid {
    display: flex;
    grid-template-columns: repeat(3, 1fr);
    margin-top: 15px;
    flex-wrap: wrap;
}

.stat-box {
    background: var(--bg-card);
    padding: 10px;
    border-radius: 16px;
    text-align: center;
    border: 2px solid var(--border-soft);
    width: 100%;
}

.tab-text {
    display: none;
}

.stat-box.-best {
    border-color: var(--accent-main);
    background: var(--fuki-bg);
}

.stat-label {
    display: block;
    font-size: 10px;
    color: var(--text-sub);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 18px;
    font-weight: 900;
    color: var(--text-main);
}

.stat-value small {
    font-size: 11px;
    margin-left: 2px;
    color: var(--text-sub);
}

/* =====================================================
   ランキングセクション
===================================================== */
.ranking-container {
    margin-top: 30px;
}

.ranking-header {
    color: var(--text-main);
    text-align: center;
    font-size: 20px;
    margin-bottom: 15px;
}

.ranking-tabs {
    display: flex;
    justify-content: center;
    gap: 5px;
}

.tab-item {
    border: 3px solid var(--border-soft);
    border-bottom: none;
    padding: 10px 15px;
    border-radius: 15px 15px 0 0;
    background: var(--bg-sub);
    color: var(--text-sub);
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
}

.tab-item.active {
    background: var(--bg-card);
    color: var(--accent-main);
    border-color: var(--border-light);
    transform: translateY(-2px);
}

.ranking-board {
    background: var(--bg-card);
    border: 3px solid var(--border-light);
    border-radius: 18px;
    overflow: hidden;
    max-width: 500px;
    margin: 0 auto;
    text-align: center;
}

/* 各アイテムの並び */
.rank-item {
    align-items: center;
    /* 垂直中央（またはflex-endで下合わせ） */
    gap: 15px;
    /* 要素間の余白 */
    margin-bottom: 15px;
    /* アイテム同士の隙間 */
}

/* 番号とアバターを横に並べるグループ（CSSで直接指定） */
.rank-number,
.rank-avatar {
    display: inline-block;
    vertical-align: middle;
}

/* 名前とスコアを縦に並べる（名前の下にスコア） */
.rank-name {
    display: block;
    /* 1行専有 */
    font-weight: bold;
    white-space: nowrap;
    /* 名前が長くても改行させない（お好みで） */
    overflow: hidden;
    text-overflow: ellipsis;
    /* 長すぎる場合は「...」にする */
}

.rank-score {
    font-size: 1.2rem;
    display: block;
    font-weight: 900;

}

.japanese .rank-score {
    color: #ff9595;
}

.math .rank-score {
    color: #4fc3f7;
}

.social .rank-score {
    color: #aed581;
}

.science .rank-score {
    color: #ba68c8;
}

.english .rank-score {
    color: #ffb74d;
}


.rank-item {
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--border-soft);
}

.rank-number {
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg-sub);
    font-weight: 900;
    color: var(--text-muted);
    display: flex;
}

/* 1-3位のメダルカラーをパステル変数から利用 */
.rank-1 .rank-number {
    background: var(--pastel-orange);
    color: #fff;
    border: 2px solid var(--pastel-shadow-orange);
}

.rank-2 .rank-number {
    background: var(--pastel-blue);
    color: #fff;
    border: 2px solid var(--pastel-shadow-blue);
}

.rank-3 .rank-number {
    background: var(--pastel-green);
    color: #fff;
    border: 2px solid var(--pastel-shadow-green);
}

.rank-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin: 0 10px;
    border: 2px solid var(--border-soft);
}

.rank-name {
    flex: 1;
    font-weight: bold;
    color: var(--text-main);
    text-align: center;
}


/* --- 浮き上がるアニメーションの定義 --- */
@keyframes rankIn {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}



/* ランキングの各行にアニメーションを適用 */
.rank-item {
    opacity: 0;
    /* 最初は隠しておく */
    animation: rankIn 0.4s ease-out forwards;
}

/* 1行目から10行目まで、少しずつ遅らせて表示（階段状の演出） */
.rank-item:nth-child(1) {
    animation-delay: 0.05s;
}

.rank-item:nth-child(2) {
    animation-delay: 0.1s;
}

.rank-item:nth-child(3) {
    animation-delay: 0.15s;
}

.rank-item:nth-child(4) {
    animation-delay: 0.2s;
}

.rank-item:nth-child(5) {
    animation-delay: 0.25s;
}

.rank-item:nth-child(6) {
    animation-delay: 0.3s;
}

.rank-item:nth-child(7) {
    animation-delay: 0.35s;
}

.rank-item:nth-child(8) {
    animation-delay: 0.4s;
}

.rank-item:nth-child(9) {
    animation-delay: 0.45s;
}

.rank-item:nth-child(10) {
    animation-delay: 0.5s;
}

/* タブを切り替えた時もふわっとさせるためのリセット用設定 */
#rank-content {
    min-height: 200px;
    /* 切り替え時にガタつかないように */
}

/* 自分の順位カード（ランキングの下に浮かせる） */
.my-rank-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    background: var(--bg-history-item);
    /* パステル系背景 */
    border-top: 3px solid var(--accent-main);
    margin-top: 5px;
    border-radius: 0 0 18px 18px;
    animation: rankIn 0.8s ease-out forwards;
}

.japanese .my-rank-item {
    background: var(--japanese-item-bg);
    color: var(--japanese-c);
}

.math .my-rank-item {
    background: var(--math-item-bg);
    color: var(--math-c);
}

.social .my-rank-item {
    background: var(--social-item-bg);
    color: var(--social-c);
}

.science .my-rank-item {
    background: var(--science-item-bg);
    color: var(--science-c);
}

.English .my-rank-item {
    background: var(--english-item-bg);
    color: var(--english-c);
}

.my-rank-item .rank-number {
    background: var(--accent-main);
    color: white;
}

.my-rank-item .rank-name {
    color: var(--accent-main);
    font-size: 14px;
}

/* ふわっと浮き上がるアニメーション（再定義） */
@keyframes rankIn {
    0% {
        opacity: 0;
        transform: translateY(15px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.rank-item {
    animation: rankIn 0.4s ease-out forwards;
}

@media (max-width: 1000px) {

    /* スタッツグリッド */
    .stats-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
        margin-top: 15px;
    }

    .tab-text {
        display: inline;
    }

    .game-card {
        margin: 25px auto;
        max-width: 500px;
    }

    .user-profile {
        display: flex;
        /* 横並びにする */
        justify-content: center;
        /* 横方向の中央寄せ */
        align-items: flex-end;
        /* 下端で揃える */
        gap: 12px;
        /* アイコンと名前の間の余白（お好みで調整） */
    }

    /* 補足：pタグなどのデフォルト余白が邪魔をする場合 */
    .user-meta p {
        margin: 0;
    }

    .avatar-frame {
        margin: 0;
    }

    .rank-item {
        display: flex;
    }
}

body.focus-mode .tab-text {
    display: inline;
}

body.focus-mode .stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 15px;
}

body.focus-mode .user-profile {
    display: flex;
    /* 横並びにする */
    justify-content: center;
    /* 横方向の中央寄せ */
    align-items: flex-end;
    /* 下端で揃える */
    gap: 12px;
    /* アイコンと名前の間の余白（お好みで調整） */
}

body.focus-mode .rank-item {
    display: flex;
}