/* Sandbox / Terrarium Mode Styles */

/* Title screen sandbox button */
.btn-sandbox-title {
    background: var(--purple);
    box-shadow: 0 4px 0 var(--purple, #8B52B8), 0 6px 20px rgba(0,0,0,0.3);
}
.btn-sandbox-title:hover {
    box-shadow: 0 6px 0 #8B52B8, 0 8px 25px rgba(0,0,0,0.3);
}

/* Layout */
.sandbox-layout {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    overflow: hidden;
}

/* Header */
.sandbox-header {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.sandbox-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text);
}

.sandbox-mode-label {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--yellow);
    background: rgba(255, 217, 61, 0.15);
    padding: 3px 14px;
    border-radius: 20px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.sandbox-creature-count {
    margin-left: auto;
    font-family: 'Fredoka', sans-serif;
    font-size: 1rem;
    color: var(--text-muted);
}

/* Main area: scene + rules panel */
.sandbox-main {
    flex: 1;
    display: flex;
    gap: 8px;
    min-height: 0;
    overflow: hidden;
}

/* Scene */
.sandbox-scene {
    flex: 1;
    position: relative;
    overflow: hidden;
    border-radius: 16px;
    border: 3px solid rgba(255,255,255,0.12);
    background:
        linear-gradient(180deg,
            #87CEEB 0%,
            #B0E2FF 35%,
            #90D26D 35.5%,
            #7BC758 50%,
            #6AB847 65%,
            #5FA840 100%
        );
    box-shadow: inset 0 0 30px rgba(0,0,0,0.08);
    cursor: default;
}

/* Grass detail overlay */
.sandbox-scene::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 15%;
    background: linear-gradient(180deg, transparent, rgba(80, 50, 20, 0.25));
    pointer-events: none;
}

/* Creatures in scene */
.sandbox-creature {
    position: absolute;
    width: 60px;
    height: 60px;
    object-fit: contain;
    cursor: pointer;
    border-radius: 12px;
    transition: box-shadow 0.15s;
    z-index: 1;
    touch-action: none;
}

.sandbox-creature.selected {
    box-shadow: 0 0 0 3px var(--yellow), 0 0 15px rgba(255, 217, 61, 0.5);
    z-index: 2;
}

.sandbox-creature.sleeping {
    opacity: 0.5;
}

/* Food items */
.sandbox-food {
    position: absolute;
    font-size: 24px;
    cursor: pointer;
    z-index: 1;
    user-select: none;
}

.sandbox-food.consumed {
    display: none;
}

/* Rules panel */
.sandbox-rules-panel {
    width: 270px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    border: 2px solid rgba(255,255,255,0.08);
}

.rules-panel-header h3 {
    font-size: 1.2rem;
    color: var(--text);
    text-align: center;
    margin-bottom: 2px;
}

.rules-hint {
    font-size: 0.8rem;
    color: var(--blue);
    text-align: center;
}

.rules-creature-name {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.85rem;
    color: var(--yellow);
    text-align: center;
    min-height: 1.2em;
}

/* Rule slots */
.rules-slots {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rule-slot {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(255,255,255,0.04);
    padding: 6px 8px;
    border-radius: 10px;
}

.rule-num {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-muted);
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.rule-arrow {
    color: var(--text-muted);
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* Drop zones */
.card-dropzone {
    flex: 1;
    min-height: 40px;
    min-width: 85px;
    border: 2px dashed rgba(255,255,255,0.2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, background 0.15s;
    position: relative;
}

.rule-if-zone {
    background: rgba(255, 159, 67, 0.08);
    border-color: rgba(255, 159, 67, 0.3);
}

.rule-then-zone {
    background: rgba(126, 217, 87, 0.08);
    border-color: rgba(126, 217, 87, 0.3);
}

.card-dropzone.drag-over {
    border-color: var(--yellow);
    background: rgba(255, 217, 61, 0.15);
}

.dropzone-label {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
    color: rgba(255,255,255,0.25);
    text-transform: uppercase;
    letter-spacing: 1px;
    pointer-events: none;
}

/* Placed card in dropzone */
.placed-card {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    padding: 2px 4px;
}

.placed-card .card-text {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
    color: white;
    flex: 1;
}

.placed-card .card-remove {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    padding: 2px;
    line-height: 1;
}

.placed-card .card-remove:hover {
    color: var(--red);
}

.placed-card-if { color: var(--orange); }
.placed-card-then { color: var(--green); }

/* Card trays */
.card-tray-section {
    flex-shrink: 0;
}

.card-tray-label {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 4px;
}

#if-cards-tray + .card-tray-label,
.card-tray-section:first-of-type .card-tray-label {
    color: var(--orange);
}

.card-tray-section:last-of-type .card-tray-label {
    color: var(--green);
}

.card-tray-items {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    touch-action: none;
}

/* Rule cards */
.rule-card {
    padding: 4px 8px;
    border-radius: 6px;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.68rem;
    font-weight: 600;
    cursor: grab;
    user-select: none;
    white-space: nowrap;
    transition: transform 0.1s, box-shadow 0.1s;
    touch-action: none;
}

.rule-card:hover {
    transform: scale(1.08);
}

.rule-card.card-selected {
    transform: scale(1.12);
    box-shadow: 0 0 0 2px var(--yellow), 0 0 12px rgba(255, 217, 61, 0.4);
    z-index: 1;
}

.card-dropzone.drop-ready {
    border-color: var(--yellow);
    border-style: solid;
    background: rgba(255, 217, 61, 0.12);
    animation: dropPulse 1s ease-in-out infinite;
}

.card-dropzone.drag-over {
    border-color: var(--yellow);
    border-style: solid;
    background: rgba(255, 217, 61, 0.25);
    animation: none;
    box-shadow: 0 0 12px rgba(255, 217, 61, 0.4);
}

@keyframes dropPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 217, 61, 0); }
    50% { box-shadow: 0 0 8px 2px rgba(255, 217, 61, 0.3); }
}

