/* Reset and Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, sans-serif;
    background-color: #f5f5f5;
    min-height: 100svh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

/* Container */
.container {
    max-width: 600px;
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: auto;
}

/* Header */
header {
    margin-bottom: 30px;
}

h1 {
    font-size: 2.5rem;
    color: #333;
    margin-bottom: 5px;
}

.subtitle {
    font-size: 1rem;
    color: #666;
    margin-bottom: 15px;
    font-weight: 400;
}

main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Challenge Controls */
.challenge-controls {
    visibility: hidden; /* Hidden but occupies space */
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin: 30px 0; /* Adjusted for consistent spacing */
    padding: 10px 0;
    height: 50px; /* Explicit height to prevent collapse */
}

.challenge-controls.visible {
    visibility: visible; /* Made visible via JS */
}

/* Challenge Button */
.btn-challenge {
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: none;
    align-items: center;
    justify-content: center;
}

.btn-challenge.visible {
    display: flex;
}

.btn-challenge:disabled {
    background-color: #e0e0e0;
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-challenge:not(:disabled):hover {
    background-color: #45a049;
    transform: scale(1.1);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.btn-challenge:not(:disabled):active {
    transform: scale(0.95);
}

.btn-challenge.active {
    background-color: #FF6B6B;
}

.btn-challenge.active:hover {
    background-color: #FF5252;
}

/* Challenge Stats */
.challenge-stats {
    display: none;
    justify-content: center; /* Centered now */
    gap: 15px;
    align-items: center;
}

.challenge-stats.visible {
    display: flex;
}

.timer-display {
    font-size: 1.5rem;
    font-weight: 700;
    color: #333;
    font-variant-numeric: tabular-nums;
    min-width: 60px;
    text-align: center;
}

.timer-display.warning {
    color: #FF6B6B;
    animation: timerPulse 1s ease-in-out infinite;
}

@keyframes timerPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.success-counter {
    font-size: 1.5rem;
    font-weight: 700;
    color: #4CAF50;
    min-width: 30px;
    text-align: center;
}

.success-counter::before {
    content: '✓ ';
    font-size: 1.2rem;
}

/* Letter Container */
.letter-container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    min-height: 100px;
    white-space: nowrap;
}

/* Letter Gaps (Drop Zones) */
.letter-gap {
    width: 12px;
    min-width: 12px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* Edge gaps (first and last) are wider for better UX */
.letter-gap.edge {
    width: 24px;
    min-width: 24px;
}

.letter-gap::before {
    content: '';
    width: 5px;
    height: 0;
    background-color: #4CAF50;
    border-radius: 3px;
    transition: height 0.1s ease;
}

.letter-gap.drag-over::before {
    height: 60px;
    background-color: #66BB6A;
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.9), 0 0 25px rgba(76, 175, 80, 0.5);
}

/* Letter Squares */
.letter-square {
    width: 60px;
    height: 60px;
    background-color: white;
    border: 2px solid black;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8rem;
    font-weight: 700;
    color: black;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
    transition: all 0.2s ease;
}

/* Drag States */
.letter-square:active {
    cursor: grabbing;
}

.letter-square.dragging {
    opacity: 0.3;
    transform: scale(0.9);
}

/* Ghost element during touch drag */
.ghost-drag {
    pointer-events: none;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    transition: none;
}

/* Just Dropped State */
.letter-square.just-dropped {
    animation: dropFeedback 0.4s ease-out;
}

@keyframes dropFeedback {
    0% {
        transform: scale(1);
    }
    40% {
        transform: scale(1.15);
        box-shadow: 0 0 15px rgba(66, 165, 245, 0.6);
    }
    100% {
        transform: scale(1);
    }
}

/* Win State */
.letter-square.won {
    background: #4CAF50;
    color: white;
    border-color: #2E7D32;
    border-width: 3px;
    cursor: default;
    animation: winPulse 0.6s ease-in-out;
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.6);
    margin: 0 3px;
}

@keyframes winPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
}

/* Confetti Container */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    overflow: hidden;
}

/* Confetti Piece */
.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: #f0f;
    top: -10px;
    opacity: 1;
    animation: confettiFall linear forwards;
}

@keyframes confettiFall {
    to {
        transform: translateY(100vh) rotate(360deg);
        opacity: 0;
    }
}

/* Different confetti shapes */
.confetti.square {
    border-radius: 0;
}

