/* ----- 1. 変数定義 ----- */
:root {
    --color-transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;

    --app-bg-color: #f8f9fa;
    --card-bg-color: #ffffff;
    --text-main: #333333;
    --text-sub: #666666;
    --border-color: #dddddd;
    --border-sub: #eeeeee;
    --checked-bg: #f0f0f0;
    --checked-text: #808080;
    --btn-color: #006ce0;
    --item-btn-bg: rgba(255, 255, 255, 0.95);
    --modal-overlay: rgba(0, 0, 0, 0.5);
    --hover-bg: #f5f5f5;
    
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    --modal-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);

    --main-color-math: #00008b;
    --main-color-english: #ff69b4;
    --main-color-modernjp: #f49200;
    --main-color-classicjp: #a0522d;
    --main-color-science: #228b22;
    --main-color-social: #e6c700;
    --main-color-others: #808080;
}

@media (prefers-color-scheme: dark) {
    :root {
        --app-bg-color: #121212;
        --card-bg-color: #1e1e1e;
        --text-main: #e0e0e0;
        --text-sub: #999999;
        --border-color: #444444;
        --border-sub: #2a2a2a;
        --checked-bg: #252525;
        --checked-text: #666666;
        --btn-color: #6c97e8;
        --item-btn-bg: rgba(45, 45, 45, 0.95);
        --modal-overlay: rgba(0, 0, 0, 0.8);
        --hover-bg: #2c2c2c;
        
        --card-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
        --modal-shadow: 0 12px 24px rgba(0, 0, 0, 0.6);

        --main-color-math: #3a86ff;
        --main-color-english: #ff69b4;
        --main-color-modernjp: #ff9f1c;
        --main-color-classicjp: #d16b3c;
        --main-color-science: #00e676;
        --main-color-social: #ffea00;
        --main-color-others: #909090;
    }
}

/* ----- 2. リセット & 全体設定 ----- */
* {
    font-family: "Noto Sans JP", sans-serif;
    -webkit-tap-highlight-color: transparent;
    transition: var(--color-transition);
}
body {
    background-color: var(--app-bg-color);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}


/* ----- 3. ユーティリティ（汎用クラス） ----- */
.invisible { visibility: hidden; }
.underlined { text-decoration: underline; }
p.no-data {
    text-align: center;
    color: var(--text-sub);
    font-size: 14px;
    padding: 4px;
}
button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--border-color) !important;
    border-color: var(--border-color) !important;
    color: var(--text-sub) !important;
}
.scrollable {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
    scroll-behavior: smooth;
}
.scrollable::-webkit-scrollbar { width: 6px; }
.scrollable::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 3px; }


/* ----- 4. メインレイアウト ----- */
.main-wrapper.full-height {
    height: 100dvh !important;
    overflow: hidden;
    padding-bottom: 0;
}


/* ----- 5. スクロール・表示制御 ----- */
.header h1 {
    color: var(--text-main);
}
.header p {
    color: var(--text-sub);
}
.display-container {
    padding-bottom: 100px;
}
.display-container.hidden { display: none; }


/* ----- 6. ツールバー（検索・フィルタエリア） ----- */
.filter-toolbar {
    background: var(--card-bg-color);
    padding: 16px;
    border-radius: var(--border-radius-size);
    margin-bottom: 16px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.search-box {
    position: relative;
    width: 100%;
    margin-bottom: 12px;
}
.search-box input {
    width: 100%;
    padding: 10px 10px 10px 36px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--app-bg-color);
    color: var(--text-main);
    font-size: 15px;
    outline: none;
    margin: 0;
}
.search-box input:focus {
    background: var(--card-bg-color);
    border-color: var(--btn-color);
}

.filter-group {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.filter-group::-webkit-scrollbar { display: none; }
.filter-btn-wrapper {
    position: relative;
    background: var(--card-bg-color);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--btn-color);
    min-width: fit-content;
    height: 36px;
    display: flex;
    align-items: center;
}
.filter-btn-wrapper:hover {
    background-color: var(--hover-bg);
    border-color: var(--btn-color);
}
.filter-btn-wrapper i {
    position: absolute;
    left: 12px;
    pointer-events: none;
    font-size: 14px;
}
.filter-btn-wrapper select {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    background-image: none !important;
    border: none;
    padding: 0 16px 0 34px;
    height: 100%;
    width: 100%;
    font-size: 13px;
    font-weight: bold;
    color: var(--text-main);
    cursor: pointer;
    margin: 0;
    outline: none;
    user-select: none;
    transition: border-color 0.2s ease;
}
#sort-items .filter-btn-wrapper {
    margin-bottom: 16px;
    width: 100%;
}
#sort-items .filter-btn-wrapper select { width: 100%; }


