/* ============================
   components.css
   共通コンポーネント（フォーム・モーダル・トースト・空状態など）
   ============================ */

/* ── フォーム要素 ── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    margin-bottom: var(--space-md);
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-input,
.form-select {
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-dim);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: border-color var(--transition-fast);
    width: 100%;
}

.form-input:focus,
.form-select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.form-select option {
    background: var(--bg-card);
}

.form-row {
    display: flex;
    gap: var(--space-md);
}

.form-row .form-group {
    flex: 1;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ── モーダル ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(6px);
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    width: 90%;
    max-width: 480px;
    animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 1px solid var(--border-subtle);
}

.modal__title {
    font-size: 1rem;
    font-weight: 700;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: var(--space-md);
}

.modal__close {
    color: var(--text-muted);
    font-size: 1rem;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.modal__close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.modal__body {
    padding: var(--space-xl);
    max-height: 70vh;
    overflow-y: auto;
}

.modal__footer {
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
    padding: var(--space-md) var(--space-xl) var(--space-lg);
    border-top: 1px solid var(--border-subtle);
}

/* ── トースト ── */
.toast-container {
    position: fixed;
    bottom: var(--space-xl);
    right: var(--space-xl);
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-card);
    border: 1px solid var(--border-dim);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-width: 360px;
    animation: toastIn 0.3s ease;
    font-size: 0.875rem;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(40px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast.out {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateX(40px);
    }
}

.toast.success {
    border-color: rgba(67, 233, 123, 0.4);
}

.toast.error {
    border-color: rgba(255, 71, 87, 0.4);
}

.toast.info {
    border-color: rgba(108, 99, 255, 0.4);
}

.toast.warning {
    border-color: rgba(247, 151, 30, 0.4);
}

.toast-icon {
    font-size: 1.25rem;
}

.toast-text {
    flex: 1;
}

/* ── 空欄表示 ── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    gap: var(--space-md);
    color: var(--text-muted);
    text-align: center;
}

.multiplier-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.multi-toggle {
    padding: 4px 10px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-subtle);
    background: var(--bg-card);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.multi-toggle.active {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.subject-btn {
    flex: 1;
    padding: var(--space-md) var(--space-lg);
    border: 2px solid var(--border-subtle);
    background: transparent;
    border-radius: var(--radius-md);
    font-weight: 700;
    color: var(--text-secondary);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.subject-btn:hover {
    border-color: var(--color-primary-light);
    background: rgba(255, 255, 255, 0.05);
}

.subject-btn[data-subject="math"] {
    border: 2px solid #3b82f6 !important;
    color: #3b82f6;
}

.subject-btn[data-subject="math"].active {
    background: #3b82f6;
    color: #fff;
}

.subject-btn[data-subject="english"] {
    border: 2px solid #f97316 !important;
    color: #f97316;
}

.subject-btn[data-subject="english"].active {
    background: #f97316;
    color: #fff;
}

.subject-btn[data-subject="japanese"] {
    border: 2px solid #10b981 !important;
    color: #10b981;
}

.subject-btn[data-subject="japanese"].active {
    background: #10b981;
    color: #fff;
}

.qty-stepper {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    padding: 6px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.stepper-btn {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: 1px solid var(--border-dim);
    background: var(--bg-input);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.stepper-btn:hover:not(:disabled) {
    background: var(--bg-surface);
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.qty-val {
    font-weight: 800;
    font-size: 1rem;
    min-width: 20px;
    text-align: center;
}

.empty-state-icon {
    font-size: 3rem;
    opacity: 0.4;
}

.empty-state-text {
    font-size: 0.875rem;
}

/* ── ローディング ── */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-dim);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── アニメーション共通 ── */
.fade-in {
    animation: fadeIn 0.3s ease;
}

.slide-up {
    animation: pageIn 0.3s ease;
}

