:root {
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-text: #f1f5f9;
    --color-text-secondary: #94a3b8;
    --color-border: #334155;
    --color-primary: #3b82f6;
    --color-primary-dark: #2563eb;
    --color-success: #10b981;
    --color-error: #ef4444;
    --color-warning: #f59e0b;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --gradient-primary: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    --gradient-bg: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

[data-theme="light"] {
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-text: #0f172a;
    --color-text-secondary: #64748b;
    --color-border: #e2e8f0;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.2);
    --gradient-bg: linear-gradient(135deg, #f8fafc 0%, #e0e7ff 100%);
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--gradient-bg);
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    transition: all 0.3s ease;
    margin: 0;
    padding: 0;
    position: relative;
}

.container {
    width: 100%;
    max-width: 450px;
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    padding: 0 12px;
    overflow: hidden;
}

/* Footer */
.footer {
    flex-shrink: 0;
    padding: 16px 0;
    text-align: center;
    margin-top: auto;
}

.privacy-link-footer {
    display: inline-block;
    color: var(--color-primary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.privacy-link-footer:hover {
    background: var(--color-surface);
    transform: translateY(-2px);
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    flex-shrink: 0;
    background: var(--color-bg);
    z-index: 10001 !important;
    position: sticky;
    top: 0;
    isolation: isolate;
}

.header-left,
.header-right {
    display: flex;
    gap: 8px;
}

.title {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -1px;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: flex;
    align-items: center;
    gap: 6px;
}

.title-icon {
    font-size: 24px;
    animation: pulse 2s ease-in-out infinite;
}

.icon-btn {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    cursor: pointer;
    padding: 8px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    position: relative;
    z-index: 10001 !important;
    pointer-events: auto !important;
}

.icon-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

/* Ensure anchor tags with icon-btn class work properly */
a.icon-btn {
    text-decoration: none !important;
    color: inherit;
    pointer-events: auto !important;
    z-index: 10002 !important;
    position: relative;
    display: flex;
}

/* Mode Selector */
.mode-selector {
    display: flex;
    gap: 4px;
    padding: 4px 0;
    justify-content: center;
    flex-shrink: 0;
}

.mode-btn {
    flex: 1;
    padding: 8px 10px;
    border: 2px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.mode-btn:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.mode-btn.active {
    background: var(--gradient-primary);
    color: white;
    border-color: transparent;
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.mode-icon {
    font-size: 18px;
}

/* Level Info */
.level-info {
    display: flex;
    gap: 8px;
    padding: 6px 12px;
    background: var(--color-surface);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    margin-bottom: 4px;
    flex-shrink: 0;
}

.info-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.info-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.info-value {
    font-size: 18px;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.info-value.hearts {
    font-size: 16px;
    background: none;
    -webkit-text-fill-color: initial;
}

/* Daily Challenge Info */
.daily-info {
    text-align: center;
    margin-bottom: 6px;
    flex-shrink: 0;
}

.daily-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--color-surface);
    color: var(--color-text);
    border: 2px solid var(--color-border);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}

.daily-badge:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
}

.daily-icon {
    font-size: 18px;
}

.daily-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-secondary);
}

/* Game Container */
.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
    overflow-y: auto;
    min-height: 0;
}

/* Instructions */
.instructions {
    text-align: center;
    padding: 12px 16px;
}

.instruction-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 12px;
}

/* Game Board */
.game-board {
    display: grid;
    gap: 3px;
    padding: 8px;
    background: var(--color-surface);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    transition: all 0.3s ease;
    width: 100%;
    max-width: min(280px, 80vw);
    aspect-ratio: 1;
}

.grid-cell {
    aspect-ratio: 1;
    background: var(--color-bg);
    border: 2px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
    min-height: 25px;
}

.grid-cell::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(255,255,255,0.1) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.grid-cell:hover::before {
    opacity: 1;
}

.grid-cell.clickable:hover {
    transform: scale(1.05);
    border-color: var(--color-primary);
}

.grid-cell.active {
    animation: cellPop 0.3s ease;
}

.grid-cell.correct {
    animation: correctPulse 0.5s ease;
    border-color: var(--color-success);
}

.grid-cell.wrong {
    animation: wrongShake 0.5s ease;
    border-color: var(--color-error);
}

/* Color Palette */
.color-palette {
    width: 100%;
    max-width: min(300px, 85vw);
    padding: 8px;
    background: var(--color-surface);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    flex-shrink: 0;
}

