:root { 
    --primary: #00f2ff; 
    --accent: #22c55e; 
    --bg: #0f172a; 
    --header-bg: #1e293b;
    --card-bg: #1e293b;
    --text: #f1f5f9; 
    --tray-bg: #0f172a;
    --border: #334155;
    --skill: #fbbf24; 
    --ability: #a78bfa; 
    --gk: #f97316; 
}

body { 
    font-family: -apple-system, sans-serif; 
    background: var(--bg); 
    color: var(--text); 
    margin: 0; 
    padding-top: 60px; /* Header height */
    padding-bottom: 120px; /* Tray height space */
}

/* Header */
.app-header {
    position: fixed; top: 0; left: 0; width: 100%;
    height: 60px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 10px; box-sizing: border-box;
    z-index: 1000;
}
.search-bar {
    flex: 1; margin: 0 10px; position: relative;
}
.search-bar input {
    width: 100%; background: #0f172a; border: 1px solid var(--border);
    padding: 8px 10px 8px 35px; border-radius: 20px; color: #fff;
    box-sizing: border-box;
}
.search-icon {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    color: #64748b; font-size: 0.8rem;
}
.icon-btn {
    background: none; border: none; color: #fff; font-size: 1.2rem; cursor: pointer; padding: 5px 10px;
}

/* Drawer */
.drawer-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 1100; display: none;
}
.app-drawer {
    position: fixed; top: 0; left: -250px; width: 250px; height: 100%;
    background: var(--header-bg); z-index: 1200;
    transition: left 0.3s ease; box-shadow: 2px 0 10px rgba(0,0,0,0.5);
    padding-top: 20px;
}
.app-drawer.open { left: 0; }
.drawer-overlay.open { display: block; }
.drawer-header {
    padding: 0 20px 20px; font-weight: bold; color: var(--primary); border-bottom: 1px solid var(--border);
}
.drawer-item {
    display: block; padding: 15px 20px; color: #fff; text-decoration: none;
    border-bottom: 1px solid #334155; transition: background 0.2s; cursor: pointer;
}
.drawer-item:hover, .drawer-item.active { background: rgba(0, 242, 255, 0.1); color: var(--primary); }
.drawer-item i { margin-right: 10px; width: 20px; text-align: center; }

/* Views */
.view-content { display: none; padding: 15px; max-width: 1200px; margin: 0 auto; }
.view-content.active { display: block; }

