:root {
    --tagify-dd-max-height: 250px;
}
.tab-active {
    border-bottom: 2px solid #3b82f6;
    color: #3b82f6;
    font-weight: 600;
}
.gift-item.selected {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
    background-color: #dbeafe; /* blue-100 */
}
.loader {
    border: 4px solid #f3f3f3; /* light grey */
    border-top: 4px solid #3498db; /* blue */
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Tagify Modern Design (Definitive Fix) --- */

/* Input area container */
.tagify {
    /* Tagifyが使用するCSS変数をここで定義し直します */
    --tags-border-color: #d1d5db; /* gray-300 */
    /* 背景色と文字色の変数を削除し、より具体的なセレクタで指定します */
    --tag-remove-btn-color: black;
    --tag-border-radius: 0.375rem; /* rounded-md */
    --tag-inset-shadow-size: 0; /* 内側の影を削除 */
    --tag-pad: 0.4em 0.7em;

    border: 1px solid var(--tags-border-color);
    border-radius: 0.5rem; /* rounded-lg */
    transition: all 0.2s ease-in-out;
}

/* Input area on focus */
.tagify--focus {
    --tags-border-color: #3b82f6; /* blue-500 */
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.4);
}

/* 以前の不要なスタイル定義を削除しました */

/* Dropdown suggestions panel */
.tagify__dropdown {
    border-radius: 0.5rem; /* rounded-lg */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid #e5e7eb; /* gray-200 */
}

/* Single item in the dropdown */
.tagify__dropdown__item {
    padding: 0.75rem 1rem;
    transition: background-color 0.2s;
}

/* Hovered or active item in the dropdown */
.tagify__dropdown__item--active {
    background: #eff6ff; /* blue-50 */
    color: #1d4ed8; /* blue-700 */
}

/* 個々のタグ要素に直接スタイルを適用します */
.tagify__tag {
   background-color: #E5E5E5; /* 明るいグレー */
   color: black; /* 黒文字 */
   border-radius: 5px;
}

/* 無効なキーワードが入力された際のタグのスタイル */
.tagify--notAllowed {
    background-color: #ffa1a1; /* 赤色 */
    color: white; /* 白文字 */
    border-radius: 5px;
}

/* --- Results Table Styles --- */
.results-table-wrapper {
    overflow-x: auto; /* テーブルが画面幅を超えた場合に横スクロールを可能にする */
    -webkit-overflow-scrolling: touch; /* iOSでのスムーズなスクロール */
    border: 1px solid #e5e7eb; /* gray-200 */
    border-radius: 0.5rem; /* rounded-lg */
}

#results-table {
    width: 100%;
    min-width: 600px; /* テーブルの最小幅を指定 */
    border-collapse: collapse;
    font-size: 0.875rem; /* text-sm */
}

#results-table th,
#results-table td {
    padding: 0.75rem; /* p-3 */
    text-align: center;
    border-bottom: 1px solid #e5e7eb; /* gray-200 */
    vertical-align: middle;
}

/* 列の間に縦線を追加 */
#results-table th:not(:first-child),
#results-table td:not(:first-child) {
    border-left: 1px solid #e5e7eb; /* gray-200 */
}

#results-table thead th {
    background-color: #f9fafb; /* gray-50 */
    font-weight: 600; /* font-semibold */
    position: sticky; /* スクロール時にヘッダーを固定 */
    top: 0;
    z-index: 10;
}

/* 最初の列（キャラクター情報）のスタイル */
#results-table td:first-child,
#results-table th:first-child {
    text-align: left;
    position: sticky;
    left: 0;
    background-color: #ffffff; /* 白背景にしてスクロール時に重なっても見やすいように */
    z-index: 5;
    border-right: 1px solid #e5e7eb; /* gray-200 */
}
#results-table thead th:first-child {
    background-color: #f9fafb; /* gray-50 */
    z-index: 15;
}


.character-cell {
    display: flex;
    align-items: center;
    gap: 0.75rem; /* gap-3 */
    min-width: 150px;
}

.character-cell img {
    width: 40px;
    height: 40px;
    border-radius: 9999px; /* rounded-full */
    object-fit: cover;
}

.gifts-cell {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.5rem; /* gap-2 */
    min-width: 120px;
}

.gifts-cell img {
    width: 48px; /* w-12 */
    height: 48px; /* h-12 */
    object-fit: contain;
}

/* --- Premium Gift Styles --- */

/* 贈り物選択リストの高級アイテム用 */
.gift-item.is-premium {
    background-color: #f3e8ff; /* purple-100 */
}
.gift-item.is-premium:hover {
    background-color: #e9d5ff; /* purple-200 */
}
/* 選択されている時のスタイルを上書き */
.gift-item.is-premium.selected {
    background-color: #d8b4fe; /* purple-300 */
    outline-color: #c084fc; /* purple-400 */
}