.if-card {
    background: rgba(255, 159, 67, 0.2);
    color: var(--orange);
    border: 1.5px solid rgba(255, 159, 67, 0.4);
}

.then-card {
    background: rgba(126, 217, 87, 0.2);
    color: var(--green);
    border: 1.5px solid rgba(126, 217, 87, 0.4);
}

/* Bottom area: tray + controls */
.sandbox-bottom {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Creature tray */
.sandbox-tray {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: rgba(255,255,255,0.06);
    border-radius: 12px;
    overflow-x: auto;
    border: 2px solid rgba(255,255,255,0.08);
}

.tray-label {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.tray-item {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 10px;
    background: rgba(255,255,255,0.08);
    padding: 3px;
    cursor: grab;
    transition: transform 0.15s;
    position: relative;
    touch-action: none;
}

.tray-item:hover {
    transform: scale(1.15);
}

.tray-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    border-radius: 8px;
}

.tray-item-name {
    position: absolute;
    bottom: -14px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.55rem;
    color: var(--text-muted);
    white-space: nowrap;
    display: none;
}

.tray-item:hover .tray-item-name {
    display: block;
}

.tray-food {
    background: rgba(255, 107, 107, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

/* Controls */
.sandbox-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.sandbox-playback {
    display: flex;
    gap: 6px;
}

.sandbox-btn {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    padding: 8px 16px;
    cursor: pointer;
    color: white;
    transition: transform 0.1s, opacity 0.15s;
}

.sandbox-btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

.sandbox-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.sandbox-btn-play { background: var(--green); }
.sandbox-btn-pause { background: var(--orange); }
.sandbox-btn-reset { background: var(--blue); }
.sandbox-btn-clear {
    background: var(--red);
    margin-left: auto;
}

/* Save/Load buttons */
.sandbox-saveload {
    display: flex;
    gap: 6px;
}

.sandbox-btn-save { background: var(--purple); }
.sandbox-btn-load { background: var(--yellow); color: #333; }

/* Save/Load toast notification */
.sandbox-toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    font-family: 'Fredoka', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    color: white;
    background: var(--purple);
    padding: 10px 24px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 9999;
}

.sandbox-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.sandbox-toast.error {
    background: var(--red);
}

/* Speed buttons */
.sandbox-speed {
    display: flex;
    align-items: center;
    gap: 4px;
}

.speed-label {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-right: 2px;
}

.speed-btn {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(255,255,255,0.08);
    color: var(--text-muted);
    border: 1.5px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.speed-btn.active {
    background: var(--purple);
    color: white;
    border-color: var(--purple);
}

.speed-btn:hover:not(.active) {
    background: rgba(255,255,255,0.12);
}

/* Drag ghost (follows pointer during drag) */
.drag-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.85;
    transform: scale(1.1);
}

.drag-ghost img {
    width: 60px;
    height: 60px;
    object-fit: contain;
}

.card-drag-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    padding: 4px 10px;
    border-radius: 6px;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 0.9;
}

.card-drag-ghost.if-card {
    background: var(--orange);
    color: white;
}

.card-drag-ghost.then-card {
    background: var(--green);
    color: white;
}

/* Sleeping zzz */
.sandbox-creature.sleeping::after {
    content: 'zzz';
    position: absolute;
    top: -8px;
    right: -4px;
    font-size: 0.6rem;
    color: var(--blue);
    font-weight: 700;
    animation: zzz 1.5s ease-in-out infinite;
}

@keyframes zzz {
    0%, 100% { transform: translateY(0); opacity: 0.5; }
    50% { transform: translateY(-6px); opacity: 1; }
}

/* Responsive */
@media (max-width: 768px) {
    .sandbox-main {
        flex-direction: column;
    }

    .sandbox-rules-panel {
        width: 100%;
        max-height: 220px;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
    }

    .rules-panel-header {
        width: 100%;
    }

    .rules-slots {
        flex: 1;
        min-width: 200px;
    }

    .card-tray-section {
        flex: 1;
        min-width: 140px;
    }

    .sandbox-controls {
        justify-content: center;
    }

    .sandbox-btn-clear {
        margin-left: 0;
    }
}

@media (max-width: 500px) {
    .sandbox-header {
        gap: 6px;
    }

    .sandbox-title {
        font-size: 1rem;
    }

    .sandbox-rules-panel {
        max-height: 180px;
        padding: 6px;
    }

    .tray-item {
        width: 40px;
        height: 40px;
    }

    .sandbox-btn {
        font-size: 0.75rem;
        padding: 6px 12px;
    }
}
