/* ============================================================
   Code Brilliance - mobile & touch layer
   Loaded after style.css / extras.css / case-study.css so it
   only needs to correct what the older rules get wrong.

   Targets: phones (Android + iOS), small tablets, landscape
   phones, and any touch-only device.
   ============================================================ */

/* ------------------------------------------------------------
   1. Global guards
   ------------------------------------------------------------ */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: auto;
}

body {
    overflow-x: hidden;
}

/* Reveal animations slide in from the sides on desktop. On phones that
   pushes elements past the viewport and creates a phantom horizontal
   scroll, so use a short vertical rise instead. */
@media (max-width: 768px) {
    [data-animate-left],
    [data-animate-right] {
        transform: translateY(24px);
    }

    [data-animate-left].visible,
    [data-animate-right].visible {
        transform: translateY(0);
    }
}

/* Media never causes a horizontal scrollbar. */
img,
video,
iframe,
embed,
object {
    max-width: 100%;
}

img {
    height: auto;
}

/* Flex/grid children default to min-width:auto, which refuses to
   shrink below their content width. That is the usual cause of
   sideways scrolling on phones. */
.services-list,
.work-grid,
.process-grid,
.stats-section,
.contact-grid,
.testimonials-grid,
.team-grid,
.cb-lab-teaser-grid,
.cb-case-chips,
.cb-quick-actions,
.lab-grid,
.cs-meta,
.cs-related > div {
    min-width: 0;
}

.services-list > *,
.work-grid > *,
.process-grid > *,
.stats-section > *,
.contact-grid > *,
.cb-lab-teaser-grid > *,
.lab-grid > *,
.cs-meta > *,
.cs-related > div > * {
    min-width: 0;
}

/* Long words, URLs and e-mail addresses wrap instead of pushing
   the layout wider than the screen. */
h1,
h2,
h3,
h4,
h5,
h6,
p,
li,
a,
dd,
dt {
    overflow-wrap: break-word;
}

/* ------------------------------------------------------------
   2. Floating actions + sticky CTA
   Keep them clear of each other and of the iPhone home bar.
   ------------------------------------------------------------ */
.cb-floating {
    right: calc(14px + env(safe-area-inset-right, 0px));
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
}

.sticky-cta {
    right: auto;
    left: calc(14px + env(safe-area-inset-left, 0px));
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
}

/* Leave room so the buttons never sit on top of footer copy. */
@media (max-width: 768px) {
    footer {
        padding-bottom: calc(50px + env(safe-area-inset-bottom, 0px));
    }

    .cs-footer {
        padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px));
    }
}

/* ------------------------------------------------------------
   3. Header and navigation
   ------------------------------------------------------------ */