/* ----- 7. カード共通（予定・教材） ----- */
.plan-item, .material-item {
    background: var(--card-bg-color);
    border-radius: var(--border-radius-size);
    box-shadow: var(--card-shadow);
    margin-bottom: 12px;
    position: relative;
    border: none;
    border-left: 5px solid transparent;
    overflow: hidden;
    cursor: pointer;
}


/* ----- 8. 予定アイテム ----- */
.plan-item {
    padding: 14px;
    display: flex;
    align-items: center;
    border-left: 5px solid transparent;
    min-height: 60px;
}
.plan-item.checked {
    opacity: 0.6;
    background-color: var(--checked-bg);
    color: var(--checked-text);
    box-shadow: none;
    border-left: 5px solid var(--border-color) !important;
    border: 1px solid var(--border-color);
}

.plan-icon {
    margin-right: 12px;
    width: 24px;
    text-align: center;
    font-size: 16px;
    flex-shrink: 0;
}
.plan-info { flex: 1; font-size: 15px; z-index: 1; }
.plan-info > div:first-child { font-weight: 700; font-size: 15px; margin-bottom: 2px; color: var(--text-main); padding-right: 4px; }
.plan-info > div { font-size: 13px; color: var(--text-sub); line-height: 1.4; }
.plan-info i { width: 14px; margin-right: 2px; }
.plan-item.checked .plan-icon i, .plan-item.checked .plan-info i { color: var(--checked-text); }


/* ----- 9. 教材アイテム ----- */
/* -- 9-1. 基本構造 -- */
.material-wrapper {
    margin: 20px 0;
    padding: 8px 0;
    border-top: 1px dashed var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.material-item {
    position: relative;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 64px;
    transition: var(--color-transition);
}

/* -- 9-2. tapped（展開状態） -- */
.material-item.tapped {
    height: 85dvh;
    padding: 0;
    overflow: hidden;
    display: block;
    z-index: 50;
    box-shadow: 0 15px 40px rgba(0,0,0,0.3);
    cursor: text;
}

.material-item .material-info {
    width: 100%;
}

.material-item.tapped .material-info {
    height: 100%;
    overflow-y: auto;
    padding: 36px 20px 70px 20px;
}

/* -- 9-3. 進捗バー -- */
.material-item::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    height: 6px;
    width: var(--material-bg-width);
    background-color: var(--checked-bg);
    z-index: 5;
}

/* -- 9-4. テキスト展開 -- */
.material-name {
    font-weight: 700;
    font-size: 16px;
    margin-bottom: 4px;
    color: var(--text-main);
    transition: font-size 0.2s ease;
}

.material-item.tapped .material-name {
    font-size: 20px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-sub);
    padding-bottom: 8px;
}

.material-date,
.material-progress,
.material-detail {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    font-size: 12px;
    color: var(--text-sub);
}

.material-item.tapped .material-date,
.material-item.tapped .material-progress,
.material-item.tapped .material-detail {
    max-height: 1200px;
    opacity: 1;
    margin-top: 4px;
    white-space: pre-wrap;
    line-height: 1.8;
}


/* ----- 10. 教科別カラー定義 ----- */
.plan-item.math, .material-item.math { border-left-color: var(--main-color-math); }
.math .plan-icon, .math i { color: var(--main-color-math); }

.plan-item.english, .material-item.english { border-left-color: var(--main-color-english); }
.english .plan-icon, .english i { color: var(--main-color-english); }

.plan-item.modernjp, .material-item.modernjp { border-left-color: var(--main-color-modernjp); }
.modernjp .plan-icon, .modernjp i { color: var(--main-color-modernjp); }

.plan-item.classicjp, .material-item.classicjp { border-left-color: var(--main-color-classicjp); }
.classicjp .plan-icon, .classicjp i { color: var(--main-color-classicjp); }

