:root {
    --bg-dark: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    
    --color-pi-1: #ec4899;
    --color-pi-2: #f43f5e;
    --color-square-1: #8b5cf6;
    --color-square-2: #6366f1;
    --color-fraction-1: #0ea5e9;
    --color-fraction-2: #10b981;
    --color-circle-1: #f59e0b;
    --color-circle-2: #e11d48;
    --color-primemult-1: #34d399;
    --color-primemult-2: #059669;
    --color-time-1: #fb923c;
    --color-time-2: #d97706;

    --color-eleven-1: #e11d48;
    --color-eleven-2: #9f1239;
    --color-speed-1: #06b6d4;
    --color-speed-2: #0891b2;
    --color-unit-1: #84cc16;
    --color-unit-2: #65a30d;

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
}

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

body {
    font-family: 'Outfit', 'Noto Sans JP', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 背景デコレーション */
.background-decor {
    position: fixed;
    width: 40vmax;
    height: 40vmax;
    border-radius: 50%;
    filter: blur(80px);
    z-index: -1;
    opacity: 0.3;
}

.blob-1 {
    background: radial-gradient(circle, var(--color-pi-1), transparent 70%);
    top: -10%;
    left: -10%;
}

.blob-2 {
    background: radial-gradient(circle, var(--color-fraction-1), transparent 70%);
    bottom: -10%;
    right: -10%;
}

/* アプリ容器 */
.app-container {
    width: 100%;
    max-width: 960px;
    min-height: 100vh;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* 画面切り替え用 */
.screen {
    display: none;
    width: 100%;
    animation: fadeIn 0.4s ease-out forwards;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ガラスモーフィズムカード */
.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    padding: 32px;
    width: 100%;
}

/* ホーム画面のヘッダー */
.game-header {
    text-align: center;
    margin-bottom: 12px;
}

.game-header h1 {
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: -1px;
    margin-bottom: 8px;
}

.game-header h1 span {
    background: linear-gradient(135deg, var(--color-pi-1), var(--color-square-1));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

/* イントロカード */
.intro-card h3 {
    font-size: 1.3rem;
    margin-bottom: 16px;
    color: #ffd700;
}

.intro-card ul {
    list-style-type: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.intro-card li {
    font-size: 1.05rem;
    line-height: 1.6;
    padding-left: 24px;
    position: relative;
}

.intro-card li::before {
    content: "🎈";
    position: absolute;
    left: 0;
    top: 0;
}

/* モード選択ボタン */
.mode-selection {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    width: 100%;
}

.btn {
    border: none;
    border-radius: 20px;
    padding: 20px 24px;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.btn-primary {
    background: linear-gradient(135deg, #4f46e5, #0ea5e9);
}

.btn-primary:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.4);
}

.btn-secondary {
    background: linear-gradient(135deg, #ec4899, #f43f5e);
}

.btn-secondary:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(236, 72, 153, 0.4);
}

.btn-icon {
    font-size: 2.2rem;
}

.btn-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
}

.btn-text strong {
    font-size: 1.2rem;
    margin-bottom: 2px;
}

.btn-text span {
    font-size: 0.85rem;
    opacity: 0.8;
}

.back-home-container {
    margin-top: 12px;
}

.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95rem;
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--text-main);
}

/* HUD (ゲーム情報ヘッダー) */
.game-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 12px;
}

.hud-btn {
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 16px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.hud-btn:hover {
    background: rgba(255,255,255,0.15);
}

.hud-stats {
    display: flex;
    gap: 20px;
}

.stat-item {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 700;
}

.question-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 16px;
    padding: 24px;
    width: 100%;
    box-sizing: border-box;
}

.question-header {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
}

.question-text {
    font-size: 2.2rem;
    font-weight: 700;
    min-height: 50px;
    display: flex;
    align-items: center;
}