.palette-title {
    text-align: center;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--color-text-secondary);
    font-size: 11px;
}

.colors {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.color-btn {
    aspect-ratio: 1;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
    position: relative;
    min-height: 30px;
}

.color-btn:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-md);
}

.color-btn.selected {
    border-color: white;
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

.color-btn::after {
    content: '✓';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.color-btn.selected::after {
    opacity: 1;
}

/* Action Buttons */
.action-buttons-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.action-buttons {
    display: flex;
    gap: 6px;
    width: 100%;
    max-width: min(300px, 85vw);
}

#inGamePrivacyLink {
    margin-top: 0;
}

.btn {
    flex: 1;
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

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

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border: 2px solid var(--color-border);
}

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

.btn-start {
    padding: 18px 48px;
    font-size: 18px;
}

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

/* Phase Indicator */
.phase-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--color-surface);
    padding: 24px 40px;
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    border: 2px solid var(--color-primary);
}

.phase-indicator.show {
    opacity: 1;
    animation: phaseSlide 0.5s ease;
}

.phase-text {
    font-size: 32px;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Toast */
.toast {
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--color-surface);
    color: var(--color-text);
    padding: 16px 32px;
    border-radius: 16px;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    z-index: 10000;
    opacity: 0;
    transition: all 0.3s ease;
    border: 2px solid var(--color-border);
    pointer-events: none;
}

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

.toast.success {
    background: var(--color-success);
    color: white;
    border-color: var(--color-success);
}

.toast.error {
    background: var(--color-error);
    color: white;
    border-color: var(--color-error);
}

/* Modals */
.modal {
    display: none !important;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(8px);
    pointer-events: none !important;
    visibility: hidden;
    opacity: 0;
}

.modal.active {
    display: flex !important;
    visibility: visible;
    opacity: 1;
    animation: fadeIn 0.3s ease;
    /* Don't intercept clicks on the backdrop - only on content */
    pointer-events: none !important;
}

.modal.active .modal-content {
    pointer-events: auto !important;
}

/* Ensure header buttons are always clickable, even when modal is open */
.modal.active ~ .header .icon-btn,
.header .icon-btn {
    pointer-events: auto !important;
    z-index: 10002 !important;
    position: relative;
}

.modal-content {
    background: var(--color-surface);
    border-radius: 24px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalSlide 0.4s ease;
    border: 1px solid var(--color-border);
    position: relative;
    z-index: 1003;
    pointer-events: auto;
}

.modal:not(.active) .modal-content {
    pointer-events: none;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px;
    border-bottom: 2px solid var(--color-border);
}

.modal-header h2 {
    font-size: 28px;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.close-btn {
    background: none;
    border: none;
    font-size: 36px;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: var(--color-border);
    color: var(--color-text);
}

.modal-body {
    padding: 24px;
}

/* Help Modal */
.help-section {
    margin-bottom: 24px;
}

.help-section h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--color-text);
}

.help-section p,
.help-section li {
    color: var(--color-text-secondary);
    line-height: 1.6;
    margin-bottom: 8px;
}

.help-section ul,
.help-section ol {
    padding-left: 24px;
}

.privacy-link-modal {
    display: block;
    text-align: center;
    color: var(--color-primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    padding: 12px 24px;
    border-radius: 10px;
    transition: all 0.2s ease;
    background: var(--color-bg);
    border: 2px solid var(--color-border);
    margin-top: 8px;
}

.privacy-link-modal:hover {
    background: var(--color-surface);
    border-color: var(--color-primary);
    transform: translateY(-2px);
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    background: var(--color-bg);
    border-radius: 16px;
    border: 2px solid var(--color-border);
}

.stat-value {
    font-size: 40px;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 8px;
}

/* Game Over Stats */
.game-over-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.big-stat {
    text-align: center;
    padding: 24px;
    background: var(--color-bg);
    border-radius: 16px;
    border: 2px solid var(--color-border);
}

.big-stat-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.big-stat-value {
    font-size: 48px;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Result Actions */
.result-actions {
    display: flex;
    gap: 12px;
}

/* Share Button */
.share-section {
    text-align: center;
    margin-top: 24px;
}

.share-btn {
    background: var(--gradient-primary);
    color: white;
    border: none;
    padding: 16px 32px;
    border-radius: 16px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-md);
}

.share-btn:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

/* Support Form */
.support-intro {
    color: var(--color-text-secondary);
    margin-bottom: 24px;
    line-height: 1.6;
}

.support-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
}