/* 結果テーブル内の高級アイテム用背景 */
.premium-gift-bg {
    background-color: #f3e8ff; /* purple-100 */
    border-radius: 0.375rem; /* rounded-md */
    padding: 0.25rem; /* p-1 */
    display: inline-block; /* 画像を正しく囲む */
    line-height: 0; /* 画像下の余分なスペースを削除 */
    border: 1px solid #e9d5ff; /* purple-200 */
}

/* --- Column Visibility Styles --- */
.hide-medium-column th:nth-child(4),
.hide-medium-column td:nth-child(4) {
    display: none;
}
/* 「中」を非表示にした際に、贈り物が一つもない行を非表示にする */
.hide-medium-column tr.is-empty {
    display: none;
}

/* --- Character Hiding Feature Styles --- */
/* Add pointer cursor to character cells only during gift search */
#results-table.gift-search-result .character-cell {
    cursor: pointer;
    transition: background-color 0.2s;
}
#results-table.gift-search-result .character-cell:hover {
    background-color: #f3f4f6; /* gray-100 */
}

/* --- Confirmation Modal Styles --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.2s ease-in-out;
}

.modal-content {
    background-color: white;
    padding: 2rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    width: 90%;
    max-width: 400px;
}

.modal-btn {
    font-weight: bold;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s;
}

.hidden {
    display: none !important;
}

/* --- Download Button --- */
/* (Styled with Tailwind, no extra CSS needed by default) */

.justify-end{
    justify-content: center;
}

/* --- Responsive Styles for Mobile (max-width: 767px) --- */
@media (max-width: 767px) {
    /* 生徒名を非表示にする */
    .character-name {
        display: none;
    }

    /* テーブルが画面幅を超える場合、横スクロールを可能にする */
    .results-table-wrapper {
        overflow-x: auto; /* 横スクロールを有効化 */
        border: 1px solid #e5e7eb; /* スクロール範囲がわかるように枠線を追加 */
        -webkit-overflow-scrolling: touch; /* iOSでのスムーズなスクロール */
    }

    /* 変更開始 */
    /* テーブルの横スクロールを正しく機能させるため、min-width: 100% の指定を削除しました。*/
    /* これにより、PC版の min-width: 600px が適用され、テーブルが画面幅を超えられるようになります。 */
    #results-table {
        font-size: 0.8rem; /* 少しフォントを小さくする */
    }
    /* 変更終了 */

    /* セルの余白を狭くする */
    #results-table th,
    #results-table td {
        padding: 0.5rem 0.25rem;
    }

    /* スマホでは追従ヘッダー（sticky）を解除 */
    #results-table thead th,
    #results-table td:first-child,
    #results-table th:first-child {
        position: static;
        background-color: transparent; /* 背景色をリセット */
        border-right: none;
    }

    /* ヘッダーの背景色だけは維持 */
    #results-table thead th {
        background-color: #f9fafb; /* gray-50 */
    }

    /* 生徒アイコンのセルを調整 */
    .character-cell {
        min-width: auto;
        justify-content: center; /* アイコンを中央揃えに */
        gap: 0;
    }
    
    /* 生徒アイコンを少し小さくする */
    .character-cell img {
        width: 32px;
        height: 32px;
    }

    /* 贈り物アイコンのセルを調整 */
    .gifts-cell {
        gap: 0.25rem; /* アイコン間の余白を狭く */
        min-width: auto;
    }

    /* 贈り物アイコンを少し小さくする */
    .gifts-cell img {
        width: 36px;
        height: 36px;
    }
    
    /* 高級贈り物の背景を調整 */
    .premium-gift-bg {
        padding: 0.125rem;
    }
}

/* --- Force Desktop View for Screenshot --- */
/* This class temporarily overrides mobile styles to capture a desktop layout image */
.force-desktop-view .character-name {
    display: inline !important; /* Important to override mobile's display: none */
}

.force-desktop-view.results-table-wrapper {
    overflow-x: auto !important;
    border: 1px solid #e5e7eb !important;
}

.force-desktop-view #results-table {
    min-width: 600px !important;
    font-size: 0.875rem !important;
}

.force-desktop-view #results-table th,
.force-desktop-view #results-table td {
    padding: 0.75rem !important;
}

.force-desktop-view #results-table thead th,
.force-desktop-view #results-table td:first-child,
.force-desktop-view #results-table th:first-child {
    position: sticky !important;
}
.force-desktop-view #results-table thead th {
     background-color: #f9fafb !important;
}
.force-desktop-view #results-table td:first-child {
    background-color: #ffffff !important;
    border-right: 1px solid #e5e7eb !important;
}

.force-desktop-view .character-cell {
    min-width: 150px !important;
    justify-content: flex-start !important;
    gap: 0.75rem !important;
}

.force-desktop-view .character-cell img {
    width: 40px !important;
    height: 40px !important;
}

.force-desktop-view .gifts-cell {
    gap: 0.5rem !important;
    min-width: 120px !important;
}

.force-desktop-view .gifts-cell img {
    width: 48px !important;
    height: 48px !important;
}

.force-desktop-view .premium-gift-bg {
    padding: 0.25rem !important;
}

