/* =================================================================
 * Page Specific Styles for Bento Grid Generator (style.css)
 * ================================================================= */

/* --- 右カラム追従 (Sticky) 設定 --- */
.tool-results-sticky {
    position: -webkit-sticky;
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}
.tool-results-sticky::-webkit-scrollbar { width: 6px; }
.tool-results-sticky::-webkit-scrollbar-thumb { background: rgba(150,150,150,0.3); border-radius: 4px; }

/* --- プレビューエリア (Bento Grid) --- */
#preview-container {
    background-color: #f8f9fa;
    border-radius: 8px;
    transition: background-color 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    min-height: 450px;
}

#bento-preview {
    display: grid;
    width: 100%;
    aspect-ratio: 16 / 10;
    max-width: 600px;
    max-height: 500px;
    transition: gap 0.2s ease, padding 0.2s ease;
    position: relative; /* ガイドラインとハンドルの基準点 */
}

/* 空きマスをクリックできることを視覚的に伝える */
#preview-container:not(.view-mobile) #bento-preview:hover {
    cursor: crosshair;
}
#preview-container:not(.view-mobile) #bento-preview:hover::before {
    opacity: 0.6; /* ホバー時にガイドラインを少し濃くする */
}

/* 個別の弁当箱（アイテム） */
.bento-item {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.5rem;
    cursor: grab; /* 掴めることを明示 */
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s ease, border-color 0.2s;
    border: 1px solid rgba(130, 130, 130, 0.2);
    box-shadow: var(--bs-box-shadow-sm);
    user-select: none;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    position: relative; /* リサイズハンドルとデリートボタンを枠内に留めるため必須 */
}

.bento-item:active {
    cursor: grabbing; /* 掴んでいる最中のカーソル */
}

.bento-item:hover {
    transform: translateY(-2px) scale(1.01);
    box-shadow: var(--bs-box-shadow);
    border-color: rgba(130, 130, 130, 0.4);
}

/* 選択中のアイテム */
.bento-item.selected {
    border-color: var(--bs-primary) !important;
    box-shadow: 0 0 0 4px rgba(var(--bs-primary-rgb), 0.25) !important;
    color: var(--bs-primary) !important;
    z-index: 10;
}

/* 個別デリートボタン */
.item-delete-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background-color: rgba(var(--bs-danger-rgb), 0.85);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 10;
}

.bento-item:hover .item-delete-btn {
    opacity: 1;
}

.item-delete-btn:hover {
    background-color: var(--bs-danger);
    transform: scale(1.15);
}

/* --- 出力エリア --- */
.code-output { 
    font-family: 'Fira Code', 'Cascadia Code', 'Courier New', monospace; 
    font-size: 0.9rem; 
    resize: none; 
    background-color: var(--bs-tertiary-bg); 
    color: var(--bs-emphasis-color);
    white-space: pre; 
    overflow-x: auto; 
    border-color: var(--bs-border-color-translucent);
    line-height: 1.5;
}

/* --- 履歴＆プリセットボタン --- */
.history-btn-wrapper { position: relative; display: inline-block; }
.history-delete-btn {
    position: absolute; top: -6px; right: -6px; width: 18px; height: 18px;
    background: var(--bs-danger); color: white; border-radius: 50%; font-size: 10px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; border: 2px solid var(--bs-body-bg); opacity: 0; transition: opacity 0.2s;
}
.history-btn-wrapper:hover .history-delete-btn { opacity: 1; }