.confetti.circle {
    border-radius: 50%;
}

.confetti.rectangle {
    width: 8px;
    height: 15px;
}

/* Button Container */
.button-container {
    display: flex;
    gap: 20px;
    justify-content: center;
    align-items: center;
}

/* New Challenge Toggle Button */
.btn-challenge-toggle {
    background-color: #e0e0e0;
    color: #333;
    border: none;
    border-radius: 50%;
    width: 70px;
    height: 70px;
    font-size: 2.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-challenge-toggle:hover {
    background-color: #d5d5d5;
    transform: scale(1.1);
}

.btn-challenge-toggle.active {
    background-color: #FF6B6B;
    color: white;
}

/* Settings Button */
.btn-settings {
    background-color: #78909C;
    color: white;
    border: none;
    border-radius: 50%;
    width: 70px;
    height: 70px;
    font-size: 2.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-settings:hover {
    background-color: #607D8B;
    transform: scale(1.1) rotate(45deg);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.btn-settings:active {
    transform: scale(0.95);
}

/* Version Number */
.version {
    margin-top: 15px;
    text-align: center;
    font-size: 0.75rem;
    color: #999;
    opacity: 0.7;
}

/* Help Button */
.btn-help {
    background-color: #42A5F5;
    color: white;
    border: none;
    border-radius: 50%;
    width: 70px;
    height: 70px;
    font-size: 2.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-help:hover {
    background-color: #1E88E5;
    transform: scale(1.1);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.btn-help:active {
    transform: scale(0.95);
}

/* Solution Button */
.btn-solution {
    background-color: #FFA726;
    color: white;
    border: none;
    border-radius: 50%;
    width: 70px;
    height: 70px;
    font-size: 2.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-solution:hover {
    background-color: #FB8C00;
    transform: scale(1.1);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.btn-solution:active {
    transform: scale(0.95);
}

.btn-solution:disabled {
    background-color: #e0e0e0;
    cursor: not-allowed;
    opacity: 0.5;
}

.btn-solution:disabled:hover {
    transform: none;
    background-color: #e0e0e0;
}

/* Salad Bowl Button */
.btn-salad {
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 50%;
    width: 70px;
    height: 70px;
    font-size: 2.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-salad:hover {
    background-color: #45a049;
    transform: scale(1.1) rotate(15deg);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.btn-salad:active {
    transform: scale(0.95);
}

footer {
    margin-top: 30px;
}

/* Help Overlay */
.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    visibility: hidden;
    opacity: 0;
}

.overlay.active {
    display: flex;
    visibility: visible;
    opacity: 1;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.overlay-content {
    background-color: white;
    padding: 30px;
    border-radius: 16px;
    max-width: 500px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease;
}

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

.overlay-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: #666;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

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

.overlay-content h2 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #333;
    font-size: 1.8rem;
}

.overlay-content h3 {
    margin-top: 10px;
    margin-bottom: 10px;
    color: #444;
    font-size: 1.3rem;
}

.help-section {
    margin-bottom: 20px;
    line-height: 1.6;
}

.help-section p {
    margin: 8px 0;
    color: #555;
}

.help-section ul {
    margin: 10px 0;
    padding-left: 20px;
}

.help-section li {
    margin: 8px 0;
    color: #555;
}

.install-section {
    background-color: #f5f5f5;
    padding: 15px;
    border-radius: 8px;
    margin-top: 25px;
}

/* Settings Overlay */
.settings-content {
    max-width: 400px;
}

.settings-section {
    margin-bottom: 20px;
}

.settings-section h3 {
    margin-bottom: 8px;
    color: #333;
}

.settings-section p {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 15px;
}

.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.settings-row label {
    font-weight: 500;
    color: #444;
}

.number-input-group {
    display: flex;
    align-items: center;
    gap: 0;
}

.number-input-group input {
    width: 50px;
    height: 40px;
    text-align: center;
    font-size: 1.2rem;
    font-weight: 600;
    border: 2px solid #ddd;
    border-left: none;
    border-right: none;
    background-color: #f9f9f9;
    color: #333;
}

.number-btn {
    width: 40px;
    height: 40px;
    border: 2px solid #ddd;
    background-color: #fff;
    font-size: 1.3rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #555;
}

.number-btn.minus {
    border-radius: 8px 0 0 8px;
}

.number-btn.plus {
    border-radius: 0 8px 8px 0;
}

.number-btn:hover {
    background-color: #4CAF50;
    border-color: #4CAF50;
    color: white;
}

.number-btn:active {
    transform: scale(0.95);
}

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

.number-btn:disabled:hover {
    background-color: #fff;
    border-color: #ddd;
    color: #555;
}

/* End Screen Overlay */
.end-screen-content {
    max-width: 400px;
    text-align: center;
}

.end-stats {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin: 30px 0;
}

.end-stat-item {
    background-color: #f5f5f5;
    padding: 20px;
    border-radius: 12px;
}

.end-stat-icon {
    font-size: 3rem;
    margin-bottom: 10px;
}

.end-stat-label {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.end-stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: #4CAF50;
}

.btn-restart-challenge {
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 15px 30px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    width: 100%;
}

.btn-restart-challenge:hover {
    background-color: #45a049;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.btn-restart-challenge:active {
    transform: translateY(0);
}

/* Landscape Orientation - 50% smaller vertical spacing */
@media (orientation: landscape) {
    header {
        margin-bottom: 15px;
    }

    .challenge-controls {
        margin: 15px 0;
    }

    footer {
        margin-top: 15px;
    }

    body {
        padding: 10px;
    }
}

/* Responsive Design */
@media (max-width: 480px) {
    .letter-square {
        width: 50px;
        height: 50px;
        font-size: 1.5rem;
    }

    .letter-gap {
        width: 10px;
        min-width: 10px;
        height: 50px;
    }

    .letter-gap.edge {
        width: 20px;
        min-width: 20px;
    }

    .letter-gap.drag-over::before {
        height: 50px;
    }

    h1 {
        font-size: 1.8rem;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    .btn-help,
    .btn-solution,
    .btn-salad,
    .btn-challenge-toggle,
    .btn-settings {
        width: 60px;
        height: 60px;
        font-size: 2rem;
    }

    .button-container {
        gap: 15px;
    }

    .overlay-content {
        padding: 25px;
        padding-top: 50px;
    }

    .overlay-content h2 {
        font-size: 1.5rem;
    }

    .overlay-content h3 {
        font-size: 1.2rem;
    }

    .challenge-controls {
        padding: 12px 15px;
        gap: 10px;
    }

    .toggle-switch {
        width: 50px;
        height: 26px;
    }

    .toggle-switch::before {
        width: 22px;
        height: 22px;
    }

    .mode-toggle-input:checked + .toggle-switch::before {
        transform: translateX(24px);
    }

    .toggle-text {
        font-size: 0.85rem;
    }

    .btn-challenge {
        width: 45px;
        height: 45px;
        font-size: 1.3rem;
    }

    .timer-display,
    .success-counter {
        font-size: 1.2rem;
    }

    .challenge-stats {
        gap: 10px;
    }

    .end-stat-icon {
        font-size: 2.5rem;
    }

    .end-stat-value {
        font-size: 2rem;
    }
}


@media (max-width: 360px) {
    .letter-square {
        width: 45px;
        height: 45px;
        font-size: 1.3rem;
    }

    .letter-gap {
        width: 8px;
        min-width: 8px;
        height: 45px;
    }

    .letter-gap.edge {
        width: 16px;
        min-width: 16px;
    }

    .letter-gap.drag-over::before {
        height: 45px;
    }

    h1 {
        font-size: 1.5rem;
    }

    .subtitle {
        font-size: 0.8rem;
    }

    .btn-help,
    .btn-solution,
    .btn-salad,
    .btn-challenge-toggle,
    .btn-settings {
        width: 55px;
        height: 55px;
        font-size: 1.8rem;
    }

    .button-container {
        gap: 12px;
    }

    .overlay-content {
        padding: 20px;
        padding-top: 45px;
        font-size: 0.95rem;
    }

    .overlay-content h2 {
        font-size: 1.3rem;
    }

    .overlay-content h3 {
        font-size: 1.1rem;
    }

    .challenge-controls {
        padding: 10px;
        justify-content: center;
    }

    .control-group {
        flex: 0 0 auto;
    }

    .challenge-stats.visible {
        flex: 0 0 auto;
    }

    .btn-challenge {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }

    .timer-display,
    .success-counter {
        font-size: 1rem;
    }

    .end-stat-value {
        font-size: 1.8rem;
    }

    .btn-restart-challenge {
        padding: 12px 20px;
        font-size: 1rem;
    }
}

