* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

/* スマホファースト: 最大幅480px、PCでは中央配置 */
.container {
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
}

header {
    text-align: center;
    color: white;
    margin-bottom: 20px;
}

header h1 {
    font-size: 1.8em;
    margin-bottom: 8px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.subtitle {
    font-size: 0.95em;
    opacity: 0.9;
}

.main-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 20px;
}

/* プレビューエリア（箱のようなデザイン） */
.preview-container {
    background: white;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.preview-box {
    position: relative;
    width: 100%;
    aspect-ratio: 9 / 16; /* 縦長のアスペクト比 */
    max-height: 800px;
    background: #f0f0f0;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 
        inset 0 0 20px rgba(0, 0, 0, 0.1),
        0 5px 15px rgba(0, 0, 0, 0.3);
    margin-bottom: 15px;
}

.layer-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden; /* 視差効果で移動した際の空白を防ぐ */
}

.layer {
    position: absolute;
    /* レイヤーを拡大して、画像の余白部分も表示できるようにする */
    width: 150%; /* 画像の拡大率に合わせる */
    height: 150%;
    top: -25%; /* 中央配置（150% - 100% = 50% / 2 = 25%） */
    left: -25%;
    will-change: transform;
    transition: transform 0.1s ease-out;
    overflow: visible; /* 画像の余白部分も表示 */
}

.layer img {
    width: 100%; /* レイヤーサイズに合わせる（150%のレイヤー内で100%） */
    height: 100%;
    object-fit: cover;
    object-position: center; /* 中央配置 */
    position: absolute;
    top: 0;
    left: 0;
}

/* レイヤーのZ-index設定 */
.background-layer {
    z-index: 1;
    pointer-events: none;
}

.character-layer {
    z-index: 2;
    pointer-events: auto;
}

.foreground-layer {
    z-index: 3;
    pointer-events: auto; /* デフォルトは有効（パララックス効果のため） */
    transition: pointer-events 0s; /* 即座に切り替え */
    /* 前景は視差効果が最大（1.0）なので、より大きな拡大率が必要 */
    width: 200%; /* 前景は200%に拡大（他のレイヤーは150%） */
    height: 200%;
    top: -50%; /* 中央配置（200% - 100% = 100% / 2 = 50%） */
    left: -50%;
}

/* キャラクター操作時は前景レイヤーを無効化 */
.character-layer.active ~ .foreground-layer,
.foreground-layer.editing-disabled {
    pointer-events: none !important;
}

#characterCanvas {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: auto;
}

/* 視差効果ON/OFFスイッチ */
.parallax-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 28px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #667eea;
}

input:checked + .slider:before {
    transform: translateX(22px);
}

.toggle-label {
    font-weight: bold;
    color: #333;
    font-size: 0.9em;
}

/* アセット選択ボタン */
.asset-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.asset-button {
    flex: 1;
    padding: 12px;
    background: white;
    border: 2px solid #667eea;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: bold;
    color: #667eea;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.asset-button:hover,
.asset-button:active {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.button-icon {
    font-size: 1.5em;
}

.button-text {
    font-size: 0.85em;
}

/* キャラクターコントロール */
.character-controls {
    margin-top: 15px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 8px;
}

.control-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.control-buttons button {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    transition: all 0.3s;
    flex: 1;
    min-width: 80px;
}

.toggle-button {
    background: #667eea;
    color: white;
}

.toggle-button:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.toggle-button.hidden {
    background: #48bb78;
}

.toggle-button.hidden:hover {
    background: #38a169;
}

.select-button {
    background: #48bb78;
    color: white;
}

.select-button:hover {
    background: #38a169;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(72, 187, 120, 0.3);
}

#deleteCharacter {
    background: #f56565;
    color: white;
}

#deleteCharacter:hover {
    background: #e53e3e;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(245, 101, 101, 0.3);
}

.control-hint {
    font-size: 0.85em;
    color: #667eea;
    margin-bottom: 12px;
    padding: 8px;
    background: #e8f0fe;
    border-radius: 5px;
    border-left: 3px solid #667eea;
}

.character-controls label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    font-size: 0.9em;
}

.character-controls input[type="range"] {
    flex: 1;
}

/* モーダルオーバーレイ */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.modal-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 20px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #eee;
}

.modal-header h2 {
    font-size: 1.3em;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2em;
    color: #666;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s;
}

.modal-close:hover {
    background: #f0f0f0;
    color: #333;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.asset-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.asset-item {
    position: relative;
    aspect-ratio: 1;
    border: 2px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s;
    background: #f9f9f9;
}

.asset-item:hover,
.asset-item:active {
    border-color: #667eea;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.asset-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.asset-item.selected {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

/* エクスポートセクション */
.export-section {
    text-align: center;
    background: white;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.export-button {
    padding: 15px 30px;
    font-size: 1.1em;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transition: all 0.3s;
    font-weight: bold;
    width: 100%;
}

.export-button:hover,
.export-button:active {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.export-note {
    margin-top: 12px;
    color: #666;
    font-size: 0.85em;
}

/* アニメーション */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* PC対応: コンテナを中央配置し、背景色が見えるように */
@media (min-width: 768px) {
    .container {
        max-width: 480px;
    }
    
    body {
        padding: 40px 20px;
    }
    
    .preview-box {
        max-height: 800px;
    }
    
    .asset-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* タブレット以上 */
@media (min-width: 1024px) {
    .asset-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* 小さなスマホ */
@media (max-width: 360px) {
    .container {
        padding: 0 10px;
    }
    
    header h1 {
        font-size: 1.5em;
    }
    
    .preview-container {
        padding: 15px;
    }
    
    .asset-buttons {
        gap: 8px;
    }
    
    .asset-button {
        padding: 10px;
        font-size: 0.8em;
    }
    
    .button-icon {
        font-size: 1.3em;
    }
}
