:root {
    --granny-apple: #d8f3dc;
    --fringy-flower: #b7e4c7;
    --vista-blue: #95d5b2;
    --silver-tree: #74c69d;
    --ocean-green: #52b788;
    --eucalyptus: #40916c;
    --green-pea: #2d6a4f;
    --everglade: #1b4332;
    --black-bean: #081c15;
    --accent: #ECA400;

    --color-motion: #4C97FF;
    --color-looks: #9966FF;
    --color-sound: #CF63CF;
    --color-events: #FFBF00;
    --color-control: #FFAB19;
    --color-sensing: #5CB1D6;
    --color-operators: #59C059;
    --color-variables: #FF8C1A;
    --color-myblocks: #FF6680;

    --font-base: clamp(0.875rem, 1vw + 0.4rem, 1rem);
    --font-lg: clamp(1rem, 1.2vw + 0.4rem, 1.15rem);
    --font-xl: clamp(1.3rem, 2vw + 0.4rem, 1.75rem);
}

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

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border-width: 0; }

html,body { width: 100%; min-height: 100vh; background: #fafafa; color: #0f172a; font-family: 'Syne Mono', monospace; cursor: none; overflow-x: hidden; }
body[dir="rtl"] { font-family: 'Noto Naskh Arabic', serif; }

#cur-dot { position: fixed; top: 0; left: 0; width: 6px; height: 6px; background: var(--accent); border-radius: 50%; pointer-events: none; z-index: 9999; will-change: transform; transition: transform 0.05s; }
#cur-ring { position: fixed; top: 0; left: 0; width: 28px; height: 28px; border: 1.5px solid var(--ocean-green); border-radius: 50%; pointer-events: none; z-index: 9998; will-change: transform; transition: transform 0.12s, border-color 0.2s; }
body.cur-hover #cur-ring { border-color: var(--accent); transform: scale(1.4); }

#bg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; display: block; pointer-events: none; }
.scanlines { display: none; }
.vignette { position: fixed; inset: 0; background: radial-gradient(ellipse at center, transparent 35%, rgba(0, 0, 0, 0.03) 100%); pointer-events: none; z-index: 2; }

#app { position: relative; z-index: 10; display: flex; flex-direction: column; min-height: 100vh; }

header { background: rgba(255, 255, 255, 0.85); border-bottom: 1px solid rgba(0, 0, 0, 0.06); backdrop-filter: blur(18px); position: sticky; top: 0; z-index: 50; padding: 0.85rem 1.5rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; direction: ltr; }
.header-left, .header-right { display: flex; align-items: center; gap: 0.5rem; flex: 1; }
.header-right { justify-content: flex-end; }
.site-title { font-family: 'Cormorant Garamond', serif; font-size: var(--font-xl); font-weight: 600; color: #0f172a; white-space: nowrap; letter-spacing: 0.04em; }
.site-title span { color: var(--accent); }

.search-wrap { flex: 0 1 500px; min-width: 220px; position: relative; }
.search-wrap svg { position: absolute; left: 0.85rem; top: 50%; transform: translateY(-50%); color: #94a3b8; pointer-events: none; }
body[dir="rtl"] .search-wrap svg { left: auto; right: 0.85rem; }
#searchInput { width: 100%; background: rgba(0, 0, 0, 0.02); border: 1px solid rgba(0, 0, 0, 0.08); border-radius: 999px; padding: 0.55rem 1rem 0.55rem 2.6rem; font-family: 'Syne Mono', monospace; font-size: 0.88rem; outline: none; color: #0f172a; transition: border-color 0.2s, background 0.2s, box-shadow 0.2s; letter-spacing: 0.02em; }
body[dir="rtl"] #searchInput { font-family: 'Noto Naskh Arabic', serif; padding: 0.55rem 2.6rem 0.55rem 1rem; }
#searchInput::placeholder { color: #94a3b8; }
#searchInput:hover { background: #f8fafc; }
#searchInput:focus { border-color: var(--ocean-green); background: #f0fdf4; box-shadow: 0 0 0 3px rgba(82, 183, 136, 0.2); }

.header-btn { background: transparent; color: #64748b; border: 1px solid rgba(0, 0, 0, 0.08); border-radius: 50%; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; cursor: none; transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1); }
.header-btn svg { width: 17px; height: 17px; transition: transform 0.2s; }
.header-btn:hover { background: #f8fafc; color: #0f172a; transform: scale(1.08) rotate(-4deg); border-color: rgba(0, 0, 0, 0.12); }
.header-btn:active { transform: scale(0.95); }
.icon-sun { display: none; }
.icon-moon { display: block; }

.category-bar { background: rgba(250, 250, 250, 0.85); border-bottom: 1px solid rgba(0, 0, 0, 0.04); backdrop-filter: blur(12px); padding: 0.6rem 1.5rem; overflow-x: auto; scrollbar-width: none; z-index: 40; position: sticky; top: 63px; }
.category-bar::-webkit-scrollbar { display: none; }
.cat-pills { display: flex; gap: 0.5rem; width: max-content; }
.cat-btn { border: 1px solid rgba(0,0,0,0.06); border-radius: 999px; padding: 0.32rem 1rem; font-family: 'Syne Mono', monospace; font-size: 0.76rem; font-weight: 700; cursor: none; transition: all 0.18s; white-space: nowrap; background: #ffffff; color: #64748b; letter-spacing: 0.05em; }
body[dir="rtl"] .cat-btn { font-family: 'Noto Naskh Arabic', serif; }
.cat-btn:hover { border-color: var(--ocean-green); color: var(--ocean-green); }
.cat-btn.active { color: #ffffff; border-color: transparent; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); }
.cat-btn[data-cat="All"].active { background: var(--eucalyptus); color: var(--granny-apple); }
.cat-btn[data-cat="Motion"].active { background: var(--color-motion); }
.cat-btn[data-cat="Looks"].active { background: var(--color-looks); color: var(--granny-apple); }
.cat-btn[data-cat="Sound"].active { background: var(--color-sound); color: var(--granny-apple); }
.cat-btn[data-cat="Events"].active { background: var(--color-events); }
.cat-btn[data-cat="Control"].active { background: var(--color-control); }
.cat-btn[data-cat="Sensing"].active { background: var(--color-sensing); }
.cat-btn[data-cat="Operators"].active { background: var(--color-operators); }
.cat-btn[data-cat="Variables"].active { background: var(--color-variables); }
.cat-btn[data-cat="My Blocks"].active { background: var(--color-myblocks); color: var(--granny-apple); }

main { flex: 1; max-width: 1400px; width: 100%; margin: 0 auto; padding: 1.5rem; }
#blocksGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1.25rem; }

.block-card { background: #ffffff; border-radius: 16px; border: 1px solid rgba(0, 0, 0, 0.04); border-top: 4px solid #cbd5e1; padding: 1.1rem; display: flex; flex-direction: column; gap: 0.5rem; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03); transition: transform 0.2s cubic-bezier(.22, 1, .36, 1), box-shadow 0.2s, border-color 0.2s, border-top-color 0.2s, background 0.2s; cursor: none; position: relative; overflow: hidden; }
.block-card::after { content: ''; position: absolute; inset: 0; background: rgba(0, 0, 0, 0); transition: background 0.2s; border-radius: 16px; pointer-events: none; }
.block-card:hover { transform: translateY(-4px) scale(1.01); box-shadow: 0 12px 36px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(82, 183, 136, 0.4); background: #f0fdf4; }
.block-card:hover::after { background: rgba(0, 0, 0, 0); }

.click-hint { position: absolute; bottom: 0.5rem; right: 0.75rem; font-size: 0.6rem; color: #94a3b8; letter-spacing: 0.08em; opacity: 0; transition: opacity 0.2s; font-family: 'Syne Mono', monospace; }
body[dir="rtl"] .click-hint { right: auto; left: 0.75rem; }
.block-card:hover .click-hint { opacity: 1; }

.block-card[data-cat="Motion"] { border-top-color: var(--color-motion); }
.block-card[data-cat="Looks"] { border-top-color: var(--color-looks); }
.block-card[data-cat="Sound"] { border-top-color: var(--color-sound); }
.block-card[data-cat="Events"] { border-top-color: var(--color-events); }
.block-card[data-cat="Control"] { border-top-color: var(--color-control); }
.block-card[data-cat="Sensing"] { border-top-color: var(--color-sensing); }
.block-card[data-cat="Operators"] { border-top-color: var(--color-operators); }
.block-card[data-cat="Variables"] { border-top-color: var(--color-variables); }
.block-card[data-cat="My Blocks"] { border-top-color: var(--color-myblocks); }

.card-cat-label { font-size: 0.64rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: #94a3b8; font-family: 'Syne Mono', monospace; }
body[dir="rtl"] .card-cat-label { font-family: 'Noto Naskh Arabic', serif; letter-spacing: 0; }

.block-svg-area { background: #f8fafc; border-radius: 10px; min-height: 52px; display: flex; align-items: center; justify-content: center; padding: 0.5rem; overflow: hidden; direction: ltr; border: 1px solid rgba(0, 0, 0, 0.03); }
.block-svg-area svg { max-width: 100%; height: auto; }

.card-name { font-size: var(--font-lg); font-weight: 800; color: #0f172a; line-height: 1.25; font-family: 'Syne Mono', monospace; }
body[dir="rtl"] .card-name { font-family: 'Noto Naskh Arabic', serif; font-weight: 700; }

.card-intent { font-size: 0.82rem; color: #64748b; line-height: 1.6; flex: 1; font-family: inherit; }
body[dir="rtl"] .card-intent { font-family: 'Noto Naskh Arabic', serif; }

.no-results { grid-column: 1/-1; text-align: center; padding: 3rem 1rem; color: var(--eucalyptus); font-size: 1.1rem; font-weight: 600; font-family: 'Syne Mono', monospace; }
#resultsInfo { font-size: 0.8rem; color: var(--eucalyptus); font-weight: 600; margin-bottom: 0.85rem; letter-spacing: 0.08em; font-family: 'Syne Mono', monospace; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.block-card { animation: fadeIn 0.22s ease both; }

#modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(8, 28, 21, 0.82); backdrop-filter: blur(8px); z-index: 200; align-items: center; justify-content: center; padding: 1rem; }
#modal-backdrop.open { display: flex; }
#modal { background: #ffffff; border: none; border-radius: 20px; max-width: 640px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 24px 80px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05); animation: modalIn 0.28s cubic-bezier(.22, 1, .36, 1); position: relative; }
@keyframes modalIn { from { opacity: 0; transform: scale(0.92) translateY(20px); } to { opacity: 1; transform: scale(1) translateY(0); } }

#modal-header { padding: 1.4rem 1.4rem 0.8rem; border-bottom: 1px solid #f1f5f9; position: sticky; top: 0; background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(12px); z-index: 1; border-radius: 20px 20px 0 0; }
.modal-cat-badge { display: inline-block; font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; padding: 0.2rem 0.7rem; border-radius: 999px; color: var(--granny-apple); margin-bottom: 0.5rem; font-family: 'Syne Mono', monospace; }
body[dir="rtl"] .modal-cat-badge { font-family: 'Noto Naskh Arabic', serif; letter-spacing: 0; }
#modal-title { font-size: 1.45rem; font-weight: 900; color: #0f172a; line-height: 1.2; font-family: 'Syne Mono', monospace; }
body[dir="rtl"] #modal-title { font-family: 'Noto Naskh Arabic', serif; }
#modal-close { position: absolute; top: 1rem; right: 1rem; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 50%; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; cursor: none; color: #64748b; font-size: 1.1rem; transition: background 0.15s, color 0.15s; line-height: 1; }
body[dir="rtl"] #modal-close { right: auto; left: 1rem; }
#modal-close:hover { background: var(--everglade); color: var(--granny-apple); }
#modal-body { padding: 1.2rem 1.4rem 1.6rem; display: flex; flex-direction: column; gap: 1.2rem; }
.modal-block-preview { background: #f8fafc; border: 1px solid #f1f5f9; border-radius: 12px; padding: 1rem; display: flex; align-items: center; justify-content: center; direction: ltr; min-height: 60px; }
.modal-section-title { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; color: var(--eucalyptus); margin-bottom: 0.45rem; font-family: 'Syne Mono', monospace; }
body[dir="rtl"] .modal-section-title { font-family: 'Noto Naskh Arabic', serif; letter-spacing: 0; }
.modal-description { font-size: 0.95rem; color: #334155; line-height: 1.7; }
body[dir="rtl"] .modal-description { font-family: 'Noto Naskh Arabic', serif; }
.use-case-list { display: flex; flex-direction: column; gap: 0.6rem; }
.use-case-item { display: flex; gap: 0.65rem; align-items: flex-start; padding: 0.7rem 0.9rem; background: #f8fafc; border-radius: 10px; border-left: 3px solid var(--ocean-green); transition: border-left-color 0.15s, background 0.15s; }
body[dir="rtl"] .use-case-item { border-left: none; border-right: 3px solid var(--ocean-green); }
.use-case-item:hover { background: #f0fdf4; border-left-color: var(--accent); }
body[dir="rtl"] .use-case-item:hover { border-right-color: var(--accent); border-left-color: transparent; }
.use-case-icon { display: flex; align-items: center; justify-content: center; flex-shrink: 0; width: 28px; height: 28px; border-radius: 8px; background: var(--ocean-green); color: var(--granny-apple); margin-top: 0.1rem; transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1); }
.use-case-item:hover .use-case-icon { background: var(--accent); color: #fff; transform: scale(1.1) rotate(-8deg); box-shadow: 0 4px 10px rgba(236, 164, 0, 0.3); }
.use-case-svg { width: 15px; height: 15px; stroke-width: 2.2; }
.use-case-text { font-size: 0.87rem; color: #334155; line-height: 1.55; }
body[dir="rtl"] .use-case-text { font-family: 'Noto Naskh Arabic', serif; }
.modal-how-to { background: #f0fdf4; border-radius: 12px; padding: 0.9rem 1rem; border: 1px solid #bbf7d0; }
.how-to-step { display: flex; gap: 0.6rem; align-items: flex-start; font-size: 0.86rem; color: #334155; line-height: 1.55; margin-bottom: 0.4rem; }
body[dir="rtl"] .how-to-step { font-family: 'Noto Naskh Arabic', serif; }
.how-to-step:last-child { margin-bottom: 0; }
.step-num { background: #e2e8f0; color: #475569; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.65rem; font-weight: 700; flex-shrink: 0; margin-top: 0.1rem; font-family: 'Syne Mono', monospace; }
#modal::-webkit-scrollbar { width: 6px; }
#modal::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 99px; }
#modal::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }

[data-theme="dark"] { background: var(--black-bean); color: var(--granny-apple); }
[data-theme="dark"] .scanlines { display: block; background: repeating-linear-gradient(to bottom, transparent 0px, transparent 3px, rgba(0, 0, 0, 0.04) 3px, rgba(0, 0, 0, 0.04) 4px); }
[data-theme="dark"] .vignette { background: radial-gradient(ellipse at center, transparent 35%, rgba(8, 28, 21, 0.82) 100%); }
[data-theme="dark"] header { background: rgba(8, 28, 21, 0.85); border-bottom: 1px solid var(--everglade); }
[data-theme="dark"] .site-title { color: var(--granny-apple); }
[data-theme="dark"] #searchInput { background: rgba(27, 67, 50, 0.35); border: 1px solid var(--green-pea); color: var(--granny-apple); }
[data-theme="dark"] #searchInput::placeholder { color: var(--eucalyptus); }
[data-theme="dark"] #searchInput:hover { background: rgba(27, 67, 50, 0.45); }
[data-theme="dark"] #searchInput:focus { background: rgba(27, 67, 50, 0.55); box-shadow: 0 0 0 3px rgba(236, 164, 0, 0.12); border-color: var(--accent); }
[data-theme="dark"] .category-bar { background: rgba(8, 28, 21, 0.7); border-bottom-color: var(--everglade); }
[data-theme="dark"] .cat-btn { background: rgba(27, 67, 50, 0.25); border-color: var(--everglade); color: var(--silver-tree); }
[data-theme="dark"] .cat-btn.active { color: var(--black-bean); box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3); }
[data-theme="dark"] .cat-btn:hover { border-color: var(--ocean-green); color: var(--granny-apple); }
[data-theme="dark"] .block-card { background: rgba(255, 255, 255, 0.03); border: 1px solid rgba(255, 255, 255, 0.08); border-top: 4px solid #cbd5e1; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2); backdrop-filter: blur(8px); }
[data-theme="dark"] .block-card:hover { box-shadow: 0 12px 36px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(236, 164, 0, 0.3); background: rgba(255, 255, 255, 0.06); }
[data-theme="dark"] .block-card:hover::after { background: rgba(236, 164, 0, 0.05); }
[data-theme="dark"] .block-svg-area { background: rgba(0, 0, 0, 0.2); border: 1px solid rgba(255, 255, 255, 0.05); }
[data-theme="dark"] .card-name { color: var(--granny-apple); }
[data-theme="dark"] .card-intent { color: var(--fringy-flower); }
[data-theme="dark"] #modal { background: rgba(8, 28, 21, 0.75); border: 1px solid rgba(183, 228, 199, 0.15); box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(236, 164, 0, 0.2); backdrop-filter: blur(24px); }
[data-theme="dark"] #modal-header { background: rgba(8, 28, 21, 0.4); border-bottom: 1px solid rgba(183, 228, 199, 0.1); }
[data-theme="dark"] #modal-title { color: var(--granny-apple); }
[data-theme="dark"] #modal-close { background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.1); color: var(--fringy-flower); }
[data-theme="dark"] #modal-close:hover { background: var(--eucalyptus); color: var(--granny-apple); }
[data-theme="dark"] .modal-block-preview { background: rgba(0, 0, 0, 0.25); border: 1px solid rgba(255, 255, 255, 0.05); }
[data-theme="dark"] .modal-description { color: var(--fringy-flower); }
[data-theme="dark"] .use-case-item { background: rgba(255, 255, 255, 0.04); }
[data-theme="dark"] .use-case-item:hover { background: rgba(255, 255, 255, 0.08); border-left-color: var(--accent); }
[data-theme="dark"] .use-case-text { color: var(--granny-apple); }
[data-theme="dark"] .modal-how-to { background: rgba(0, 0, 0, 0.2); border: 1px solid rgba(64, 145, 108, 0.3); }
[data-theme="dark"] .how-to-step { color: var(--fringy-flower); }
[data-theme="dark"] .step-num { background: var(--eucalyptus); color: var(--granny-apple); }
[data-theme="dark"] #modal::-webkit-scrollbar-track { background: var(--granny-apple); }
[data-theme="dark"] #modal::-webkit-scrollbar-thumb { background: var(--eucalyptus); }
[data-theme="dark"] .header-btn { color: var(--fringy-flower); border-color: rgba(255, 255, 255, 0.1); }
[data-theme="dark"] .header-btn:hover { background: rgba(255, 255, 255, 0.08); color: var(--accent); border-color: rgba(255, 255, 255, 0.2); }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

@media (pointer: coarse) {
  #cur-dot, #cur-ring { display: none; }
  body, button, a, .header-btn, .cat-btn, .block-card { cursor: auto; }
}

@media (max-width: 600px) {
  header {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }

  .header-left {
    flex: 0 0 auto;
  }

  .header-right {
    flex: 0 0 auto;
    gap: 0.35rem;
  }

  .site-title {
    font-size: 1rem;
  }

  .search-wrap {
    flex: 1 1 100%;
    min-width: 0;
    order: 3;
    width: 100%;
  }

  .header-btn {
    width: 34px;
    height: 34px;
  }
}
