/* marble-run-builder style.css */

.builder-layout {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 1000px;
    margin: 0 auto;
}

@media (min-width: 768px) {
    .builder-layout {
        flex-direction: column;
    }
}

/* Palette Panel */
.palette-panel {
    background: rgba(30, 41, 59, 0.85); /* 半透過のみ（blurなし） */
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    position: sticky;
    bottom: 10px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1.5rem;
}

.palette-panel.unpinned {
    position: relative;
}

.palette-title {
    display: none;
}

.parts-grid {
    display: grid;
    grid-template-columns: repeat(11, 1fr);
    gap: 0.4rem;
    margin-bottom: 0;
    width: 60%;
    margin: 0;
}

.part-btn {
    background: var(--background-color);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    width: 100%;
    min-width: 40px;
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    padding: 0.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-sizing: border-box;
    color: #cbd5e1;
}

.bounce-btn {
    background: rgba(30, 41, 59, 0.8);
    border: 2px solid #b45309;
    color: #fcd34d;
    border-radius: 8px;
    width: 100%;
    min-width: 40px;
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    padding: 0.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.glass-btn {
    background: rgba(30, 41, 59, 0.8);
    border: 2px solid #0284c7;
    color: #38bdf8;
    border-radius: 8px;
    width: 100%;
    min-width: 40px;
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    padding: 0.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-sizing: border-box;
}


.part-label {
    font-size: 0.55rem;
    color: #94a3b8;
    line-height: 1;
    white-space: nowrap;
    transform: scale(0.9);
}

.part-btn:hover {
    background: #1e293b;
    border-color: #94a3b8;
    transform: translateY(-2px);
}

.bounce-btn:hover {
    background: rgba(30, 41, 59, 1);
    transform: translateY(-2px);
}

.glass-btn:hover {
    background: rgba(30, 41, 59, 1);
    transform: translateY(-2px);
}

.part-btn.active {
    background: #1e293b;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.bounce-btn.active {
    border-color: #ea580c;
    color: #f97316;
    box-shadow: 0 0 0 2px rgba(234, 88, 12, 0.3);
}

.glass-btn.active {
    border-color: #0284c7;
    color: #0ea5e9;
    box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.3);
}

.part-btn.active .part-label {
    color: #3b82f6;
}

.control-actions {
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
    flex: 1;
    justify-content: flex-end;
}