.plan-item.science, .material-item.science { border-left-color: var(--main-color-science); }
.science .plan-icon, .science i { color: var(--main-color-science); }

.plan-item.social, .material-item.social { border-left-color: var(--main-color-social); }
.social .plan-icon, .social i { color: var(--main-color-social); }

.plan-item.others, .material-item.others { border-left-color: var(--main-color-others); }
.others .plan-icon, .others i { color: var(--main-color-others); }


/* ----- 11. 編集・削除ボタン（アニメーション含む） ----- */
@keyframes popIn {
    from { opacity: 0; transform: scale(0.85); }
    to   { opacity: 1; transform: scale(1); }
}
.plan-item, .material-item {
    position: relative;
}

.item-buttons {
    display: none;
    position: absolute;
    background: var(--item-btn-bg);
    margin: auto;
    padding: 4px;
    border-radius: 30px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    vertical-align: middle;
    align-items: center;
    z-index: 100;
    animation: popIn 0.2s ease;
}

/* 表示条件 */
.plan-item.tapped .item-buttons,
.material-item.tapped .item-buttons {
    display: flex;
}

/* 位置指定 */
.material-item.tapped .item-buttons {
    right: 16px;
    bottom: 20px;
    top: auto;
    left: auto;
}
.plan-item.tapped .item-buttons {
    right: 10px;
    bottom: 10px;
    top: auto;
    left: auto;
}
#sort-container .material-item {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 12px 14px;
    min-height: 60px;
    outline: none;
    user-select: none;
    cursor: default;
}
#sort-container .material-item.tapped {
    height: auto;
    overflow: visible;
    box-shadow: var(--card-shadow);
    outline: var(--btn-color) 2px solid;
}
#sort-container .material-item.tapped .item-buttons {
    right: 10px;
    left: auto;
    margin: auto 0;
    height: fit-content;
    top: 0;
    bottom: 0;
    transform: none;
}

/* ボタン本体 */
.item-buttons button {
    background: transparent;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 2px;
}

.item-buttons button:hover,
.item-buttons button:active {
    background-color: var(--checked-bg);
}

.item-buttons button i {
    font-size: 16px !important;
}


/* ----- 12. ユーティリティボタン・操作ボタン ----- */
.util-btn-wrapper {
    margin-left: 4px;
    margin-bottom: 20px;
    user-select: none;
}
.util-btn {
    align-items: center;
    width: fit-content;
    background: var(--card-bg-color);
    border: 1px solid var(--border-color);
    color: var(--btn-color);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    margin-bottom: 8px;
    text-decoration: none;
}
.util-btn:hover {
    background-color: var(--hover-bg);
    border-color: var(--btn-color);
}
.util-btn i { margin-right: 8px; }


/* ----- 13. フッター ----- */
.button-group {
    width: 100%;
    max-width: var(--main-max-width);
    height: calc(60px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    
    border-top: 1px solid var(--border-sub);
    background: var(--item-btn-bg);
    box-shadow: 0 -2px 5px rgba(0,0,0,0.03);
    backdrop-filter: blur(5px);
    
    display: flex;
    justify-content: space-around;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0 auto;
    z-index: 200;
}
.footer-btn {
    flex: 1;
    border: none;
    background: none;
    color: var(--text-sub);
    font-size: 11px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    user-select: none;
}
.footer-btn i { font-size: 18px; }
.footer-btn:hover { color: var(--btn-color); background: rgba(0,0,0,0.02); }


/* ----- 14. フォーム共通（input / select / textarea） ----- */
input[type="text"], input[type="number"], input[type="time"], input[type="datetime-local"], select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 16px;
    background: var(--card-bg-color);
    color: var(--text-main);
    outline: none;
    margin-bottom: 8px;
    appearance: none;
    -webkit-appearance: none;
}
select {
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2210%22%20height%3D%226%22%3E%3Cpath%20d%3D%22M0%200l5%206%205-6z%22%20fill%3D%22%23666%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 25px;
}
textarea {
    resize: vertical;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--btn-color);
}

