/* ============================================================
   responsive.css - tablet (max 900px) and phone (max 600px)
   breakpoints plus the reduced-motion fallbacks. Loaded last.
   ============================================================ */

@media (max-width: 900px) {
  /* Mobile perf: halve the blur radii so the stacked effects
     (header + hero photo) don't jank on low-end GPUs. */
  .header {
    background: rgba(30, 36, 48, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }

  .page-hero__title {
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }

  .reviews-layout {
    grid-template-columns: 1fr;
  }

  .about {
    display: flex;
    flex-direction: column;
    gap: 24px;
  }

  /* On stacked screens the logical order is: the company card, then
     the founder's portrait, then the facts row. */
  .about__text {
    order: 1;
  }

  .about__photo {
    order: 2;
  }

  .about__facts {
    order: 3;
  }

  /* The portrait card no longer stretches to the column height, so the
     flip card gets its size from the photo itself: the front face
     returns to the flow with a 2:3 crop, the back face still fills
     the same box. */
  .about__flip-inner {
    height: auto;
  }

  .about__flip-face--front {
    position: static;
  }

  .about__flip-face--front img {
    height: auto;
    aspect-ratio: 2 / 3;
  }

  /* One column on tablets/phones: the split columns collapse into a
     single stack, and flex-grow from the desktop layout must be reset
     so a short second column does not stretch. */
  .callouts-list {
    flex-direction: column;
  }

  .callouts-col {
    flex: none;
    width: 100%;
  }

  /* Calculator: stack the card and the photo on tablets so the fixed
     card width never crushes the image. */
  .calculator-layout {
    display: flex;
    flex-direction: column;
    gap: 24px;
  }

  .calculator-layout.is-result {
    gap: 0;
  }

  .calc-visual {
    min-height: 260px;
  }

  .contacts-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .works-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Best works on tablets: two columns. */
  .best-works {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  /* Compact vertical rhythm on phones: the desktop 80px section
     padding adds up with the neighbouring section to a huge gap. */
  .section {
    padding: 44px 0;
  }

  /* Phones: no reveal animations - content appears immediately and
     the page stays light (no heavy fades while scrolling). */
  .scroll-fade--hidden,
  .fact-letter {
    opacity: 1;
    transform: none;
    transition: none;
  }

  /* Tap hint on clickable cards: a small dark circle with the tap
     icon in the corner tells that the whole card is tappable.
     Cards are position: static by default, so make them relative
     here. The callouts (services and FAQ) get no badge - their
     toggle arrow already hints at tappability. The work card and
     best-work badges sit at the bottom (their vote row is
     left-aligned). */
  .work-card,
  .best-work {
    position: relative;
  }

  .work-card::after,
  .best-work::after {
    content: "";
    position: absolute;
    top: 10px;
    right: 10px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(15, 19, 28, 0.72) url(../icons/tap.svg) center / 18px 18px no-repeat;
    border: 1px solid rgba(255, 255, 255, 0.25);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    z-index: 2;
    pointer-events: none;
  }

  .work-card::after,
  .best-work::after {
    top: auto;
    bottom: 10px;
  }

  /* Hero: the same composition as on desktop, restyled for phones -
     anchored to the bottom (it was stuck to the header before). */
  .hero__content {
    left: 16px;
    right: 16px;
    top: auto;
    bottom: 72px;
    transform: none;
    gap: 12px;
    max-width: none;
  }

  .hero__content-logo {
    width: 200px;
  }

  .hero__content-title {
    font-size: clamp(21px, 6.4vw, 26px);
  }

  /* The sub-slogan: much smaller on phones than the desktop 48px. */
  .hero__subline {
    top: 68px;
    font-size: clamp(20px, 5.5vw, 26px);
  }

  /* How-we-work timeline: the horizontal line and the alternating
     labels do not fit narrow screens - the line turns vertical,
     every label moves to the right of its dot. */
  .how-we-work {
    grid-template-columns: 1fr;
  }

  .how-we-work::before {
    top: 0;
    bottom: 0;
    left: 20px;
    right: auto;
    width: 2px;
    height: auto;
    background: linear-gradient(
      180deg,
      rgba(255, 255, 255, 0),
      rgba(255, 255, 255, 0.28) 8%,
      rgba(255, 255, 255, 0.28) 92%,
      rgba(255, 255, 255, 0)
    );
  }

  .how-we-work__step {
    min-height: auto;
    text-align: left;
    padding: 0 0 30px 56px;
  }

  .how-we-work__dot {
    left: 0;
    top: 0;
    transform: none;
  }

  /* The dot is anchored to the cell's left edge on phones, so the
     hover grow must not add the desktop translateX centring. */
  .how-we-work__step:hover .how-we-work__dot {
    transform: scale(1.15);
  }

  .how-we-work__label {
    position: static;
    transform: none;
    width: auto;
    /* Vertically centre the single-line label on the 40px dot:
       8 = (40 - line-height 23) / 2. */
    padding-top: 8px;
    font-size: 16px;
  }

  /* Gallery viewer: swipe flips photos on phones; the prev/next
     arrows stay visible and vertically centred as an alternative,
     just smaller and pinned inside the screen edges. */
  .lightbox__nav {
    width: 40px;
    height: 40px;
    font-size: 24px;
  }

  .lightbox__nav--prev {
    left: 8px;
  }

  .lightbox__nav--next {
    right: 8px;
  }

  /* Sort tabs (works/reviews pages): keep them in a row, wrapping
     to the next line only when the row overflows (narrow phones). */
  .sort-control {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  /* Phone perf: drop all backdrop filters entirely. High-DPI screens
     (e.g. Galaxy A52 at 450 DPI) make blur extremely expensive,
     especially in Firefox. Solid fallbacks look nearly identical. */
  .header {
    background: rgba(30, 36, 48, 0.95);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .page-hero__inner {
    min-height: 240px;
  }

  .page-hero__title {
    padding: 20px 24px;
    font-size: 26px;
    background: rgba(20, 26, 36, 0.55);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .contacts-grid,
  .works-grid {
    grid-template-columns: 1fr;
  }

  /* Best works on phones: single column. */
  .best-works {
    grid-template-columns: 1fr;
  }

  /* Calculator on phones: the card stacks into a single column and
     the decorative photo is dropped entirely. */
  .calc-card {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 24px 18px;
  }

  .calc-card .section__title {
    margin-bottom: 4px;
  }

  .calc {
    order: 1;
  }

  /* Chips above the price, not after it. */
  .calc-result__options {
    order: 2;
  }

  .calc-result {
    order: 3;
  }

  .calc-visual {
    display: none;
  }

  /* Card body info/link are already shown on touch via
     @media (hover: none); on phones they get the clamped teaser. */
  .best-work__info,
  .best-work__link {
    display: block;
  }

  .best-work__info {
    font-size: 13.5px;
    line-height: 1.5;
    color: #aab2c0;
    margin-top: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .best-work__link {
    margin-top: 8px;
    font-weight: 700;
    font-size: 14px;
    color: var(--accent);
  }

  .reviews-media {
    grid-template-columns: 1fr;
  }

  .reviews-media__item {
    height: 220px;
  }

  .section--page .reviews-layout {
    padding: 14px;
    border-radius: 12px;
  }

  /* Calculator buttons: stack full-width on phones. On larger cards
     flex-wrap already falls back to this when the row is too narrow. */
  .calc__actions {
    flex-direction: column;
    align-items: stretch;
  }

  /* Reviews page: the form goes above the list on phones - with the
     vote form at the bottom every new review required scrolling
     through the whole page. align-items: stretch overrides the
     desktop "start", otherwise the columns would shrink to their
     content width. */
  .reviews-layout {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 24px;
  }

  .review-form-wrap {
    order: -1;
  }

  /* Footer on phones: stack the elements so nothing crowds the edge. */
  .footer__inner {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 16px;
  }

  /* About on phones: the framed cards are the base style now, only
     the compact paddings and facts stay mobile-specific. The portrait
     sits right under the company card. */
  .about__text {
    padding: 24px 18px;
  }

  .about__photo {
    padding: 12px;
  }

  .about__facts {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  /* The flip buttons swap their arrow for a tap badge on phones: a
     dark circle with the tap glyph, hinting that the card reacts to a
     tap. */
  .about__flip-arrow-char {
    display: none;
  }

  .about__flip-arrow-icon {
    display: inline-block;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(15, 19, 28, 0.72) url(../icons/tap.svg) center / 16px 16px no-repeat;
    border: 1px solid rgba(255, 255, 255, 0.25);
  }

  .about__facts li {
    padding: 12px 8px;
  }

  .about__facts strong {
    font-size: 18px;
  }

  /* Mobile nav: compact context-menu-style panel anchored to the burger. */
  .nav {
    position: absolute;
    top: 60px;
    right: 12px;
    flex-direction: column;
    gap: 2px;
    min-width: 210px;
    padding: 6px;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.15);
    background: rgba(30, 36, 48, 0.95);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
    transform-origin: top right;
    opacity: 0;
    transform: scale(0.95) translateY(-6px);
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
  }

  .nav.open {
    opacity: 1;
    transform: scale(1) translateY(0);
    visibility: visible;
    pointer-events: auto;
  }

  .nav a {
    display: block;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 14px;
  }

  .nav a:hover,
  .nav a.active {
    color: var(--accent);
    background: rgba(255, 255, 255, 0.08);
  }

  .nav-toggle {
    display: flex;
  }

  /* Header contact button on phones: a round icon-only button
     pushed to the burger; the label is hidden. */
  .btn.header__contact-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    margin-left: auto;
    margin-right: 8px;
    border-radius: 50%;
    justify-content: center;
  }

  .header__contact-text {
    display: none;
  }
}

/* ----- Reduced motion -----
   Users who opt out of animations get the final state immediately. */

@media (prefers-reduced-motion: reduce) {
  .scroll-fade {
    transition: none;
  }

  .scroll-fade--hidden {
    opacity: 1;
    transform: none;
  }

  .fact-letter {
    opacity: 1;
    transform: none;
    transition: none;
  }

  /* The portrait card flips instantly for users who opt out of
     motion. */
  .about__flip-inner {
    transition: none;
  }

  .work-gallery__img,
  .work-gallery__item--video,
  .work-fact {
    transition: none;
  }

  .work-gallery {
    transition: none;
  }

  .back-link {
    transition: none;
    animation: none;
  }
}