/* Database Grid */
.card-grid-visual {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px; padding-bottom: 20px;
}
.db-card {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: 8px; overflow: hidden; position: relative;
    cursor: pointer; transition: transform 0.1s;
}
.db-card:active { transform: scale(0.98); }
.db-card.fav { border-color: #ec4899; box-shadow: 0 0 5px rgba(236, 72, 153, 0.3); }
.db-card-img { width: 100%; aspect-ratio: 3/4; object-fit: cover; background: #000; display: block; }
.db-info { padding: 5px; font-size: 0.75rem; }
.db-name { font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.db-badges { display: flex; gap: 3px; margin-top: 3px; flex-wrap: wrap; }
.badge { padding: 1px 4px; border-radius: 3px; font-size: 0.6rem; font-weight: bold; }
.badge.SSR { background: rgba(251, 191, 36, 0.2); color: #fbbf24; border: 1px solid #fbbf24; }
.badge.SR { background: rgba(255,255,255,0.1); color: #fff; border: 1px solid #999; }
.fav-icon {
    position: absolute; top: 5px; right: 5px;
    color: #ec4899; font-size: 1rem; filter: drop-shadow(0 0 2px #000);
    display: none;
}
.db-card.fav .fav-icon { display: block; }

/* Bottom Tray */
.tray-container {
    position: fixed; bottom: 0; left: 0; width: 100%;
    background: var(--tray-bg); border-top: 1px solid var(--primary);
    z-index: 900; box-shadow: 0 -5px 15px rgba(0,0,0,0.5);
    transform: translateY(calc(100% - 30px)); /* Handle only visible */
    transition: transform 0.3s ease;
}
.tray-container.open { transform: translateY(0); }
.tray-handle {
    height: 30px; background: rgba(0, 242, 255, 0.1);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 15px; cursor: pointer; color: var(--primary); font-size: 0.8rem;
}
.tray-content { padding: 10px; display: flex; gap: 10px; overflow-x: auto; align-items: center; height: 80px;}
.tray-list { display: flex; gap: 5px; flex: 1; min-height: 50px; border: 1px dashed #444; border-radius: 6px; padding: 5px; align-items: center; }
.tray-item { position: relative; cursor: pointer; }
.tray-item img { width: 50px; height: 65px; border-radius: 4px; object-fit: cover; border: 1px solid #555; }
.tray-placeholder { color:#666; font-size:0.8rem; margin: auto; }

/* Modal & Common */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85); z-index: 1000;
    display: flex; justify-content: center; align-items: center;
}
.modal-content {
    background: var(--card-bg); width: 90%; max-width: 500px; max-height: 90vh;
    border-radius: 10px; border: 1px solid #334155; display: flex; flex-direction: column;
}

.modal-body {
    padding: 15px;
    overflow-y: auto;
    flex: 1;
    min-height: 200px; /* 中身が空でも最低限の高さを確保 */
}
.modal-footer {
    display: flex; justify-content: space-between; gap: 10px;
    padding: 15px; border-top: 1px solid #333;
}
.btn-close { background: transparent; border: none; color: #fff; font-size: 1.5rem; cursor: pointer; }

/* Buttons */
.btn { padding: 10px; border-radius: 6px; border: none; cursor: pointer; font-weight: bold; width: 100%; box-sizing: border-box; }
.btn-sm { width: auto; padding: 4px 8px; font-size: 0.75rem; }
.btn-primary { background: var(--primary); color: #000; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-icon { background: #334155; padding: 10px; flex: 1; border-radius: 6px; border: none; color: #fff; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 0.7rem; }
.btn-icon.active { background: #ec4899; color: white; }
.btn-icon i { font-size: 1.2rem; }

/* Sim/Form Elements */
.card-box { background: var(--card-bg); padding: 15px; border-radius: 10px; margin-bottom: 15px; border: 1px solid #334155; }
input, textarea, select { background: #000; border: 1px solid #334155; color: #fff; padding: 8px; border-radius: 6px; width: 100%; box-sizing: border-box; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-top: 10px; }
.tag { font-size: 0.65rem; padding: 2px 6px; border-radius: 4px; margin-right: 5px; }
.tag-skill { background: var(--skill); color: #000; }
.tag-ability { background: var(--ability); color: #fff; }

/* UI Parts from previous styles */
.condition-selector { display: flex; gap: 2px; background: #000; padding: 2px; border-radius: 8px; border: 1px solid #334155; margin-top: 5px; }
.cond-btn { flex: 1; background: transparent; border: none; color: #94a3b8; padding: 8px 0; font-size: 0.75rem; cursor: pointer; border-radius: 6px; transition: 0.2s; }
.cond-btn.active { background: var(--accent); color: #fff; font-weight: bold; }
.pos-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 15px; }
.pos-chip { padding: 12px 0; border-radius: 4px; background: #1e293b; border: 1px solid #334155; color: #f1f5f9; font-size: 0.8rem; font-weight: bold; text-align: center; cursor: pointer; transition: 0.2s; }
.pos-chip.active[data-group="gk"] { background: #9a4710; border-color: #f97316; }
.pos-chip.active[data-group="df"] { background: #1e40af; border-color: #3b82f6; }
.pos-chip.active[data-group="mf"] { background: #166534; border-color: #22c55e; }
.pos-chip.active[data-group="fw"] { background: #991b1b; border-color: #ef4444; }
.style-grid { display: grid; grid-template-columns: 1fr; gap: 6px; margin-top: 10px; max-height: 400px; overflow-y: auto; }
.style-card { display: flex; align-items: center; background: #1e293b; border: 1px solid #334155; border-radius: 6px; padding: 8px 12px; cursor: pointer; transition: 0.2s; }
.style-card.active { border-color: var(--primary); background: rgba(0, 242, 255, 0.15); }
.style-card img { width: 32px; height: 32px; object-fit: contain; margin-right: 12px; background: #0f172a; border-radius: 4px; padding: 2px; }
.slot-active { border: 2px solid var(--primary); background: rgba(0,242,255,0.1); }
.slot-empty { border: 2px dashed #444; }
.list-item { background: #1e293b; margin-bottom: 5px; padding: 8px; border-radius: 6px; display: flex; justify-content: space-between; align-items: center; border: 1px solid #334155; }
.btn-edit { padding: 4px 8px; border-radius: 4px; border: none; cursor: pointer; font-size: 0.7rem; color: white; background: #3b82f6; }
.area-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; width: 120px; margin-top: 5px; }
.area-cell { height: 35px; background: #444; cursor: pointer; border: 1px solid #555; }
.area-cell.active { background: var(--skill); border: 1px solid white; }
#admin-status { display: none; position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: rgba(0, 0, 0, 0.8); color: #00f2ff; padding: 8px 15px; border-radius: 20px; font-size: 0.8rem; z-index: 1000; border: 1px solid #00f2ff; pointer-events: none; }

/* --- Phase 2 追加スタイル --- */

/* Filter Chips */
.filter-section { margin-bottom: 15px; }
.filter-section label { display: block; font-size: 0.8rem; color: #94a3b8; margin-bottom: 5px; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-check { position: relative; }
.chip-check input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip-check label {
    display: inline-block; padding: 6px 12px; background: #334155; 
    border-radius: 20px; font-size: 0.8rem; color: #ccc; cursor: pointer; 
    transition: 0.2s; border: 1px solid transparent;
}
.chip-check input:checked + label {
    background: rgba(0, 242, 255, 0.2); color: var(--primary); 
    border-color: var(--primary); font-weight: bold;
}

/* Comparison Table */
.comp-table-wrapper { overflow-x: auto; }
.comp-table {
    width: 100%; border-collapse: collapse; font-size: 0.8rem; text-align: center;
    white-space: nowrap;
}
.comp-table th, .comp-table td {
    padding: 8px 5px; border-bottom: 1px solid #334155; border-right: 1px solid #334155;
}
.comp-table th:first-child, .comp-table td:first-child {
    position: sticky; left: 0; background: #1e293b; z-index: 10;
    border-right: 2px solid #475569; font-weight: bold; color: #94a3b8;
    min-width: 80px; text-align: left; padding-left: 10px;
}
.comp-table thead th {
    position: sticky; top: 0; background: #0f172a; z-index: 20;
    border-bottom: 2px solid #475569; padding-top: 10px; padding-bottom: 10px;
}
.comp-table thead th:first-child { z-index: 30; background: #0f172a; }

/* Comparison Header Card */
.comp-card-header img {
    width: 50px; height: 65px; object-fit: cover; border-radius: 4px; border: 1px solid #555;
    margin-bottom: 5px;
}
.comp-card-name { font-size: 0.7rem; font-weight: bold; white-space: normal; line-height: 1.2; }

/* Comparison Highlight */
.comp-val { font-family: monospace; font-size: 0.9rem; }
.comp-win { color: var(--primary); font-weight: bold; background: rgba(0,242,255,0.1); }
.comp-best { color: #fbbf24; font-weight: bold; text-decoration: underline; } /* 全体ベスト */

/* --- Phase 2.5 追加・修正スタイル --- */

/* Viewごとの表示制御 */

/* Header Tools (検索バーとボタンをまとめるコンテナ) */
.header-tools {
    display: flex; flex: 1; align-items: center; margin: 0 10px;
    gap: 10px;
}

/* Detailed Filter Modal Layout */
.filter-group {
    margin-bottom: 15px; border-bottom: 1px dashed #334155; padding-bottom: 10px;
}
.filter-group-title {
    font-size: 0.8rem; color: var(--primary); font-weight: bold; margin-bottom: 8px;
    display: flex; justify-content: space-between; align-items: center;
}
.filter-grid-compact {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 6px;
}
.filter-grid-params {
    display: grid;
    grid-template-columns: repeat(7, 1fr) !important; /* 7列固定 */
    gap: 3px;
    margin-top: 5px;
}

/* --- 既存の .chk-btn 関連を以下に差し替え --- */

.chk-btn {
    position: relative;
    flex: 1; /* 親コンテナ内で均等に広げる */
    min-width: 0; /* Flexboxでのはみ出し防止 */
}

.chk-btn input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.chk-btn label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 10px 4px; /* タップ領域を拡大 */
    background: #1e293b; /* 暗めの背景 */
    border: 1px solid #475569;
    border-radius: 6px;
    font-size: 0.75rem;
    color: #94a3b8;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
    user-select: none;
    white-space: nowrap;
    box-sizing: border-box;
}

/* 選択時のスタイル：視認性を高める */
.chk-btn input:checked + label {
    background: var(--primary); /* シアン色背景 */
    color: #000; /* 黒文字 */
    border-color: var(--primary);
    font-weight: bold;
    box-shadow: 0 0 8px rgba(0, 242, 255, 0.4);
}

/* パラメータ選択時はアクセントカラー（緑）にする場合 */
.chk-btn.param input:checked + label {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.4);
}

/* モーダル内の閉じるボタン等の配置調整 */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: #1e293b;
    border-bottom: 1px solid #334155;
}

/* トレイが非表示の時の下部余白調整 */
body:not([data-view="database"]) {
    padding-bottom: 20px; /* トレイがないので少し詰める */
}

/* --- Header Mode Switch --- */
.mode-switch-container {
    display: flex;
    background: #0f172a;
    border: 1px solid var(--border);
    border-radius: 20px;
    overflow: hidden;
    margin-right: 5px;
}
.mode-btn {
    background: transparent;
    border: none;
    color: #64748b;
    padding: 6px 12px;
    font-size: 0.75rem;
    cursor: pointer;
    font-weight: bold;
    transition: 0.2s;
}
.mode-btn.active {
    background: var(--primary);
    color: #000;
}

/* --- List View Styles --- */
/* Grid View (Default) - 既存の .card-grid-visual を流用 */

/* List View Override */
.card-grid-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 20px;
}
.card-grid-list .db-card {
    display: flex;
    flex-direction: row;
    height: 80px; /* 固定高さ */
    align-items: center;
}
.card-grid-list .db-card-img {
    width: 60px;
    height: 80px;
    aspect-ratio: auto;
    border-right: 1px solid var(--border);
}
.card-grid-list .db-info {
    flex: 1;
    padding: 5px 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}
.card-grid-list .db-name {
    font-size: 0.85rem;
    margin-bottom: 2px;
}
.card-grid-list .list-stats {
    font-size: 0.7rem;
    color: #ccc;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.card-grid-list .list-skills {
    margin-top: 2px;
}

/* --- Detail Modal Level Buttons --- */
.level-btn-group {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
    background: #0f172a;
    padding: 5px;
    border-radius: 6px;
    overflow-x: auto;
}
.lvl-btn {
    flex: 1;
    background: #334155;
    border: 1px solid #475569;
    color: #fff;
    padding: 6px 0;
    border-radius: 4px;
    font-size: 0.7rem;
    cursor: pointer;
    white-space: nowrap;
}
.lvl-btn.active {
    background: var(--primary);
    color: #000;
    border-color: var(--primary);
    font-weight: bold;
}

/* --- Modal Tabs --- */
.modal-tab-header {
    display: flex;
    background: #1e293b;
    border-bottom: 1px solid #334155;
    padding: 0 10px;
}
.modal-tab-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    padding: 12px 15px;
    font-weight: bold;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: 0.2s;
}
.modal-tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.filter-tab-content {
    display: none;
}
.filter-tab-content.active {
    display: block;
}

/* --- Comparison Table Updates --- */
/* カードごとのレベル操作UI用 */
.comp-card-ctrl {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 5px;
}
.comp-lvl-btns {
    display: flex;
    gap: 1px;
    justify-content: center;
}
.comp-lvl-btn {
    padding: 6px 4px; /* タップ領域拡大 */
    flex: 1; /* 横幅いっぱいに広げる */
    font-size: 0.7rem; /* 文字サイズ拡大 */
    border: 1px solid #444;
    background: #0f172a;
    color: #ccc;
    cursor: pointer;
    border-radius: 4px; /* 丸みを追加 */
    margin: 0 1px;
}
.comp-lvl-btn.active {
    background: var(--primary);
    color: #000;
    border-color: var(--primary);
    font-weight: bold;
}
.comp-lvl-btn.active {
    background: var(--primary);
    color: #000;
    border-color: var(--primary);
}

/* --- 修正: 文字切れ対策（折り返し・サイズ調整） --- */
.filter-grid-params .chk-btn label {
    padding: 2px 0; /* 余白を詰める */
    height: 38px;   /* 高さを固定して2行表示に対応 */
    font-size: 0.6rem; /* 小さめ */
    
    /* 文字折り返し設定 */
    white-space: normal; 
    word-break: break-all;
    line-height: 1.1; /* 行間を詰める */
    
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
}

/* GK項目を目立たせる（JSでクラス付与） */
.chk-btn.param-gk label {
    color: var(--gk);
    border-color: rgba(249, 115, 22, 0.3);
}
.chk-btn.param-gk input:checked + label {
    background: var(--gk);
    color: #000;
    border-color: var(--gk);
    box-shadow: 0 0 8px rgba(249, 115, 22, 0.4);
}

/* --- Phase 3 追加スタイル --- */

/* MyCardsモード時の未所持カード表現 */
body[data-view="database"] .db-card.unowned {
    opacity: 0.6;
    filter: grayscale(0.8);
    border: 1px dashed #444;
}
/* 所持カードは少し明るく */
body[data-view="database"] .db-card.owned {
    border-color: var(--accent);
    box-shadow: 0 0 5px rgba(34, 197, 94, 0.2);
}

/* 育成スライダー周辺 */
.level-slider-container {
    background: #0f172a;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #334155;
    margin-bottom: 10px;
}
.level-control-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.level-slider {
    flex: 1;
    cursor: pointer;
}
.level-display {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--primary);
    min-width: 50px;
    text-align: right;
}
.mgmt-tools {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

/* --- Phase 3 修正スタイル --- */

/* 未所持カード表現: MyCardsモード時のみ適用 */
body[data-app-mode="mycards"] .db-card.unowned {
    opacity: 0.6;
    filter: grayscale(0.8);
    border: 1px dashed #444;
}
/* Viewモード(図鑑)では未所持でもフルカラー (通常のスタイルを維持) */
body[data-app-mode="view"] .db-card.unowned {
    opacity: 1;
    filter: none;
}

/* 所持カード共通スタイル */
.db-card.owned {
    border-color: var(--accent);
    box-shadow: 0 0 5px rgba(34, 197, 94, 0.2);
}

/* --- モーダル改善 --- */

/* 画像上のお気に入りアイコン */
.card-img-container {
    position: relative;
    width: 100px;
    height: 133px;
    flex-shrink: 0;
}
.card-fav-overlay {
    position: absolute;
    top: 5px;
    left: 5px;
    font-size: 1.2rem;
    color: #ec4899;
    filter: drop-shadow(0 0 2px rgba(0,0,0,0.8));
    cursor: pointer;
    z-index: 10;
    transition: transform 0.1s;
}
.card-fav-overlay:active {
    transform: scale(1.2);
}
.card-fav-overlay i {
    /* 白フチをつける */
    text-shadow: 0 0 2px #000;
}

/* スライダー操作系 */
.level-slider-container {
    background: #0f172a;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #334155;
    margin-bottom: 10px;
}
.level-control-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.level-slider {
    flex: 1;
    cursor: pointer;
    padding: 10px 0; /* タップ領域確保 */
}
.level-display {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--primary);
    min-width: 50px;
    text-align: right;
}

.search-clear-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 5px;
    display: none; /* 入力がない時は非表示 */
}
.search-clear-btn:hover {
    color: #fff;
}

/* 図鑑(database)以外のビューでは、ヘッダー内のツール群と下部トレイを非表示にする */
body:not([data-view="database"]) .header-tools,
body:not([data-view="database"]) #compareTray {
    display: none !important;
}

/* MyCardsモーダル用: 右上の閉じるボタンを消す */
#cardDetailModal.mycards-mode .btn-close {
    display: none !important;
}

/* --- Phase 4: 一括操作モード --- */

/* 選択モード時のカードスタイル */
body[data-select-mode="true"] .db-card {
    cursor: pointer;
}
/* 選択されたカード */
.db-card.bulk-selected {
    border: 2px solid var(--primary) !important;
    box-shadow: 0 0 8px var(--primary), inset 0 0 10px rgba(0, 242, 255, 0.3);
    position: relative;
}
/* 選択チェックマーク */
.db-card.bulk-selected::after {
    content: "\f00c"; /* FontAwesome Check */
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    color: var(--primary);
    text-shadow: 0 0 5px #000;
    pointer-events: none;
    z-index: 10;
}

/* 一括操作バー (下部固定) */
.bulk-action-bar {
    position: fixed; bottom: 0; left: 0; width: 100%;
    background: #1e293b; border-top: 1px solid var(--primary);
    padding: 10px 15px; box-sizing: border-box;
    display: none; /* 初期非表示 */
    align-items: center; justify-content: space-between;
    z-index: 2000; /* トレイより上 */
    box-shadow: 0 -5px 15px rgba(0,0,0,0.5);
}
.bulk-action-bar.active {
    display: flex;
}
.bulk-info {
    font-weight: bold; color: var(--primary); font-size: 0.9rem;
}
.bulk-tools {
    display: flex; gap: 8px;
}

/* --- v1.1 追加スタイル --- */

/* 3.1. ターゲット選択ボタン */
.tag-selector-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 5px;
}
.tag-btn-select {
    border: 1px solid #475569;
    background: #1e293b;
    color: #94a3b8;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: 0.2s;
}
.tag-btn-select:hover {
    background: #334155;
    color: #fff;
}
/* 選択状態: スキルは黄色系、アビリティは紫系 */
.tag-btn-select.selected-skill {
    background: var(--skill);
    color: #000;
    border-color: var(--skill);
    font-weight: bold;
}
.tag-btn-select.selected-ability {
    background: var(--ability);
    color: #fff;
    border-color: var(--ability);
    font-weight: bold;
}

/* 5. シミュレータ カードスロット (画像表示対応) */
.slot-active {
    position: relative;
    padding: 0 !important; /* 内側のpaddingをリセット */
    overflow: hidden;
    border: 2px solid var(--primary) !important;
}
.slot-bg-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.6; /* 少し暗くする */
}
.slot-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
    padding: 20px 2px 2px 2px;
    color: #fff;
    font-size: 0.65rem;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.slot-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.7);
    color: #fbbf24;
    font-size: 0.6rem;
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid #fbbf24;
}

/* 2.2. 一括レベル変更モーダル用 */
.bulk-level-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    padding: 20px;
}
.bulk-val-display {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary);
}

/* --- v1.2 シミュレータUI改修 --- */

/* 1. スロットコンテナ: 6枚横並び対応 */
#simSlots {
    display: grid !important;
    /* 6列固定。画面が狭い場合はスクロールさせる */
    grid-template-columns: repeat(6, minmax(70px, 1fr)) !important;
    gap: 6px;
    margin-bottom: 20px;
    overflow-x: auto; /* 横スクロール有効化 */
    padding-bottom: 5px; /* スクロールバーの干渉防止 */
}

/* 2. スロット個別の形状: 縦長カード型(3:4)にする */
.slot-active, .slot-empty {
    height: auto !important; /* 固定高さを解除 */
    aspect-ratio: 3 / 4;     /* 縦横比を固定 */
    border-radius: 6px;
    position: relative;
    /* フレックス配置の設定（空スロットの文字中央寄せ用） */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* 空スロットのデザイン調整 */
.slot-empty {
    border: 2px dashed #444;
    font-size: 0.7rem;
    color: #666;
    background: rgba(0, 0, 0, 0.2);
}

/* 3. カード選択モーダル(Picker)のグリッド調整 */
/* --- v1.2.1 修正スタイル (カード選択モーダル用) --- */

/* --- v1.2.1 修正スタイル (カード選択モーダル用) --- */

/* グリッドコンテナ */
#simPickerGrid {
    display: grid;
    /* カード幅を固定気味にして配置 */
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)) !important;
    gap: 10px;
    padding: 15px;
    align-content: start; /* 上詰め */
}

/* カード枠: 縦横比を強制固定し、Flexを解除 */
#simPickerGrid .db-card {
    position: relative !important;
    display: block !important; /* Flex解除 */
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 3 / 4 !important; /* 比率固定 */
    border: 1px solid #555;
    border-radius: 6px;
    overflow: hidden;
    background: #000;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    margin: 0 !important; /* 余計なマージン排除 */
}

/* 画像: 枠に対して絶対配置で全域を埋める */
#simPickerGrid .db-card-img {
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    border: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    z-index: 1;
}

/* 情報テキスト: 画像の上に重ねる */
#simPickerGrid .db-info {
    position: absolute !important;
    bottom: 0;
    left: 0;
    width: 100%;
    /* 文字が見やすいようにグラデーション背景 */
    background: linear-gradient(to top, rgba(0,0,0,0.95) 0%, rgba(0,0,0,0.6) 60%, transparent 100%) !important;
    padding: 20px 4px 4px 4px !important;
    box-sizing: border-box;
    z-index: 2;
    display: block !important;
}

/* 名前テキスト調整 */
#simPickerGrid .db-name {
    font-size: 0.65rem !important;
    font-weight: bold;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    margin-bottom: 2px;
}

/* レベル表示などの微調整 */
#simPickerGrid .db-info > div:last-child {
    font-size: 0.6rem;
    color: #fbbf24; /* 金色 */
    text-shadow: 0 1px 2px black;
    line-height: 1;
}

/* --- v1.3 シミュレータ選択モード時の表示制御 --- */

/* 選択モード中は特定のUIを非表示にしてブロックする */
body[data-sim-selecting="true"] #btnDrawer,            /* ハンバーガー */
body[data-sim-selecting="true"] .mode-switch-container,/* モード切替 */
body[data-sim-selecting="true"] #btnSelectMode,        /* 一括選択 */
body[data-sim-selecting="true"] #btnFilterOpen,        /* フィルタ */
body[data-sim-selecting="true"] #compareTray           /* 比較トレイ */
{
    display: none !important;
}

/* キャンセルボタンを表示 */
body[data-sim-selecting="true"] #btnSimCancel {
    display: block !important;
}

/* 念のためドロワー操作も無効化 (オーバーレイクリック等) */
body[data-sim-selecting="true"] .drawer-overlay {
    pointer-events: none;
}

/* --- Admin改修用スタイル --- */

/* カード編集エリア */
.admin-editor-container {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.card-preview-area {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
    border: 1px dashed #444;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    min-height: 200px;
    position: relative;
}

.card-preview-img {
    max-width: 150px;
    max-height: 200px;
    object-fit: contain;
    border: 1px solid #555;
    border-radius: 6px;
}

.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid var(--primary);
    color: var(--primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: 0.2s;
}
.nav-btn:hover { background: var(--primary); color: #000; }
.nav-btn.prev { left: -10px; }
.nav-btn.next { right: -10px; }

/* 管理画面 カードリスト(グリッド) */
.admin-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
    margin-top: 15px;
}
.admin-card-item {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}
.admin-card-thumb {
    width: 100%;
    aspect-ratio: 3/4;
    object-fit: cover;
    background: #000;
}
.admin-card-tools {
    display: flex;
    padding: 5px;
    gap: 5px;
    background: rgba(0,0,0,0.8);
    position: absolute;
    bottom: 0;
    width: 100%;
    box-sizing: border-box;
}

/* スキル/アビリティ管理 */
.sa-editor-row {
    margin-bottom: 8px;
}
.sa-type-badge {
    display: inline-block;
    padding: 2px 6px;
    font-size: 0.65rem;
    border-radius: 4px;
    margin-right: 5px;
    border: 1px solid #555;
    color: #fff;
}
.sa-gold { background: linear-gradient(135deg, #fbbf24, #d97706); border-color: #fbbf24; color:#000; text-shadow: none; }
.sa-silver { background: linear-gradient(135deg, #e2e8f0, #94a3b8); border-color: #cbd5e1; color:#000; text-shadow: none; }
.sa-bronze { background: linear-gradient(135deg, #b45309, #78350f); border-color: #d97706; color:#fff; }

.warning-icon {
    color: #ef4444;
    font-size: 0.8rem;
    margin-left: 5px;
    animation: flash 2s infinite;
}
@keyframes flash { 0%,100%{opacity:1;} 50%{opacity:0.5;} }

.param-input-group {
    display: grid;
    grid-template-columns: 1fr repeat(5, 1fr) 30px;
    gap: 3px;
    align-items: center;
    margin-bottom: 5px;
    background: #1e293b;
    padding: 5px;
    border-radius: 4px;
}
.param-input-group input {
    text-align: center;
    padding: 4px 0;
    font-size: 0.7rem;
}
.param-header {
    display: grid;
    grid-template-columns: 1fr repeat(5, 1fr) 30px;
    gap: 3px;
    font-size: 0.65rem;
    color: #94a3b8;
    text-align: center;
    margin-bottom: 2px;
}

.cond-btn-group {
    display: flex;
    gap: 5px;
    margin-top: 5px;
}
.cond-select-btn {
    flex: 1;
    background: #0f172a;
    border: 1px solid #334155;
    color: #94a3b8;
    padding: 8px 0;
    font-size: 0.7rem;
    cursor: pointer;
    border-radius: 4px;
}
.cond-select-btn.active {
    background: var(--ability);
    color: #fff;
    border-color: var(--ability);
    font-weight: bold;
}

/* レアリティバッジ (共通) */
.sa-badge {
    display: inline-block;
    padding: 2px 6px;
    font-size: 0.65rem;
    border-radius: 4px;
    margin-right: 4px;
    border: 1px solid #555;
    font-weight: bold;
    text-shadow: none;
}
.sa-rainbow { background: linear-gradient(135deg, #ef4444, #f59e0b, #10b981, #06b6d4, #8b5cf6); border-color: #f43f5e; color:#fff; text-shadow: 0 0 2px #000; }
.sa-gold { background: linear-gradient(135deg, #fbbf24, #d97706); border-color: #fbbf24; color:#000; }
.sa-silver { background: linear-gradient(135deg, #e2e8f0, #94a3b8); border-color: #cbd5e1; color:#000; }
.sa-bronze { background: linear-gradient(135deg, #b45309, #78350f); border-color: #d97706; color:#fff; }

.bd-rainbow { border-left-color: #ec4899; }
.bd-gold { border-left-color: #fbbf24; }
.bd-silver { border-left-color: #cbd5e1; }
.bd-bronze { border-left-color: #d97706; }

.skill-tag-chip.bd-rainbow { border-color: #ec4899; color: #f472b6; background: rgba(236, 72, 153, 0.15); }
/* 詳細モーダル内のスキルリスト */
.modal-skill-row {
    display: flex;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid #334155;
    cursor: pointer;
    transition: background 0.2s;
}
.modal-skill-row:hover {
    background: rgba(255, 255, 255, 0.05);
}
.modal-skill-lv {
    font-size: 0.7rem;
    color: var(--primary);
    margin-left: 5px;
    font-weight: bold;
}

/* スキル詳細モーダル (saModal) 用 */
.sa-modal-param-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px dashed #333;
    font-size: 0.85rem;
}
.sa-modal-val {
    font-weight: bold;
    color: var(--primary);
}

/* --- Admin: スキルセレクター用 --- */
.skill-selector-container {
    position: relative;
    width: 100%;
}

.skill-search-input {
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
    background: #0f172a;
    border: 1px solid #334155;
    color: #fff;
    border-radius: 4px;
}

.skill-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    max-height: 200px;
    overflow-y: auto;
    background: #1e293b;
    border: 1px solid #475569;
    border-radius: 0 0 4px 4px;
    z-index: 1000;
    display: none; /* JSで制御 */
    box-shadow: 0 4px 6px rgba(0,0,0,0.5);
}

.skill-suggestion-item {
    padding: 8px;
    border-bottom: 1px solid #334155;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
}
.skill-suggestion-item:hover {
    background: rgba(0, 242, 255, 0.1);
}

/* 選択済みスキルタグリスト */
.linked-skills-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 8px;
}

.linked-skill-tag {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: #0f172a;
    border-radius: 4px;
    border-left-width: 4px;
    border-left-style: solid;
}

/* レアリティ別の色定義 (既存クラスと統一感を持たせる) */
.bd-gold { border-left-color: #fbbf24; }
.bd-silver { border-left-color: #cbd5e1; }
.bd-bronze { border-left-color: #d97706; }

.remove-skill-btn {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1rem;
    padding: 0 5px;
}
.remove-skill-btn:hover { color: #ff0000; }

/* --- v1.4 追加スタイル --- */

/* シミュレータ: セレクターとスロットの間隔 */
#selectionArea {
    margin-bottom: 25px; /* 行間を広げる */
}

/* 一括選択モード中はヘッダーのモード切替を無効化するスタイル */
body[data-select-mode="true"] .mode-switch-container {
    opacity: 0.3;
    pointer-events: none;
}

/* --- Phase 5: Native App Feel Adjustments --- */

/* 全要素でタップ時のハイライト色を透明にする */
* {
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

/* テキスト選択の無効化 (アプリっぽくするため) */
body {
    -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none;   /* Safari */
    -khtml-user-select: none;    /* Konqueror HTML */
    -moz-user-select: none;      /* Firefox */
    -ms-user-select: none;       /* Internet Explorer/Edge */
    user-select: none;           /* Non-prefixed version */
}

/* 入力フォーム内のテキストは選択可能にする */
input, textarea, [contenteditable="true"] {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* ボタンを押したときのアニメーション効果（青枠の代わり） */
.btn:active, .icon-btn:active, .chk-btn label:active, .drawer-item:active {
    opacity: 0.7;
    transform: scale(0.98);
}

/* チェックボックス付きラベルの挙動調整 */
.chk-btn label {
    touch-action: manipulation; /* ダブルタップズームの防止 */
}

/* --- Phase 6: UI Improvements --- */

/* Skill Tags in List View */
.skill-tag-container {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none; /* Firefox */
    padding-bottom: 2px;
}
.skill-tag-container::-webkit-scrollbar { 
    display: none; /* Chrome/Safari */
}
.skill-tag-chip {
    display: inline-flex;
    align-items: center;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    background: #0f172a;
    border: 1px solid #444;
    color: #ccc;
    flex-shrink: 0;
}
.skill-tag-chip.bd-gold { border-color: #fbbf24; color: #fbbf24; background: rgba(251, 191, 36, 0.1); }
.skill-tag-chip.bd-silver { border-color: #cbd5e1; color: #cbd5e1; background: rgba(203, 213, 225, 0.1); }
.skill-tag-chip.bd-bronze { border-color: #d97706; color: #d97706; background: rgba(217, 119, 6, 0.1); }

.skill-type-icon {
    font-weight: bold;
    margin-right: 4px;
    font-size: 0.6rem;
    width: 12px;
    text-align: center;
    display: inline-block;
}
.type-S { color: var(--skill); }
.type-A { color: var(--ability); }

/* Simulator Mode Selector */
.sim-mode-group {
    display: flex;
    background: #000;
    border-radius: 8px;
    border: 1px solid #334155;
    padding: 3px;
    margin-top: 5px;
}
.sim-mode-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: #64748b;
    padding: 8px 0;
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: 6px;
    transition: 0.2s;
    font-weight: bold;
}
.sim-mode-btn.active {
    background: var(--primary);
    color: #000;
    box-shadow: 0 0 5px rgba(0, 242, 255, 0.3);
}

/* Result Progress Bars */
.res-row {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    font-size: 0.75rem;
}
.res-name { width: 70px; color: #ccc; }
.res-val { width: 45px; text-align: right; font-weight: bold; margin-right: 8px; }
.res-bar-container {
    flex: 1;
    height: 6px;
    background: #333;
    border-radius: 3px;
    /* overflow: hidden; はみ出し描画のため削除 */
    position: relative;
    margin-right: 8px;
}
.res-bar-target-marker {
    position: absolute;
    top: -2px;
    bottom: -2px;
    width: 2px;
    background-color: #fbbf24; /* 金色の目印 */
    z-index: 10;
}
.res-bar-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.5s ease;
}
.res-bar-fill.overflow { background: #ef4444; } /* あふれ */
.res-bar-fill.complete { background: #22c55e; } /* 完了 */
.res-remain { width: 50px; text-align: right; font-size: 0.7rem; color: #94a3b8; }

.res-summary {
    background: rgba(0, 242, 255, 0.1);
    border: 1px solid var(--primary);
    border-radius: 6px;
    padding: 8px;
    margin-bottom: 10px;
    text-align: center;
}
.res-sum-title { font-size: 0.7rem; color: var(--primary); margin-bottom: 2px; }
.res-sum-val { font-size: 1.2rem; font-weight: bold; color: #fff; }
.res-sum-sub { font-size: 0.7rem; color: #aaa; }

/* Custom Weight Modal */
.cw-row {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    background: #1e293b;
    padding: 8px;
    border-radius: 6px;
}
.cw-rank {
    width: 30px;
    font-weight: bold;
    color: var(--primary);
}
.cw-select {
    flex: 1;
    background: #000;
    border: 1px solid #334155;
    color: #fff;
    padding: 5px;
    border-radius: 4px;
}

/* --- Phase 7: Mobile Sim Layout --- */

/* 共通：スマホ用の新規要素はPCでは非表示 */
.sim-mobile-toggle,
.inline-stat-res,
.mobile-target-btn-container,
.sim-nav-btn {
    display: none;
}

/* スマホ表示時における画面全体の横揺れ（スクロール）防止 */
html, body {
    overflow-x: hidden;
    position: relative;
    max-width: 100%;
}

@media (max-width: 768px) {
    /* 共通スマホ表示 */
    .sim-mobile-toggle {
        display: flex !important;
    }
    
    /* PC用の実行ボタンを消す */
    .pc-only-btn {
        display: none !important;
    }

    #simConfigRow, #simResultsRow {
        display: flex !important;
        flex-direction: column;
        gap: 15px;
    }

    /* ------------------------------------- */
    /* ステータス入力欄 (グリッド) の最適化  */
    /* ------------------------------------- */
    .stat-item {
        padding: 3px !important;
    }
    .stat-item label {
        font-size: 0.55rem !important; /* 省略せず表示できるサイズに限界まで縮小 */
        letter-spacing: -0.05em;
        white-space: nowrap;
        overflow: visible !important;
        text-overflow: clip !important;
        margin-bottom: 2px !important;
        display: block;
        text-align: center;
    }
    .stat-input-row {
        flex-direction: column !important; /* 枠の潰れ防止のため常に縦並び */
        gap: 1px !important;
    }
    .stat-input-row input {
        padding: 1px !important;
        font-size: 0.65rem !important;
        text-align: center;
        height: 20px;
    }
    
    /* ------------------------------------- */
    /* 手動モード (Manual)                   */
    /* ------------------------------------- */
    body[data-mobile-sim="manual"] #simPolicy { display: none !important; }
    body[data-mobile-sim="manual"] #simTargets { display: none !important; }
    body[data-mobile-sim="manual"] .mobile-target-btn-container { display: none !important; }
    body[data-mobile-sim="manual"] #btnMobileAutoRun { display: none !important; }
    /* totalResults の非表示を解除し、メーターを見せる */
    
    /* 手動モード結果のインライン表示サイズ調整 */
    .inline-stat-res {
        flex-direction: column;
        align-items: center;
        font-size: 0.6rem;
        line-height: 1.1;
        margin-top: 3px !important;
        gap: 1px;
    }

    /* Flex Order を用いた並び替え (手動モード) */
    body[data-mobile-sim="manual"] #simSliderContainer {
        display: flex;
        flex-direction: column;
        width: 100%;
        transform: none !important; /* スライドを無効化 */
    }
    body[data-mobile-sim="manual"] .sim-pane { display: contents; width: 100%; }
    
    body[data-mobile-sim="manual"] #simPlayerInfo { order: 1; margin-bottom:15px; }
    body[data-mobile-sim="manual"] #simConfigRow { order: 2; }
    body[data-mobile-sim="manual"] #simSlotsContainer { order: 3; }
    body[data-mobile-sim="manual"] #simResultsRow { order: 4; }

    /* ------------------------------------- */
    /* 自動モード (Auto) スライダー          */
    /* ------------------------------------- */
    /* .sim-pane の中にいる時だけ非表示にする（モーダル内に移動したら表示される） */
    body[data-mobile-sim="auto"] .sim-pane #simTargets { display: none !important; }
    body[data-mobile-sim="auto"] .mobile-target-btn-container { display: block !important; }
    body[data-mobile-sim="auto"] #btnMobileAutoRun { display: block !important; width: 100%; }
    
    /* 左右スライドコンテナ (幅200%で画面2枚分確保) */
    body[data-mobile-sim="auto"] #simSliderContainer {
        display: flex;
        width: 200%;
        transition: transform 0.3s ease;
    }
    body[data-mobile-sim="auto"] .sim-pane {
        width: 50%; /* 親の200%に対する50% = 画面幅100% */
        padding: 0 10px; 
        box-sizing: border-box;
    }
    
    /* スライド状態 (左へ50% = 1画面分移動) */
    body[data-mobile-sim="auto"].sim-slide-right #simSliderContainer {
        transform: translateX(-50%);
    }

    /* ナビゲーションボタン */
    body[data-mobile-sim="auto"] .sim-nav-btn {
        position: fixed;
        top: 50%;
        transform: translateY(-50%);
        width: 45px;
        height: 45px;
        background: rgba(0, 0, 0, 0.7);
        border: 2px solid var(--primary);
        color: var(--primary);
        border-radius: 50%;
        display: flex !important;
        align-items: center;
        justify-content: center;
        z-index: 100;
        backdrop-filter: blur(2px);
        font-size: 1.2rem;
    }
    body[data-mobile-sim="auto"] #simNavLeft { left: 5px; }
    body[data-mobile-sim="auto"] #simNavRight { right: 5px; }
    
    /* 状態に応じたナビボタン非表示制御 */
    body[data-mobile-sim="auto"]:not(.sim-slide-right) #simNavLeft { display: none !important; }
    body[data-mobile-sim="auto"].sim-slide-right #simNavRight { display: none !important; }
    
    /* 結果がない場合はRightボタンを隠す */
    body[data-mobile-sim="auto"].sim-no-result #simNavRight { display: none !important; }
}

/* 自動モード結果専用モーダル ボーナスハイライト */
.bonus-highlight {
    background: rgba(34, 197, 94, 0.2);
    border: 1px solid var(--accent);
    color: #fff;
    font-weight: bold;
}
.bonus-inactive {
    opacity: 0.5;
    filter: grayscale(1);
    border: 1px solid #333;
}

/* トグルスイッチ */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 18px;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #334155;
    transition: .2s;
    border-radius: 18px;
}
.toggle-slider:before {
    position: absolute;
    content: "";
    height: 14px; width: 14px;
    left: 2px; bottom: 2px;
    background-color: white;
    transition: .2s;
    border-radius: 50%;
}
input:checked + .toggle-slider {
    background-color: var(--primary);
}
input:checked + .toggle-slider:before {
    transform: translateX(16px);
}
input:disabled + .toggle-slider {
    cursor: not-allowed;
}

/* シミュレータスロットのクリアボタン */
.slot-clear-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(239, 68, 68, 0.9);
    color: #fff;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 0 3px #000;
}

/* シミュレータ結果表示の幅調整 */
.res-name { width: 100px !important; }
.res-val { width: 35px !important; }
.res-remain { width: 45px !important; }

/* --- 詳細モーダル 順位レイアウト用 --- */
.modal-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    padding: 3px 4px;
    border-radius: 3px;
    border: 1px solid transparent;
}
.modal-stat-val-wrap {
    display: flex;
    align-items: center;
}
.modal-stat-rank {
    margin-left: 8px;
    font-size: 0.65rem;
    color: #fbbf24;
}

@media (max-width: 768px) {
    .modal-stat-row {
        flex-direction: column;
        align-items: stretch;
    }
    .modal-stat-row > div:first-child {
        margin-bottom: 2px;
    }
    .modal-stat-val-wrap {
        justify-content: space-between;
    }
    .modal-stat-rank {
        margin-left: 0;
    }
}

/* --- モバイル比較テーブルUIの圧縮調整（改） --- */
@media (max-width: 768px) {
    .comp-table {
        table-layout: fixed;
        width: 100%;
    }
    /* 1列目（項目名）は狭く、2・3列目（カード）で等分 */
    .comp-table th:first-child, .comp-table td:first-child {
        width: 25% !important;
        min-width: 0 !important;
        padding-left: 2px !important;
        font-size: 0.65rem;
        white-space: normal;
        word-break: break-all;
    }
    .comp-table th, .comp-table td {
        width: 37.5% !important;
        padding: 4px 2px !important;
        white-space: normal;
        word-break: break-word;
    }
    .comp-card-header img {
        width: 40px;
        height: 52px;
    }
}

/* 画像出力時専用の表示クラス */
.export-only {
    display: none;
}

/* --- Admin 管理画面用UI調整 --- */
.edit-stat-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
    margin-top: 10px;
}
.edit-stat-grid .stat-item {
    background: #0f172a;
    padding: 2px;
    border-radius: 4px;
    text-align: center;
}
.edit-stat-grid label {
    font-size: 0.6rem;
    color: #94a3b8;
    display: block;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.edit-stat-grid input {
    font-size: 0.75rem;
    padding: 4px 0;
    text-align: center;
    width: 100%;
    box-sizing: border-box;
}

@media (max-width: 768px) {
    .edit-stat-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* 矢印ボタンを画像領域の内側に配置 */
.card-preview-area .nav-btn.prev { left: 10px; }
.card-preview-area .nav-btn.next { right: 10px; }

/* 管理画面用ボタングループ */
.admin-pos-btn {
    background: #1e293b; border: 1px solid #475569; color: #94a3b8;
    padding: 6px 0; border-radius: 4px; font-size: 0.7rem; cursor: pointer;
}
.admin-pos-btn.active {
    background: var(--primary); color: #000; border-color: var(--primary); font-weight: bold;
}/* --- .chk-btn ボタン内チェックボックス視認性向上 --- */

.chk-btn {
    position: relative;
    flex: 1;
    min-width: 0;
}

.chk-btn input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.chk-btn label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 8px 4px;
    background: #1e293b;
    border: 1px solid #475569;
    border-radius: 6px;
    font-size: 0.75rem;
    color: #94a3b8;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
    user-select: none;
    white-space: nowrap;
    box-sizing: border-box;
}

/* チェックボックスアイコン (未チェック時: 空の四角枠) */
.chk-btn label::before {
    content: "";
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 1px solid #64748b;
    border-radius: 3px;
    margin-right: 5px;
    background: rgba(0, 0, 0, 0.4);
    flex-shrink: 0;
    transition: all 0.2s ease;
}

/* チェックON時: チェックマーク付きの枠 */
.chk-btn input:checked + label {
    background: var(--primary);
    color: #000;
    border-color: var(--primary);
    font-weight: bold;
    box-shadow: 0 0 8px rgba(0, 242, 255, 0.4);
}

.chk-btn input:checked + label::before {
    content: "\f00c"; /* FontAwesome check mark */
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    font-size: 0.65rem;
    color: var(--primary);
    background: #000;
    border-color: #000;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* パラメータ選択（緑色）時のアイコン調整 */
.chk-btn.param input:checked + label {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.4);
}

.chk-btn.param input:checked + label::before {
    color: var(--accent);
    background: #000;
    border-color: #000;
}

/* 7列パラメータ表示用のアイコンサイズ微調整 */
.filter-grid-params .chk-btn label::before {
    width: 10px;
    height: 10px;
    font-size: 0.55rem;
    margin-right: 2px;
}

/* --- 必須スキル/アビ選択モーダルのレイアウト最適化 --- */
.tag-selector-container {
    max-height: 38vh; /* パネル閉じ時はゆったり大きく表示 */
    overflow-y: auto;
    padding: 6px;
    border: 1px solid #334155;
    border-radius: 6px;
    background: #0f172a;
    transition: max-height 0.2s ease;
}

/* 絞り込みパネルが開いている時のコンパクト表示 */
.tag-selector-container.compact-view {
    max-height: 95px;
}

/* ボタンの余白と文字サイズを最適化して1行に入る数を増加 */
.tag-selector-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px !important;
}

.tag-selector-grid .tag-btn-select {
    padding: 4px 8px !important;
    font-size: 0.72rem !important;
    border-radius: 12px !important;
}

/* --- 必須スキル/アビ選択モーダルの外枠・レイアウト最適化 --- */
#simTargetModal .modal-content {
    overflow: hidden !important; /* ボタンのはみ出しを防止 */
    height: auto !important;
    max-height: 85vh;
    border-radius: 10px;
}

#simTargetModal .modal-body {
    padding: 10px 12px !important;
    overflow-y: auto;
    flex: 1 1 auto; /* 中身に合わせて伸縮 */
}

/* 候補エリア：囲み枠と背景を削除 */
.tag-selector-container {
    max-height: 40vh;
    overflow-y: auto;
    padding: 2px 0;
    border: none !important; /* 枠線を削除 */
    background: transparent !important; /* 背景色を削除 */
    transition: max-height 0.2s ease;
}

/* 絞り込みパネル開いている時の高さ調整 */
.tag-selector-container.compact-view {
    max-height: 120px;
}

/* タグボタンの配置 */
.tag-selector-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 5px !important;
}

.tag-selector-grid .tag-btn-select {
    padding: 4px 8px !important;
    font-size: 0.72rem !important;
    border-radius: 12px !important;
}
/* --- 必須スキル/アビ選択モーダルの外枠・レイアウト最適化 --- */
#simTargetModal .modal-content {
    overflow: hidden !important; /* ボタンのはみ出しを防止 */
    height: auto !important;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    border-radius: 10px;
}

#simTargetModal .modal-body {
    padding: 10px 12px !important;
    overflow-y: auto;
    flex: 1 1 auto; /* 中身に合わせて伸縮 */
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* 絞り込みパネルの高さ制限 */
#simSaFilterPanel {
    max-height: 35vh;
    overflow-y: auto;
    flex-shrink: 0;
}

/* タブコンテンツ */
#simTargetSkillTabContent,
#simTargetAbilityTabContent {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* 候補エリア：囲み枠と背景を削除し、親の高さに柔軟フィット */
.tag-selector-container {
    flex: 1;
    min-height: 80px;
    max-height: none !important; /* 固定上限を解除して領域全体を埋める */
    overflow-y: auto;
    padding: 2px 0;
    border: none !important; /* 枠線を削除 */
    background: transparent !important; /* 背景色を削除 */
    transition: none;
}

.tag-selector-container.compact-view {
    max-height: none !important;
}

/* タグボタンの配置 */
.tag-selector-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 5px !important;
}

.tag-selector-grid .tag-btn-select {
    padding: 4px 8px !important;
    font-size: 0.72rem !important;
    border-radius: 12px !important;
}

/* --- 絞り込みパネルのアニメーション設定 --- */
#simSaFilterPanel {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
    background: #0f172a;
    border-bottom: 0px solid var(--primary);
    flex-shrink: 0;
    box-sizing: border-box;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.25s ease,
                padding 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                border-bottom-width 0.35s ease;
}

/* パネル開（アニメーション到達状態） */
#simSaFilterPanel.open {
    max-height: 35vh;
    opacity: 1;
    padding-top: 10px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary);
    overflow-y: auto;
}

/* タブコンテンツとスキル容器のアニメーション連動 */
#simTargetSkillTabContent,
#simTargetAbilityTabContent {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.tag-selector-container {
    flex: 1;
    min-height: 80px;
    max-height: none !important;
    overflow-y: auto;
    padding: 2px 0;
    border: none !important;
    background: transparent !important;
    transition: flex 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 管理画面 スキル編集用ボタンチップ */
.sa-btn-chip {
    background: #1e293b;
    border: 1px solid #475569;
    color: #94a3b8;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.72rem;
    cursor: pointer;
    transition: all 0.2s;
}
.sa-btn-chip.active {
    background: var(--primary);
    color: #000;
    border-color: var(--primary);
    font-weight: bold;
    box-shadow: 0 0 6px rgba(0, 242, 255, 0.4);
}

/* MyCardsモーダル用: 右上の閉じるボタンの非表示ルールを解除（表示させる） */
#cardDetailModal.mycards-mode .btn-close {
    display: block !important;
}

/* --- 管理画面 レアリティボタンのアクティブ時カラー定義 --- */
.sa-btn-chip[data-group="saRarity"].active[data-val="Rainbow"],
.sa-btn-chip[data-group="saAbilityRarity"].active[data-val="Rainbow"] {
    background: linear-gradient(135deg, #ef4444, #f59e0b, #10b981, #06b6d4, #8b5cf6) !important;
    color: #fff !important;
    border-color: #f43f5e !important;
    font-weight: bold;
}

.sa-btn-chip[data-group="saRarity"].active[data-val="Gold"],
.sa-btn-chip[data-group="saAbilityRarity"].active[data-val="Gold"] {
    background: #d97706 !important;
    color: #fff !important;
    border-color: #fbbf24 !important;
    font-weight: bold;
}

.sa-btn-chip[data-group="saRarity"].active[data-val="Silver"],
.sa-btn-chip[data-group="saAbilityRarity"].active[data-val="Silver"] {
    background: #64748b !important;
    color: #fff !important;
    border-color: #cbd5e1 !important;
    font-weight: bold;
}

.sa-btn-chip[data-group="saRarity"].active[data-val="Bronze"],
.sa-btn-chip[data-group="saAbilityRarity"].active[data-val="Bronze"] {
    background: #78350f !important;
    color: #fff !important;
    border-color: #d97706 !important;
    font-weight: bold;
}