/* ==========================================================
   Fonts
========================================================== */
@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn-ExtraBold.woff2') format('woff2');
    font-weight: 800;
    font-style: normal;
    font-display: swap;
}

/* ==========================================================
   Base
========================================================== */
:root {
    --bg: #050510;
    --surface: #1e1e2f;
    --ink: #222;
    --muted: #6e6e6e;
    --accent: #a9ddf8;
    --focus: #00bfff;
}

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

html {
    scroll-behavior: smooth;
    scroll-padding-top: 64px;
}

body {
    display: flex;
    flex-direction: column;
    min-width: 320px;
    min-height: 100vh;
    background: var(--bg);
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    overflow-x: hidden;
}

body.modal-open {
    overflow: hidden;
}

main {
    flex: 1 0 auto;
    width: 100%;
}

img {
    max-width: 100%;
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

.skip-link {
    position: absolute;
    z-index: 2000;
    top: -70px;
    right: 12px;
    padding: 10px 16px;
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    font-size: 14px;
    text-decoration: none;
}

.skip-link:focus {
    top: 12px;
}

/* ==========================================================
   Header / main menu
========================================================== */
.site-header {
    position: sticky;
    top: 0;
    z-index: 900;
    height: 64px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(5, 5, 16, 0.92);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: 100%;
    max-width: 1150px;
    margin: 0 auto;
    padding: 0 20px;
}

.header-brand {
    color: #fff;
    font-size: 17px;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.main-nav a {
    padding: 8px 14px;
    border-radius: 8px;
    color: #c4c4d0;
    font-size: 14px;
    text-decoration: none;
    white-space: nowrap;
    transition: 0.25s ease;
}

.main-nav a:hover,
.main-nav a.active {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* ==========================================================
   Hero
========================================================== */
.hero-section {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: calc(100vh - 64px);
    min-height: calc(100svh - 64px);
    overflow: hidden;
    background: var(--bg);
}

#starry-sky {
    position: absolute;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.profile-wrapper {
    position: relative;
    z-index: 2;
    width: 90%;
    max-width: 350px;
    padding: 3px;
    border-radius: 20px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
}

.profile-wrapper::before {
    content: '';
    position: absolute;
    z-index: -2;
    top: -75%;
    left: -75%;
    width: 250%;
    height: 250%;
    background: conic-gradient(
        transparent 60%,
        rgba(0, 191, 255, 0.4) 80%,
        rgba(135, 206, 250, 0.9) 95%,
        #fff 100%
    );
    animation: rotateBorder 4s linear infinite;
}

.profile-wrapper::after {
    content: '';
    position: absolute;
    inset: 3px;
    z-index: -1;
    border-radius: 17px;
    background: #fff;
}

@keyframes rotateBorder {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.profile-card {
    width: 100%;
    padding: 40px 30px;
    border-radius: 17px;
    background: rgba(255, 255, 255, 0.96);
    text-align: center;
}

.avatar-container {
    margin-bottom: 15px;
}

.avatar {
    display: block;
    width: 120px;
    height: 120px;
    margin: 0 auto;
    border: 4px solid #fff;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.12);
}

.avatar-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ink);
    color: #fff;
    font-size: 44px;
    font-weight: 800;
}

.name {
    margin-bottom: 10px;
    color: var(--ink);
    font-size: 24px;
    font-weight: 800;
}

.small-text {
    margin-bottom: 30px;
    color: #666;
    font-size: 14px;
}

.button-group {
    display: flex;
    gap: 12px;
}

.btn {
    flex: 1;
    min-height: 46px;
    padding: 10px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    transition: 0.25s ease;
}

.btn-primary {
    border: 2px solid var(--ink);
    background: var(--ink);
    color: #fff;
}

.btn-primary:hover {
    background: #444;
    border-color: #444;
    transform: translateY(-2px);
}

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

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

.inline-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    padding: 11px 22px;
    text-decoration: none;
}

.scroll-hint {
    position: absolute;
    z-index: 2;
    bottom: 25px;
    left: 50%;
    width: 25px;
    height: 40px;
    border: 2px solid rgba(255, 255, 255, 0.65);
    border-radius: 20px;
    transform: translateX(-50%);
}

.scroll-hint span {
    position: absolute;
    top: 7px;
    left: 50%;
    width: 5px;
    height: 8px;
    border-radius: 5px;
    background: #fff;
    transform: translateX(-50%);
    animation: scrollDown 1.5s infinite;
}

@keyframes scrollDown {
    0% { opacity: 0; transform: translate(-50%, 0); }
    40% { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, 17px); }
}

