/* LinkaVel Deck Builder Styles */

/* 全体コンテナ */
#deck-builder-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    background-color: #0a0a0a;
    color: #f0f0f0;
    overflow: hidden;
    position: relative;
    /* セーフエリア対応 */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

/* --- 1. Header Area --- */
.builder-header {
    height: 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    background: #151515;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}

.deck-name-input {
    background: transparent;
    border: none;
    border-bottom: 1px solid #555;
    color: #fff;
    font-size: 1rem;
    width: 140px;
    padding: 4px;
    font-family: inherit;
}
.deck-name-input:focus {
    outline: none;
    border-bottom-color: var(--accent-blue);
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.deck-count-indicator {
    font-size: 0.8rem;
    font-weight: bold;
    color: #888;
}
.deck-count-indicator.valid { color: var(--accent-blue); }
.deck-count-indicator.invalid { color: var(--accent-red); }

.builder-btn {
    padding: 6px 12px;
    border-radius: 4px;
    border: 1px solid #444;
    background: #222;
    color: #fff;
    font-size: 0.75rem;
    cursor: pointer;
}
.builder-btn.save {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #000;
    font-weight: bold;
}
.builder-btn:disabled {
    opacity: 0.5;
    filter: grayscale(1);
}

/* --- 2. Current Deck Area (Top) --- */
.current-deck-area {
    flex: 0 0 25%; /* 画面の25% */
    background: #1a1a1a;
    border-bottom: 1px solid #333;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.deck-stats-bar {
    height: 24px;
    background: #222;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    font-size: 0.7rem;
    color: #aaa;
    border-bottom: 1px solid #333;
}

.deck-grid-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 4px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-auto-rows: max-content;
    gap: 4px;
    align-content: start;
}

/* デッキ内のカード (リッチ表示) */
.deck-thumb {
    position: relative;
    width: 100%;
    height: auto;
    aspect-ratio: 14 / 19;
    cursor: pointer;
    display: flex;
    justify-content: center;
}
.deck-thumb .builder-card {
    width: 100% !important;
    height: 100% !important;
    border-width: 1px !important;
}
.deck-thumb .count-badge {
    position: absolute;
    top: -4px; right: -4px;
    background: var(--accent-blue);
    color: #000;
    font-weight: bold;
    font-size: 0.6rem;
    width: 16px; height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #fff;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* --- 3. Detail Area (Middle) --- */
.builder-detail-area {
    flex: 0 0 20%; /* 画面の20% */
    background: rgba(20, 20, 20, 0.95);
    border-bottom: 1px solid #333;
    display: flex;
    padding: 8px;
    gap: 10px;
    position: relative;
}

/* デュエル画面のスタイルを模倣 */
.detail-img-box {
    flex: 0 0 80px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.detail-img-box img {
    max-width: 100%;
    max-height: 100%;
    border: 1px solid #555;
    border-radius: 4px;
}

.detail-info-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 1px solid #444;
    padding-bottom: 2px;
    margin-bottom: 4px;
}
.detail-name {
    font-weight: bold;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #fff;
}
.detail-attr {
    font-size: 0.7rem;
    color: #aaa;
    margin-left: 8px;
    flex-shrink: 0;
}

.detail-stats {
    display: flex;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--accent-blue);
    font-weight: bold;
    margin-bottom: 4px;
}

.detail-text {
    flex: 1;
    font-size: 0.7rem;
    line-height: 1.3;
    color: #ddd;
    overflow-y: auto;
    white-space: pre-wrap;
    background: rgba(0,0,0,0.3);
    padding: 4px;
    border-radius: 4px;
}

.detail-actions {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    margin-left: 4px;
}

.action-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid #555;
    background: #333;
    color: #fff;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.1s;
}
.action-btn.add { border-color: var(--accent-blue); color: var(--accent-blue); }
.action-btn.remove { border-color: var(--accent-red); color: var(--accent-red); }
.action-btn:active { transform: scale(0.9); background: #444; }

/* --- 4. Library Area (Bottom) --- */
.library-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #000;
    overflow: hidden;
}

.library-filter-bar {
    padding: 6px;
    background: #222;
    border-bottom: 1px solid #333;
    display: flex;
    gap: 6px;
    overflow-x: auto;
}

.filter-select {
    background: #333;
    color: #fff;
    border: 1px solid #555;
    border-radius: 4px;
    font-size: 0.7rem;
    padding: 4px;
}

.library-grid {
    flex: 1;
    overflow-y: auto;
    padding: 4px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    align-content: start;
}

.lib-item {
    position: relative;
    width: 100%;
    /* アスペクト比ハックを解除し、中身のカードに委ねる */
    height: auto;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    border: none;
    display: flex;
    justify-content: center;
}

/* ビルダー用カードスタイルの上書き (マイクロサイズ対応) */
.builder-card.card-mini {
    width: 100% !important;
    height: auto !important;
    max-width: none !important;
    max-height: none !important;
    aspect-ratio: 14 / 19;
    margin: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.5);
    border-width: 1px !important;
}
/* 文字サイズ等の微調整 */
.builder-card .card-name-text { font-size: 8cqi !important; }
.builder-card .card-lv-text { font-size: 12cqi !important; }
.builder-card .card-atk-text { font-size: 14cqi !important; }
.builder-card .card-magic-type { font-size: 10cqi !important; }

.lib-item.selected .builder-card {
    border-color: var(--accent-blue) !important;
    box-shadow: 0 0 10px var(--accent-blue);
    transform: translateY(-2px);
}
/* 所持数バッジ */
.lib-count-badge {
    position: absolute;
    top: -4px; right: -4px;
    background: var(--accent-blue);
    color: #000;
    font-weight: bold;
    font-size: 0.7rem;
    width: 20px; height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.lib-item.max-copy .builder-card {
    filter: grayscale(1) brightness(0.6);
    opacity: 0.7;
}
.lib-item.max-copy {
    opacity: 0.5;
    filter: grayscale(1);
}

/* トースト通知 */
#builder-toast {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 210, 255, 0.9);
    color: #000;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: bold;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 2000;
}
#builder-toast.show { opacity: 1; }

/* デッキ選択リストのカスタムスタイル */
.custom-deck-item {
    border-left: 4px solid var(--accent-blue) !important;
}
.delete-deck-btn {
    background: #444;
    border: none;
    color: #aaa;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    margin-left: 10px;
    cursor: pointer;
}

/* デッキ管理画面用スタイル */
.deck-manage-item {
    background: #222;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.deck-manage-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
    padding-bottom: 6px;
}
.deck-manage-title {
    font-weight: bold;
    color: #fff;
    font-size: 1rem;
}
.deck-manage-tag {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    background: #333;
    color: #aaa;
}
.deck-manage-tag.starter { background: #2c3e50; color: #3498db; }
.deck-manage-tag.user { background: #2c2c2c; color: var(--accent-blue); }

.deck-manage-actions {
    display: flex;
    gap: 8px;
}
.dm-btn {
    flex: 1;
    padding: 8px;
    border: 1px solid #555;
    background: #333;
    color: #fff;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    text-align: center;
}
.dm-btn.primary { background: var(--accent-blue); color: #000; border-color: var(--accent-blue); font-weight: bold; }
.dm-btn.danger { background: #444; color: var(--accent-red); border-color: #555; }
.dm-btn:active { transform: scale(0.98); }