:root {
    --primary-color: #8B008B;  /* Purple for Mardi Gras */
    --secondary-color: #FFD700; /* Gold */
    --tertiary-color: #008000; /* Green */
    --background-color: #f8f9fa;
    --text-color: #333;
    --border-radius: 8px;
    --box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: 'Arial', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--background-color);
    color: var(--text-color);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    margin-bottom: 2rem;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

h1 {
    color: var(--primary-color);
    margin: 0;
}

nav {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin: 0.5rem 0 1.5rem;
    padding: 0.5rem;
    position: sticky;
    top: 0;
    background-color: var(--background-color);
    z-index: 10;
    border-radius: var(--border-radius);
}

.category-btn {
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: var(--border-radius);
    background-color: #fff;
    color: var(--text-color);
    cursor: pointer;
    transition: transform 0.2s ease, background-color 0.3s ease;
    box-shadow: var(--box-shadow);
    flex: 1;
    min-width: 120px;
    max-width: 200px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    font-size: 0.95em;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.category-btn:hover {
    background-color: var(--secondary-color);
    transform: translateY(-2px);
}

.category-btn.active {
    background-color: var(--primary-color);
    color: white;
}

main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    background-color: white;
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    scroll-margin-top: 1rem;
}

#voting-section {
    scroll-margin-top: 1rem;
}

#rankings-section {
    scroll-margin-top: 1rem;
}

