/* --- CSS変数定義 (カラーテーマ) --- */
:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --background-color: #f8f9fa;
    --surface-color: #ffffff;
    --text-color: #212529;
    --muted-text-color: #6c757d;
    --border-color: #dee2e6;
    --correct-color: #28a745;
    --incorrect-color: #dc3545;
    --warning-color-bg: #fff3cd;
    --warning-color-text: #856404;
    --warning-color-border: #ffeeba;
    --font-family: 'Noto Sans JP', sans-serif;
}

/* --- 基本スタイルとリセット --- */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.7;
    margin: 0;
}

/* --- ヘッダーとフッター --- */
.site-header {
    background: var(--primary-gradient);
    color: white;
    padding: 1em 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.site-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1em;
    max-width: 1200px;
}
.site-header h1 {
    margin: 0;
    font-size: 1.5rem;
    border: none;
}
.site-header a {
    color: white;
    text-decoration: none;
    transition: opacity 0.2s;
}
.site-header a:hover {
    opacity: 0.8;
}
.site-header nav {
    display: flex;
    align-items: center;
    gap: 1.5em;
}
span.user-display-name {
    align-self: center;
    font-weight: 700;
    color: white;
}
.button-signup {
    background: none;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.8);
    padding: 8px 16px;
    font-size: 0.9em;
    border-radius: 50px;
    text-decoration: none;
}
.button-signup:hover {
    background: rgba(255, 255, 255, 0.1);
}
.site-footer {
    text-align: center;
    padding: 2em 0;
    margin-top: 4em;
    color: var(--muted-text-color);
    font-size: 0.9em;
}

/* --- メインコンテンツとコンテナ --- */
main.container {
    background-color: var(--surface-color);
    padding: 2.5em;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    margin: 2em auto;
    max-width: 800px;
}
h2, h3 {
    color: var(--text-color);
    border-bottom: 2px solid #ecf0f1;
    padding-bottom: 0.5em;
    margin-top: 0;
}
h3 {
    font-size: 1.2rem;
    margin-top: 1.5em;
}
.muted-text {
    color: var(--muted-text-color);
    font-size: 0.9em;
}

/* --- フォーム関連 --- */
.form-group { margin-bottom: 1.5em; }
.form-group label {
    display: block;
    margin-bottom: 0.5em;
    font-weight: 700;
}
.form-actions { display: flex; flex-direction: column; gap: 1em; }
input[type="file"], input[type="text"], input[type="password"], input[type="number"], input[type="email"], select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    font-family: var(--font-family);
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fff;
}
input[type="file"] { padding: 8px; }
input:focus, select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}
input[type="number"] { width: auto; min-width: 80px; }