.control-actions button {
    padding: 0 1rem;
    height: 42px;
    font-size: 0.95rem;
    font-weight: 700;
    border-radius: 8px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* Icons for parts */
.part-icon {
    width: 90%;
    height: 100%;
    position: relative;
    overflow: hidden;
    border-radius: 2px;
}

.part-floor::after {
    content: '';
    position: absolute;
    background: var(--part-color, #475569);
    height: 25%;
    width: 100%;
    top: 70%;
    left: 0;
    transform: scale(0.8);
}

.part-ramp::after, .part-ramp-right::after {
    content: '';
    position: absolute;
    width: 160%;
    height: 25%;
    background: var(--part-color, #475569);
    top: 35%;
    left: -30%;
    transform: rotate(45deg) scale(0.7);
}

.part-curve::after, .part-curve-right::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: radial-gradient(circle farthest-side at 100% 0%, transparent 75%, var(--part-color, #475569) 75%, var(--part-color, #475569) 100%, transparent 100%);
    transform: scale(0.8);
}

.part-block {
    background: var(--part-color, #475569);
    width: 100%; height: 100%;
}

.part-blackhole {
    width: 80%; height: 80%; margin: 10%;
    border-radius: 50%;
    background: radial-gradient(circle at center, #000 40%, #4c1d95 80%, rgba(76, 29, 149, 0.4) 100%);
    box-shadow: 0 0 12px #8b5cf6, inset 0 0 8px #000;
}

.part-warp {
    width: 70%; height: 70%; margin: 15%;
    background: linear-gradient(135deg, #e879f9 0%, #a855f7 50%, #7e22ce 100%);
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
    animation: spinY 2.5s infinite linear;
}

@keyframes spinY {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(360deg); }
}

.part-ball {
    width: 60%; height: 60%; margin: 20%;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #60a5fa, #2563eb);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Bounce Mode Styles */
.bounce-mode .part-icon {
    --part-color: #f59e0b; /* トランポリンの色 */
}

/* Glass Mode Styles */
.glass-mode .part-icon {
    --part-color: #38bdf8; /* ガラスの色 */
}

/* Bounce + Glass Mode Styles */
.bounce-mode.glass-mode .part-icon {
    --part-color: #22c55e; /* バウンス＋ガラスの中間色（グリーン） */
}

.part-blackhole::after {
    content: ''; position: absolute;
    width: 100%; height: 100%; border-radius: 50%;
    border: 2px dashed rgba(139, 92, 246, 0.5);
    top: -2px; left: -2px;
}

@keyframes spin-bh {
    0% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(180deg) scale(0.9); }
    100% { transform: rotate(360deg) scale(1); }
}

.part-block {
    width: 100%; height: 100%;
    background-color: var(--part-color, #94a3b8);
}

/* Canvas Panel */
.canvas-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#canvas-container {
    background: #0f172a; /* Dark background for the physics world */
    border-radius: 16px;
    border: 2px solid var(--border-color);
    overflow: hidden;
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
    touch-action: none; /* Prevent scrolling when drawing on touch devices */
}

#canvas-container canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

/* Grid Overlay for Editing Mode */
#grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto; /* Catch clicks for placing blocks */
    background-size: calc(100% / 20) calc(100% / 15);
    --current-grid-alpha: var(--grid-opacity, 0.3);
    background-image:
      linear-gradient(to right, rgba(255,255,255, var(--current-grid-alpha)) 1px, transparent 1px),
      linear-gradient(to bottom, rgba(255,255,255, var(--current-grid-alpha)) 1px, transparent 1px);
    z-index: 10;
}

/* Start Zone Indicator */
#grid-overlay::before {
    content: 'START';
    position: absolute;
    top: 0;
    left: calc(100% / 20);
    width: calc(100% / 20);
    height: calc(100% / 15);
    background: rgba(239, 68, 68, 0.2);
    border: 1px dashed #ef4444;
    color: #ef4444;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Palette Playing State */
/* (Removed to allow changing tools during play) */

/* Ghost Part for Hover Preview */
#ghost-part {
    position: absolute;
    width: calc(100% / 20);
    height: calc(100% / 15);
    pointer-events: none;
    z-index: 10;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 1;
}

#ghost-part.glass-mode #ghost-icon {
    border: 2px solid #38bdf8 !important;
    background-color: rgba(56, 189, 248, 0.15) !important;
    border-radius: 4px;
}
#ghost-icon {
    pointer-events: none;
}

.playing #grid-overlay::before {
    display: none;
}

.canvas-instructions {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 12px;
    font-size: 0.9rem;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

/* Layout classes for tool panel */
.play-controls {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
}

.play-controls-row {
    display: contents;
}

.spawn-settings-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    font-size: 0.85rem;
    color: #cbd5e1;
    background: rgba(15, 23, 42, 0.5);
    padding: 0 0.5rem;
    border-radius: 6px;
    border: 1px solid #334155;
    white-space: nowrap;
    height: 42px;
    box-sizing: border-box;
}

.spawn-settings-wrapper input[type="text"] {
    background: transparent;
    border: none;
    color: #fff;
    text-align: right;
    border-bottom: 1px solid #475569;
    padding: 0;
    outline: none;
    height: 2em;
}

#spawn-interval-input {
    width: 2.5rem;
    margin: 0;
}

#spawn-count-input {
    width: 2rem;
    margin: 0 0 0 0.25rem;
}

.save-settings-blocks {
    display: flex;
    flex-wrap: nowrap;
    gap: 1.5rem;
    align-items: stretch;
    overflow-x: auto;
    overflow-y: hidden;
    justify-content: center;
    padding-bottom: 4px;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .palette-panel {
        position: relative !important;
        bottom: auto !important;
    }
    #btn-pin {
        display: none !important;
    }
    .parts-grid {
        grid-template-columns: repeat(10, 1fr) !important;
        width: 100% !important;
        gap: 0.15rem;
    }
    .part-btn, .bounce-btn, .glass-btn {
        min-width: 0 !important;
        padding: 0.1rem !important;
        border-width: 1px !important;
        border-radius: 4px !important;
    }
    .part-label {
        font-size: 0.5rem !important;
        transform: scale(0.85);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: clip;
        max-width: 100%;
        margin-top: 0.1rem;
    }
    .spacer-mobile-hide {
        display: none !important;
    }
    .play-controls {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }
    .play-controls-row {
        display: flex;
        gap: 0.5rem;
        width: 100%;
        justify-content: space-between;
    }
    .play-controls-row button, .spawn-settings-wrapper {
        flex: 1;
        justify-content: center;
    }
    .save-settings-blocks {
        flex-direction: column !important;
        gap: 1rem !important;
    }
}
