/* 全体の基本設定 */
body {
    font-family: "Helvetica Neue", Arial, "Hiragino Sans", "Noto Sans JP", sans-serif;
    background-color: #f5f7fa;
    color: #333;
    margin: 0;
    padding: 0;
    line-height: 1.6;
}

/* コンテナ */
.container {
    max-width: 840px;
    margin: 26px auto;
    padding: 20px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
    box-sizing: border-box;
}
@media (max-width: 860px) {
    .container {
        margin: 10px;
    }
}

/* タイトル */
h1 {
    font-size: 1.8rem;
    text-align: center;
    margin-bottom: 20px;
    color: #2c3e50;
}

/* 問題表示 */
.question {
    font-size: 1.2rem;
    margin-bottom: 15px;
    background: #eef2f7;
    padding: 12px;
    border-radius: 8px;
}

/* 問題オプション */
.options {
    margin: 15px 0;
    padding: 10px;
    background: #f0f4f8;
    border-radius: 8px;
    font-size: 0.95rem;
}
.options label {
    display: inline-block;
    margin: 6px 0;
}

/* テキストエリア */
.answer-wrapper {
  position: relative;   /* ボタンを相対配置の基準にする */
  display: block;
}

textarea#answer {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    font-size: 1rem;
    border: 1px solid #ccc;
    border-radius: 8px;
    resize: vertical;
    box-sizing: border-box;
    transition: border-color 0.3s;
}

textarea#answer:focus {
    border-color: #4a90e2;
    outline: none;
}

#answer-count {
    text-align: right;
    margin-top: -4px;
    margin-bottom: -4px;
    margin-right: 4px;
    font-size: 14px;
    color: #666;
}

/* ボタン共通 */
button {
    display: inline-block;
    margin: 6px 4px;
    padding: 10px 18px;
    font-size: 1rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

/* ボタンの色分け */
#speak-btn,
.speak-btn {
    background: #3498db;
    color: #fff;
    margin: 0;
    margin-left: 6px;
    padding: 5px 10px;
    font-size: 14px;
    width: auto !important;
}
#voice-btn {
    position: absolute;
    bottom: 14px;
    right: 8px;
    background: #27ae60;
    color: #fff;
    margin: 0;
    margin-left: 6px;
    padding: 5px 10px;
    font-size: 14px;
    width: auto !important;
}
#check-btn {
    background: #e74c3c;
    color: #fff;
}
#hint-btn {
    background: #f1c40f;
    color: #333;
    margin: 0;
}
#next-btn {
    background: #9b59b6;
    color: #fff;
}

/* ボタンのホバー効果 */
button:hover {
    opacity: 0.9;
    transform: translateY(-2px);
}
button:active {
    transform: translateY(0);
}

/* ボタンの無効状態 */
button:disabled {
    pointer-events: none;
    opacity: 0.7;
}

/* ボタンの処理中状態 */
button.loading {
    position: relative;
    padding-right: 35px;
}

/* スピナー */
button.loading::after {
    content: "";
    position: absolute;
    right: 10px;
    top: 50%;
    width: 16px;
    height: 16px;
    border: 2px solid #fff;
    border-top: 2px solid transparent;
    border-radius: 50%;
    transform: translateY(-50%);
    animation: spin 0.8s linear infinite;
}

/* スピンアニメーション */
@keyframes spin {
    0% { transform: translateY(-50%) rotate(0deg); }
    100% { transform: translateY(-50%) rotate(360deg); }
}

/* 結果表示 */
#check-result {
    margin-top: 20px;
    font-size: 1.1rem;
    padding: 12px;
    border-radius: 8px;
}

/* 結果が非表示状態のとき */
#check-result:empty {
    display: none;
}

/* 正解/不正解の色 */
#check-result.correct {
    background: #dff0d8;
    color: #3c763d;
}
#check-result.incorrect {
    background: #f2dede;
    color: #a94442;
}

/* ヒント表示エリア */
.hint-container {
    margin-top: 15px;
    padding: 12px;
    border-radius: 8px;
    font-size: 1rem;
    background: #fcf8e3;  /* 薄い黄色背景で「ヒント感」 */
    color: #8a6d3b;       /* 茶色で読みやすく */
    border: 1px solid #faebcc;
}
#hint {
    margin-top: 12px;
}

/* ヒントが非表示状態のとき */
#hint:empty {
    display: none;
}

/* 単語ヒント */
.hint-words > div {
    border-bottom: 1px solid gray;
    margin-bottom: 12px;
    padding-left: 8px;
    padding-right: 8px;
}
.hint-words > div:last-child {
    border-bottom: none;
    margin-bottom: 0;
}
.hint-word {
    display: inline;
    font-weight: bold;
    font-size: large;
}
.hint-romaji,
.hint-pronunciation {
    margin-left: 0.5em;
    display: inline;
    font-size: large;
}
.hint-meaning {
    margin-left: 0.5em;
    display: inline;
    font-weight: bold;
    font-size: large;
}
.hint-model_answer_group {
    margin: 1em 0;
    padding: 0.5em;
    border: 1px solid gray;
    border-radius: 0.5em;
}
.hint-model_answer_group > div {
    display: block;
    font-size: inherit;
}