.question-container {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.question-container.drag-over {
    border-color: #38bdf8;
    background: rgba(56, 189, 248, 0.08);
    transform: scale(1.01);
}

.game-instruction {
    font-size: 0.95rem;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: -4px;
    font-weight: 600;
}

.hint-text-box {
    font-size: 0.9rem;
    color: #ffd700; /* ヒントは目立つゴールドイエロー */
    margin-top: 8px;
    min-height: 24px;
    line-height: 1.4;
    text-align: center;
    transition: opacity 0.3s ease;
    opacity: 0;
    pointer-events: none;
    width: 100%;
}

.hint-text-box.show {
    opacity: 1;
}

#answer-effect-zone {
    width: 100%;
    min-height: 65px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 45%; /* 問題テキスト（#question-text）の位置にぴったり合わせる */
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 5;
}

/* カテゴリ行 (上段・下段) */
.categories-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    width: 100%;
}

.category-box {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 20px;
    height: 220px;
    display: flex;
    flex-direction: column;
    overflow: visible;
    position: relative;
    transition: border-color 0.3s, box-shadow 0.3s;
}

/* カテゴリごとの枠線と背景の薄いグラデーション */
.category-box[data-category="pi"] {
    border-color: rgba(236, 72, 153, 0.4);
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.05), rgba(30, 41, 59, 0.7));
}
.category-box[data-category="square"] {
    border-color: rgba(139, 92, 246, 0.4);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.05), rgba(30, 41, 59, 0.7));
}
.category-box[data-category="fraction"] {
    border-color: rgba(14, 165, 233, 0.4);
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.05), rgba(30, 41, 59, 0.7));
}
.category-box[data-category="circle"] {
    border-color: rgba(245, 158, 11, 0.4);
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.05), rgba(30, 41, 59, 0.7));
}
.category-box[data-category="primemult"] {
    border-color: rgba(52, 211, 153, 0.4);
    background: linear-gradient(135deg, rgba(52, 211, 153, 0.05), rgba(30, 41, 59, 0.7));
}
.category-box[data-category="time"] {
    border-color: rgba(251, 146, 60, 0.4);
    background: linear-gradient(135deg, rgba(251, 146, 60, 0.05), rgba(30, 41, 59, 0.7));
}
.category-box[data-category="eleven_mult"] {
    border-color: rgba(225, 29, 72, 0.4);
    background: linear-gradient(135deg, rgba(225, 29, 72, 0.05), rgba(30, 41, 59, 0.7));
}
.category-box[data-category="speed_conv"] {
    border-color: rgba(6, 182, 212, 0.4);
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.05), rgba(30, 41, 59, 0.7));
}
.category-box[data-category="unit_conv"] {
    border-color: rgba(132, 204, 22, 0.4);
    background: linear-gradient(135deg, rgba(132, 204, 22, 0.05), rgba(30, 41, 59, 0.7));
}

/* タイトルを背景の巨大な透かし文字に変更 */
.category-title {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.8rem;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.08); /* 視認性を高めるため少し濃く変更 */
    z-index: 0;
    pointer-events: none;
    white-space: nowrap;
    text-align: center;
    width: 100%;
    transition: all 0.4s ease-in-out;
}

/* プレビュー確認時間中のウォーターマーク強調 */
.category-title.preview-active {
    color: rgba(255, 255, 255, 0.45) !important;
    text-shadow: 0 0 15px rgba(255, 255, 255, 0.25);
    z-index: 10; /* バルーン(z-index: 2)より前面に */
    transform: translate(-50%, -50%) scale(1.06);
}

/* プレビュー中のバルーンの半透明化 */
.preview-mode .balloon {
    opacity: 0.25;
    filter: grayscale(40%);
    pointer-events: none; /* ドラッグ不可 */
}

/* 中段：3カラムレイアウト（左カテゴリ、中央問題、右カテゴリ） */
.middle-row {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1.8fr) minmax(0, 1.6fr);
    gap: 16px;
    width: 100%;
    align-items: center;
}

.middle-row .category-box {
    height: 230px; /* 横幅を広げたので高さを少し低く調整 */
}

.middle-row .balloon-shelf {
    grid-template-columns: repeat(3, 1fr); /* 3列表示に変更 */
    grid-template-rows: repeat(3, 1fr);
    gap: 6px;
}

