/* Final visual and responsive pass. Loaded last to resolve earlier theme layers. */

:root[data-theme="dark"] {
  --bg: #030a18;
  --bg-soft: #071329;
  --surface: rgba(19, 34, 60, 0.72);
  --surface-strong: rgba(12, 25, 47, 0.92);
  --text: #eef2fb;
  --text-strong: #ffffff;
  --muted: #aeb8ce;
  --faint: #77849f;
  --line: rgba(169, 187, 221, 0.15);
  --line-strong: rgba(185, 199, 227, 0.25);
  --shadow: 0 22px 62px rgba(0, 4, 15, 0.42);
}

:root[data-theme="dark"] body,
:root[data-theme="dark"] .projects-body,
:root[data-theme="dark"] .blog-page {
  background: #030a18;
}

:root[data-theme="dark"] main > .section,
:root[data-theme="dark"] .identity,
:root[data-theme="dark"] .project-directory,
:root[data-theme="dark"] .case-study,
:root[data-theme="dark"] .toolkit-modules,
:root[data-theme="dark"] .project-summary,
:root[data-theme="dark"] .blog-feed,
:root[data-theme="dark"] .blog-footer {
  background-color: #030a18;
  background-image: none;
}

:root[data-theme="dark"] .case-study:nth-child(even),
:root[data-theme="dark"] .project-summary,
:root[data-theme="dark"] .toolkit-modules {
  background-color: #061126;
}

:root[data-theme="dark"] .ambient {
  background: #030a18;
}

:root[data-theme="dark"] .ambient__grid,
:root[data-theme="dark"] .ambient__glow,
:root[data-theme="dark"] .iridescence-bg {
  opacity: 0.26;
}

:root[data-theme="dark"] .dot-field-container {
  opacity: 0.42;
}

:root[data-theme="dark"] .nav--pill,
:root[data-theme="dark"] .site-header.scrolled .nav--pill {
  background: rgba(4, 12, 28, 0.88);
  border-color: rgba(185, 199, 227, 0.18);
}

/* Explicit visual reading order for Persian navigation. */
html[dir="rtl"] .nav--pill {
  direction: rtl;
}

html[dir="rtl"] .gooey-nav-list {
  direction: rtl;
  flex-direction: row;
}

html[dir="rtl"] .nav__utilities,
html[dir="rtl"] .nav__lang {
  direction: rtl;
}

html[dir="rtl"] .nav__link--cta {
  margin-right: 8px;
  margin-left: 0;
}

/* Persian pages keep the same centered canvas while every content flow is RTL. */
html[dir="rtl"] body,
html[dir="rtl"] main,
html[dir="rtl"] .section,
html[dir="rtl"] .project-directory,
html[dir="rtl"] .case-study,
html[dir="rtl"] .toolkit-modules,
html[dir="rtl"] .blog-feed {
  direction: rtl;
}

html[dir="rtl"] .section__header,
html[dir="rtl"] .magic-rings-section__copy,
html[dir="rtl"] .reflective-card,
html[dir="rtl"] .skill-card,
html[dir="rtl"] .service-card,
html[dir="rtl"] .project-card__body,
html[dir="rtl"] .timeline__item,
html[dir="rtl"] .contact__form,
html[dir="rtl"] .contact__card,
html[dir="rtl"] .case-study__content,
html[dir="rtl"] .toolkit-module__body,
html[dir="rtl"] .project-directory__bar,
html[dir="rtl"] .project-hero__content,
html[dir="rtl"] .blog-card__body,
html[dir="rtl"] .blog-hero__intro,
html[dir="rtl"] .blog-footer {
  direction: rtl;
  text-align: right;
}

html[dir="rtl"] .section__label,
html[dir="rtl"] .case-study__features,
html[dir="rtl"] .case-study__tags,
html[dir="rtl"] .case-study__actions,
html[dir="rtl"] .contact__links,
html[dir="rtl"] .footer__inner,
html[dir="rtl"] .footer__nav {
  direction: rtl;
}

html[dir="rtl"] .form-label,
html[dir="rtl"] .form-input,
html[dir="rtl"] .form-textarea {
  direction: rtl;
  text-align: right;
}

html[dir="rtl"] .timeline__content,
html[dir="rtl"] .contact__card-content,
html[dir="rtl"] .skill-card__content,
html[dir="rtl"] .service-card__content {
  margin-right: 0;
  margin-left: auto;
}

html[dir="rtl"] .portfolio__heading,
html[dir="rtl"] .portfolio__heading .portfolio__intro,
html[dir="rtl"] .portfolio .section__header,
html[dir="rtl"] .portfolio .section__title {
  text-align: center;
}

