* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #ff6b6b;
    --primary-dark: #ee5a6f;
    --secondary-color: #4ecdc4;
    --accent-color: #ffe66d;
    --success-color: #51cf66;
    --error-color: #ff6b6b;
    --warning-color: #ffd93d;
    --bg-color: #fff9e6;
    --card-bg: #ffffff;
    --text-primary: #2d3436;
    --text-secondary: #636e72;
    --border-color: #dfe6e9;
    --shadow: 0 8px 16px rgba(0, 0, 0, 0.15), 0 4px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.2), 0 6px 12px rgba(0, 0, 0, 0.15);
    --gradient-primary: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
    --gradient-secondary: linear-gradient(135deg, #4ecdc4 0%, #44a08d 100%);
    --gradient-happy: linear-gradient(135deg, #ffe66d 0%, #ff6b6b 50%, #4ecdc4 100%);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    background: url('background.svg') no-repeat center center fixed;
    background-size: cover;
    min-height: 100vh;
    padding: 12px;
    color: var(--text-primary);
    direction: rtl;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--gradient-happy);
    opacity: 0.95;
    z-index: -1;
    pointer-events: none;
}

.app-container {
    max-width: 100%;
    margin: 0 auto;
    width: 100%;
}

@media (min-width: 768px) {
    .app-container {
        max-width: 600px;
    }
    body {
        padding: 20px;
    }
}

/* Header */
.app-header {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    border: 3px solid var(--accent-color);
}

.app-title {
    font-size: 24px;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 12px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

@media (min-width: 768px) {
    .app-header {
        padding: 24px;
        margin-bottom: 24px;
    }
    .app-title {
        font-size: 28px;
    }
}

.progress-bar {
    position: relative;
    width: 100%;
    height: 36px;
    background: var(--border-color);
    border-radius: 18px;
    overflow: hidden;
    border: 2px solid var(--accent-color);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.progress-fill {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: 18px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(255, 107, 107, 0.4);
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: 600;
    color: var(--text-primary);
    z-index: 1;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
    border: 3px solid var(--accent-color);
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--gradient-primary);
}

@media (min-width: 768px) {
    .card {
        padding: 32px;
        margin-bottom: 24px;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card h2 {
    font-size: 22px;
    margin-bottom: 16px;
    color: var(--text-primary);
    font-weight: 800;
}

.card h3 {
    font-size: 18px;
    margin-bottom: 12px;
    color: var(--text-primary);
    font-weight: 700;
}

@media (min-width: 768px) {
    .card h2 {
        font-size: 24px;
    }
    .card h3 {
        font-size: 20px;
    }
}

/* Welcome Card */
.welcome-card {
    text-align: center;
}

.welcome-card p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 16px;
}

/* Game Card */
.hint-box {
    background: var(--gradient-primary);
    color: white;
    padding: 20px;
    border-radius: 16px;
    margin-bottom: 20px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.3);
    position: relative;
    overflow: hidden;
}

.hint-box::before {
    content: '💡';
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 24px;
    opacity: 0.3;
}

.hint-text {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.6;
    position: relative;
    z-index: 1;
}

@media (min-width: 768px) {
    .hint-box {
        padding: 24px;
        margin-bottom: 24px;
    }
    .hint-text {
        font-size: 18px;
    }
}

/* Scanner Section */
.scanner-section {
    margin-bottom: 32px;
}

.scanner-instruction {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 12px;
    font-style: italic;
}

.scanner-container {
    position: relative;
    width: 100%;
    max-width: 400px;
    margin: 0 auto 16px;
    border-radius: 12px;
    overflow: hidden;
    background: #f1f5f9;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--border-color);
}

.scanner-placeholder {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
}

.scanner-placeholder p {
    margin: 4px 0;
    font-size: 14px;
}

.scanner-placeholder p:first-of-type {
    font-weight: 600;
    color: var(--text-primary);
}

#video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scanner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scanner-frame {
    width: 70%;
    height: 70%;
    border: 3px solid var(--primary-color);
    border-radius: 12px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    position: relative;
    z-index: 2;
}

/* Security pattern overlay */
.security-pattern {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255, 255, 255, 0.1) 2px, rgba(255, 255, 255, 0.1) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(255, 255, 255, 0.1) 2px, rgba(255, 255, 255, 0.1) 4px),
        radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.2) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(139, 92, 246, 0.2) 0%, transparent 50%);
    pointer-events: none;
    z-index: 1;
    opacity: 0.6;
    animation: patternMove 3s ease-in-out infinite;
}

@keyframes patternMove {
    0%, 100% {
        transform: translate(0, 0);
    }
    50% {
        transform: translate(2px, 2px);
    }
}

