/* === 基本設定とデザインシステム === */
*, *::before, *::after {
  box-sizing: border-box;
}

:root {
    --primary-color: #4527A0;        /* Main Deep Purple */
    --primary-hover-color: #311B92;   /* Darker Purple on hover */
    --secondary-color: #546E7A;      /* Slate Blue */
    --secondary-hover-color: #455A64; /* Darker Slate Blue on hover */
    --success-color: #26A69A;        /* Teal Green Accent */
    --danger-color: #dc3545;         /* Unchanged Red */
    --light-bg-color: #F6F5FA;       /* Very Light Purple Background */
    --border-color: #dee2e6;
    --text-color: #212529;
    --text-muted-color: #6c757d;
    --font-family-base: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    --border-radius: 0.5rem; /* 角の丸みを少し統一 */
}

body {
    font-family: var(--font-family-base);
    background-color: var(--light-bg-color);
    color: var(--text-color);
    line-height: 1.6;
    margin: 0;
    padding: 1rem;
}

.container {
    background-color: #ffffff;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    max-width: 800px;
    width: 100%;
    margin: 2rem auto;
    box-sizing: border-box;
}

/* PC表示では少し余白を広げる */
@media (min-width: 768px) {
    .container {
        padding: 2.5rem;
    }
}

/* === [追加] カードヘッダーのスタイル === */
.card .card-header {
    background-color: var(--light-bg-color);
    margin: -1.5rem -1.5rem 1rem -1.5rem; /* カードの余白を相殺して幅いっぱいに広げます */
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    border-top-left-radius: var(--border-radius);
    border-top-right-radius: var(--border-radius);
}

/* === ヘッダーのスタイル === */
.page-header {
    background-color: #ffffff;
    padding: 0.75rem 0; /* 左右のパディングを削除 */
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.page-header.sticky {
    position: sticky;
    top: 0;
    z-index: 1000;
    width: 100%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px; /* .container の最大幅に合わせます */
    margin: 0 auto;
    padding: 0 1.5rem; /* コンテナの左右パディングに合わせます */
}

.logo {
    font-family: 'M PLUS Rounded 1c', sans-serif;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
    text-decoration: none;
}

.user-nav {
    display: flex;
    align-items: center;
}

.user-menu {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.username {
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
    color: var(--text-muted-color);
}

.user-buttons {
    display: flex;
    gap: 0.5rem;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.875rem;
    width: auto;
    margin-bottom: 0;
}

/* === タイポグラフィ === */
h1, h2, h3 {
    line-height: 1.3;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    font-weight: 600;
}
h1 { font-size: 2rem; color: var(--primary-color); text-align: center; }
h2 { font-size: 1.5rem; border-bottom: 2px solid var(--border-color); padding-bottom: 0.5rem; }
h3 { font-size: 1.25rem; }
p { margin-bottom: 1rem; }
a { color: var(--primary-color); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === ボタンのスタイル統一 === */
.btn {
    display: block;
    width: 100%;
    padding: 0.8rem 1rem;
    margin-bottom: 0.5rem;
    background-color: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    text-align: center;
}
.btn:hover {
    background-color: var(--primary-hover-color);
    color: #fff;
    text-decoration: none;
    transform: translateY(-2px);
}
.btn-secondary {
    background-color: var(--secondary-color);
}
.btn-secondary:hover {
    background-color: #5a6268;
}
.btn-danger {
    background-color: var(--danger-color);
}
.btn-danger:hover {
    background-color: #c82333;
}
form .btn {
    width: 100%;
    margin-top: 1rem;
}

.btn-centered {
    margin-left: auto;
    margin-right: auto;
    margin-top: 1.5rem;
    max-width: 300px;
}

/* === フォーム要素の統一 === */
.form-group {
    margin-bottom: 1.25rem;
}
.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    box-sizing: border-box;
}
.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    outline: none;
}

/* === Flashメッセージ === */
.flashes {
    list-style: none;
    padding: 0;
    margin: 0 0 1.5rem 0;
}
.flashes li {
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: var(--border-radius);
    font-weight: 500;
    border: 1px solid transparent;
}
.flashes li.success {
    background-color: #E0F2F1; /* Light Teal */
    color: #004D40; /* Dark Teal Text */
    border-color: #B2DFDB; /* Lighter Teal */
}
.flashes li.error {
    background-color: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}

/* === テーブルのスタイル === */
.table-container {
    overflow-x: auto;
    width: 100%;
}
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}
th, td {
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    text-align: left;
    vertical-align: middle;
}
th {
    background-color: var(--light-bg-color);
    font-weight: 600;
}
tbody tr:nth-child(odd) {
    background-color: #fdfdfd;
}

/* === クイズ画面の選択肢スタイル === */
.choices-container label {
    display: block;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}
.choices-container label:hover {
    background-color: var(--light-bg-color);
    border-color: var(--primary-color);
}
.choices-container input[type="radio"] {
    margin-right: 0.75rem;
}

/* === 結果表示スタイル === */
.result-item {
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    border-left: 5px solid;
}
.result-item.correct {
    background-color: #FFF8E1; /* Light Amber */
    border-color: var(--success-color);
}
.result-item.incorrect {
    background-color: #fcebeb;
    border-color: var(--danger-color);
}
/* === 管理者ページ専用スタイル === */
.admin-nav {
    background-color: #343a40;
    color: #fff;
    padding: 0.75rem 1.5rem;
    margin-bottom: 1.5rem;
    width: 100%;
    box-sizing: border-box;
}