.preset-btn {
    width: 44px; height: 44px; border-radius: 0.375rem; border: 2px solid transparent;
    cursor: pointer; padding: 0; transition: border-color 0.2s; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.preset-btn:hover { 
    border-color: var(--bs-primary); 
    transform: translateY(-2px);
}

/* --- フローティング保存ボタン --- */
.floating-save-btn {
    position: fixed !important;
    bottom: 30px !important;
    right: 30px !important;
    width: 60px !important;
    height: 60px !important;
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50% !important;
    padding: 0 !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.floating-save-btn:hover {
    transform: scale(1.05) translateY(-3px);
    box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.3) !important;
}

/* --- フォームパーツの視認性向上 --- */
.form-label { font-size: 0.95rem; margin-bottom: 0.5rem; }
.form-range::-webkit-slider-thumb { width: 1.25rem; height: 1.25rem; background: var(--bs-primary); border: 2px solid var(--bs-body-bg); }
.form-range::-webkit-slider-runnable-track { background-color: var(--bs-border-color-translucent); height: 8px; border-radius: 4px; }
.form-control-color { cursor: pointer; height: 38px; border-radius: 0.375rem; }
.badge.bg-secondary-subtle { font-size: 0.85rem !important; font-weight: 600; padding: 0.4em 0.75em; border: 1px solid var(--bs-border-color-translucent); }

/* --- ドラッグ＆ドロップ関連 --- */

/* ドラッグ中のスタイル */
.bento-item.dragging {
    opacity: 0.6;
    z-index: 1000;
    pointer-events: none; /* ドラッグ中に下の要素を検知させるため */
}

/* ドロップ先のターゲット（重なった時） */
.bento-item.drop-target {
    outline: 4px dashed var(--bs-primary);
    outline-offset: -4px;
    background-color: rgba(var(--bs-primary-rgb), 0.1) !important;
    transform: scale(0.98);
}

/* リサイズハンドル */
.resizer-handle {
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 14px;
    height: 14px;
    background: var(--bs-primary);
    clip-path: polygon(100% 0, 100% 100%, 0 100%);
    border-radius: 0 0 2px 0;
    cursor: nwse-resize;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 5;
}

.bento-item:hover .resizer-handle,
.bento-item.selected .resizer-handle {
    opacity: 0.8;
}

.resizer-handle:hover {
    opacity: 1 !important;
    transform: scale(1.2);
}

/* 空きマスのガイド表示 */
#bento-preview::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(var(--bs-border-color-translucent) 1px, transparent 1px),
        linear-gradient(90deg, var(--bs-border-color-translucent) 1px, transparent 1px);
    background-size: 
        calc((100% + var(--grid-gap, 16px)) / var(--grid-cols, 4)) 
        calc((100% + var(--grid-gap, 16px)) / var(--grid-rows, 3));
    pointer-events: none;
    opacity: 0.3;
}

/* 空きマスのプレースホルダー（追加予告UI） */
#empty-placeholder {
    position: absolute;
    border: 2px dashed rgba(var(--bs-primary-rgb), 0.5);
    background-color: rgba(var(--bs-primary-rgb), 0.05);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(var(--bs-primary-rgb), 0.6);
    font-size: 2rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease, top 0.1s ease-out, left 0.1s ease-out;
    z-index: 1;
}

/* --- デバイス別プレビュー幅の制御 --- */
#preview-container.view-tablet #bento-preview {
    max-width: 480px; /* タブレット想定の幅 */
}

#preview-container.view-mobile #bento-preview {
    max-width: 320px; /* スマホ想定の幅 */
    aspect-ratio: auto; /* 縦長になるため解除 */
}

#preview-container.view-mobile #bento-preview .bento-item {
    grid-column: span 1 !important;
    grid-row: span 1 !important;
    aspect-ratio: 1 / 1; 
}

/* --- コンテンツ・シミュレーター用 --- */
.bento-content-text {
    width: 100%;
    height: 100%;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: left;
    pointer-events: none; /* ドラッグ操作を妨害しない */
    box-sizing: border-box;
}

.bento-dummy-title {
    font-size: 1.25rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

.bento-dummy-text {
    font-size: 0.85rem;
    opacity: 0.8;
    margin: 0;
    line-height: 1.5;
    /* 3行でリーダー（...）にする */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* コンテンツがある時の左上の小さな番号バッジ */
.bento-num-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.4);
    color: #ffffff !important;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: normal;
    pointer-events: none;
    z-index: 2;
    backdrop-filter: blur(4px);
}