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

html {
    height: auto;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background-attachment: fixed;
    min-height: 100vh;
    height: auto;
    padding: 20px;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    position: relative;
}

.container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding-top: 20px;
    padding-bottom: 40px;
}

header {
    text-align: center;
    color: white;
    margin-bottom: 30px;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

.version {
    font-size: 0.8rem;
    opacity: 0.6;
    margin-top: 5px;
}

.screen {
    background: white;
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    animation: fadeIn 0.5s ease;
    animation-fill-mode: forwards;
    position: relative;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

.hidden {
    display: none !important;
}

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

.welcome {
    text-align: center;
}

.welcome h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 2rem;
}

.welcome p {
    color: #666;
    margin-bottom: 30px;
    font-size: 1.1rem;
}

.user-email {
    color: #667eea;
    font-weight: 600;
}

.login-status {
    margin-top: 20px;
    font-size: 1rem;
}

#googleSignInBtn {
    margin: 20px auto;
    display: flex;
    justify-content: center;
}

.welcome label {
    display: block;
    margin-bottom: 10px;
    font-size: 1.1rem;
    color: #333;
}

.welcome select {
    width: 200px;
    padding: 12px;
    font-size: 1.1rem;
    border: 2px solid #667eea;
    border-radius: 10px;
    margin-bottom: 30px;
    cursor: pointer;
    background: white;
}

.btn-primary, .btn-secondary {
    padding: 15px 40px;
    font-size: 1.2rem;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

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

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: #f0f0f0;
    color: #333;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e0e0e0;
    border-radius: 10px;
    margin-bottom: 20px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transition: width 0.3s ease;
    width: 0%;
}

.question-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

#questionNumber {
    font-size: 1.1rem;
    color: #667eea;
    font-weight: 600;
}

.question-card {
    margin-bottom: 30px;
}

.question-card h2 {
    color: #333;
    font-size: 2rem;
    margin-bottom: 30px;
    text-align: center;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.answer-choices {
    display: grid;
    grid-template-columns: repeat(4, 190px);
    grid-template-rows: repeat(4, auto);
    gap: 12px;
    margin-top: 30px;
    padding-left: 0;
    justify-content: center;
}

/* 1段目: -1(2), 0(7), 1(12), なし(14) */
.answer-choices .choice-btn:nth-child(2) { grid-row: 1; grid-column: 1; }
.answer-choices .choice-btn:nth-child(7) { grid-row: 1; grid-column: 2; }
.answer-choices .choice-btn:nth-child(12) { grid-row: 1; grid-column: 3; }
.answer-choices .choice-btn:nth-child(14) { grid-row: 1; grid-column: 4; }

/* 2段目: -√3(1), -√3/3(6), √3/3(8), √3(13) */
.answer-choices .choice-btn:nth-child(1) { grid-row: 2; grid-column: 1; }
.answer-choices .choice-btn:nth-child(6) { grid-row: 2; grid-column: 2; }
.answer-choices .choice-btn:nth-child(8) { grid-row: 2; grid-column: 3; }
.answer-choices .choice-btn:nth-child(13) { grid-row: 2; grid-column: 4; }

/* 3段目: -√3/2(3), -1/2(5), 1/2(9), √3/2(11) */
.answer-choices .choice-btn:nth-child(3) { grid-row: 3; grid-column: 1; }
.answer-choices .choice-btn:nth-child(5) { grid-row: 3; grid-column: 2; }
.answer-choices .choice-btn:nth-child(9) { grid-row: 3; grid-column: 3; }
.answer-choices .choice-btn:nth-child(11) { grid-row: 3; grid-column: 4; }

/* 4段目: -√2/2(4), √2/2(10) - 位置1.5, 3.5（position: relativeで0.5個分右にずらす） */
.answer-choices .choice-btn:nth-child(4) {
    grid-row: 4;
    grid-column: 1;
    position: relative;
    left: 101px;
}
.answer-choices .choice-btn:nth-child(10) {
    grid-row: 4;
    grid-column: 3;
    position: relative;
    left: 101px;
}

.choice-btn {
    padding: 15px 10px;
    font-size: 1.1rem;
    border: 2px solid #ddd;
    border-radius: 10px;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    color: #333;
    width: 190px !important;
    min-width: 190px !important;
    max-width: 190px !important;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box !important;
    flex-shrink: 0 !important;
    overflow: hidden;
}

/* KaTeXでレンダリングされた要素も幅を固定 */
.choice-btn .katex {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.choice-btn:hover {
    background: #f8f9fa;
    border-color: #667eea;
    transform: translateY(-2px);
}

.choice-btn:active {
    transform: translateY(0);
}

.choice-btn.selected {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
}

.choice-btn.correct {
    background: #28a745;
    color: white;
    border-color: #28a745;
}

.choice-btn.incorrect {
    background: #dc3545;
    color: white;
    border-color: #dc3545;
}

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

.button-group {
    text-align: center;
}

.feedback {
    margin-top: 20px;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
}

.feedback.correct {
    background: #d4edda;
    border: 2px solid #28a745;
}

.feedback.incorrect {
    background: #f8d7da;
    border: 2px solid #dc3545;
}

.feedback-content p {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: #333;
}

#feedbackText {
    font-weight: 600;
    font-size: 1.4rem;
}

.result-card {
    text-align: center;
}

.result-card h2 {
    color: #333;
    font-size: 2.5rem;
    margin-bottom: 30px;
}

.score-display {
    margin: 40px 0;
}

.score-circle {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto 20px;
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}

.score-circle span {
    color: white;
    font-size: 3rem;
    font-weight: 700;
}

.score-percentage {
    font-size: 2rem;
    color: #667eea;
    font-weight: 600;
}

/* 送信状態表示のスタイル */
.send-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 15px 25px;
    border-radius: 10px;
    margin: 20px auto;
    max-width: 400px;
    font-size: 1.1rem;
    font-weight: 600;
    transition: all 0.3s ease;
}

