/* Perplexd - Daily Word Puzzle Game - Enhanced */

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #475569;
    --easy: #22c55e;
    --medium: #f59e0b;
    --hard: #ef4444;
}

html, body {
    margin: 0;
    padding: 0;
    max-width: 100%;
    overflow-x: hidden;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.ad-banner {
    width: 100%;
    max-width: 728px;
    height: 90px;
    background: var(--surface);
    border: 1px dashed var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 14px;
    margin: 10px auto;
}

.ad-banner-bottom {
    margin-top: auto;
}

.container {
    width: 100%;
    max-width: 480px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    box-sizing: border-box;
    position: relative;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 5px;
    text-align: center;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 25px;
    text-align: center;
}

/* Sound Toggle */
.sound-toggle {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 20px;
    transition: all 0.2s ease;
    z-index: 10;
}

.sound-toggle:hover {
    background: var(--surface-light);
    transform: scale(1.1);
}

/* Difficulty Selector */
.difficulty-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    width: 100%;
}

.diff-btn {
    flex: 1;
    padding: 12px 8px;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    position: relative;
}

.diff-label {
    font-size: 16px;
}

.diff-btn .diff-letters {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
}

.diff-btn:hover:not(:disabled) {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.diff-btn.active {
    transform: translateY(-2px);
}

.diff-btn.easy.active {
    border-color: var(--easy);
    background: rgba(34, 197, 94, 0.15);
}

.diff-btn.medium.active {
    border-color: var(--medium);
    background: rgba(245, 158, 11, 0.15);
}

.diff-btn.hard.active {
    border-color: var(--hard);
    background: rgba(239, 68, 68, 0.15);
}

.diff-btn.completed::after {
    content: '✓';
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: var(--success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.5);
}

.completion-percentage {
    position: absolute;
    bottom: 2px;
    font-size: 10px;
    color: var(--success);
    font-weight: 700;
}

.diff-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Next Timer */
.next-timer {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 20px;
}

/* Start Button */
.start-btn {
    padding: 16px 48px;
    font-size: 18px;
    font-weight: 600;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.start-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.5);
}

.start-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Pulse animation for start button */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.pulse {
    animation: pulse 2s ease-in-out infinite;
}

/* Ghost Tiles Preview */
.ghost-tiles-container {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 25px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.ghost-tiles-container.visible {
    opacity: 1;
}

.ghost-tile {
    width: 50px;
    height: 60px;
    background: var(--surface);
    border: 2px dashed var(--border);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    color: var(--text-muted);
    opacity: 0.5;
}

/* Timer Container with Circular Progress */
.timer-container {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 20px;
    display: none;
}

.timer-container.visible {
    display: block;
}

.timer-circle {
    width: 100%;
    height: 100%;
}

#timerProgress {
    transition: stroke 0.3s ease, stroke-dashoffset 1s linear;
}

.game-timer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 32px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    transition: color 0.3s ease;
}

.game-timer.warning {
    color: var(--warning);
}

.game-timer.danger {
    color: var(--danger);
}

.game-timer.overtime {
    color: var(--danger);
    font-size: 28px;
}

.timer-message {
    color: var(--warning);
    font-size: 14px;
    min-height: 20px;
    margin-bottom: 15px;
    text-align: center;
    font-weight: 600;
}

/* Letters Container */
.letters-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-bottom: 15px;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    min-height: 70px;
}

.letters-container.single-line {
    flex-wrap: nowrap;
    justify-content: center;
}

.letters-container.single-line .letter-tile {
    width: 40px;
    height: 54px;
    font-size: 24px;
}

.letters-container.visible {
    opacity: 1;
    transform: translateY(0);
}

.letter-tile {
    width: 50px;
    height: 60px;
    background: linear-gradient(145deg, var(--surface-light), var(--surface));
    border: 2px solid var(--border);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    box-shadow: 0 4px 8px rgba(15, 23, 42, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    text-shadow: 0 1px 2px rgba(15, 23, 42, 0.9);
    position: relative;
}

/* Cascade animation for letter tiles */
@keyframes cascadeIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.letter-tile.cascade {
    animation: cascadeIn 0.4s ease-out forwards;
}

.letter-tile:hover:not(.used):not(.hint) {
    border-color: var(--primary);
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 6px 12px rgba(99, 102, 241, 0.4);
}

.letter-tile.used {
    opacity: 0.3;
    transform: scale(0.95);
    cursor: default;
    border-color: var(--primary);
    background: linear-gradient(145deg, rgba(99, 102, 241, 0.2), rgba(99, 102, 241, 0.1));
}

.letter-tile.hint {
    background: linear-gradient(145deg, rgba(99, 102, 241, 0.4), rgba(99, 102, 241, 0.2));
    border-color: var(--primary);
    cursor: default;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.5);
}

/* Shuffle animation */
@keyframes shuffle {
    0%, 100% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(0.8) rotate(180deg); }
}

.letter-tile.shuffling {
    animation: shuffle 0.6s ease-in-out;
}

/* Character Counter */
.char-counter {
    text-align: center;
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 10px;
    min-height: 20px;
    font-weight: 600;
}

.char-counter .check-icon {
    color: var(--success);
    margin-left: 5px;
}

/* Input Section */
.input-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
}

.input-section.visible {
    opacity: 1;
    transform: translateY(0);
}

.guess-input {
    width: 100%;
    padding: 16px 20px;
    font-size: 24px;
    font-weight: 600;
    text-align: center;
    letter-spacing: 4px;
    text-transform: uppercase;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    outline: none;
    transition: all 0.2s ease;
}

