/* Deck Builder Specific Styles */

#deck-builder-view {
    display: none;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    background-color: #1a1a1a;
    color: #fff;
    overflow: hidden;
    position: relative;
}

/* --- Header --- */
.builder-header {
    height: var(--header-height);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    background: #222;
    border-bottom: 1px solid #444;
}

.builder-header h2 {
    font-size: 1rem;
    margin: 0;
}

.header-btn {
    padding: 4px 12px;
    border-radius: 4px;
    border: none;
    font-size: 0.8rem;
    font-weight: bold;
    cursor: pointer;
}

.save-btn {
    background-color: var(--primary-color);
    color: white;
}

.home-btn {
    background-color: #444;
    color: white;
}

/* --- Main Layout --- */
.builder-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 1. Upper: Current Deck Area (6列) */
.current-deck-area {
    height: 30%;
    /* 少し狭めて詳細エリアに譲る */
    display: flex;
    border-bottom: 1px solid #333;
    background: #252525;
}

.deck-list-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.deck-sort-bar {
    height: 24px;
    background: #333;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 8px;
    gap: 4px;
    border-bottom: 1px solid #444;
}

.mini-select {
    background: #555;
    color: white;
    border: 1px solid #666;
    border-radius: 3px;
    font-size: 0.7rem;
    padding: 1px 4px;
}

.mini-icon-btn {
    background: #555;
    color: white;
    border: 1px solid #666;
    border-radius: 3px;
    width: 20px;
    height: 20px;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.deck-list-scroll {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-auto-rows: min-content;
    gap: 4px;
    padding: 8px;
    overflow-y: auto;
    overflow-x: hidden;
}

.deck-stats {
    width: 90px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: 10px 4px;
    align-items: center;
    background: #333;
    font-size: 0.7rem;
    border-left: 1px solid #444;
}

/* 2. Middle: Detail Area (Sim-like) */
.builder-detail-area {
    height: 25%;
    display: flex;
    background: #151515;
    padding: 8px;
    gap: 12px;
    border-bottom: 1px solid #333;
}

.detail-image-box {
    height: 100%;
    /* ライブカードが横向きでもこのコンテナ幅以上にはならないようにする */
    width: 28%;
    max-width: 120px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
    border-radius: 4px;
    flex-shrink: 0;
}

.detail-image-box img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

/* LiveカードはJSでクラスがつかないが、画像自体が横長なので
   object-fit:contain でコンテナ内に収まる */

.detail-info-box {
    flex: 1;
    overflow-y: auto;
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
}

/* --- deck_builder.css の修正箇所 --- */

/* 1. ヘッダーを「コンテナ」として定義し、中身が縮めるようにする */
.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 1px solid #444;
    padding-bottom: 2px;
    margin-bottom: 2px;

    /* 追加：コンテナクエリを有効化 */
    container-type: inline-size;
    overflow: hidden;
    /* はみ出し防止 */
}

/* 2. カード名のスタイル：改行を禁止し、幅に合わせてフォントを縮小 */
.preview-name {
    font-weight: bold;
    color: var(--primary-color);

    /* 修正：固定サイズではなく、コンテナ幅に応じた可変サイズ（clampで上下限を設定） */
    font-size: clamp(0.7rem, 4.5cqi, 0.9rem);

    white-space: nowrap;
    /* 改行禁止 */
    flex: 1;
    /* 余ったスペースを埋める */
    min-width: 0;
    /* flexアイテムが縮むために必須 */
    margin-right: 5px;
}

/* 3. カード番号（ID）のスタイル：こちらも改行禁止 */
.preview-rarity {
    font-size: 0.7rem;
    color: #aaa;
    white-space: nowrap;
    /* 改行禁止 */
    flex-shrink: 0;
    /* IDはこれ以上縮まないように固定 */
}

.preview-subinfo {
    font-size: 0.7rem;
    color: #888;
    margin-bottom: 2px;
}

.preview-stat-pill {
    background: #333;
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    border: 1px solid #555;
}

.preview-text-box {
    background: #222;
    padding: 4px;
    border-radius: 4px;
    font-size: 0.75rem;
    line-height: 1.3;
    flex: 1;
    overflow-y: auto;
    border: 1px solid #333;
}

.preview-yell-box {
    margin-top: 4px;
    background: #1a1a2e;
    padding: 4px;
    border-radius: 4px;
    border: 1px solid #334;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
}

/* 3. Lower: Library */
.card-library-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #000;
}

.library-filter-bar {
    background: #2a2a2a;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-bottom: 1px solid #444;
}

.filter-row {
    display: flex;
    gap: 4px;
}

.filter-input {
    padding: 4px;
    font-size: 0.8rem;
    background: #111;
    border: 1px solid #444;
    color: white;
    border-radius: 4px;
}

.filter-select {
    flex: 1;
    font-size: 0.7rem;
    background: #333;
    color: white;
    border: 1px solid #555;
    border-radius: 3px;
    padding: 4px 2px;
    min-width: 0;
    /* Flexbox内での縮小許可 */
}