.send-status.sending {
    background: #e3f2fd;
    border: 2px solid #2196f3;
    color: #1976d2;
}

.send-status.retrying {
    background: #fff3e0;
    border: 2px solid #ff9800;
    color: #f57c00;
}

.send-status.success {
    background: #e8f5e9;
    border: 2px solid #4caf50;
    color: #2e7d32;
}

.send-status.failed {
    background: #ffebee;
    border: 2px solid #f44336;
    color: #c62828;
}

#sendStatusIcon {
    font-size: 1.5rem;
}

/* 手動再送信ボタンのスタイル */
.btn-manual-retry {
    padding: 12px 30px;
    font-size: 1.1rem;
    border: 2px solid #ff6b6b;
    border-radius: 10px;
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    margin: 15px auto;
    display: block;
}

.btn-manual-retry:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(255, 107, 107, 0.4);
}

.btn-manual-retry:active {
    transform: translateY(0);
}

.result-details {
    margin: 30px 0;
    text-align: left;
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
}

.result-item {
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 8px;
    border-left: 4px solid #ddd;
}

.result-item.correct {
    background: #d4edda;
    border-left-color: #28a745;
}

.result-item.incorrect {
    background: #f8d7da;
    border-left-color: #dc3545;
}

.result-item-question {
    font-weight: 600;
    margin-bottom: 5px;
    color: #333;
}

.result-item-answer {
    font-size: 1rem;
    color: #333;
}

.result-item-answer strong {
    font-weight: 700;
    color: #000;
}

.result-item-answer .user-wrong {
    color: #dc3545;
}

.math-inline {
    display: inline-block;
    vertical-align: middle;
}

/* 説明画面のスタイル */
.instruction {
    text-align: left;
    max-width: 700px;
    margin: 0 auto;
    min-height: calc(100vh - 40px);
    position: relative;
}

.instruction h2 {
    color: #333;
    font-size: 2rem;
    margin-bottom: 30px;
    text-align: center;
}

.instruction-content {
    background: #f8f9fa;
    padding: 30px;
    border-radius: 15px;
    margin-bottom: 30px;
}

