:root {
    /* تم تاریک (پیش‌فرض) */
    --bg-body: #0b1220;
    --bg-radial: rgba(245, 158, 11, 0.12);
    --text-primary: #ffffff;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    --bg-input: #111827;
    --border-input: #1f2937;
    --border-focus: #f59e0b;
    --shadow-focus: rgba(245, 158, 11, 0.15);
    
    --bg-tag: #111827;
    --border-tag: #1f2937;
    --text-tag: #d1d5db;
    --bg-tag-active: #f59e0b;
    --text-tag-active: #111827;
    --border-tag-hover: rgba(245, 158, 11, 0.7);
    
    --bg-card: rgba(255, 255, 255, 0.045);
    --border-card: rgba(255, 255, 255, 0.08);
    --shadow-card: rgba(0, 0, 0, 0.22);
    --bg-card-hover: rgba(255, 255, 255, 0.065);
    --border-card-hover: rgba(245, 158, 11, 0.25);
    --bg-image: #111827;
    
    --cat-color: #fbbf24;
    
    --btn-open-bg: #f59e0b;
    --btn-open-text: #111827;
    --btn-copy-bg: #1f2937;
    --btn-copy-text: #ffffff;
    --btn-copy-hover: #374151;
    
    --search-bg: rgba(11, 18, 32, 0.92);
    
    --toast-bg: #1f2937;
    --toast-text: #ffffff;
    
    --toggle-bg: #1f2937;
    --toggle-icon: #fbbf24;
}

/* تم روشن */
[data-theme="light"] {
    --bg-body: #f3f4f6;
    --bg-radial: rgba(245, 158, 11, 0.08);
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #6b7280;
    
    --bg-input: #ffffff;
    --border-input: #d1d5db;
    --border-focus: #f59e0b;
    --shadow-focus: rgba(245, 158, 11, 0.2);
    
    --bg-tag: #ffffff;
    --border-tag: #d1d5db;
    --text-tag: #4b5563;
    --bg-tag-active: #f59e0b;
    --text-tag-active: #ffffff;
    --border-tag-hover: #f59e0b;
    
    --bg-card: #ffffff;
    --border-card: #e5e7eb;
    --shadow-card: rgba(0, 0, 0, 0.05);
    --bg-card-hover: #fafafa;
    --border-card-hover: #f59e0b;
    --bg-image: #e5e7eb;
    
    --cat-color: #d97706;
    
    --btn-open-bg: #f59e0b;
    --btn-open-text: #ffffff;
    --btn-copy-bg: #e5e7eb;
    --btn-copy-text: #111827;
    --btn-copy-hover: #d1d5db;
    
    --search-bg: rgba(243, 244, 246, 0.92);
    
    --toast-bg: #111827;
    --toast-text: #ffffff;
    
    --toggle-bg: #e5e7eb;
    --toggle-icon: #4b5563;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Vazirmatn', sans-serif;
    -webkit-tap-highlight-color: transparent; /* حذف هایلایت آبی در موبایل */
}

body {
    min-height: 100vh;
    background: radial-gradient(circle at top, var(--bg-radial), transparent 360px), var(--bg-body);
    color: var(--text-primary);
    transition: background 0.3s ease, color 0.3s ease;
    padding-bottom: env(safe-area-inset-bottom); /* فاصله استاندارد برای گوشی‌های ناچ‌دار */
}

button, input {
    font: inherit;
}

button {
    cursor: pointer;
    border: none;
    background: none;
}

/* دکمه تغییر تم */
#theme-toggle {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 100;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--toggle-bg);
    color: var(--toggle-icon);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transition: transform 0.2s ease, background 0.3s ease;
}

#theme-toggle:active {
    transform: scale(0.9);
}

.icon-sun, .icon-moon {
    position: absolute;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

[data-theme="dark"] .icon-sun { opacity: 1; transform: rotate(0); }
[data-theme="dark"] .icon-moon { opacity: 0; transform: rotate(-90deg); }
[data-theme="light"] .icon-sun { opacity: 0; transform: rotate(90deg); }
[data-theme="light"] .icon-moon { opacity: 1; transform: rotate(0); }

.app {
    width: 100%;
    max-width: 650px;
    margin: 0 auto;
    padding: 14px 14px 40px;
}

.header {
    text-align: center;
    padding: 22px 0 12px;
}

h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

p {
    margin-top: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

.search-wrap {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 10px 0;
    background: var(--search-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border-input);
    border-radius: 14px;
    outline: none;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.3s;
}

input::placeholder {
    color: var(--text-muted);
}

input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--shadow-focus);
}

#tags {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 0;
    scrollbar-width: none;
}

#tags::-webkit-scrollbar {
    display: none;
}

.tag {
    flex: 0 0 auto;
    padding: 8px 13px;
    border: 1px solid var(--border-tag);
    border-radius: 999px;
    background: var(--bg-tag);
    color: var(--text-tag);
    font-size: 12px;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.tag.active {
    border-color: var(--bg-tag-active);
    background: var(--bg-tag-active);
    color: var(--text-tag-active);
    font-weight: 700;
}

#grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
}

.card {
    overflow: hidden;
    border: 1px solid var(--border-card);
    border-radius: 16px;
    background: var(--bg-card);
    box-shadow: 0 12px 28px var(--shadow-card);
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.card img {
    display: block;
    width: 100%;
    height: 155px;
    object-fit: cover;
    background: var(--bg-image);
}

.content {
    padding: 12px;
}

.title {
    font-size: 16px;
    font-weight: 700;
}

.cat {
    margin: 5px 0 10px;
    font-size: 12px;
    color: var(--cat-color);
}

.btns {
    display: flex;
    gap: 10px;
}

.btn {
    flex: 1;
    padding: 12px;
    border: 0;
    border-radius: 11px;
    font-size: 13px;
    font-weight: 700;
    transition: filter 0.2s, background 0.2s, transform 0.1s;
}

.open {
    background: var(--btn-open-bg);
    color: var(--btn-open-text);
}

.copy {
    background: var(--btn-copy-bg);
    color: var(--btn-copy-text);
}

.no-result {
    padding: 36px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--toast-bg);
    color: var(--toast-text);
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
    z-index: 1000;
}

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

/* افکت‌های هاور فقط برای دسکتاپ */
@media (hover: hover) {
    .card:hover {
        transform: translateY(-4px);
        border-color: var(--border-card-hover);
        background: var(--bg-card-hover);
    }

    .tag:hover {
        border-color: var(--border-tag-hover);
        color: var(--text-primary);
    }

    .open:hover {
        filter: brightness(1.08);
    }

    .copy:hover {
        background: var(--btn-copy-hover);
    }
}

.btn:active, .tag:active {
    transform: scale(0.96);
}

/* بهینه‌سازی برای موبایل */
@media (max-width: 480px) {
    .app {
        padding: 12px 12px 32px;
    }

    h1 {
        font-size: 25px;
    }

    .card img {
        height: 145px;
    }
    
    #theme-toggle {
        top: 12px;
        left: 12px;
        width: 36px;
        height: 36px;
    }
}