/* --- ライブラリグリッドの修正 --- */
.library-grid {
    flex: 1;
    overflow-y: auto;
    padding: 5px;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    /* 少し広げてタップしやすく */
    /* 追加：カードが少ない時も上詰めにし、高さを維持する */
    align-content: start;
}

/* --- ライブラリアイテムの完全固定（重なり防止版） --- */
.library-item {
    width: 100%;
    cursor: pointer;
    position: relative;
    display: block;
    background: #111;
    border-radius: 3px;
    /* 重要: aspect-ratioではなくpadding-bottomを使うことで、
       中身が浮いていても(absolute)必ず高さを確保します */
    height: 0;
    padding-bottom: 140%;
    /* 縦横比 0.714 (1 / 0.714) */
    overflow: hidden;
}

/* 通常のカード画像（共通設定） */
.library-item img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 3px;
    transition: opacity 0.2s;
}

/* ライブカード専用の回転設定 */
.library-item.live-card img {
    top: 50%;
    left: 50%;
    /* 縦長の枠に対して、横長の画像を回転させてフィットさせるための比率計算 */
    width: 140.06%;
    /* 1 / 0.714 */
    height: 71.39%;
    /* 1 / 1.4 */
    object-fit: fill;
    transform: translate(-50%, -50%) rotate(90deg);
}




/* --- Icons --- */
.icon-blade {
    width: 14px;
    height: 14px;
    vertical-align: middle;
}

.icon-energy {
    width: 14px;
    height: 14px;
    vertical-align: middle;
}

/* CSS Hearts */
.heart-icon {
    display: inline-block;
    width: 12px;
    height: 12px;
    background-color: currentColor;
    mask: url('data:image/svg+xml;utf8,<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"><path d="M16,29 L14.6,27.6 C4.4,18.2 0,13.8 0,8.5 C0,4.2 3.4,0.8 7.7,0.8 C10.2,0.8 12.5,1.9 14,3.7 C15.5,1.9 17.8,0.8 20.3,0.8 C24.6,0.8 28,4.2 28,8.5 C28,13.8 23.6,18.2 13.4,27.6 L12,29 L16,29 Z" /></svg>') no-repeat center / contain;
    -webkit-mask: url('data:image/svg+xml;utf8,<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"><path d="M23.6,0c-3.4,0-6.3,2.5-7.6,5.6C14.7,2.5,11.8,0,8.4,0C3.8,0,0,3.8,0,8.4c0,9.4,16,23.6,16,23.6s16-14.2,16-23.6C32,3.8,28.2,0,23.6,0z"/></svg>') no-repeat center / contain;
    margin: 0 1px;
    vertical-align: middle;
}

.color-pk {
    background-color: #ff69b4;
}

.color-r {
    background-color: #e74c3c;
}

.color-y {
    background-color: #f1c40f;
}

.color-g {
    background-color: #2ecc71;
}

.color-b {
    background-color: #3498db;
}

.color-p {
    background-color: #9b59b6;
}

.color-w {
    background-color: #95a5a6;
}

/* 白/無色はグレーで見やすく */

/* --- Modals --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: #2c2c2c;
    width: 85%;
    max-width: 400px;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    max-height: 80vh;
    overflow-y: auto;
}

/* PC向け: モーダルサイズを適切に制限 */
@media screen and (min-width: 600px) {
    .modal-overlay {
        padding: 20px;
    }

    .modal-content {
        width: 90%;
        max-width: 450px;
    }
}

.modal-title {
    font-size: 1.2rem;
    margin-bottom: 15px;
    text-align: center;
    color: var(--primary-color);
}

.deck-select-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 300px;
    overflow-y: auto;
}

/* デッキアイテムの文字色を白にし、レイアウトを調整 */
.deck-item {
    background: #3a3a3a;
    /* 少し明るめのグレーにして境界を明確に */
    padding: 12px;
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #ffffff !important;
    /* 文字色を強制的に白に固定 */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* 無効化された選択ボタンのスタイルを追記 */
.save-btn:disabled {
    background-color: #555 !important;
    color: #888 !important;
    cursor: not-allowed;
    border: 1px solid #444;
    box-shadow: none;
}


.new-deck-btn {
    width: 100%;
    margin-top: 15px;
    padding: 10px;
    background: var(--accent-color);
    border: none;
    color: white;
    font-weight: bold;
    border-radius: 4px;
}

/* --- 上のデッキエリア(Deckthumb)の共通設定 --- */
.builder-deck-thumb {
    width: 100%;
    cursor: pointer;
    position: relative;
    display: block;
    background: #111;
    border-radius: 2px;
    /* 枠を必ず縦長(140%)に固定する */
    height: 0;
    padding-bottom: 140%;
    overflow: hidden;
}

/* 枠の中の画像の設定 */
.builder-deck-thumb img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ライブカードのみ、画像だけを90度右回転させる */
.builder-deck-thumb.live-card img {
    top: 50%;
    left: 50%;
    /* 縦の枠に横長画像をフィットさせるためのサイズ計算 */
    width: 140.06%;
    height: 71.39%;
    object-fit: fill;
    transform: translate(-50%, -50%) rotate(90deg);
    /* 90度右回転 */
}