/* ── レスポンシブ ── */
@media (max-width: 900px) {
    :root {
        --sidebar-width: 220px;
    }

    .calculator-layout {
        grid-template-columns: 1fr;
    }

    .shop-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    :root {
        --sidebar-width: 0px;
    }

    .sidebar {
        display: none;
    }

    .main-content {
        margin-left: 0;
        padding: var(--space-md);
        max-width: 100vw;
    }
}

/* ── アイテム商品画像 ── */
.item-visual {
    width: 100%;
    height: 130px;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-input);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 2px;
}

.item-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform var(--transition-base);
}

.item-card:hover .item-img {
    transform: scale(1.04);
}

/* カード内 編集/削除 アクション（ホバー時表示） */
.item-card-actions {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.item-card:hover .item-card-actions {
    opacity: 1;
}

/* ── 画像アップロードエリア ── */
.image-upload-area {
    width: 100%;
    min-height: 130px;
    border: 2px dashed var(--border-dim);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    position: relative;
    transition: border-color var(--transition-fast), background var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-input);
}

.image-upload-area:hover,
.image-upload-area.drag-over {
    border-color: var(--color-primary);
    background: rgba(108, 99, 255, 0.06);
}

.image-upload-area.drag-over {
    border-style: solid;
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.8rem;
    pointer-events: none;
    padding: 16px;
    text-align: center;
}

.upload-preview {
    width: 100%;
    height: 100%;
    object-fit: contain;
    max-height: 180px;
    border-radius: var(--radius-md);
    display: block;
}

/* ── ポイント履歴 ── */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.history-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border-subtle);
    transition: background var(--transition-fast);
}

/* 履歴モーダル拡張 */
.modal-history,
.modal-lg {
    max-width: 800px !important;
    width: 90%;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-group {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    overflow: hidden;
    transition: all 0.2s ease;
    flex-shrink: 0;
    /* 折りたたまれないように */
    display: block;
    /* Flexの子要素としての挙動を安定させる */
}

.history-group.has-children .history-row-parent {
    cursor: pointer;
}

.history-group.has-children .history-row-parent:hover {
    background: var(--bg-input);
}

.history-row-parent {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
}

.history-sub-rows {
    background: rgba(0, 0, 0, 0.03);
    border-top: 1px dashed var(--border-subtle);
    display: none;
    padding: 4px 0;
    position: relative;
}

.history-group.expanded .history-sub-rows {
    display: block;
}

.history-sub-row {
    display: flex;
    align-items: center;
    padding: 8px 16px 8px 48px;
    font-size: 0.875rem;
    gap: 12px;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(0, 0, 0, 0.02);
}

.history-sub-row:last-child {
    border-bottom: none;
}

.history-sub-icon {
    font-size: 0.9rem;
    opacity: 0.6;
    flex-shrink: 0;
}

.history-toggle-icon {
    font-size: 0.75rem;
    transition: transform 0.3s ease;
    color: var(--text-muted);
    display: inline-block;
}

.history-group.expanded .history-toggle-icon {
    transform: rotate(180deg);
}

.history-reason {
    font-weight: 600;
    font-size: 0.95rem;
    word-break: break-all;
}

.history-sub-reason {
    flex: 1;
}

.history-pts.is-zero {
    color: var(--text-muted) !important;
    font-weight: 400;
    font-size: 0.8rem;
}

/* 既存の箇所の調整 */
.history-row {
    margin: 0 !important;
    border-bottom: none !important;
}

.history-row:hover {
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-sm);
}

.history-icon {
    font-size: 1.1rem;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
    margin-top: 1px;
}

.history-body {
    flex: 1;
    min-width: 0;
}