/* 質問フォーム */
.ask-form {
    margin-top: 30px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 1px solid #ddd;
}

.ask-form h2 {
    font-size: 1.2rem;
    margin-bottom: 10px;
    color: #2c3e50;
}

/* 質問入力欄 */
#ask-form-text {
    margin-bottom: 10px;
    width: 100%;
    padding: 10px;
    font-size: 1rem;
    border: 1px solid #ccc;
    border-radius: 8px;
    box-sizing: border-box;
}

/* 送信ボタン */
#send-ask-btn {
    background: #2980b9;
    color: #fff;
    font-size: 1rem;
}

#ask-voice-btn {
    background: #27ae60;
    color: #fff;
}

/* サーバーからの返信表示エリア */
#ask-response {
    margin-bottom: 10px;
    padding: 10px;
    font-size: 0.95rem;
    border-radius: 6px;
    background: #eef6fc;
    color: #2c3e50;
}
#ask-response:empty {
    display: none;
}

.ask-exchange {
    margin-bottom: 12px;
    padding: 10px;
    border-radius: 8px;
    background: #f9f9f9;
    border: 1px solid #ddd;
}
.ask-exchange .ask-question {
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 6px;
}
.ask-exchange .ask-answer {
    color: #333;
}
.ask-exchange.ask-error-exchange {
    background: #fcebea;
    border: 1px solid #f5c6cb;
    color: #a94442;
}
.ask-exchange .ask-answer.ask-loading {
    font-style: italic;
    color: #888;
}

/* レーティング */
.rating {
    text-align: right;
    font-size: small;
}

.rating[data-type="question"] {
    margin-top: -1.5em;
    margin-bottom: -1.5em;
}

.rating button {
    font-size: small;
    padding: 0.5em;
}

/* 評価ボタン */
.rate-btn[data-value="5"] {      /* 良い */
    background-color: #4CAF50;   /* 緑 */
    color: #fff;
}
.rate-btn[data-value="5"]:hover {
    background-color: #45a049;
}

.rate-btn[data-value="0"] {      /* 悪い */
    background-color: #f44336;   /* 赤 */
    color: #fff;
}
.rate-btn[data-value="0"]:hover {
    background-color: #d32f2f;
}

.rate-btn.disabled-gray {
    background-color: #ccc !important;
    color: #666 !important;
    border-color: #aaa !important;
}

#comment-popup {
    width: 300px;
    max-width: 90vw;  /* 画面幅を超えない */
    max-height: 60vh; /* 画面高さを超えない */
    overflow-y: auto; /* 高さ超えたらスクロール */
    position: fixed;
    background: #fff;
    border: 1px solid #ccc;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    z-index: 1000;
    box-sizing: border-box;
}
#comment-popup p {
    font-size: 12px;
    margin-top: 0;
    margin-bottom: 4px;
}
#comment-popup textarea {
    width: 100%;
    box-sizing: border-box;
    overflow-y: hidden;
}
#comment-count {
    margin-top: -6px;
    font-size: 12px;
    color: #666;
    float: right;
}

/* コメントポップアップの送信・キャンセル */
#comment-popup div:has(button) {
    margin-top: 0;
}
#comment-popup button {
    font-size: small;
    padding: 0.5em 1em;
}

#submit-comment {
    background-color: #2196F3;   /* 青 */
    color: #fff;
}
#submit-comment:hover {
    background-color: #1976d2;
}

#cancel-comment {
    background-color: #9E9E9E;   /* グレー */
    color: #fff;
}
#cancel-comment:hover {
    background-color: #757575;
}

/* コース遷移ダイアログ */
#custom-dialog {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.4);
    z-index: 9999;
}
#custom-dialog .dialog-box {
    background: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    width: 300px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
#custom-dialog button {
    margin: 10px;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}
#custom-dialog .next-btn { background: #4CAF50; color: white; }
#custom-dialog .stay-btn { background: #ccc; }

/* コース選択 */
.course-links {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2em;
    font-size: 1rem;
    gap: 10px;
}

.course-link.disabled {
    color: #aaa;
    pointer-events: none;
    text-decoration: line-through;
    cursor: default;
}

.center-course {
    margin: 0 auto;
}

/* 平均点表示 */
.average-score {
    position: absolute;
    top: 10px;
    right: 10px;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 16px;
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 0.5s ease, transform 0.5s ease, background-color 0.4s ease, color 0.4s ease;
}

/* スマホ対応 */
@media (max-width: 600px) {
    .container {
        margin: 10px;
        padding: 15px;
    }
    h1 {
        font-size: 1.5rem;
    }
    button {
        width: 100%;
        margin: 6px 0;
        font-size: 1.1rem;
    }
    textarea#answer {
        min-height: 100px;
        font-size: 1rem;
    }

    button.loading {
        padding-right: 18px;
    }

    .rating button {
        width: auto;
    }

    .average-score {
        position: absolute;
        top: -3px;
        right: -3px;
    }
}