/* Keep the exact portrait, but prevent browser interpolation from reviving edge halos. */
.hero__portrait-img {
  transform: translateZ(0);
  backface-visibility: hidden;
}

:root[data-theme="dark"] .hero__portrait-img {
  filter: contrast(1.035) saturate(1.01) drop-shadow(0 24px 38px rgba(0, 0, 0, 0.46));
}

body {
  -webkit-user-select: text;
  user-select: text;
}

/* The hero already exposes portfolio and CV actions; remove repeated contact copy. */
.hero .bento__cell--touch,
.hero .bento__cell--cta,
.hero .bento__cell--highlight {
  display: none;
}

@media (min-width: 901px) {
  .bento--intro {
    min-height: 100svh;
    padding-top: calc(var(--header-height) + 34px);
    padding-bottom: 26px;
  }

  .bento__cell--title {
    padding-bottom: 34px;
  }

  .bento-card--portrait,
  .bento-card--portrait:hover,
  :root[data-theme="light"] .bento-card--portrait,
  :root[data-theme="light"] .bento-card--portrait:hover {
    min-height: 560px;
  }

  .hero__portrait-img {
    width: min(42vw, 490px);
    max-width: 490px;
  }
}

.section__title,
.project-hero h1,
.case-study__content h2,
.blog-hero h1 {
  text-wrap: balance;
}

.hero__bio,
.portfolio__intro,
.project-card__desc,
.skill-card__desc,
.service-card__desc,
.timeline__desc,
.contact__card-text,
.case-study__lead,
.blog-card p {
  text-wrap: pretty;
}

.btn:focus-visible,
.nav__link:focus-visible,
.portfolio__filter:focus-visible,
.cv__tab:focus-visible,
.contact__social-link:focus-visible,
.form-input:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 3px;
}

@media (max-width: 900px) {
  :root,
  :root[data-theme="light"],
  :root[data-theme="dark"] {
    --container: min(100vw - 36px, 760px);
    --header-height: 72px;
    --section-padding: 68px;
  }

  .site-header {
    padding-top: 12px;
  }

  .nav--pill {
    min-height: 58px;
    padding: 8px 12px;
  }

  .nav__logo-img {
    width: 38px;
    height: 38px;
  }

  .nav__logo-text {
    max-width: 160px;
    font-size: 0.7rem;
  }

  .nav__toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .nav__menu {
    position: fixed;
    top: 82px;
    right: 18px;
    left: 18px;
    bottom: auto;
    z-index: 1001;
    flex-direction: column;
    align-items: stretch;
    max-height: calc(100svh - 100px);
    overflow-y: auto;
    padding: 12px;
    border-radius: 8px;
    opacity: 0;
    visibility: hidden;
  }

  .nav__menu.open {
    opacity: 1;
    visibility: visible;
  }

  html[dir="rtl"] .gooey-nav-list {
    flex-direction: column;
  }

  html[dir="rtl"] .gooey-nav-container .gooey-nav-list > li > a,
  html[dir="rtl"] .nav__link {
    justify-content: flex-start;
    text-align: right;
  }

  .hero {
    min-height: auto;
  }

  .bento--intro {
    gap: 16px;
    min-height: auto;
    padding-top: calc(var(--header-height) + 48px);
    padding-bottom: 52px;
  }

  .hero__title {
    max-width: 100%;
    font-size: clamp(2.3rem, 7.2vw, 3.8rem);
    line-height: 0.96;
  }

  html[dir="rtl"] .hero__title {
    line-height: 1.18;
  }

  .hero__role {
    max-width: 34ch;
    margin-top: 16px;
    font-size: 0.92rem;
    line-height: 1.55;
  }

  .bento-card--portrait,
  .bento-card--portrait:hover,
  :root[data-theme="light"] .bento-card--portrait,
  :root[data-theme="light"] .bento-card--portrait:hover {
    min-height: clamp(320px, 68vw, 470px);
  }

  .hero__portrait-img {
    width: min(66vw, 380px);
    max-height: 440px;
  }

  .hero__bio {
    font-size: 0.92rem;
    line-height: 1.75;
  }

  .section__title {
    font-size: clamp(2rem, 7vw, 3.4rem);
  }

  .skill-card,
  .service-card,
  .timeline__item,
  .tool-item {
    min-height: 0;
    padding: 20px;
  }

  .project-card__body,
  .contact__form,
  .contact__card {
    padding: 22px;
  }

  .project-hero {
    min-height: 620px;
  }

  .project-hero__content {
    padding-top: 150px;
    padding-bottom: 54px;
  }

  .project-hero h1 {
    font-size: clamp(3rem, 11vw, 5.4rem);
  }

  .case-study__inner {
    min-height: 0;
    padding-top: 66px;
    padding-bottom: 66px;
  }
}