.history-reason {
    font-size: .875rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-date {
    font-size: .72rem;
    color: var(--text-muted);
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.history-type-badge {
    font-size: .64rem;
    padding: 1px 7px;
    border-radius: var(--radius-full);
    font-weight: 600;
}

.history-pts {
    font-size: .9rem;
    font-weight: 800;
    font-family: 'Inter', sans-serif;
    white-space: nowrap;
    flex-shrink: 0;
}


/* ── ショップ追加スタイル ── */

/* ── ショップ追加スタイル ── */

/* ソートUI */
.shop-sort-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: -10px 0 20px 0;
    padding: 0 4px;
}

/* アイテム画像拡大オーバーレイ */
.item-visual {
    position: relative;
    cursor: pointer;
    overflow: hidden;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    background: #000;
}

.item-visual:hover .item-img {
    transform: scale(1.05);
}

.item-visual-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: .9rem;
    opacity: 0;
    transition: opacity var(--transition-normal);
    pointer-events: none;
    z-index: 2;
}

.item-visual:hover .item-visual-overlay {
    opacity: 1;
}

.item-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform var(--transition-normal);
}

/* 拡大モーダル用 */
.modal-body img {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* ボタン調整 */
.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-outline:hover {
    background: var(--bg-app);
    color: var(--text-primary);
}

/* ── 教科選択スタイル ── */
.subject-select-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.subject-radio {
    cursor: pointer;
    flex: 1;
    min-width: 80px;
}

.subject-radio input {
    display: none;
}

.subject-label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    border: 2px solid var(--border-dim);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: .875rem;
    font-weight: 600;
    transition: all var(--transition-fast);
}

.subject-radio input:checked+.subject-label {
    color: #fff;
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.subject-label.math {
    border-color: var(--color-subject-math);
}

.subject-radio input:checked+.subject-label.math {
    background: var(--color-subject-math);
}

.subject-label.japanese {
    border-color: var(--color-subject-japanese);
}

.subject-radio input:checked+.subject-label.japanese {
    background: var(--color-subject-japanese);
}

.subject-label.english {
    border-color: var(--color-subject-english);
}

.subject-radio input:checked+.subject-label.english {
    background: var(--color-subject-english);
}

.subject-label.other {
    border-color: var(--text-muted);
}

.subject-radio input:checked+.subject-label.other {
    background: var(--text-muted);
}


/* ── ダッシュボード 教科別内訳 ── */

/* ── ダッシュボード 教科別内訳 ── */
.user-subjects-mini {
    display: flex;
    gap: 4px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-dim);
    font-size: .65rem;
    color: var(--text-muted);
}

.sub-badge {
    padding: 2px 5px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
}

.sub-math {
    color: #60a5fa;
}

.sub-jp {
    color: #f87171;
}

.sub-en {
    color: #34d399;
}

/* ── ショップUI並び調整 ── */
.section-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 16px;
}

.shop-sort-row {
    margin: 0 !important;
    /* 位置調整 */
}

.shop-sort-select {
    background: var(--bg-input);
    border: 1px solid var(--border-dim);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 4px 10px;
    font-size: .8rem;
    outline: none;
    cursor: pointer;
}

.shop-sort-select:hover {
    border-color: var(--color-primary);
}

/* ── 設定リストの一貫性 ── */
.settings-list:empty::after {
    content: "項目がありません";
    display: block;
    padding: var(--space-lg);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    border: 1px dashed var(--border-dim);
    border-radius: var(--radius-md);
}

.settings-item__move-btns {
    width: 32px;
}

.settings-item__move-btns button {
    height: 18px;
    padding: 0;
    line-height: 1;
    font-size: 0.6rem;
    min-width: 24px;
    color: var(--text-muted);
}