.form-group input,
.form-group textarea {
    padding: 12px 16px;
    border: 2px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    transition: all 0.2s ease;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 120px;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.form-actions .btn {
    flex: 1;
}

.support-message-status {
    margin-top: 16px;
    padding: 16px;
    border-radius: 10px;
    text-align: center;
    font-weight: 600;
}

.support-message-status.success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--color-success);
    border: 2px solid var(--color-success);
}

.support-message-status.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--color-error);
    border: 2px solid var(--color-error);
}

/* Animations */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

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

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

@keyframes phaseSlide {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
    }
}

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

@keyframes correctPulse {
    0%, 100% { transform: scale(1); }
    50% { 
        transform: scale(1.15);
        box-shadow: 0 0 20px var(--color-success);
    }
}

@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* Responsive */
@media (max-width: 480px) {
    .container {
        padding: 0 8px;
    }
    
    .header {
        padding: 6px 0;
    }
    
    .title {
        font-size: 24px;
    }
    
    .title-icon {
        font-size: 20px;
    }
    
    .mode-btn {
        padding: 6px 6px;
        font-size: 11px;
    }
    
    .level-info {
        padding: 4px 8px;
        gap: 6px;
    }
    
    .info-value {
        font-size: 16px;
    }
    
    .info-label {
        font-size: 9px;
    }
    
    .game-board {
        padding: 6px;
        max-width: min(250px, 75vw);
    }
    
    .grid-cell {
        min-height: 20px;
    }
    
    .color-palette {
        padding: 6px;
        max-width: min(250px, 75vw);
    }
    
    .color-btn {
        min-height: 25px;
    }
    
    .action-buttons {
        max-width: min(250px, 75vw);
    }
    
    .btn {
        padding: 8px 16px;
        font-size: 12px;
    }
    
    .privacy-link-modal {
        padding: 10px 20px;
        font-size: 13px;
    }
    
    .footer {
        padding: 12px 0;
    }
    
    .privacy-link-footer {
        font-size: 12px;
        padding: 6px 12px;
    }
    
    .support-form {
        gap: 16px;
    }
    
    .form-group input,
    .form-group textarea {
        padding: 10px 14px;
        font-size: 13px;
    }
    
    .form-actions {
        flex-direction: column;
    }
}

/* iPhone specific adjustments - moderate height reduction */
@media (max-width: 430px) and (max-height: 932px) {
    .container {
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile */
        padding: 0 8px;
    }
    
    .header {
        padding: 6px 0;
    }
    
    .title {
        font-size: 22px;
    }
    
    .title-icon {
        font-size: 20px;
    }
    
    .mode-selector {
        padding: 3px 0;
        gap: 3px;
    }
    
    .mode-btn {
        padding: 5px 5px;
        font-size: 10px;
    }
    
    .level-info {
        padding: 4px 8px;
        gap: 5px;
        margin-bottom: 3px;
    }
    
    .info-value {
        font-size: 15px;
    }
    
    .info-label {
        font-size: 8px;
    }
    
    .game-container {
        gap: 2px;
        padding: 2px 0;
    }
    
    .daily-info {
        margin-bottom: 3px;
    }
    
    .daily-badge {
        padding: 5px 10px;
    }
    
    .daily-text {
        font-size: 12px;
    }
    
    .daily-icon {
        font-size: 15px;
    }
    
    .instructions {
        padding: 8px 12px;
    }
    
    .instruction-text {
        font-size: 13px;
        margin-bottom: 8px;
    }
    
    .game-board {
        padding: 6px;
        max-width: min(240px, 75vw);
    }
    
    .grid-cell {
        min-height: 22px;
    }
    
    .color-palette {
        padding: 6px;
        max-width: min(240px, 75vw);
    }
    
    .palette-title {
        font-size: 10px;
        margin-bottom: 4px;
    }
    
    .colors {
        gap: 4px;
    }
    
    .color-btn {
        min-height: 28px;
    }
    
    .action-buttons {
        max-width: min(240px, 75vw);
        gap: 5px;
    }
    
    .btn {
        padding: 7px 14px;
        font-size: 11px;
    }
    
    .privacy-link-modal {
        padding: 8px 16px;
        font-size: 12px;
    }
    
    .footer {
        padding: 10px 0;
    }
    
    .privacy-link-footer {
        font-size: 11px;
        padding: 5px 10px;
    }
    
    .phase-indicator {
        padding: 18px 28px;
    }
    
    .phase-text {
        font-size: 26px;
    }
}