/* バルーンの配置棚 */
.balloon-shelf {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 6px;
    padding: 10px;
    align-items: center;
    justify-items: center;
    position: relative;
    z-index: 2;
}

/* バルーンのデザイン */
.balloon {
    position: relative;
    width: 48px;
    height: 56px;
    border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-weight: 800; /* 極太ウェイトに変更 */
    font-size: 1.05rem; /* 文字サイズを拡大 */
    cursor: grab;
    touch-action: none;
    box-shadow: inset -4px -6px 12px rgba(0,0,0,0.3), 
                inset 3px 3px 6px rgba(255,255,255,0.4),
                0 6px 12px rgba(0,0,0,0.3);
    transition: transform 0.1s, opacity 0.2s;
    animation: float 3s ease-in-out infinite alternate;
}

/* バルーンの種類別カラー */
.balloon[data-category="pi"] {
    background: radial-gradient(circle at 35% 35%, #ff75c3, var(--color-pi-1));
}
.balloon[data-category="square"] {
    background: radial-gradient(circle at 35% 35%, #b794f4, var(--color-square-1));
}
.balloon[data-category="fraction"] {
    background: radial-gradient(circle at 35% 35%, #38bdf8, var(--color-fraction-1));
}
.balloon[data-category="circle"] {
    background: radial-gradient(circle at 35% 35%, #fbbf24, var(--color-circle-1));
}
.balloon[data-category="primemult"] {
    background: radial-gradient(circle at 35% 35%, #6ee7b7, var(--color-primemult-1));
}
.balloon[data-category="time"] {
    background: radial-gradient(circle at 35% 35%, #fdba74, var(--color-time-1));
}
.balloon[data-category="eleven_mult"] {
    background: radial-gradient(circle at 35% 35%, #fda4af, var(--color-eleven-1));
}
.balloon[data-category="speed_conv"] {
    background: radial-gradient(circle at 35% 35%, #67e8f9, var(--color-speed-1));
}
.balloon[data-category="unit_conv"] {
    background: radial-gradient(circle at 35% 35%, #bef264, var(--color-unit-1));
}

/* バルーンの下の結び目（三角形の擬似要素） */
.balloon::after {
    content: "";
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 6px solid rgba(0, 0, 0, 0.4);
    z-index: -1;
}
/* カテゴリごとの結び目の色調整 */
.balloon[data-category="pi"]::after { border-bottom-color: var(--color-pi-1); }
.balloon[data-category="square"]::after { border-bottom-color: var(--color-square-1); }
.balloon[data-category="fraction"]::after { border-bottom-color: var(--color-fraction-1); }
.balloon[data-category="circle"]::after { border-bottom-color: var(--color-circle-1); }
.balloon[data-category="primemult"]::after { border-bottom-color: var(--color-primemult-1); }
.balloon[data-category="time"]::after { border-bottom-color: var(--color-time-1); }
.balloon[data-category="eleven_mult"]::after { border-bottom-color: var(--color-eleven-1); }
.balloon[data-category="speed_conv"]::after { border-bottom-color: var(--color-speed-1); }
.balloon[data-category="unit_conv"]::after { border-bottom-color: var(--color-unit-1); }

/* バルーン内の文字の折り返しやサイズ調整 */
.balloon-text {
    text-align: center;
    line-height: 1;
    pointer-events: none;
    /* 黒いしっかりとしたフチ取りを追加してコントラストを劇的に向上 */
    text-shadow: -1.2px -1.2px 0 #000, 1.2px -1.2px 0 #000, -1.2px 1.2px 0 #000, 1.2px 1.2px 0 #000, 0 2px 4px rgba(0,0,0,0.8);
}

.balloon:active {
    cursor: grabbing;
    transform: scale(1.1);
}

.balloon.dragging {
    opacity: 0.4;
    z-index: 1000 !important;
}

/* 浮遊アニメーション */
@keyframes float {
    0% { transform: translateY(0) rotate(-2deg); }
    100% { transform: translateY(-6px) rotate(2deg); }
}

/* ドラッグ中に指/マウスに追従するバルーンのクローン */
.drag-balloon {
    position: fixed;
    width: 65px;
    height: 75px;
    border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-weight: bold;
    font-size: 1.1rem;
    pointer-events: none;
    z-index: 9999;
    box-shadow: inset -5px -7px 15px rgba(0,0,0,0.35), 
                inset 4px 4px 8px rgba(255,255,255,0.45),
                0 10px 20px rgba(0,0,0,0.4);
    transform: translate(-50%, -50%) scale(1.1);
}

.drag-balloon::after {
    content: "";
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 7px solid rgba(0, 0, 0, 0.4);
}

/* リザルト画面 */
.result-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    text-align: center;
}

.result-card h2 {
    font-size: 2.2rem;
    font-weight: 800;
}

.result-stats {
    display: flex;
    justify-content: space-around;
    width: 100%;
    gap: 16px;
}

.result-stat {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px;
    flex: 1;
}

.res-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.res-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #ffd700;
}

.result-actions {
    display: flex;
    gap: 16px;
    width: 100%;
}

.result-actions .btn {
    flex: 1;
    justify-content: center;
}

/* 間違えた問題リスト */
.wrong-answers-container {
    width: 100%;
    background: rgba(239, 68, 68, 0.05);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 16px;
    padding: 16px;
    text-align: left;
}

.wrong-answers-container h3 {
    font-size: 1.05rem;
    margin-bottom: 12px;
    color: #ef4444;
}

.wrong-answers-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 150px;
    overflow-y: auto;
}

.wrong-item {
    font-size: 0.95rem;
    display: flex;
    justify-content: space-between;
    padding: 6px 12px;
    background: rgba(255,255,255,0.03);
    border-radius: 8px;
}

.wrong-q {
    font-weight: 600;
}

.wrong-a {
    color: #10b981;
}

/* 正解・不正解時のアニメーション効果 */
@keyframes correctPop {
    0% { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
    20% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
    70% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
}

.balloon-pop {
    position: absolute;
    top: 50%;
    left: 50%;
    animation: correctPop 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards !important;
}

.mobile-layout-toggle {
    display: none;
}

/* ゲームボードのPC版のデフォルトレイアウト */
.game-board {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    width: 100%;
}

@media (max-width: 768px) {
    .game-hud {
        position: sticky;
        top: 0;
        background: rgba(15, 23, 42, 0.85);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        padding: 6px 8px;
        z-index: 1000; /* バルーン等の上に表示 */
        margin-bottom: 16px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .hud-btn {
        padding: 6px 10px;
        font-size: 0.8rem;
        border-radius: 8px;
    }

    .hud-stats {
        gap: 6px;
    }

    .stat-item {
        padding: 6px 8px;
        gap: 4px;
        border-radius: 10px;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    .stat-value {
        font-size: 0.85rem;
        font-variant-numeric: tabular-nums; /* 数字の幅を一定に固定し、タイマーカウント時のチラツキを解消 */
    }

    .mobile-layout-toggle {
        display: flex;
        flex-direction: column;
        gap: 6px;
        position: absolute;
        left: 10px;
        top: 50%;
        transform: translateY(-50%);
        width: auto;
        z-index: 5;
    }

    .layout-toggle-btn {
        background: rgba(255, 255, 255, 0.08);
        border: 1px solid rgba(255, 255, 255, 0.15);
        color: var(--text-muted);
        width: 32px;
        height: 32px;
        border-radius: 50%;
        font-size: 0.85rem;
        font-weight: 800;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
        padding: 0;
    }
    
    .layout-toggle-btn.active {
        background: var(--text-main);
        color: #0f172a;
        border-color: var(--text-main);
        box-shadow: 0 0 10px rgba(255, 255, 255, 0.15);
    }

    /* スマホ用の縦積みFlexレイアウト */
    .game-board {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .game-header h1 {
        font-size: 2.2rem;
    }
    
    .mode-selection {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .categories-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .middle-row {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }


    .middle-row .category-box {
        height: 180px;
    }

    .middle-row .balloon-shelf {
        grid-template-columns: repeat(6, 1fr);
        grid-template-rows: repeat(2, 1fr);
        gap: 4px;
    }

    .category-box {
        height: 180px;
    }

    .balloon-shelf {
        grid-template-columns: repeat(6, 1fr);
        grid-template-rows: repeat(2, 1fr);
        gap: 4px;
        padding: 6px;
    }

    .balloon {
        width: 42px;
        height: 48px;
        font-weight: 800;
        font-size: 0.9rem; /* スマホ表示時の文字サイズも拡大 */
    }
    
    .question-container {
        position: relative;
        padding-left: 52px !important;
        scroll-margin-top: 72px; /* スティッキーヘッダー(HUD)と被るのを防止 */
        scroll-margin-bottom: 24px; /* 画面下端の余白 */
    }
    
    .question-text {
        font-size: 1.8rem;
    }

    .result-stats {
        flex-direction: column;
        gap: 10px;
    }

    .result-actions {
        flex-direction: column;
    }
}

/* 正解ポップアップ */
.correct-popup {
    position: fixed;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    padding: 16px 36px;
    border-radius: 50px;
    font-size: 2.2rem;
    font-weight: 800;
    box-shadow: 0 10px 30px rgba(16, 185, 129, 0.5);
    z-index: 10000;
    pointer-events: none;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    animation: popupAnim 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popupAnim {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    25% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
    75% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(0.85); opacity: 0; }
}

/* 不正解ポップアップ */
.incorrect-popup {
    position: fixed;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, #ef4444, #b91c1c);
    color: white;
    padding: 16px 36px;
    border-radius: 50px;
    font-size: 2.2rem;
    font-weight: 800;
    box-shadow: 0 10px 30px rgba(239, 68, 68, 0.5);
    z-index: 10000;
    pointer-events: none;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    animation: incorrectPopupAnim 0.8s ease forwards;
}

@keyframes incorrectPopupAnim {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    15% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    25% { transform: translate(-53%, -50%) scale(1); }
    35% { transform: translate(-47%, -50%) scale(1); }
    45% { transform: translate(-52%, -50%) scale(1); }
    55% { transform: translate(-48%, -50%) scale(1); }
    65% { transform: translate(-50%, -50%) scale(1); }
    80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(0.85); opacity: 0; }
}

/* ヒントスイッチのスタイル */
.hint-toggle-container {
    position: absolute;
    top: 16px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 10;
}

.hint-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.15);
    transition: .3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #10b981;
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* ヒント時のパネル点灯（ハイライト・点滅）効果 */
.category-box.hint-highlight {
    transform: scale(1.02);
}

.category-box.hint-highlight[data-category="pi"] {
    animation: blink-pi 1.2s ease-in-out infinite;
}
.category-box.hint-highlight[data-category="square"] {
    animation: blink-square 1.2s ease-in-out infinite;
}
.category-box.hint-highlight[data-category="fraction"] {
    animation: blink-fraction 1.2s ease-in-out infinite;
}
.category-box.hint-highlight[data-category="circle"] {
    animation: blink-circle 1.2s ease-in-out infinite;
}
.category-box.hint-highlight[data-category="primemult"] {
    animation: blink-primemult 1.2s ease-in-out infinite;
}
.category-box.hint-highlight[data-category="time"] {
    animation: blink-time 1.2s ease-in-out infinite;
}

/* 点滅キーフレーム定義 */
@keyframes blink-pi {
    0%, 100% { border-color: rgba(255, 255, 255, 0.1); box-shadow: none; }
    50% { border-color: var(--color-pi-1); box-shadow: 0 0 20px rgba(236, 72, 153, 0.5); }
}
@keyframes blink-square {
    0%, 100% { border-color: rgba(255, 255, 255, 0.1); box-shadow: none; }
    50% { border-color: var(--color-square-1); box-shadow: 0 0 20px rgba(139, 92, 246, 0.5); }
}
@keyframes blink-fraction {
    0%, 100% { border-color: rgba(255, 255, 255, 0.1); box-shadow: none; }
    50% { border-color: var(--color-fraction-1); box-shadow: 0 0 20px rgba(14, 165, 233, 0.5); }
}
@keyframes blink-circle {
    0%, 100% { border-color: rgba(255, 255, 255, 0.1); box-shadow: none; }
    50% { border-color: var(--color-circle-1); box-shadow: 0 0 20px rgba(245, 158, 11, 0.5); }
}
@keyframes blink-primemult {
    0%, 100% { border-color: rgba(255, 255, 255, 0.1); box-shadow: none; }
    50% { border-color: var(--color-primemult-1); box-shadow: 0 0 20px rgba(52, 211, 153, 0.5); }
}
@keyframes blink-time {
    0%, 100% { border-color: rgba(255, 255, 255, 0.1); box-shadow: none; }
    50% { border-color: var(--color-time-1); box-shadow: 0 0 20px rgba(251, 146, 60, 0.5); }
}

.category-box.hint-highlight[data-category="eleven_mult"] {
    animation: blink-eleven 1.2s ease-in-out infinite;
}
.category-box.hint-highlight[data-category="speed_conv"] {
    animation: blink-speed 1.2s ease-in-out infinite;
}
.category-box.hint-highlight[data-category="unit_conv"] {
    animation: blink-unit 1.2s ease-in-out infinite;
}

@keyframes blink-eleven {
    0%, 100% { border-color: rgba(255, 255, 255, 0.1); box-shadow: none; }
    50% { border-color: var(--color-eleven-1); box-shadow: 0 0 20px rgba(225, 29, 72, 0.5); }
}
@keyframes blink-speed {
    0%, 100% { border-color: rgba(255, 255, 255, 0.1); box-shadow: none; }
    50% { border-color: var(--color-speed-1); box-shadow: 0 0 20px rgba(6, 182, 212, 0.5); }
}
@keyframes blink-unit {
    0%, 100% { border-color: rgba(255, 255, 255, 0.1); box-shadow: none; }
    50% { border-color: var(--color-unit-1); box-shadow: 0 0 20px rgba(132, 204, 22, 0.5); }
}

/* 難易度設定カード */
.difficulty-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    margin-bottom: 24px;
    width: 100%;
    max-width: 450px;
    margin-left: auto;
    margin-right: auto;
}

.difficulty-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 1px;
    text-transform: uppercase;
}

.difficulty-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 100%;
    background: rgba(15, 23, 42, 0.6);
    padding: 4px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.diff-option {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-muted);
}

.diff-option input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.diff-option:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.03);
}

.diff-option.active {
    color: #0f172a;
    background: var(--text-main);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* --- リザルト画面の問題一覧 & 解説吹き出しのスタイル --- */
.played-questions-container {
    margin-top: 24px;
    width: 100%;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
    text-align: left;
}

.played-questions-container h3 {
    font-size: 1.05rem;
    margin-bottom: 10px;
    color: var(--text-main);
    font-weight: 700;
}

.played-questions-list {
    max-height: 250px;
    overflow-y: auto;
    background: rgba(15, 23, 42, 0.5);
    border-radius: 14px;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* スクロールバーのカスタマイズ */
.played-questions-list::-webkit-scrollbar {
    width: 6px;
}
.played-questions-list::-webkit-scrollbar-track {
    background: transparent;
}
.played-questions-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}
.played-questions-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* リストアイテムの親ラッパー */
.played-q-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.played-q-wrapper:last-child {
    border-bottom: none;
}

.played-q-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 4px;
    gap: 8px;
}

.q-status {
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
.q-status.correct { color: #10b981; }
.q-status.incorrect { color: #ef4444; }

.q-info {
    flex: 1;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
}

.q-ans-info {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: right;
}
.q-ans-info span.correct-val {
    color: #10b981;
    font-weight: 700;
}
.q-ans-info .wrong-ans {
    color: #ef4444;
    text-decoration: line-through;
    margin-right: 6px;
    opacity: 0.8;
}

/* 解説ボタン */
.btn-explain {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}
.btn-explain:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-main);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-explain.active {
    background: #ffd700;
    color: #0f172a;
    border-color: #ffd700;
}

/* 解説吹き出し (各問題アイテムの直下アコーディオン型) */
.explain-bubble-box {
    position: relative;
    background: linear-gradient(135deg, #1e293b, #0f172a);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    padding: 12px 14px;
    margin: 4px 4px 12px 4px;
    color: #ffd700; /* ゴールドでヒント感を演出 */
    font-size: 0.82rem;
    line-height: 1.45;
    font-weight: 600;
    pointer-events: auto;
    animation: bubbleSlide 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* 吹き出しの上向き三角形の突起 */
.explain-bubble-box::after {
    content: "";
    position: absolute;
    bottom: 100%;
    right: 28px;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid #1e293b;
}
.explain-bubble-box::before {
    content: "";
    position: absolute;
    bottom: 100%;
    right: 28px;
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-bottom: 9px solid rgba(255, 255, 255, 0.15);
    z-index: -1;
    margin-bottom: 1px;
}

@keyframes bubbleSlide {
    from { opacity: 0; transform: translateY(-6px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ドラッグ間違いリアクション吹き出し */
.reaction-bubble {
    position: absolute;
    bottom: 110%; /* バルーンの少し上 */
    left: 50%;
    transform: translateX(-50%);
    background: #f59e0b; /* 警告イエロー・オレンジ */
    color: #0f172a;
    font-size: 0.85rem;
    font-weight: 900;
    padding: 4px 8px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(245, 158, 11, 0.4);
    pointer-events: none;
    white-space: nowrap;
    z-index: 100;
    animation: reactionPopUp 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* 吹き出しの小さな三角形の突起 */
.reaction-bubble::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid #f59e0b;
}

@keyframes reactionPopUp {
    0% { transform: translateX(-50%) scale(0.3); opacity: 0; }
    15% { transform: translateX(-50%) scale(1.15); opacity: 1; }
    80% { transform: translateX(-50%) scale(1) translateY(-6px); opacity: 1; }
    100% { transform: translateX(-50%) scale(0.8) translateY(-15px); opacity: 0; }
}

/* 集中特訓モードボタン */
.btn-practice {
    background: linear-gradient(135deg, #0ea5e9, #10b981) !important;
}
.btn-practice:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(16, 185, 129, 0.4);
}

/* 特訓カテゴリ選択カード */
.practice-category-select-card {
    margin-top: 24px;
    padding: 20px 24px;
    width: 100%;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    animation: fadeIn 0.4s ease-out forwards;
}

.practice-category-select-card h3 {
    font-size: 1.05rem;
    margin-bottom: 16px;
    color: var(--text-main);
    font-weight: 700;
}

.practice-category-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.practice-cat-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    padding: 12px 8px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.practice-cat-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-main);
    border-color: rgba(255, 255, 255, 0.2);
}

.practice-cat-btn.active {
    background: var(--text-main);
    color: #0f172a;
    border-color: var(--text-main);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.25);
}

.btn-start-practice {
    background: linear-gradient(135deg, #fb923c, #fb7185);
    color: white;
    font-weight: 800;
    padding: 12px 32px;
    border-radius: 50px;
    border: none;
    cursor: pointer;
    font-size: 1.05rem;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(251, 146, 60, 0.3);
}

.btn-start-practice:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(251, 146, 60, 0.5);
}

/* 集中特訓モード時のグリッド調整 */
.practice-mode-active .middle-row {
    display: flex !important;
    justify-content: center;
    align-items: stretch;
    gap: 24px;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
}
.practice-mode-active .middle-row > .category-box {
    width: 100%;
    max-width: 480px; /* 10個のバルーンでもはみ出さないよう拡張 */
    height: auto;
    min-height: 230px;
    flex: 1;
}
.practice-mode-active .middle-row > #question-panel {
    width: 100%;
    max-width: 480px;
    flex: 1;
}

/* スマホ表示時の集中特訓モードレイアウト調整 */
@media (max-width: 768px) {
    .practice-mode-active .middle-row {
        flex-direction: column !important;
        align-items: center !important;
        gap: 16px;
    }
    .practice-mode-active .middle-row > .category-box,
    .practice-mode-active .middle-row > #question-panel {
        max-width: 100% !important; /* 横幅いっぱい使用 */
    }
}