/* ── 設定リスト アイテム・カード・レイアウト拡張 ── */
.card-list-item {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

.card-list-item:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.settings-item__drag-handle {
    cursor: grab;
    color: var(--text-muted);
    font-size: 1.2rem;
    padding: 0 4px;
    user-select: none;
    opacity: 0.5;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-list-item:hover .settings-item__drag-handle {
    opacity: 1;
}

.settings-item__drag-handle:active {
    cursor: grabbing;
}

/* ドラッグ中のスタイル */
.card-list-item.dragging {
    opacity: 0.5;
    background: var(--bg-surface);
    border: 1px dashed var(--color-primary);
    box-shadow: none;
    transform: none;
}

/* ドロップ先のスタイル */
.card-list-item.drag-over {
    border-top: 2px solid var(--color-primary);
    margin-top: 10px; /* ちょっと隙間をあける */
}

/* ──── フェーズ6.5: リストのグリッド化 & タップ可能化 ──── */
.settings-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
    padding-bottom: 8px;
}

/* 以前の margin-bottom を打ち消して gap に任せる */
.card-list-item {
    margin-bottom: 0 !important;
    cursor: pointer; /* カード全体をタップ可能に */
    position: relative;
    align-items: flex-start; /* 縦揃えを上に。ポイントなどが横並びになるので統一感を出す */
}

/* ドラッグハンドルはクリックイベントを止めたいので相対配置等で調整 */
.settings-item__drag-handle {
    cursor: grab;
    padding: 8px 4px; /* タップしやすく */
    margin-top: 2px;
}

/* カテゴリ絞り込みタブ */
.category-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--border-subtle);
}

.category-tab {
    padding: 6px 14px;
    border-radius: 20px;
    background: var(--bg-input);
    border: 1px solid var(--border-dim);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.category-tab:hover {
    background: var(--bg-surface);
    border-color: var(--color-primary-light);
}

.category-tab.active {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
    box-shadow: 0 2px 6px rgba(108, 99, 255, 0.3);
}


/* ==========================================================================
   RPG風モーダル拡張 (game-modal-style)
   ========================================================================== */
.modal.game-modal-style {
    background: #1a0f05 !important;
    border: 3px solid #8b4513 !important;
    border-radius: 15px !important; /* 角丸を適用 */
    overflow: hidden !important;   /* はみ出しを防止 */
    box-shadow: 0 0 30px rgba(0,0,0,0.8), 0 0 15px rgba(139, 69, 19, 0.4) !important;
    color: #fdf5e6 !important;
    max-width: 850px !important; /* 横幅を広げて4人並びを可能に */
    width: 90% !important;
}

.modal.game-modal-style .modal__header {
    background: #4a2d10 !important;
    border-bottom: 2px solid #8b4513 !important;
    padding: 15px 25px !important;
}

.modal.game-modal-style .modal__title {
    font-family: 'Cinzel', serif !important;
    font-size: 1.4rem !important;
    color: #ffd700 !important;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5) !important;
}

.modal.game-modal-style .modal__close {
    background: #8b4513 !important;
    color: #ffd700 !important;
    border: 1px solid #d4af37 !important;
    opacity: 0.8;
}

.modal.game-modal-style .modal__close:hover {
    opacity: 1;
    background: #a0522d !important;
}

.modal.game-modal-style .modal__body {
    background: radial-gradient(circle at center, #2a1a0a 0%, #1a1005 100%) !important;
    padding: 25px !important;
    max-height: 80vh !important;
}

.modal.game-modal-style .modal__footer {
    border-top: 2px solid #8b4513 !important;
    background: rgba(0,0,0,0.3) !important;
    padding: 20px !important;
}

/* フォーム入力欄 */
.modal.game-modal-style .form-input {
    background: #000 !important;
    border: 1px solid #8b4513 !important;
    color: #64ffda !important;
}

.modal.game-modal-style .form-label {
    color: #d2b48c !important;
}

/* ボタン */
.modal.game-modal-style .btn-primary {
    background: linear-gradient(180deg, #d4af37, #b8860b) !important;
    color: #1a0f05 !important;
    border: 1px solid #8b4513 !important;
}

.modal.game-modal-style .btn-outline {
    background: #3d2b1f !important;
    color: #d2b48c !important;
    border-color: #5d4a36 !important;
}