.cake-display {
    text-align: center;
    padding: 2rem;
    background-color: white;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

.cake-image {
    max-width: 100%;
    height: auto;
    border-radius: var(--border-radius);
    margin: 0 auto 1rem;
}

.cake-display h2 {
    color: var(--primary-color);
    font-size: 1.8em;
    margin-bottom: 0.5rem;
}

.cake-display p {
    color: var(--text-color);
    font-size: 1.2em;
}

.cake-description {
    font-style: italic;
    color: #666;
    line-height: 1.4;
}

.controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.rating-controls {
    display: flex;
    gap: 0.25rem;
    margin: 1rem 0;
    justify-content: center;
}

.rating-btn {
    width: 60px;
    height: 60px;
    padding: 10px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(145deg, #FFD700, #FDB813);
    color: #8B4513;
    font-size: 1.2em;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

.rating-btn:hover:not(:disabled) {
    transform: scale(1.15);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.6),
                0 0 30px rgba(255, 215, 0, 0.3),
                inset 0 0 5px rgba(255, 255, 255, 0.5);
    background: linear-gradient(145deg, #FFE55C, #FFD700);
}

.rating-btn.current-vote {
    background: linear-gradient(145deg, var(--primary-color), #6a006a);
    color: white;
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(139, 0, 139, 0.4),
                0 0 30px rgba(139, 0, 139, 0.2),
                inset 0 0 5px rgba(255, 255, 255, 0.3);
}

.rating-btn.current-vote:hover:not(:disabled) {
    background: linear-gradient(145deg, var(--primary-color), #6a006a);
    transform: scale(1.15);
}

.not-tried-btn {
    padding: 12px 24px;
    border: 2px solid var(--tertiary-color);
    border-radius: 25px;
    background-color: white;
    color: var(--tertiary-color);
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-top: 1rem;
    width: 100%;
    max-width: 300px;
}

.not-tried-btn:hover:not(:disabled) {
    background-color: rgba(0, 128, 0, 0.05);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.reset-btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--border-radius);
    background-color: #DC3545;
    color: white;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.3s ease;
}

.reset-btn:hover {
    background-color: #C82333;
    transform: translateY(-2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.reset-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.turnstile-container {
    margin: 1rem auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    max-width: 100%;
    overflow: hidden;
    transform-origin: top center;
    padding: 1rem;
    background-color: #f8f9fa;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

.turnstile-container .turnstile-message {
    color: var(--primary-color);
    font-weight: bold;
    margin: 0;
}

.turnstile-container.hidden {
    opacity: 0;
    pointer-events: none;
    height: 0;
    margin: 0;
    padding: 0;
    transform: scale(0.9);
}

@media (max-width: 480px) {
    .turnstile-container {
        transform: scale(0.85);
        margin: 0.5rem auto;
    }
    
    .turnstile-container iframe {
        max-width: 100%;
    }
}

#rankings-section {
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

#rankings-section h2 {
    color: var(--mardi-gras-purple);
    margin-bottom: 25px;
    text-align: center;
    font-size: 1.8em;
}

#rankings-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.ranking-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background-color: #f9f9f9;
    border-radius: 8px;
    transition: transform 0.2s ease, background-color 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    position: relative;
    overflow: hidden;
}

.ranking-item:not(.voted):hover {
    background-color: #f0f0f0;
}

.ranking-item:not(.voted):active {
    transform: scale(0.98);
    background-color: #e8e8e8;
}

@media (hover: hover) {
    .ranking-item:not(.voted):hover {
        transform: translateX(5px);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }
}

.ranking-item::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: radial-gradient(circle, rgba(255,255,255,0.7) 0%, transparent 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.ranking-item:active::after {
    opacity: 1;
}

/* Loading State */
body.loading {
    pointer-events: none;
    opacity: 0.7;
}

body.loading button {
    position: relative;
    overflow: hidden;
}

body.loading button::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 200%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.2),
        transparent
    );
    animation: loading 1.5s infinite;
}

@keyframes loading {
    from { transform: translateX(-100%); }
    to { transform: translateX(100%); }
}

/* Custom Modal */
.custom-modal {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    background: white;
    max-width: 90%;
    width: 300px;
    animation: slideIn 0.3s ease;
}

.custom-modal.error {
    background: #ffebee;
    border-left: 4px solid #f44336;
}

.custom-modal.info {
    background: #e3f2fd;
    border-left: 4px solid #2196f3;
}

.custom-modal .modal-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.custom-modal button {
    align-self: flex-end;
    padding: 5px 15px;
    border: none;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.1);
    cursor: pointer;
    font-size: 0.9em;
}

@keyframes slideIn {
    from {
        transform: translate(-50%, -100%);
        opacity: 0;
    }
    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

/* Pull to Refresh Indicator */
body::before {
    content: '↓ Pull to refresh';
    display: block;
    text-align: center;
    padding: 10px;
    background: var(--background-color);
    color: var(--text-color);
    font-size: 0.9em;
    opacity: 0;
    transition: opacity 0.3s ease;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

body.pulling::before {
    opacity: 1;
}

/* Touch Action Improvements */
* {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

button:active {
    transform: scale(0.98);
}

.ranking-item .rating-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
}

.ranking-item .rating-info span:first-child {
    font-weight: bold;
    color: var(--primary-color);
}

.ranking-item .not-tried {
    font-size: 0.9em;
    color: var(--mardi-gras-green);
}

.ranking-item.voted {
    border-left: 4px solid var(--mardi-gras-purple);
    padding-left: 11px;
}

.cake-display.voted {
    position: relative;
}

.cake-display.voted::after {
    content: "✓ Voted";
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: var(--mardi-gras-purple);
    color: white;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.9em;
}

.completion-message {
    margin-top: 1rem;
    padding: 1rem;
    background-color: var(--secondary-color);
    color: var(--primary-color);
    border-radius: var(--border-radius);
    text-align: center;
    font-weight: bold;
    animation: fadeIn 0.5s ease;
    box-shadow: var(--box-shadow);
}

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

@media (max-width: 768px) {
    main {
        grid-template-columns: 1fr;
        padding: 1rem;
    }
    
    nav {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .category-btn {
        flex: 1 1 calc(50% - 0.5rem);
        min-width: 140px;
        padding: 0.6rem 1rem;
        font-size: 0.95em;
    }
    
    h1 {
        font-size: 1.6em;
    }
    
    .container {
        padding: 10px;
    }
    
    .cake-display, #rankings-section {
        padding: 15px;
        margin: 0;
    }

    .header-content {
        flex-direction: column;
        gap: 0.8rem;
        align-items: stretch;
    }

    .header-content h1 {
        text-align: center;
    }

    .rating-controls {
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .not-tried-btn {
        padding: 10px 20px;
        font-size: 1em;
    }

    .ranking-item {
        padding: 12px;
        font-size: 0.95em;
    }

    /* Improve touch targets */
    .reset-btn {
        padding: 10px 20px;
        width: 100%;
        margin-top: 0.5rem;
    }
}

@media (max-width: 480px) {
    .category-btn {
        flex: 1 1 100%;
        margin: 0.2rem 0;
    }
    
    .rating-controls {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.8rem;
    }
    
    .rating-btn {
        width: 55px;
        height: 55px;
        font-size: 1.3em;
    }

    .cake-display h2 {
        font-size: 1.5em;
    }

    .cake-display p {
        font-size: 1.1em;
    }

    #rankings-section h2 {
        font-size: 1.5em;
    }

    .ranking-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .ranking-item .rating-info {
        align-items: flex-start;
        width: 100%;
    }

    /* Add touch-friendly improvements */
    button,
    .category-btn,
    .rating-btn,
    .not-tried-btn,
    .reset-btn,
    .ranking-item {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
}

/* Add safe area insets for modern mobile browsers */
@supports (padding: max(0px)) {
    .container {
        padding-left: max(15px, env(safe-area-inset-left));
        padding-right: max(15px, env(safe-area-inset-right));
        padding-bottom: max(15px, env(safe-area-inset-bottom));
    }
}