/* ==========================================================
   Sections (portfolio / notes)
========================================================== */
.portfolio-section {
    width: 100%;
    padding: 90px 30px;
    background: #fff;
    color: var(--ink);
}

.notes-section {
    width: 100%;
    padding: 90px 30px;
    background: #f5f5f5;
    color: var(--ink);
}

.portfolio-container {
    width: 100%;
    max-width: 1150px;
    margin: 0 auto;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
}

.section-heading h1,
.section-heading h2 {
    color: var(--ink);
    font-size: 30px;
    font-weight: 800;
}

.section-heading span {
    width: 65px;
    height: 2px;
    background: var(--ink);
}

.section-description {
    margin: 14px 0 42px;
    color: var(--muted);
    font-size: 14px;
    text-align: center;
}

.center-action {
    margin-top: 35px;
    text-align: center;
}

.empty-state {
    flex: 1 0 100%;
    padding: 45px;
    color: var(--muted);
    text-align: center;
}

/* Project logos (centered rows, 4 / 3 / 2 per row) */
.portfolio-logo-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 42px 34px;
    margin-top: 34px;
}

.project-logo-item {
    display: flex;
    flex: 0 0 calc((100% - 102px) / 4);
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 14px;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.project-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 118px;
    height: 118px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.055);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.18);
    overflow: hidden;
    transition: transform 0.28s ease, box-shadow 0.28s ease, border-color 0.28s ease, background 0.28s ease;
}

.project-logo img {
    display: block;
    width: 78%;
    height: 78%;
    object-fit: contain;
    transition: transform 0.28s ease;
}

.project-logo span {
    color: var(--ink);
    font-size: 38px;
    font-weight: 800;
    line-height: 1;
}

.project-logo-item h3 {
    max-width: 170px;
    margin: 0;
    overflow: hidden;
    font-size: 15px;
    font-weight: 800;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.project-logo-item:hover .project-logo {
    transform: translateY(-7px);
    border-color: rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.085);
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

.project-logo-item:hover .project-logo img {
    transform: scale(1.06);
}

/* Post cards (3 / 2 / 1 per row) */
.post-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 24px;
}

.post-card {
    flex: 0 0 calc((100% - 48px) / 3);
    min-width: 0;
    overflow: hidden;
    border: 1px solid #e2e2e2;
    border-radius: 16px;
    background: #fff;
    color: var(--ink);
    text-decoration: none;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.06);
    transition: 0.3s;
}

.post-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.12);
}

.post-card > img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
}

.post-card > div {
    padding: 20px;
}

.post-card small {
    color: #767676;
}

.post-card h3 {
    margin: 8px 0;
    color: var(--ink);
}

.post-card p {
    display: -webkit-box;
    overflow: hidden;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.9;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
}

/* Listing pages (white) */
.listing-page {
    padding: 50px 20px;
    background: #fff;
    color: var(--ink);
}

.listing-page .portfolio-logo-grid,
.listing-page .post-grid {
    margin-top: 36px;
}

.listing-page .project-logo {
    border-color: #e5e5e9;
    background: #f7f7f9;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.07);
}

.listing-page .project-logo-item h3 {
    color: var(--ink);
}

.back-link {
    display: inline-block;
    margin-bottom: 30px;
    color: inherit;
    text-decoration: none;
}

.back-link:hover {
    text-decoration: underline;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 40px;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 42px;
    height: 42px;
    padding: 0 12px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    color: var(--ink);
    font-size: 14px;
    font-weight: 800;
    text-decoration: none;
    transition: 0.25s ease;
}

.pagination a:hover,
.pagination .current {
    background: var(--ink);
    color: #fff;
}

/* ==========================================================
   Detail pages (dark)
========================================================== */
.detail-page {
    padding: 50px 20px;
    background: var(--bg);
    color: #fff;
}