@media (max-width: 620px) {
  :root,
  :root[data-theme="light"],
  :root[data-theme="dark"] {
    --container: calc(100vw - 28px);
    --section-padding: 54px;
  }

  .nav--pill {
    min-height: 54px;
    padding: 7px 10px;
  }

  .nav__logo-img {
    width: 36px;
    height: 36px;
  }

  .nav__logo-text {
    display: inline-block;
    max-width: 128px;
    font-size: 0.64rem;
  }

  .nav__toggle {
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
  }

  .bento--intro {
    gap: 12px;
    padding-top: calc(var(--header-height) + 36px);
    padding-bottom: 44px;
  }

  .hero__title {
    font-size: clamp(1.85rem, 8.5vw, 2.65rem);
  }

  .hero__role {
    margin-top: 12px;
    padding-inline-start: 12px;
    font-size: 0.82rem;
  }

  [dir="rtl"] .hero__role {
    padding-right: 12px;
  }

  .bento-card--portrait,
  .bento-card--portrait:hover,
  :root[data-theme="light"] .bento-card--portrait,
  :root[data-theme="light"] .bento-card--portrait:hover {
    min-height: min(74vw, 330px);
  }

  .hero__portrait-img {
    width: min(72vw, 310px);
    max-height: 340px;
  }

  .hero__bio {
    font-size: 0.84rem;
    line-height: 1.7;
  }

  .bento-card--touch,
  .bento-card--email {
    min-height: 70px;
    padding: 16px;
  }

  .bento-card--actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .btn {
    min-height: 44px;
    padding: 0 14px;
    font-size: 0.78rem;
  }

  .section__header {
    gap: 10px;
    margin-bottom: 26px;
  }

  .section__label {
    font-size: 0.66rem;
  }

  .section__title,
  html[dir="rtl"] .portfolio .section__title {
    font-size: clamp(1.72rem, 7.6vw, 2.35rem);
    line-height: 1.12;
    white-space: normal;
    text-wrap: balance;
  }

  .portfolio__heading .section__title {
    font-size: clamp(1.72rem, 7.6vw, 2.35rem);
  }

  .portfolio__intro {
    font-size: 0.84rem;
    line-height: 1.7;
  }

  .portfolio__filters {
    gap: 7px;
    margin-bottom: 24px;
  }

  .portfolio__filter,
  .cv__tab {
    min-height: 38px;
    padding: 0 12px;
    font-size: 0.68rem;
  }

  .skill-card,
  .service-card,
  .timeline__item,
  .tool-item,
  .project-card__body,
  .contact__form,
  .contact__card {
    padding: 18px;
  }

  .skill-card__icon {
    width: 42px;
    height: 42px;
    margin-bottom: 14px;
  }

  .skill-card__title,
  .service-card__title,
  .project-card__title {
    font-size: 0.98rem;
  }

  .skill-card__desc,
  .service-card__desc,
  .project-card__desc,
  .timeline__desc {
    font-size: 0.8rem;
    line-height: 1.7;
  }

  .contact__socials {
    grid-template-columns: 1fr 1fr;
  }

  .form-input {
    min-height: 46px;
    padding: 12px 14px;
    font-size: 0.88rem;
  }

  .form-textarea {
    min-height: 124px;
  }

  .project-hero {
    min-height: 520px;
  }

  .project-hero__content {
    padding-top: 126px;
    padding-bottom: 42px;
  }

  .project-hero h1 {
    font-size: clamp(2.45rem, 13vw, 3.7rem);
  }

  .project-hero__lead,
  .project-directory__bar p,
  .case-study__lead,
  .toolkit-modules__header p {
    font-size: 0.86rem;
    line-height: 1.72;
  }

  .project-summary__item {
    padding: 20px 14px;
  }

  .project-summary__value {
    font-size: 1.18rem;
  }

  .case-study__inner {
    gap: 28px;
    padding-top: 52px;
    padding-bottom: 52px;
  }

  .case-study__content h2 {
    font-size: clamp(1.75rem, 9vw, 2.7rem);
  }

  .case-study__features {
    grid-template-columns: 1fr;
  }

  .blog-hero {
    padding: 128px 0 58px;
  }

  .blog-hero h1 {
    font-size: clamp(2.25rem, 12vw, 3.2rem);
  }

  .blog-feed {
    padding: 54px 0 66px;
  }

  .blog-card__body {
    padding: 18px;
  }
}

@media (max-width: 380px) {
  .nav__logo-text {
    display: none;
  }

  .bento-card--actions,
  .contact__socials {
    grid-template-columns: 1fr;
  }
}

@media (hover: none) {
  .project-card__hover {
    display: none;
  }
}