/* Loading spinner */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(99, 102, 241, 0.2);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Buttons */
.btn {
    padding: 14px 24px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    width: 100%;
    margin-bottom: 12px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    border: 2px solid var(--primary-dark);
}

.btn-primary:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 16px rgba(255, 107, 107, 0.4);
}

.btn-primary:active {
    transform: translateY(-1px) scale(0.98);
}

.btn-secondary {
    background: var(--accent-color);
    color: var(--text-primary);
    border: 2px solid var(--warning-color);
}

.btn-secondary:hover {
    background: var(--warning-color);
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 16px rgba(255, 217, 61, 0.4);
}

.btn-secondary:active {
    transform: translateY(-1px) scale(0.98);
}

/* Form */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.input-field {
    padding: 16px 18px;
    border: 3px solid var(--accent-color);
    border-radius: 12px;
    font-size: 16px;
    transition: all 0.3s ease;
    width: 100%;
    font-family: inherit;
    background: var(--card-bg);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.input-field:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(255, 107, 107, 0.2), 0 4px 8px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.input-field::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Words Grid */
.words-card {
    background: linear-gradient(135deg, #fff9e6 0%, #ffeaa7 100%);
    border: 3px solid var(--accent-color);
}

.words-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
    margin-top: 16px;
}

@media (min-width: 768px) {
    .words-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 12px;
    }
}

.word-badge {
    background: white;
    padding: 12px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    border: 2px solid var(--accent-color);
}

.word-badge:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.word-number {
    background: var(--gradient-primary);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 800;
    box-shadow: 0 2px 4px rgba(255, 107, 107, 0.3);
    flex-shrink: 0;
}

.word-text {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 14px;
}

/* Complete Card */
.complete-card {
    text-align: center;
    background: var(--gradient-secondary);
    color: white;
    border: 4px solid var(--accent-color);
    position: relative;
    overflow: hidden;
}

.complete-card::before {
    content: '🎉';
    position: absolute;
    top: -20px;
    right: -20px;
    font-size: 120px;
    opacity: 0.2;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% {
        transform: translateY(0) rotate(0deg);
    }
    50% {
        transform: translateY(-20px) rotate(10deg);
    }
}

.celebration {
    font-size: 80px;
    margin-bottom: 16px;
    animation: bounce 1s ease infinite;
    position: relative;
    z-index: 1;
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0) scale(1);
    }
    50% {
        transform: translateY(-20px) scale(1.1);
    }
}

.complete-card h2 {
    color: white;
    margin-bottom: 24px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    position: relative;
    z-index: 1;
}

.sentence-display {
    background: rgba(255, 255, 255, 0.25);
    padding: 20px;
    border-radius: 16px;
    margin-bottom: 24px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    position: relative;
    z-index: 1;
}

.complete-sentence {
    font-size: 20px;
    font-weight: 800;
    line-height: 1.8;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

@media (min-width: 768px) {
    .complete-sentence {
        font-size: 24px;
    }
}

/* Manual Input Section */
.manual-input-section {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 2px solid var(--border-color);
}

.manual-start-section {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 2px solid var(--border-color);
    text-align: center;
}

.manual-start-section p {
    margin-bottom: 12px;
    color: var(--text-secondary);
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    left: 24px;
    max-width: 600px;
    margin: 0 auto;
    background: var(--card-bg);
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: slideUp 0.3s ease;
    text-align: center;
    font-weight: 600;
}

.toast.success {
    background: var(--success-color);
    color: white;
}

.toast.error {
    background: var(--error-color);
    color: white;
}

/* Scanner improvements for mobile */
.scanner-container {
    border: 3px solid var(--accent-color) !important;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2) !important;
}

.scanner-frame {
    border: 4px solid var(--primary-color) !important;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6) !important;
}

/* Toast improvements */
.toast {
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    font-weight: 700;
}

.toast.success {
    background: var(--gradient-secondary);
}

.toast.error {
    background: var(--gradient-primary);
}

/* Loading spinner */
.loading-spinner {
    border: 4px solid rgba(255, 107, 107, 0.2) !important;
    border-top-color: var(--primary-color) !important;
}

/* Responsive improvements */
@media (max-width: 640px) {
    .app-title {
        font-size: 22px;
    }
    
    .card h2 {
        font-size: 20px;
    }
    
    .hint-text {
        font-size: 15px;
    }
    
    .btn {
        padding: 16px 20px;
        font-size: 16px;
    }
    
    .input-field {
        padding: 14px 16px;
        font-size: 16px;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 48px;
    }
    
    .input-field {
        min-height: 48px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