/* ハンドル名入力欄 */
.handle-input-group {
    display: flex;
    align-items: center;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.handle-input-group:focus-within {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}
.handle-prefix {
    padding: 12px;
    background-color: #f8f9fa;
    border-right: 1px solid var(--border-color);
    color: var(--muted-text-color);
}
.handle-input-group input {
    border: none;
    margin-bottom: 0;
}
.handle-input-group input:focus {
    box-shadow: none;
}

/* --- ボタン --- */
button, .button-small {
    display: inline-block;
    background: var(--primary-gradient);
    color: white;
    padding: 14px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 700;
    width: 100%;
    text-align: center;
    text-decoration: none;
    transition: transform 0.2s, box-shadow 0.2s;
}
button:hover, .button-small:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}
button:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}
.cancel-button { background: var(--muted-text-color); }
.cancel-button:hover { background: #95a5a6; }
.button-secondary {
    background: var(--surface-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}
.button-secondary:hover {
    background: #f8f9fa;
    transform: none;
    box-shadow: none;
}
.link-button {
    background: none; border: none; padding: 0; margin: 0;
    color: #0056b3; text-decoration: underline; cursor: pointer;
    font-size: inherit; font-family: inherit;
}
.link-button:hover { color: #003d80; }

/* --- ローダー --- */
.loader {
    display: flex;
    align-items: center;
    gap: 0.8em;
    justify-content: center;
    margin: 30px auto;
}
.spinner {
    border: 4px solid #e2e8f0;
    border-top: 4px solid #3182ce;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    animation: spin 0.7s linear infinite;
    margin-right: 0.4em;
}
@keyframes spin {
  0% { transform: rotate(0deg);}
  100% { transform: rotate(360deg);}
}
.loading-text {
    font-size: 1em;
    color: #3182ce;
}

/* --- 認証ページ専用 --- */
.auth-container {
    max-width: 370px;
    margin: 2.5em auto;
    padding: 2.5em 2em 2em 2em;
    background: #f9fafb;
    border-radius: 12px;
    box-shadow: 0 4px 18px 0 #e5e9f2;
}
.auth-container h2 {
    margin-bottom: 0.7em;
    font-size: 1.35em;
    text-align: center;
}
.auth-link {
    text-align: center;
    margin-top: 1em;
    font-size: 0.98em;
}
.auth-link a {
    color: #3b82f6;
    text-decoration: underline;
}
.auth-link a:hover {
    color: #1e40af;
}
.error-text {
    color: var(--incorrect-color);
    font-size: 1em;
    text-align: center;
    margin-bottom: 0.6em;
}
.success-text {
    color: var(--correct-color);
    font-size: 1em;
    text-align: center;
    margin-bottom: 0.6em;
}

/* ヘッダー用auth-status */
#auth-status {
    display: flex;
    align-items: center;
    gap: 1em;
    justify-content: flex-end;
    margin-bottom: 1em;
    font-size: 1em;
}
.user-display-name {
    font-weight: bold;
    color: #374151;
}
.alert-warning {
    background: #fffbe6;
    color: #b7791f;
    border: 1px solid #faf089;
    border-radius: 7px;
    padding: 0.8em 1em;
    margin-bottom: 1em;
    font-size: 0.98em;
}
.site-footer {
    background: #f3f6fa;
    padding: 1.6em 0 1.1em 0;
    margin-top: 2em;
    text-align: center;
    font-size: 0.98em;
    color: #555;
}

/* --- 通知バー --- */
.alert {
    padding: 1em;
    margin-bottom: 1.5em;
    border-radius: 8px;
    border: 1px solid transparent;
}
.alert-warning {
    color: var(--warning-color-text);
    background-color: var(--warning-color-bg);
    border-color: var(--warning-color-border);
}
.inline-form { display: inline; margin-left: 0.5em; }

/* --- クイズと結果表示 --- */
.source-text-accordion { border: 1px solid var(--border-color); border-radius: 8px; margin-bottom: 2em; }
.source-text-accordion summary { padding: 1em; font-weight: 700; cursor: pointer; outline: none; transition: background-color 0.2s; }
.source-text-accordion summary:hover { background-color: #f8f9fa; }
.source-text-accordion[open] summary { border-bottom: 1px solid var(--border-color); }
.source-text-accordion .text-container { padding: 1em; }
.source-text-accordion h4 { font-size: 1rem; border: none; margin-bottom: 0.5em; margin-top: 0; }
.text-container { display: flex; gap: 20px; }
.text-box { flex: 1; }
.ocr-text { background-color: #f8f9fa; padding: 1em; border: 1px solid var(--border-color); border-radius: 8px; white-space: pre-wrap; word-wrap: break-word; max-height: 250px; overflow-y: auto; font-size: 0.9em; }
.ocr-text.corrected { background-color: #e9f5ff; border-color: #a3d3ff; }

.problem, .problem-result { background-color: var(--surface-color); border: 1px solid var(--border-color); padding: 1.5em; margin-bottom: 1em; border-radius: 8px; }
.score-summary { font-size: 1.5rem; font-weight: 700; text-align: center; padding: 1em; margin-bottom: 1.5em; background-color: #f8f9fa; border-radius: 8px; }
.question { font-weight: 700; margin-top: 0; }
.problem-result { border-left-width: 6px; }
.problem-result.correct { border-left-color: var(--correct-color); }
.problem-result.incorrect { border-left-color: var(--incorrect-color); }
.judgement { font-weight: 700; font-size: 1.2rem; }
.correct .judgement { color: var(--correct-color); }
.incorrect .judgement { color: var(--incorrect-color); }
.feedback { margin-top: 1em; padding: 0.8em; background-color: #e9ecef; border-radius: 8px; font-size: 0.95em; border-left: 4px solid var(--muted-text-color); }
.feedback strong { color: #495057; }
.explanation { margin-top: 1em; padding: 1em; background-color: #f8f9fa; border-top: 1px solid var(--border-color); border-radius: 0 0 8px 8px; font-size: 0.95em; }
.explanation strong { color: #667eea; }

/* --- アカウントと履歴ページ --- */
.navigation-links { margin-top: 2em; display: flex; flex-wrap: wrap; gap: 1em; justify-content: center; }
.navigation-links a { background: var(--surface-color); color: #667eea; border: 1px solid #667eea; padding: 10px 20px; border-radius: 8px; font-weight: 700; transition: background-color 0.2s, color 0.2s; }
.navigation-links a:hover { background-color: #667eea; color: white; text-decoration: none; }
.history-list { list-style-type: none; padding: 0; }
.history-list li { background: var(--surface-color); border: 1px solid var(--border-color); margin-bottom: 1em; padding: 1em 1.5em; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1em; }
.history-info { display: flex; flex-direction: column; }
.history-title { font-weight: 700; font-size: 1.1em; }
.history-date { font-size: 0.9em; color: var(--muted-text-color); }
.history-actions { display: flex; gap: 10px; }
.button-small { padding: 8px 16px; font-size: 0.9rem; width: auto; }
.button-small.retry { background: #17a2b8; }
.button-small.retry:hover { background: #138496; }
.account-section { margin-top: 2em; padding-top: 1.5em; border-top: 1px solid var(--border-color); }
.account-section .sub-form { margin-top: 1.5em; padding-top: 1.5em; border-top: 1px dashed var(--border-color); }
.status-badge { display: inline-block; padding: 0.2em 0.6em; font-size: 0.8em; font-weight: 700; border-radius: 50px; margin-left: 0.5em; vertical-align: middle; }
.status-badge.success { background-color: #e9f7ef; color: #155724; }
.status-badge.error { background-color: #f8d7da; color: #721c24; }

/* --- レスポンシブ対応 --- */
@media (max-width: 768px) {
    main.container { padding: 1.5em; margin-top: 1em; margin-bottom: 1em; }
    .site-header .container { flex-direction: column; gap: 0.5em; }
    .form-actions { flex-direction: column; }
    .text-container { flex-direction: column; }
    .history-list li { flex-direction: column; align-items: flex-start; }
    .history-actions { margin-top: 1em; width: 100%; }
    .history-actions a { flex-grow: 1; text-align: center; }
}

/* --- クイズ編集画面の選択肢・問題編集用CSS --- */
.problem-edit-box {
    background: #f9fafd;
    border: 1px solid #dadada;
    border-radius: 8px;
    padding: 1em 1.5em;
    margin-bottom: 1.5em;
    box-shadow: 0 1px 6px 0 #e3e9f1;
}
.question-edit {
    width: 100%;
    font-size: 1.1em;
    border-radius: 6px;
    border: 1px solid #ccc;
    margin-bottom: 0.7em;
    padding: 0.6em;
}
.choices-edit-section label {
    font-weight: bold;
    margin-right: 0.5em;
}
.choice-edit {
    display: flex;
    align-items: center;
    margin-bottom: 0.5em;
    gap: 0.3em;
}
.choice-input {
    flex: 1;
    padding: 0.5em;
    border: 1px solid #aaa;
    border-radius: 6px;
    margin-right: 0.5em;
    background: #f8f8ff;
    font-size: 1em;
}
.choice-delete, .choice-undo {
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 0.25em 1em;
    cursor: pointer;
    font-size: 0.95em;
    margin-right: 0.3em;
    transition: background 0.2s;
}
.choice-undo {
    background: #27ae60;
}
.choice-delete:hover {
    background: #b91c1c;
}
.choice-undo:hover {
    background: #219150;
}
.choice-unsaved {
    opacity: 0.5;
    text-decoration: line-through;
}
.choice-add-btn {
    background: #667eea;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.3em 1.2em;
    margin: 0.6em 0 1em 0;
    font-weight: bold;
    cursor: pointer;
    font-size: 1em;
    transition: background 0.2s;
}
.choice-add-btn:hover {
    background: #5a67d8;
}
.answers-section label {
    font-weight: bold;
}
.answers-input {
    width: 100%;
    margin: 0.3em 0 0.8em 0;
    padding: 0.5em;
    border-radius: 5px;
    border: 1px solid #ccc;
}
.save-btn {
    background: #667eea;
    border: none;
    color: white;
    padding: 0.8em 2.5em;
    border-radius: 7px;
    font-weight: bold;
    font-size: 1.15em;
    cursor: pointer;
    margin-right: 1em;
}
.button-secondary {
    background: #eee;
    color: #333;
    border: none;
    border-radius: 7px;
    font-size: 1.05em;
    padding: 0.7em 1.6em;
    cursor: pointer;
    margin-right: 1em;
}
.save-btn:hover {
    background: #5a67d8;
}
.button-secondary:hover {
    background: #e2e8f0;
}
hr {
    margin: 1.5em 0;
    border: none;
    border-top: 1px solid #e2e8f0;
}