/* ----- 15. モーダル共通 ----- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--modal-overlay);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.modal-container {
    background: var(--card-bg-color);
    padding: 24px 16px;
    border-radius: 8px;
    width: 90%;
    max-width: 540px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--modal-shadow);
}
.modal-container h2 {
    text-align: center;
    margin: 0 0 20px 0;
    font-size: 18px;
    color: var(--text-main);
}
.modal-container label, p {
    display: block;
    margin-top: 8px;
    font-size: 15px;
    user-select: none;
}

#new-category-input {
    margin-top: 4px;
    border-color: var(--btn-color);
    transition: border-color 0.3s ease, background-color 0.3s ease;
}

.modal-btns {
    display: flex;
    gap: 10px;
    margin-top: 24px;
}
.modal-btns button {
    flex: 1;
    padding: 10px;
    border-radius: 4px;
    border: none;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
}
.modal-btns .cancel { background: var(--checked-bg); color: var(--text-main); }
.modal-btns .ok { background: var(--btn-color); color: white; }


/* ----- 16. まとめて追加モーダル ----- */
/* まとめて追加モーダルのリスト */
#bulk-material-list {
    max-height: 50dvh;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    padding: 8px;
    border-radius: 4px;
}
.bulk-item-label {
    display: flex;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid var(--border-sub);
    cursor: pointer;
}
.bulk-item-label:last-child {
    border-bottom: none;
}
.bulk-item-label input {
    margin: 0 10px 0 0 !important;
    width: auto !important;
}
.bulk-item-label span {
    font-size: 14px;
    color: var(--text-main);
}


/* ----- 17. 教材ステータスバッジ ----- */
.status-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    z-index: 10;
}

/* 各ステータスの色定義 */
.status-badge.learning { background-color: var(--btn-color); }
.status-badge.waiting { background-color: #bbb; }
.status-badge.completed { background-color: #3cd651; }


/* ----- 18. 履歴・統計表示モーダル ----- */
/* -- 18-1. 総実施数・最終更新日 -- */
/* stats = statistics（統計） */
.stats-summary-container {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}
.stats-summary-card {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    padding: 10px;
    min-height: auto;
    border: 1px solid var(--border-color);
    box-shadow: none;
    cursor: default;
    background: var(--app-bg-color);
}
.stats-label {
    font-size: 12px;
    color: var(--text-sub);
    margin-bottom: 2px;
}
.stats-value {
    font-size: 18px;
    font-weight: bold;
    color: var(--text-main);
}

/* -- 18-2. 学習バランス（統計バー） -- */
.balance-list-wrapper {
    margin-bottom: 20px;
    border-bottom: 1px dashed var(--border-color);
    padding-bottom: 12px;
}
.balance-row {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
}
.balance-bar-container {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
    overflow: hidden;
}
@keyframes growBar {
    from { width: 0; }    /* to は不要 */
}
.balance-bar {
    height: 100%;
    border-radius: 4px;
    animation: growBar 0.5s ease forwards;
}

/* 教科別カラー（既存変数を流用） */
.balance-bar.math      { background-color: var(--main-color-math); }
.balance-bar.english   { background-color: var(--main-color-english); }
.balance-bar.modernjp  { background-color: var(--main-color-modernjp); }
.balance-bar.classicjp { background-color: var(--main-color-classicjp); }
.balance-bar.science   { background-color: var(--main-color-science); }
.balance-bar.social    { background-color: var(--main-color-social); }
.balance-bar.others    { background-color: var(--main-color-others); }

.subject-name {
    width: 50px;
    font-size: 12px;
    color: var(--text-sub);
    text-align: right;
}
.subject-percent {
    width: 35px;
    font-size: 12px;
    color: var(--text-main);
    font-weight: bold;
}

/* 現在の教材の教科を強調 */
.current-subject .subject-name {
    color: var(--text-main);
    font-weight: bold;
}

/* -- 18-3. 詳細履歴リスト -- */
.history-card {
    min-height: auto !important;
    padding: 10px 14px !important;
    margin-bottom: 8px;
    cursor: default !important;
}
.history-date {
    font-size: 12px;
    color: var(--text-main);
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 5px;
}
.history-range {
    font-size: 13px;
}
.history-time-badge {
    font-size: 12px;
    color: var(--text-sub);
    margin-left: auto;
}


/* ----- 19. このアプリについて ----- */
.about-info-wrapper {
    text-align: center;
    margin: 24px 0;
    user-select: none;
}
.about-btn {
    background: none;
    border: none;
    padding: 0;
    font-size: 13px;
    color: var(--text-sub);
    cursor: pointer;
}
.about-btn:hover { color: var(--text-main); }