.detail-card {
    max-width: 900px;
    margin: 0 auto;
    padding: 35px;
    border-radius: 18px;
    background: var(--surface);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.detail-cover {
    display: block;
    width: 100%;
    max-height: 500px;
    margin-bottom: 25px;
    border-radius: 14px;
    object-fit: cover;
}

.detail-card h1 {
    margin: 10px 0 15px;
    font-size: 32px;
    line-height: 1.6;
}

.post-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 22px;
    color: #9a9aab;
    font-size: 13px;
}

.lead {
    color: #aaa;
    font-size: 16px;
    line-height: 2;
}

.detail-card .project-tags {
    margin: 20px 0;
}

.project-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.project-tags span {
    padding: 4px 9px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 20px;
    color: #cfd3dc;
    direction: ltr;
    font-family: Arial, sans-serif;
    font-size: 11px;
}

.rich-content {
    margin: 30px 0;
    color: #ddd;
    font-size: 15px;
    line-height: 2.4;
}

.rich-content > :first-child { margin-top: 0; }
.rich-content p { margin-bottom: 16px; }

.rich-content h2,
.rich-content h3 {
    margin: 34px 0 10px;
    color: #fff;
    font-weight: 800;
    line-height: 1.8;
}

.rich-content h2 { font-size: 22px; }
.rich-content h3 { font-size: 18px; }

.rich-content ul,
.rich-content ol {
    margin: 0 0 18px;
    padding-inline-start: 26px;
}

.rich-content li { margin-bottom: 6px; line-height: 2.2; }

.rich-content blockquote {
    margin: 18px 0;
    padding: 4px 18px;
    border-inline-start: 3px solid var(--accent);
    color: #c8c8d4;
}

.rich-content a {
    color: var(--accent);
    text-underline-offset: 4px;
}

.rich-content code {
    padding: 2px 6px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.08);
    direction: ltr;
    font-family: Consolas, 'Courier New', monospace;
    font-size: 0.9em;
    unicode-bidi: embed;
}

.rich-content pre {
    margin: 18px 0;
    padding: 16px;
    border-radius: 10px;
    background: #12121f;
    line-height: 1.8;
    overflow-x: auto;
    text-align: left;
}

.rich-content pre code {
    padding: 0;
    background: none;
}

.rich-content em { font-style: italic; }
.rich-content del { color: #9a9aab; }

.rich-content figure {
    margin: 26px 0;
    text-align: center;
}

.rich-content figure img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
    border-radius: 12px;
}

.rich-content figcaption {
    margin-top: 10px;
    color: #9a9aab;
    font-size: 13px;
    line-height: 1.8;
}

.rich-content .table-scroll {
    margin: 22px 0;
    overflow-x: auto;
}

.rich-content table {
    width: 100%;
    border-collapse: collapse;
    line-height: 1.9;
}

.rich-content th,
.rich-content td {
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    text-align: right;
}

.rich-content th {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.rich-content hr {
    margin: 28px 0;
    border: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.post-cta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-top: 36px;
    padding-top: 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    color: #ddd;
    font-size: 14px;
}

.detail-card .btn-secondary {
    border-color: #fff;
    color: #fff;
}

.detail-card .btn-secondary:hover {
    background: #fff;
    color: var(--ink);
}

/* Contact page */
.contact-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    margin-top: 28px;
}

.contact-grid a {
    align-items: center;
    padding: 18px;
    background: rgba(255, 255, 255, 0.03);
}

.contact-grid strong {
    font-size: 14px;
}

.contact-grid span {
    overflow-wrap: anywhere;
    font-size: 14px;
}

@media (max-width: 650px) {
    .contact-grid { grid-template-columns: 1fr; }
}

/* ==========================================================
   Error pages
========================================================== */
.error-page {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    background: var(--bg);
    color: #fff;
    text-align: center;
}

.error-code {
    display: block;
    color: rgba(255, 255, 255, 0.18);
    font-size: 96px;
    font-weight: 800;
    line-height: 1.2;
}

.error-box h1 {
    margin: 10px 0;
    font-size: 26px;
}

.error-box p {
    margin-bottom: 28px;
    color: #aaa;
    line-height: 2;
}

/* ==========================================================
   Footer
========================================================== */
.site-footer {
    flex-shrink: 0;
    padding: 22px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: var(--bg);
    color: #9a9aab;
    font-size: 13px;
    text-align: center;
}