.admin-nav-links {
    display: flex;
    justify-content: flex-start; /* flex-start に変更 */
    gap: 1.5rem;
    max-width: 800px;
    margin: 0 auto;

    overflow-x: auto; /* 横方向のスクロールを許可 */
    white-space: nowrap; /* テキストの折り返しを禁止 */
    padding-bottom: 5px; /* スクロールバーのための余白 */
    -webkit-overflow-scrolling: touch; /* iOSでのスムーズなスクロール */
}

.admin-nav a {
    color: #fff;
    text-decoration: none;
    padding: 0.5rem 0;
    border-bottom: 2px solid transparent;
    transition: border-bottom-color 0.2s;
}

.admin-nav a:hover, .admin-nav a.active {
    border-bottom-color: var(--primary-color);
}

/* === モーダル (ポップアップ) のスタイル === */
.modal {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
    padding-top: 60px;
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 2rem;
    border: 1px solid #888;
    width: 90%;
    max-width: 600px;
    border-radius: var(--border-radius);
    position: relative;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.close-button {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}
/* === ドロップダウンメニューのスタイル === */
.dropdown {
    position: relative;
    display: inline-block;
}

.user-icon-button {
    background: none;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    padding: 0;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    background-color: #ffffff;
    min-width: 200px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.dropdown-content a {
    color: var(--text-color);
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    font-size: 0.95rem;
}

.dropdown-content a:hover {
    background-color: #f1f1f1;
}

.dropdown-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.dropdown-header .greeting {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted-color);
}

.dropdown-header .username-display {
    display: block;
    font-weight: bold;
    font-size: 1rem;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === 苦手リストのカードスタイル === */
.weakness-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.weakness-card {
    background-color: #fff;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.weakness-card .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
}

.weakness-card .lesson-tag {
    background-color: var(--primary-color);
    color: #fff;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.8rem;
    font-weight: bold;
}

.weakness-card .card-content .label {
    font-size: 0.8rem;
    color: var(--text-muted-color);
    margin-bottom: 0.25rem;
}

.weakness-card .card-content .question-text,
.weakness-card .card-content .answer-text {
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

.weakness-card .card-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.weakness-card .card-actions {
    display: flex;
    gap: 0.5rem;
}

.icon-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    font-size: 1.2rem;
    color: var(--text-muted-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.icon-button:hover {
    background-color: #f0f0f0;
}

.memo-section {
    display: none;
    margin-top: 1rem;
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
}

.memo-section textarea {
    width: 100%;
    min-height: 80px;
    margin-bottom: 0.5rem;
}

/* === [追加] SVGアイコンの基本スタイル === */
.icon {
    display: inline-block;
    width: 1.2rem;
    height: 1.2rem;
    stroke-width: 2;
    stroke: currentColor;
    fill: none;
    vertical-align: middle;
}

.user-icon-button .icon {
    width: 2rem;
    height: 2rem;
}

.speak-button {
    margin-left: 0.5rem;
    cursor: pointer;
}

/* === テーブルのレスポンシブ対応 === */
@media screen and (max-width: 768px) {
    .table-container {
        border: none;
    }
    table {
        border: 0;
    }
    table thead {
        display: none;
    }
    table tr {
        display: block;
        margin-bottom: 1em;
        border-bottom: 2px solid var(--primary-color);
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right; /* テキストを右寄せに */
        border-bottom: 1px dotted #ccc;
    }
    table td::before {
        content: attr(data-label);
        /* float: left; を削除 */
        font-weight: bold;
        text-transform: uppercase;
        text-align: left; /* ラベル自体は左寄せに */
        margin-right: 1rem; /* ラベルとコンテンツの間に余白を追加 */
    }
    table td:last-child {
        border-bottom: 0;
    }
    .user-actions-container {
        width: 100% !important;
        margin: 0.5rem 0;
    }
}

/* === ダッシュボードのレスポンシブレイアウト === */

.dashboard-grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: 1fr;
}

.tab-content canvas {
    max-width: 100%;
    height: auto;
}

/* スマホの場合 (767px以下) */
@media (max-width: 767px) {
    .dashboard-grid {
        grid-template-columns: 1fr; /* 1列表示 */
    }
}

/* タブレットの場合 (768px以上) */
@media (min-width: 768px) and (max-width: 1199px) {
    .dashboard-grid {
        grid-template-columns: 1fr 1fr; /* 2列表示 */
    }
}

/* PCなど大画面の場合 (1200px以上) */
@media (min-width: 1200px) {
    .container {
        max-width: 1400px; /* ページ全体の最大幅を広げる */
    }
    .dashboard-grid {
        grid-template-columns: 1fr 1fr 1fr; /* 3列表示 */
    }
}

/* === ページネーションのスタイル === */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 2rem;
}

.pagination .page-info {
    font-size: 1rem;
    font-weight: bold;
    color: var(--text-muted-color);
}

.pagination .btn {
    width: auto;
    padding: 0.5rem 1rem;
}

/* === ダッシュボード編集モーダル用のスタイル === */
#card-list-container {
    margin-top: 1.5rem;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: var(--light-bg-color);
}

.card-list-item {
    background-color: #fff;
    padding: 0.75rem 1.25rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: grab;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.card-list-item:last-child {
    margin-bottom: 0;
}

.card-list-item:active {
    cursor: grabbing;
    background-color: #f0f0f0;
}

.card-list-item .card-name {
    font-weight: bold;
}

/* SortableJSがドラッグ中に追加するゴースト要素のスタイル */
.sortable-ghost {
    opacity: 0.4;
    background: #c8ebfb;
}

/*
 * ページ内リンクで移動した際に、
 * 固定ヘッダーに隠れてしまうのを防ぐためのスタイル
 */
[id] {
    scroll-margin-top: 80px; /* ヘッダーの高さより少し多めの余白を設定 */
}