@media (max-width: 768px) {
    header {
        padding-top: calc(8px + env(safe-area-inset-top, 0px));
        padding-bottom: 8px;
    }

    header.scrolled {
        padding-top: calc(6px + env(safe-area-inset-top, 0px));
        padding-bottom: 6px;
    }

    nav {
        max-width: 100%;
        gap: 4px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    nav::-webkit-scrollbar {
        display: none;
    }

    nav a {
        flex: 0 0 auto;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 44px;
        padding: 8px 12px;
        font-size: 12px;
        white-space: nowrap;
    }

    /* The fixed logo only appears after scrolling. Below this
       width it overlaps the centred nav, so drop it. */
    .nav-logo {
        display: none;
    }

    .sticky-cta {
        padding: 11px 18px;
        font-size: 12px;
        max-width: calc(100vw - 90px);
    }
}

@media (max-width: 400px) {
    nav a {
        font-size: 11px;
        padding: 8px 9px;
        letter-spacing: -0.2px;
    }
}

/* Bootstrap-based pages (contact / services / work / email_sent) */
.legacy-brand {
    visibility: hidden;
}

@media (max-width: 767px) {
    header.legacy-header {
        position: relative;
        display: block;
        padding: 0;
    }

    header.legacy-header .legacy-brand {
        visibility: visible;
        display: flex;
        align-items: center;
        height: 52px;
        padding: 8px 0;
        float: left;
    }

    header.legacy-header .legacy-brand img {
        height: 34px;
        width: auto;
        max-width: 150px;
        object-fit: contain;
    }

    header.legacy-header .container,
    header.legacy-header .container-fluid {
        padding-left: 12px;
        padding-right: 12px;
    }

    header.legacy-header .navbar {
        margin-bottom: 0;
        min-height: 52px;
        border: 0;
    }

    header.legacy-header .navbar-toggle {
        margin: 3px 0;
        min-width: 46px;
        min-height: 46px;
        padding: 10px 12px;
    }

    header.legacy-header .navbar-collapse {
        border-top: 1px solid rgba(0, 0, 0, 0.08);
        box-shadow: none;
    }

    header.legacy-header .navbar-nav {
        margin: 6px 0;
    }

    header.legacy-header .navbar-nav > li > a {
        display: flex;
        align-items: center;
        min-height: 46px;
        padding: 12px 14px;
        font-size: 15px;
    }

    header.legacy-header .navbar-default {
        background: transparent;
        border: 0;
    }
}

/* Case-study / lab header */
@media (max-width: 640px) {
    .cs-header-inner {
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
        padding-bottom: 10px;
        gap: 8px;
    }

    .cs-header nav {
        width: 100%;
        gap: 2px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .cs-header nav::-webkit-scrollbar {
        display: none;
    }

    .cs-header nav a {
        display: inline-flex;
        align-items: center;
        flex: 0 0 auto;
        min-height: 44px;
        padding: 8px 10px;
        font-size: 12px;
    }

    .cs-brand img {
        height: 30px;
    }
}

/* ------------------------------------------------------------
   4. Type scale
   ------------------------------------------------------------ */
@media (max-width: 768px) {
    .hero {
        min-height: 100svh;
        padding-left: 18px;
        padding-right: 18px;
    }

    .hero h1 {
        font-size: clamp(1.5rem, 8.4vw, 2.6rem);
        letter-spacing: clamp(2px, 1.4vw, 6px);
        line-height: 1.25;
        margin-bottom: 14px;
    }

    .hero p {
        font-size: clamp(0.95rem, 3.8vw, 1.1rem);
        line-height: 1.7;
        max-width: 34ch;
    }

    .hero img {
        max-width: min(220px, 52vw);
        margin-bottom: 26px;
    }

    .hero-rotating-words {
        display: inline;
        min-width: 0;
    }

    .hero-subtitle {
        max-width: 100%;
    }

    .section-title {
        font-size: clamp(1.35rem, 6.6vw, 2.2rem);
        letter-spacing: 1.5px;
        line-height: 1.25;
    }

    .section-subtitle {
        font-size: 14px;
        line-height: 1.65;
        padding: 0 4px;
    }

    section {
        padding-left: 16px;
        padding-right: 16px;
    }

    .tech-stack {
        padding-left: 0;
        padding-right: 0;
    }

    .cta-btn {
        padding: 14px 24px;
        min-height: 48px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }
}

/* ------------------------------------------------------------
   5. Component fixes
   ------------------------------------------------------------ */
@media (max-width: 768px) {
    /* Services */
    .service-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 18px;
        padding: 22px 18px;
    }

    .service-visual {
        width: 100%;
        align-self: center;
        text-align: center;
    }

    .service-visual img {
        max-height: 190px;
        width: auto;
        margin: 0 auto;
    }

    .service-text h4 {
        font-size: 19px;
    }

    .service-text p {
        font-size: 14px;
        line-height: 1.65;
    }

    /* Work cards */
    .work-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .work-item {
        padding: 18px;
        gap: 16px;
        align-items: center;
    }

    .work-item img {
        height: 68px;
        width: 68px;
    }

    /* Stats */
    .stats-section {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 14px;
        padding: 28px 14px;
    }

    .stat-number {
        font-size: 30px;
    }

    .stat-label {
        font-size: 11px;
        letter-spacing: 0.5px;
    }

    /* Process */
    .process-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    /* Clients */
    .clients-section {
        padding: 44px 16px;
        border-radius: 18px;
        margin-top: 34px;
    }

    .clients-track {
        gap: 40px;
    }

    .clients-track img {
        height: 64px;
        padding: 12px 16px;
        max-width: 140px;
    }

    /* Contact / map */
    .contact-grid {
        grid-template-columns: 1fr;
        gap: 26px;
    }

    .contact-form-wrapper {
        padding: 24px 16px;
        border-radius: 18px;
    }

    .contact-form-wrapper h4 {
        font-size: 20px;
        letter-spacing: 1px;
    }

    .contact-info h4 {
        font-size: 19px;
    }

    .google-map,
    .google-map iframe {
        width: 100% !important;
        min-width: 0;
        height: 240px;
        border: 0;
    }

    /* Quick actions */
    .cb-quick-actions {
        gap: 8px;
    }

    .cb-quick-actions a {
        flex: 1 1 auto;
        justify-content: center;
        min-height: 44px;
        padding: 11px 14px;
        font-size: 12px;
        letter-spacing: 0.3px;
    }

    /* Case study chips */
    .cb-case-strip {
        padding: 36px 0 0;
    }

    .cb-case-strip h2 {
        font-size: 24px;
        letter-spacing: 1px;
    }

    .cb-case-chips {
        gap: 8px;
    }

    .cb-case-chips a {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
        padding: 10px 14px;
        font-size: 12px;
    }

    /* Lab */
    .cb-lab-teaser {
        padding: 60px 16px;
    }

    .lab-card-head {
        flex-wrap: wrap;
    }

    .lab-stage canvas {
        height: 210px;
    }

    .lab-controls {
        gap: 10px;
    }

    .lab-controls .cs-btn,
    .lab-controls > .lab-index {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    .lab-details pre {
        max-height: 240px;
        font-size: 11px;
    }

    /* Floating buttons stay comfortable for thumbs */
    .cb-fab {
        width: 48px;
        height: 48px;
    }

    /* Give the form status room on very narrow screens */
    .cb-form-status {
        font-size: 13px;
    }
}

@media (max-width: 420px) {
    .service-text h4 {
        font-size: 18px;
    }

    .work-item {
        flex-direction: column;
        text-align: center;
    }

    .work-item img {
        height: 72px;
        width: 72px;
    }

    .stats-section {
        grid-template-columns: 1fr 1fr;
    }

    .stat-number {
        font-size: 26px;
    }

    .contact-form-wrapper {
        padding: 20px 14px;
    }

    .cb-quick-actions a {
        flex: 1 1 100%;
    }
}

/* ------------------------------------------------------------
   6. iOS form zoom + comfortable targets
   Inputs below 16px make Safari zoom the whole page on focus.
   ------------------------------------------------------------ */
@media (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    select,
    textarea,
    .form-control {
        font-size: 16px;
        line-height: 1.4;
        min-height: 46px;
    }

    textarea,
    textarea.form-control {
        min-height: 130px;
    }

    .contact-form button[type="submit"],
    form[data-contact-form] button[type="submit"] {
        width: 100%;
        min-height: 48px;
        font-size: 14px;
    }
}

/* ------------------------------------------------------------
   7. Case study / lab article pages
   ------------------------------------------------------------ */
@media (max-width: 640px) {
    .cs-wrap {
        width: calc(100% - 32px);
    }

    main {
        padding-top: 34px;
    }

    h1 {
        font-size: clamp(1.9rem, 9vw, 2.8rem);
        line-height: 1.08;
    }

    .cs-lede {
        font-size: 1rem;
        margin-bottom: 30px;
    }

    .cs-hero {
        border-radius: 14px;
    }

    .cs-hero img {
        aspect-ratio: 4 / 3;
    }

    .cs-body {
        padding-top: 28px;
    }

    .cs-body section {
        margin-bottom: 34px;
    }

    .cs-body h2 {
        font-size: 19px;
    }

    .cs-cta {
        margin: 40px 0;
        padding: 22px 16px;
        border-radius: 14px;
    }

    .cs-cta-actions {
        flex-direction: column;
    }

    .cs-cta-actions .cs-btn {
        width: 100%;
        min-height: 48px;
    }

    .cs-related > div {
        gap: 10px;
    }

    .cs-related a {
        min-height: 56px;
    }

    .lab-back {
        margin-bottom: 24px;
    }

    .lab-intro p {
        font-size: 1rem;
    }
}

/* ------------------------------------------------------------
   8. Touch devices: no sticky hover states, no tap flash
   ------------------------------------------------------------ */
@media (hover: none) {
    .cb-fab:hover,
    .cb-quick-actions a:hover,
    .cb-case-chips a:hover,
    .cb-lab-tile:hover,
    .cs-btn:hover,
    .cs-related a:hover,
    .cs-header nav a:hover,
    .sticky-cta:hover,
    .service-item:hover,
    .work-item:hover,
    .process-card:hover,
    .tech-tag:hover,
    .clients-track img:hover,
    .stat-item:hover {
        transform: none;
    }

    .work-item::before {
        display: none;
    }

    a,
    button,
    .cb-fab,
    .cs-btn {
        -webkit-tap-highlight-color: transparent;
    }

    /* Touch devices cannot hover: keep focus feedback only. */
    .cb-fab:focus-visible,
    .cb-quick-actions a:focus-visible,
    .cb-case-chips a:focus-visible,
    .cb-lab-tile:focus-visible,
    .cs-btn:focus-visible,
    .cs-related a:focus-visible {
        transform: none;
    }
}

/* ------------------------------------------------------------
   9. Landscape phones
   ------------------------------------------------------------ */
@media (max-height: 500px) and (orientation: landscape) {
    .hero {
        min-height: auto;
        padding-top: 96px;
        padding-bottom: 48px;
    }

    .hero img {
        max-width: 120px;
        margin-bottom: 14px;
    }

    .hero h1 {
        font-size: 1.5rem;
    }

    .scroll-indicator {
        display: none;
    }

    .sticky-cta,
    .cb-floating {
        bottom: 10px;
    }
}

/* ------------------------------------------------------------
   10. Very small screens / older Android
   ------------------------------------------------------------ */
@media (max-width: 340px) {
    .section-title {
        font-size: 1.2rem;
        letter-spacing: 1px;
    }

    .cb-lab-teaser,
    .clients-section {
        padding-left: 12px;
        padding-right: 12px;
    }

    .cb-fab {
        width: 46px;
        height: 46px;
    }
}

/* ------------------------------------------------------------
   11. Print
   ------------------------------------------------------------ */
@media print {
    header,
    .cb-floating,
    .sticky-cta,
    #scroll-progress,
    #webgl {
        display: none !important;
    }

    body {
        background: #fff !important;
        color: #000 !important;
    }
}
