:root {
    --primary: #667eea;
    --primary-dark: #5a67d8;
    --accent: #f6ad55;
    --bg: #f7fafc;
    --text: #2d3748;
    --success: #48bb78;
    --error: #f56565;
}

/* ステータスエリアのレイアウト */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 2行3列 */
    gap: 15px;
    margin-top: 15px;
}

.status-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.8rem;
    font-weight: bold;
    transition: transform 0.2s ease;
}

.status-item:hover {
    transform: translateY(-3px);
}

.status-icon {
    font-size: 1.5rem;
    margin-bottom: 8px;
    line-height: 1;
}

/* 円形プログレスバーの本体 */
.status-circle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: conic-gradient(var(--color) var(--progress-deg, 0deg), #e9ecef 0deg);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.06), 0 4px 6px rgba(0,0,0,0.04);
    transition: background 1s cubic-bezier(0.25, 1, 0.5, 1);
}

/* 円の中央（レベルを表示） */
.status-circle::after {
    content: attr(data-lv);
    position: absolute;
    width: 48px;
    height: 48px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}

.status-label {
    color: #4a5568;
    white-space: nowrap;
    margin-top: 8px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* ヘッダー・ユーザー情報エリア */
.user-stats-bar {
    background: white;
    padding: 15px 25px;
    border-radius: 16px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 15px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-avatar {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 1.2rem;
}

.level-badge {
    background: var(--text);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: bold;
}

.xp-container {
    flex-grow: 1;
    max-width: 300px;
    margin: 0 20px;
}

.xp-label {
    font-size: 0.8rem;
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    font-weight: 600;
}

.xp-bar-bg {
    height: 10px;
    background: #edf2f7;
    border-radius: 5px;
    overflow: hidden;
}

.xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #48bb78, #38b2ac);
    width: 0%;
    transition: width 0.5s ease;
}

.settings-btn {
    background: transparent;
    border: 1px solid #cbd5e0;
    color: #718096;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.settings-btn:hover {
    background: #edf2f7;
    color: var(--text);
}

/* メインコンテンツエリア */
.challenge-area {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

/* 難易度選択画面 */
.difficulty-selector {
    text-align: center;
    padding: 20px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.difficulty-selector h2 {
    margin-bottom: 10px;
    color: var(--text);
}

.current-chapter-display {
    background: #ebf8ff;
    color: #2b6cb0;
    display: inline-block;
    padding: 8px 20px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 0.9rem;
}

/* アコーディオン全体の容器 */
.focus-topics-container {
    margin: 15px auto;
    max-width: 800px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
}

/* カテゴリごとのドロップダウン */
.category-dropdown {
    border-bottom: 1px solid #edf2f7;
}

.category-header {
    width: 100%;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    cursor: pointer;
    transition: background 0.2s;
    user-select: none;
}

.category-header:hover {
    background: #f8fafc;
}

.category-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.category-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--cat-color);
}

.category-name {
    font-size: 0.85rem;
    font-weight: bold;
    color: #4a5568;
}

/* 選択済みバッジ */
.selected-count {
    background: var(--cat-color);
    color: white;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    display: none; /* 0個の時は隠す */
}

/* 中身のチップエリア */
.category-content {
    display: none; /* 初期状態は非表示 */
    padding: 12px;
    background: #f1f5f9;
    flex-wrap: wrap;
    gap: 8px;
}

/* 開いている時のスタイル */
.category-dropdown.open .category-content {
    display: flex;
}

.category-dropdown.open .chevron {
    transform: rotate(180deg);
}

.chevron {
    transition: transform 0.2s;
    color: #a0aec0;
}

.topic-chip {
    display: inline-flex;
    align-items: center;
    background-color: #f1f5f9; /* 基本は薄いグレー */
    border: 1px solid #cbd5e0;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.72rem;
    color: #4a5568;
    transition: all 0.2s;
    user-select: none;
}

/* ★ 修正ポイント：チェック時に背景色と文字色を確定させる */
.topic-chip.active {
    background-color: var(--cat-color) !important; /* JSから渡された色 */
    color: #ffffff !important; /* 文字を白に */
    border-color: transparent;
    font-weight: bold;
}

.topic-chip input {
    display: none; /* チェックボックス本体は隠す */
}

.difficulty-cards {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.diff-card {
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 30px;
    width: 200px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.diff-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: 0 10px 20px rgba(102, 126, 234, 0.15);
}

.diff-card h3 {
    margin-top: 0;
    color: var(--text);
}

.diff-card .stars {
    color: var(--accent);
    font-size: 1.5rem;
    margin-bottom: 10px;
}

/* 問題表示エリア */
.problem-container {
    display: none; /* 初期状態は非表示 */
    animation: fadeIn 0.5s ease;
}

/* コントロールバー (新規追加) */
.control-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.control-group {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.control-select {
    padding: 8px 12px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    background: white;
    font-size: 0.9rem;
    color: #4a5568;
    max-width: 200px;
}

.problem-header {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    margin-bottom: 20px;
    border-left: 5px solid var(--primary);
}

.problem-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.problem-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #2d3748;
    margin: 0;
}

.problem-difficulty {
    background: #ebf4ff;
    color: var(--primary);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.problem-content {
    color: #4a5568;
    line-height: 1.8;
    white-space: pre-wrap;
}

/* エディタと出力のレイアウト */
.workspace {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    min-width: 0;
    width: 100%;
}

.editor-section, .output-section {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.section-header {
    font-weight: 700;
    color: #4a5568;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* aiChallenge.html の <style> 内に追加 */
.CodeMirror {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    height: 400px;
    font-size: 14px;
    width: 100% !important; /* 幅の突き抜け防止 */
}

.CodeMirror-gutters {
    border-right: 1px solid #ddd;
    background-color: #272822; /* monokaiテーマの背景色に合わせる */
    min-width: 30px;
}

.run-btn {
    background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 15px;
    width: 100%;
    transition: transform 0.1s;
}

.run-btn:active {
    transform: scale(0.98);
}

.run-btn:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
}

.output-box {
    background: #1a202c;
    color: #68d391;
    font-family: 'Courier New', monospace;
    padding: 15px;
    border-radius: 8px;
    flex-grow: 1;
    min-height: 200px;
    white-space: pre-wrap;
    overflow-y: auto;
    font-size: 0.9rem;
}

/* AIフィードバックエリア */
.ai-feedback {
    margin-top: 20px;
    padding: 15px;
    border-radius: 8px;
    display: none;
}

.ai-feedback.correct {
    background: #f0fff4;
    border: 1px solid #c6f6d5;
}

.ai-feedback.incorrect {
    background: #fff5f5;
    border: 1px solid #fed7d7;
}

.ai-feedback h4 {
    margin-top: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.next-btn-area {
    margin-top: 15px;
    text-align: center;
    display: none;
}

.btn-next {
    background: #48bb78;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    box-shadow: 0 4px 6px rgba(72, 187, 120, 0.2);
    transition: all 0.2s;
}

.btn-next:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(72, 187, 120, 0.3);
}

/* ローディングアニメーション */
.loader-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    display: none;
}

.loader-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #edf2f7;
    border-top: 5px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* モーダル */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    display: none;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #4a5568;
}

.form-group input, .form-group select  {
    width: 100%;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    box-sizing: border-box;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}

.btn-primary-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

.btn-primary-outline:hover {
    background: var(--primary);
    color: white;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.9rem;
}
.btn-secondary {
    background: #e2e8f0;
    color: #4a5568;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}

/* レスポンシブ */
@media (max-width: 768px) {
    .workspace {
        grid-template-columns: 1fr;
        width: 100%;
    }
    .problem-header {
            /* パディングが大きすぎて圧迫している場合があるため調整 */
            padding: 15px;
        }

    .problem-content {
        /* 長い英単語やコードが改行されるようにする */
        word-break: break-all;
        overflow-wrap: break-word;
    }

    .output-box {
        /* 出力ボックスも突き抜けないように */
        max-width: 100%;
        box-sizing: border-box;
    }
    .CodeMirror {
        height: 300px;
    }
    .user-stats-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .xp-container {
        max-width: 100%;
        margin: 10px 0;
    }
    .control-bar {
        flex-direction: column;
        align-items: stretch;
        padding: 16px 0px;
    }
    .control-group {
        flex-direction: column;
        align-items: stretch;
    }
    .control-select, .btn-sm {
        max-width: 100%;
        width: 90%;
        margin: auto;
    }
}