:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg-color: #f3f4f6;
    --panel-bg: rgba(255, 255, 255, 0.85);
    --text-color: #1f2937;
    --border-radius: 16px;
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    background: linear-gradient(135deg, #e0e7ff 0%, #dbeafe 100%);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.app-container {
    width: 95vw;
    max-width: 1200px;
    height: 95vh;
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    flex-wrap: wrap;
    gap: 10px;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.progress-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
}

.progress-bar {
    width: 150px;
    height: 10px;
    background: #e5e7eb;
    border-radius: 5px;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    width: 0%;
    background: var(--primary);
    transition: width 0.3s ease;
}

button.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

button.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

button.btn-secondary {
    background: #e2e8f0;
    color: #475569;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
button.btn-secondary:hover {
    background: #cbd5e1;
    transform: translateY(-2px);
}

.timer {
    font-family: monospace;
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--primary);
    background: #fff;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.left-panel {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    position: relative;
    background: rgba(255, 255, 255, 0.4);
}

.map-wrapper {
    position: relative;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 374.675 / 355.999;
}

.map-bg {
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0.7; /* Made darker as requested */
    pointer-events: none;
    filter: drop-shadow(0 4px 10px rgba(0,0,0,0.1));
}

#drop-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.right-panel {
    width: 320px;
    background: rgba(255, 255, 255, 0.7);
    border-left: 1px solid rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
}

.tray-header {
    padding: 1rem;
    font-weight: 600;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    text-align: center;
    background: rgba(0,0,0,0.02);
}

.tray {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 15px;
    align-content: start;
    transition: opacity 0.3s;
}
.tray.disabled {
    opacity: 0.3;
    pointer-events: none;
    filter: grayscale(1);
}

.piece {
    position: relative;
    cursor: grab;
    transition: transform 0.2s, filter 0.2s;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.2));
    width: 100%;
    height: auto;
    user-select: none;
    touch-action: none; /* For mobile support later */
    object-fit: contain;
    max-height: 80px;
}

.piece:hover {
    transform: scale(1.1);
    filter: drop-shadow(4px 4px 8px rgba(0,0,0,0.3));
    z-index: 10;
}

.piece:active, .piece.dragging {
    cursor: grabbing;
    transform: scale(1.15);
    filter: drop-shadow(8px 8px 15px rgba(0,0,0,0.4));
    opacity: 0.9;
    z-index: 100;
    max-height: none;
}

.piece.placed {
    position: absolute;
    cursor: default;
    pointer-events: none;
    max-height: none;
    /* Apply hue-rotate to turn green into light blue */
    filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.3)) hue-rotate(60deg) saturate(1.2) brightness(1.1);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    animation: place-pop 0.4s ease-out forwards;
}

@keyframes place-pop {
    0% { transform: scale(1.2); filter: drop-shadow(4px 4px 8px rgba(0,0,0,0.3)) hue-rotate(60deg) saturate(1.2) brightness(1.5); }
    50% { transform: scale(0.95); }
    100% { transform: scale(1); filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.3)) hue-rotate(60deg) saturate(1.2) brightness(1.1); }
}

/* Modal */
.hidden { display: none !important; }
#celebration {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fade-in 0.5s;
}

.celebration-content {
    background: white;
    padding: 3rem 4rem;
    border-radius: var(--border-radius);
    text-align: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    transform: scale(0);
    animation: pop-in 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.celebration-content h2 {
    color: var(--primary);
    margin-bottom: 0.5rem;
    font-size: 2rem;
}

.final-time {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 1.5rem;
    color: #475569;
}

.kusudama {
    font-size: 5rem;
    margin-bottom: 1rem;
    animation: swing 2s ease-in-out infinite alternate;
    transform-origin: top center;
}

@keyframes swing {
    0% { transform: rotate(-10deg); }
    100% { transform: rotate(10deg); }
}

#drag-label {
    position: fixed;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: bold;
    z-index: 2000;
    white-space: nowrap;
    transform: translate(-50%, -150%);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { to { transform: scale(1); } }

/* Responsive adjustments */
@media (max-width: 768px) {
    body {
        align-items: stretch;
    }
    .app-container { 
        width: 100vw; 
        height: 100vh;
        max-width: none;
        max-height: none;
        border-radius: 0;
    }
    header {
        padding: 0.8rem;
    }
    h1 {
        font-size: 1.2rem;
        width: 100%;
        text-align: center;
        margin-bottom: 5px;
    }
    .controls {
        width: 100%;
        justify-content: center;
        gap: 0.5rem;
    }
    button.btn-primary, button.btn-secondary {
        padding: 0.5rem 0.8rem;
        font-size: 0.85rem;
    }
    main { 
        flex-direction: column; 
    }
    .left-panel {
        padding: 0.5rem;
        flex: 1.5; /* Give map more space */
    }
    .right-panel { 
        width: 100%; 
        flex: 1; /* Tray gets rest of space */
        border-left: none; 
        border-top: 2px solid rgba(0,0,0,0.1); 
    }
    .map-wrapper { 
        max-height: 100%; 
        width: 100%;
    }
    .tray {
        grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
        gap: 10px;
        padding: 0.5rem;
    }
}
