:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #ec4899;
    --bg-dark: #0f172a;
    --text-white: #f8fafc;
    --text-muted: #94a3b8;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --font-main: 'Inter', 'Noto Sans JP', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-dark);
    color: var(--text-white);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* 上部から配置してスクロール可能に */
    padding: 2.5rem 1rem; /* 上下の余白を確保 */
    overflow-y: auto; /* コンテンツ量に応じてスクロール */
}

/* 背景装飾 */
.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    filter: blur(80px);
}

.blob {
    position: absolute;
    border-radius: 50%;
    opacity: 0.6;
    animation: move 20s infinite alternate;
}

.blob-1 {
    width: 400px;
    height: 400px;
    background: var(--primary);
    top: -100px;
    left: -100px;
}

.blob-2 {
    width: 500px;
    height: 500px;
    background: var(--secondary);
    bottom: -150px;
    right: -100px;
    animation-delay: -5s;
}

.blob-3 {
    width: 300px;
    height: 300px;
    background: #06b6d4;
    top: 40%;
    left: 50%;
    animation-delay: -10s;
}

@keyframes move {
    from { transform: translate(0, 0) scale(1); }
    to { transform: translate(100px, 50px) scale(1.1); }
}

/* 共通パーツ */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2.5rem;
    width: 600px; /* 横幅を完全に固定 */
    max-width: 95vw; /* モバイル対応 */
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    text-align: center;
    transition: all 0.3s ease;
}

.screen {
    display: none;
    width: 100%;
    justify-content: center;
    padding: 20px;
}

.screen.active {
    display: flex;
    flex-direction: column; /* 常に縦に並べる */
    align-items: center;
    animation: fadeIn 0.5s ease-out;
}

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

/* ボタン */
button {
    cursor: pointer;
    border: none;
    border-radius: 12px;
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    color: var(--text-white); /* 追加 */
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary), #818cf8);
    color: white;
    width: 100%;
    margin-top: 2rem;
    box-shadow: 0 10px 15px -3px rgba(99, 102, 241, 0.3);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 20px 25px -5px rgba(99, 102, 241, 0.4);
}

.secondary-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: white;
    margin-top: 2rem;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* クイズヘッダー */
.quiz-header {
    width: 100%;
    max-width: 600px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem; /* 余白を確保 */
}

.progress-container {
    flex-grow: 1;
    margin-right: 2rem;
}

.progress-text {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.progress-bar-bg {
    width: 100%;
    height: 8px;
    background: var(--glass-bg);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    width: 0%;
    transition: width 0.3s ease;
}

/* タイマー */
.timer-container {
    position: relative;
    width: 60px;
    height: 60px;
}

.timer-svg {
    transform: rotate(-90deg);
}

.timer-bg {
    fill: none;
    stroke: var(--glass-bg);
    stroke-width: 8;
}

.timer-progress {
    fill: none;
    stroke: var(--secondary);
    stroke-width: 8;
    stroke-dasharray: 283;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1s linear;
}

#timer-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: 700;
    font-size: 1.2rem;
}

/* 問題と選択肢 */
.question-card h2 {
    font-size: 1.8rem;
    margin-bottom: 2rem;
    line-height: 1.4;
}

.options-grid {
    display: grid;
    gap: 1rem;
    width: 100%;
}

.option {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.2rem;
    text-align: left;
    transition: all 0.2s;
    font-size: 1.1rem;
    color: var(--text-white); /* 追加 */
    width: 100%;
}

.option:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.3);
}

.option.correct {
    background: rgba(34, 197, 94, 0.2);
    border-color: #22c55e;
}

.option.wrong {
    background: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
}

/* 特殊問題用 UI */
.audio-btn {
    background: var(--glass-bg);
    border: 1px solid var(--primary);
    color: var(--text-white);
    margin-bottom: 1.5rem;
    padding: 0.8rem;
    width: 100%;
    border-radius: 12px;
}

.audio-btn:hover {
    background: rgba(99, 102, 241, 0.1);
}

.fill-input {
    width: 100%;
    padding: 1.2rem;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid var(--glass-border);
    border-radius: 16px;
    color: white;
    font-size: 1.2rem;
    text-align: center;
    outline: none;
    transition: all 0.2s;
}

.fill-input:focus {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.1);
}

/* 結果 */
.result-card {
    display: flex;
    flex-direction: column;
}

.result-icon {
    font-size: 3.5rem;
    margin-bottom: 0.5rem;
}

.score-display {
    font-size: 3.5rem;
    font-weight: 800;
    margin: 0.5rem 0;
    color: var(--primary);
}

.score-total {
    font-size: 1.5rem;
    color: var(--text-muted);
}

.result-summary {
    margin-bottom: 1.5rem;
}

.stat-item {
    background: var(--glass-bg);
    padding: 0.8rem;
    border-radius: 12px;
}

.stat-label {
    display: block;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.1rem;
}

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

/* 結果グリッド */
.result-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.8rem;
    margin: 1.5rem 0;
    padding: 0.5rem;
}

.result-item-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.result-item-icon:hover {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.1);
}

.result-item-icon.correct {
    background: rgba(34, 197, 94, 0.3);
    border-color: #22c55e;
}

.result-item-icon.wrong {
    background: rgba(239, 68, 68, 0.3);
    border-color: #ef4444;
}

.result-item-icon.active {
    box-shadow: 0 0 0 4px var(--primary-hover);
    transform: scale(1.1);
}

/* 詳細パネル */
.result-detail-panel {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 16px;
    padding: 1.5rem;
    text-align: left;
    min-height: 200px; /* 自動伸長させる（ジャンプ防止のため最小値は確保） */
    height: auto;
    overflow: visible;
    border: 1px solid var(--glass-border);
    margin-bottom: 1rem;
}

/* パネル内スクロールバーのカスタマイズ */
.result-detail-panel::-webkit-scrollbar {
    width: 6px;
}
.result-detail-panel::-webkit-scrollbar-track {
    background: transparent;
}
.result-detail-panel::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 10px;
}

.placeholder-text {
    text-align: center;
    color: var(--text-muted);
    line-height: 180px; /* 高さに合わせて調整 */
}

.detail-q {
    font-weight: 700;
    margin-bottom: 1rem;
    font-size: 1.1rem;
    line-height: 1.5;
    overflow-wrap: anywhere; /* 意図しない幅の拡大を防止 */
    word-break: normal;
}

.detail-ans-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.95rem;
}

.detail-label {
    color: var(--text-muted);
    margin-right: 0.5rem;
    font-weight: 600;
}

.user-ans.correct { color: #22c55e; }
.user-ans.wrong { color: #ef4444; }
.correct-ans { color: #818cf8; }

#restart-btn {
    width: 100%;
}

/* 低い画面（モバイルの横向きなど）へのレスポンシブ対応 */
@media (max-height: 700px) {
    body {
        padding: 1rem;
    }
    .glass-card {
        padding: 1.5rem;
    }
    .result-icon {
        font-size: 2.5rem;
    }
    .score-display {
        font-size: 2.5rem;
    }
    .result-grid {
        gap: 0.5rem;
        margin: 1rem 0;
    }
    .result-detail-panel {
        padding: 1rem;
        min-height: 150px;
    }
    .quiz-header {
        margin-bottom: 1rem;
    }
}

@media (max-width: 480px) {
    .glass-card {
        padding: 1.5rem;
    }
    .result-grid {
        grid-template-columns: repeat(4, 1fr); /* 4列に変更 */
    }
}
