#app {
    width: 100%;
    max-width: 600px;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
}

h1 {
    font-weight: 700;
    letter-spacing: 1px;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    position: relative;
    overflow: visible;
    min-height: 0;
}

#game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    flex: 1 1 0;
    min-height: 0;
    justify-content: flex-start;
    padding-top: 10px;
    position: relative;
    overflow: visible;
}

/* Compact mode: target and grid side by side when vertical space is limited */
#game-area.compact {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 15px;
    padding-top: 10px;
}

#game-area.compact #target-wrapper {
    order: 1;
    flex: 0 0 auto;
}

#game-area.compact #box-wrapper {
    order: 2;
    flex: 0 0 auto;
}

/* Ultra-compact mode: tray moves to the right of grid, scrolls vertically */
.ultra-compact main {
    flex-direction: row;
    flex-wrap: nowrap;
    /* Never wrap to horizontal */
    gap: 5px;
    /* Reduced gap */
    align-items: flex-start;
}

.ultra-compact #game-area {
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
    max-height: calc(100vh - 100px);
    /* Prevent cutting off at bottom */
    overflow: visible;
}

/* In ultra-compact, target and grid should always be side-by-side */
.ultra-compact #game-area.compact {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: flex-start;
    justify-content: center;
    gap: 10px;
}

/* Shrink the target more in ultra-compact mode */
.ultra-compact #target-container {
    padding: 10px;
}

.ultra-compact #target-container h2 {
    font-size: 0.7rem;
    margin-bottom: 4px;
}

.ultra-compact #tray-wrapper {
    flex: 0 0 auto;
    width: fit-content;
    /* Fit to content width */
    min-width: min-content;
    /* Ensure pieces are visible */
    max-width: none;
    height: auto;
    max-height: calc(100vh - 120px);
    margin-bottom: 0;
}

.ultra-compact #tray-container {
    flex-direction: column;
    overflow-y: auto;
    overflow-x: visible;
    width: fit-content;
    min-width: min-content;
    max-height: 100%;
    gap: 8px;
    padding: 8px;
    padding-right: 20px;
    /* Extra padding for scrollbar */
    scrollbar-width: thin;
    /* Firefox */
}

/* Webkit scrollbar styling for ultra-compact tray */
.ultra-compact #tray-container::-webkit-scrollbar {
    width: 8px;
}

.ultra-compact #tray-container::-webkit-scrollbar-track {
    background: transparent;
}

.ultra-compact #tray-container::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

/* Hide horizontal scroll hints in ultra-compact, show vertical ones */
.ultra-compact .scroll-hint.left,
.ultra-compact .scroll-hint.right {
    display: none;
}

.ultra-compact .scroll-hint.top,
.ultra-compact .scroll-hint.bottom {
    display: block;
}

/* Pieces in ultra-compact mode should not shrink horizontally */
.ultra-compact .piece {
    flex-shrink: 0;
}

/* Allow vertical scrolling in ultra-compact tray, horizontal drag */
.ultra-compact #tray-container .piece {
    touch-action: pan-y;
}