/* ==========================================================
   Modal
========================================================== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.7);
    opacity: 0;
    visibility: hidden;
    transition: 0.25s ease;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 500px;
    max-height: 100%;
    padding: 32px 25px 25px;
    border-radius: 14px;
    background: var(--surface);
    color: #fff;
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 10px 35px rgba(0, 0, 0, 0.5);
    transform: translateY(-20px);
    transition: 0.25s ease;
}

.modal.active .modal-content {
    transform: translateY(0);
}

.close-btn {
    position: absolute;
    top: 8px;
    right: 13px;
    border: 0;
    background: transparent;
    color: #aaa;
    font-family: Arial, sans-serif;
    font-size: 29px;
    cursor: pointer;
}

.close-btn:hover {
    color: #fff;
}

.modal-divider {
    width: 85%;
    height: 1px;
    margin: 20px auto;
    background: rgba(255, 255, 255, 0.2);
}

.contact-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.contact-list a {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    padding: 13px 15px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #fff;
    text-decoration: none;
}

.contact-list a:hover {
    background: rgba(255, 255, 255, 0.08);
}

.contact-list strong {
    color: #aaa;
    font-size: 13px;
}

.contact-list span {
    color: var(--accent);
    direction: ltr;
    font-family: Arial, sans-serif;
    font-size: 13px;
}

.about-text {
    color: #ddd;
    font-size: 14px;
    line-height: 2.2;
    text-align: right;
}

/* ==========================================================
   Responsive
========================================================== */
@media (max-width: 800px) {
    .portfolio-logo-grid { gap: 34px 20px; }
    .project-logo-item { flex-basis: calc((100% - 40px) / 3); }
    .post-card { flex-basis: calc((100% - 24px) / 2); }
}

@media (max-width: 550px) {
    .header-brand { display: none; }
    .header-inner { justify-content: center; padding: 0 8px; }
    .main-nav a { padding: 8px 9px; font-size: 13px; }
    .profile-card { padding: 30px 20px; }
    .avatar { width: 100px; height: 100px; }
    .name { font-size: 22px; }
    .portfolio-section,
    .notes-section { padding: 70px 18px; }
    .section-heading h1,
    .section-heading h2 { font-size: 24px; }
    .section-heading span { width: 35px; }
    .portfolio-logo-grid { gap: 30px 16px; }
    .project-logo-item { flex-basis: calc((100% - 16px) / 2); }
    .project-logo { width: 100px; height: 100px; border-radius: 24px; }
    .project-logo-item h3 { max-width: 145px; font-size: 14px; }
    .post-card { flex-basis: 100%; }
    .detail-card { padding: 22px; }
    .detail-card h1 { font-size: 25px; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }

    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}

/* ==========================================================
   Language switch (header)
========================================================== */
.main-nav .lang-switch {
    margin-inline-start: 6px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    color: #fff;
    font-size: 13px;
}

.main-nav .lang-switch:hover {
    border-color: rgba(255, 255, 255, 0.5);
}

@media (max-width: 550px) {
    .main-nav { gap: 2px; }
    .main-nav .lang-switch { margin-inline-start: 2px; }
}

/* ==========================================================
   English site (html[dir="ltr"]): system font stack, left-aligned text, tighter line heights
========================================================== */
html[lang="en"] body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Vazirmatn', sans-serif;
}

html[dir="ltr"] .skip-link { right: auto; left: 12px; }
html[dir="ltr"] .rich-content th,
html[dir="ltr"] .rich-content td,
html[dir="ltr"] .about-text { text-align: left; }
html[dir="ltr"] .about-text { line-height: 1.9; }
html[dir="ltr"] .rich-content { line-height: 1.9; }
html[dir="ltr"] .rich-content li { line-height: 1.8; }
html[dir="ltr"] .rich-content h2,
html[dir="ltr"] .rich-content h3 { line-height: 1.4; }
html[dir="ltr"] .lead { line-height: 1.7; }
html[dir="ltr"] .detail-card h1 { line-height: 1.3; }
html[dir="ltr"] .post-card p { line-height: 1.7; }
html[dir="ltr"] .error-box p { line-height: 1.7; }
html[dir="ltr"] .project-logo-item h3 { font-weight: 700; }