.guess-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.guess-input.complete {
    border-color: var(--success);
}

.guess-input::placeholder {
    font-size: 16px;
    letter-spacing: normal;
    text-transform: none;
    color: var(--text-muted);
}

/* Shake animation for wrong answers */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
    20%, 40%, 60%, 80% { transform: translateX(10px); }
}

.shake {
    animation: shake 0.5s ease-in-out;
    border-color: var(--danger) !important;
}

.btn-row {
    display: flex;
    gap: 10px;
}

.btn {
    flex: 1;
    padding: 14px 20px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

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

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border);
}

.btn-hint {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    display: none;
    width: 100%;
}

.btn-hint.visible {
    display: block;
}

.btn-hint:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
}

/* Loading spinner */
.spinner {
    display: inline-block;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none;
}

/* On-screen keyboard */
.keyboard {
    margin-top: 16px;
    display: none;
}

.keyboard.visible {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    max-width: 480px;
    margin-inline: auto;
}

.keyboard-row {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.key {
    flex: 0 0 auto;
    min-width: 40px;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--surface-light);
    border: 1px solid var(--border);
    color: var(--text);
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
    user-select: none;
    text-align: center;
    box-shadow: 0 3px 6px rgba(15, 23, 42, 0.7);
    transition: all 0.1s ease;
}

.key:active:not(:disabled) {
    transform: translateY(2px);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.7);
}

.key:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.key-action {
    padding: 10px 16px;
    min-width: 64px;
    font-size: 14px;
}

.key.used {
    background: var(--primary);
    border-color: var(--primary-dark);
    box-shadow: 0 3px 6px rgba(99, 102, 241, 0.5);
}

/* Message */
.message {
    padding: 12px 24px;
    border-radius: 10px;
    font-weight: 600;
    text-align: center;
    margin: 15px 0;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.message.success {
    background: rgba(34, 197, 94, 0.2);
    border: 2px solid var(--success);
    color: var(--success);
    opacity: 1;
}

.message.error {
    background: rgba(239, 68, 68, 0.2);
    border: 2px solid var(--danger);
    color: var(--danger);
    opacity: 1;
}

/* Grade Container */
.grade-container {
    text-align: center;
    margin: 20px 0;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.4s ease;
}

.grade-container.visible {
    opacity: 1;
    transform: scale(1);
}

.stars {
    font-size: 40px;
    margin-bottom: 8px;
    letter-spacing: 5px;
}

.grade-label {
    font-size: 18px;
    font-weight: 600;
    color: var(--success);
}

/* Answer Reveal */
.answer-reveal {
    text-align: center;
    margin: 20px 0;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.4s ease;
}

.answer-reveal.visible {
    opacity: 1;
    transform: scale(1);
}

.answer-word {
    font-size: 36px;
    font-weight: 700;
    letter-spacing: 4px;
    color: var(--primary);
    margin-bottom: 8px;
}

.answer-label {
    color: var(--text-muted);
    font-size: 14px;
}

/* Stats - Card Layout */
.stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 25px 0;
    width: 100%;
}

.stat-card {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    flex: 1;
    max-width: 120px;
    transition: all 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.stat-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

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

.stat-value.pulse-animation {
    animation: statPulse 0.4s ease-out;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Share Button */
.share-btn {
    width: 100%;
    padding: 14px 32px;
    font-size: 16px;
    font-weight: 600;
    background: linear-gradient(135deg, var(--success), #16a34a);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0;
    visibility: hidden;
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

.share-btn.visible {
    opacity: 1;
    visibility: visible;
}

.share-btn:hover {
    background: linear-gradient(135deg, #16a34a, #15803d);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(34, 197, 94, 0.4);
}

/* Footer */
.footer {
    color: var(--text-muted);
    font-size: 12px;
    padding: 15px;
    text-align: center;
}

/* Overtime Overlay */
.overtime-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1;
}

.overtime-overlay.visible {
    opacity: 1;
}

/* Confetti */
.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    pointer-events: none;
    animation: confetti-fall 3s ease-out forwards;
    z-index: 1000;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* Responsive */
@media (max-width: 480px) {
    .container {
        padding: 15px;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    .diff-btn {
        padding: 10px 6px;
        font-size: 14px;
    }
    
    .letter-tile {
        width: 42px;
        height: 52px;
        font-size: 24px;
    }
    
    .game-timer {
        font-size: 28px;
    }
    
    .guess-input {
        font-size: 20px;
        letter-spacing: 3px;
    }
    
    .stats {
        gap: 15px;
    }
    
    .stat-card {
        padding: 12px;
    }
    
    .stat-value {
        font-size: 24px;
    }

    .stat-icon {
        font-size: 20px;
    }
    
    .ad-banner {
        max-width: 100%;
        height: auto;
    }
    
    .letters-container.single-line .letter-tile {
        width: min(9vw, 40px);
        height: min(12vw, 54px);
        font-size: min(6vw, 24px);
    }

    .keyboard.visible {
        max-width: 320px;
        padding-inline: 8px;
    }

    .keyboard-row {
        gap: 6px;
    }

    .key {
        min-width: 30px;
        padding: 8px 6px;
        font-size: 14px;
    }

    .key-action {
        min-width: 50px;
        font-size: 13px;
        padding: 8px 8px;
    }

    .timer-container {
        width: 100px;
        height: 100px;
    }

    .game-timer {
        font-size: 28px;
    }
}

/* Prevent double-tap zoom */
.letters-container,
.input-section,
.keyboard {
    touch-action: manipulation;
}