.instruction-content h3 {
    color: #667eea;
    font-size: 1.3rem;
    margin-bottom: 15px;
    margin-top: 25px;
}

.instruction-content h3:first-child {
    margin-top: 0;
}

.instruction-content p {
    color: #333;
    font-size: 1.1rem;
    line-height: 1.8;
    margin-bottom: 15px;
}

.instruction-content strong {
    color: #667eea;
    font-weight: 700;
}

/* 説明画面の選択肢（無効化） */
.example-answer-choices .choice-btn {
    cursor: default !important;
    opacity: 0.8;
}

.example-answer-choices .choice-btn:hover {
    transform: none !important;
    background: white !important;
    border-color: #ddd !important;
}

#angleExampleChoices {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.example-chip {
    padding: 8px 16px;
    background: white;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    color: #333;
}

.example-submit {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    border: 2px solid #28a745;
    cursor: not-allowed;
    opacity: 0.7;
    margin-top: 5px;
    padding: 12px 16px;
}

.note {
    color: #666 !important;
    font-size: 0.95rem !important;
    font-style: italic;
    margin-top: 10px;
}

.warning {
    color: #d63031 !important;
    font-size: 1.05rem !important;
    font-weight: 600 !important;
    background: #fff3cd;
    border-left: 4px solid #ff6b6b;
    padding: 15px 20px;
    border-radius: 8px;
    margin: 10px 0 0 0;
}

.instruction .btn-primary,
.instruction .btn-secondary {
    margin: 0 10px;
}

/* メニュー画面のスタイル */
.menu-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-menu {
    padding: 30px 40px;
    border: 3px solid #667eea;
    border-radius: 15px;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 250px;
}

.btn-menu:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4);
}

.btn-menu:hover .menu-btn-title,
.btn-menu:hover .menu-btn-desc {
    color: white;
}

.menu-btn-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #333;
    margin-bottom: 10px;
}

.menu-btn-desc {
    font-size: 1rem;
    color: #666;
}

/* 角度選択のスタイル */
.angle-choices {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    max-width: 500px;
    margin: 0 auto;
}

.angle-btn {
    padding: 20px;
    font-size: 1.3rem;
    border: 2px solid #ddd;
    border-radius: 10px;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    color: #333;
}

.angle-btn:hover {
    background: #f8f9fa;
    border-color: #667eea;
    transform: translateY(-2px);
}

.angle-btn.selected {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
}

.btn-submit {
    grid-column: 1 / -1;
    padding: 20px;
    font-size: 1.4rem;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 700;
    margin-top: 10px;
}

.btn-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(40, 167, 69, 0.4);
}

.btn-submit:active {
    transform: translateY(0);
}

.btn-submit:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

/* iPad向けレスポンシブ対応 */
@media (max-width: 1024px) {
    header h1 {
        font-size: 2rem;
    }

    .screen {
        padding: 30px;
    }

    .question-card h2 {
        font-size: 1.8rem;
    }

    .answer-choices {
        gap: 10px;
        grid-template-columns: repeat(4, 165px);
    }

    .choice-btn {
        width: 165px !important;
        min-width: 165px !important;
        max-width: 165px !important;
    }

    .answer-choices .choice-btn:nth-child(4) { left: 87px; }
    .answer-choices .choice-btn:nth-child(10) { left: 87px; }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    .screen {
        padding: 20px;
    }

    .question-card h2 {
        font-size: 1.5rem;
    }

    .btn-primary, .btn-secondary {
        padding: 12px 30px;
        font-size: 1.1rem;
    }

    .answer-choices {
        gap: 8px;
        grid-template-columns: repeat(4, 1fr);
    }

    .choice-btn {
        padding: 12px 8px;
        font-size: 0.9rem;
        width: auto !important;
        min-width: 100px !important;
        max-width: none !important;
        height: 60px;
    }

    .answer-choices .choice-btn:nth-child(4) { left: 50%; }
    .answer-choices .choice-btn:nth-child(10) { left: 50%; }
}
