/* Keep the existing header controls in their desktop flex layout. */
.workbench-header-actions { display: contents; }
.workbench-mobile-brand,
.workbench-mobile-heading,
.site-header .workbench-mobile-nav-link,
.workbench-mobile-filter,
.workbench-mobile-art,
#workbench-motion,
#workbench-back { display: none; }

/* Use the compact header on narrow screens and when a touch phone rotates. */
@media (max-width: 620px), (max-width: 950px) and (max-height: 500px) and (orientation: landscape) and (hover: none) and (pointer: coarse) {
  .site-header:has(.workbench-menu:not([hidden]), #side-switch[aria-pressed="true"]:not([hidden])) {
    position: sticky;
    top: 0;
    z-index: 12;
    display: flex;
    flex-wrap: nowrap;
    width: 100%;
    min-height: 65px;
    margin-inline: 0;
    padding: 4px max(12px, env(safe-area-inset-right)) 4px max(12px, env(safe-area-inset-left));
    gap: 8px;
    background: #080f10;
  }

  body[data-side="creative"] .site-header:has(#side-switch:not([hidden])) {
    background: #180d13;
    border-bottom-color: #633541;
  }
  .site-header:has(#side-switch:not([hidden])) .brand-group { flex: 1; min-width: 0; }
  .site-header:has(#side-switch:not([hidden])) .brand {
    font-size: .87rem;
    line-height: 1.3;
    white-space: normal;
  }
  .site-header:has(#side-switch:not([hidden])) .pixel-switch {
    flex: 0 0 54px;
    width: 54px;
    height: 54px;
  }
  .site-header:has(#side-switch:not([hidden])) .robot-figure { width: 50px; height: 50px; }
  .site-header:has(.workbench-menu:not([hidden])) .workbench-mobile-brand {
    display: block;
    margin-top: 3px;
    color: var(--accent);
    font: .67rem/1.25 Consolas, monospace;
    letter-spacing: .08em;
    text-transform: uppercase;
  }
  .workbench-menu {
    flex-shrink: 0;
    min-height: 44px;
    padding: 0 10px;
    color: var(--ink);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    font: inherit;
    cursor: pointer;
  }
  .workbench-menu[aria-expanded="true"] { border-color: var(--line); }
  .site-header > #side-switch {
    flex: 0 0 auto;
    min-height: 44px;
    margin: 0;
    padding: 6px 9px;
    font-size: .76rem;
    line-height: 1.2;
  }
  .site-header > #side-switch > span[aria-hidden="true"] { display: none; }
  @media (max-width: 350px) {
    .site-header:has(#side-switch:not([hidden])) .brand { font-size: .78rem; }
    .site-header:has(.workbench-menu:not([hidden])) .workbench-mobile-brand,
    .workbench-menu > span { display: none; }
    .workbench-menu { padding-inline: 5px; }
  }
  .workbench-menu:not([hidden]) + .workbench-header-actions {
    position: absolute;
    inset: 100% 12px auto;
    display: grid;
    gap: 8px;
    max-height: calc(100vh - 66px);
    max-height: calc(100dvh - 66px);
    overflow: auto;
    padding: 10px;
    border: 1px solid #35544a;
    border-radius: 0 0 8px 8px;
    background: #0b1816;
  }
  .workbench-menu[aria-expanded="false"]:not([hidden]) + .workbench-header-actions { display: none; }
  .workbench-menu:not([hidden]) + .workbench-header-actions nav {
    order: 0;
    justify-content: flex-start;
    gap: 4px 14px;
    margin: 0;
  }
  .workbench-menu:not([hidden]) + .workbench-header-actions .workbench-mobile-nav-link { display: inline-flex; }
  .workbench-menu:not([hidden]) + .workbench-header-actions :is(.search-trigger, #workbench-motion) {
    display: flex;
    order: 0;
    justify-content: flex-start;
    min-height: 44px;
    margin: 0;
  }
  .workbench-menu:not([hidden]) + .workbench-header-actions #workbench-motion {
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
  }
  .workbench-menu:not([hidden]) + .workbench-header-actions kbd { display: none; }

  /* Anchor jumps leave the selected content below the sticky header. */
  body:has(.workbench-menu:not([hidden]), #side-switch[aria-pressed="true"]:not([hidden])) :is(main[id], section[id], article[id]) {
    scroll-margin-top: 77px;
  }
}

@media (max-width: 620px) {
  /* Use the existing Matrix and wireframe canvases. The code stays in the
     right lane, and geometry.js already avoids the Matrix canvas bounds. */
  #professional-view .hero { isolation: auto; }
  #professional-view #matrix-rain {
    position: fixed;
    z-index: -1;
    top: 65px;
    right: 0;
    width: 49%;
    height: calc(100vh - 65px);
    height: calc(100lvh - 65px);
    opacity: .35;
    mask-image: linear-gradient(105deg, transparent 4%, #000 85%);
  }
  #professional-view .hero-copy { background: linear-gradient(90deg, #070f10e6, #070f1077); }
  #featured { background: rgb(10 29 25 / 47%); box-shadow: none; }

  #projects:has(.case-carousel) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    column-gap: 10px;
    padding-block: 24px 14px;
  }
  #projects:has(.case-carousel) .section-heading {
    grid-area: 1 / 1 / 2 / -1;
    margin: 0;
    min-width: 0;
  }
  #projects:has(.case-carousel) #projects-title {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  #projects:has(.case-carousel) .decode-note {
    align-content: start;
    gap: 3px;
    min-height: 44px;
    margin: 0;
    padding: 4px 0 8px;
    font-size: .73rem;
  }
  #projects:has(.case-carousel) .decode-note .workbench-mobile-heading {
    display: flex;
    align-items: center;
    grid-row: 1;
    min-height: 37px;
    font-weight: 700;
    font-size: .86rem;
    letter-spacing: .07em;
    color: var(--accent);
  }
  #projects:has(.case-carousel) .decode-note :is(.decode-width, .decode-text) { grid-row: 2; }
  #projects:has(.case-carousel) .decode-note:not(.is-revealed) .decode-text { visibility: hidden; }
  #projects:has(.case-carousel) .decode-note:not(.is-revealed)::after {
    content: "▰▰▰▰ · Tap to decode";
    grid-area: 2 / 1;
    font-size: .68rem;
  }
  #projects .project-toolbar {
    grid-area: 1 / 2;
    z-index: 1;
    justify-self: end;
    margin: 0;
  }
  #projects .project-filters { display: none; }
  #projects #filter-status {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .workbench-mobile-filter { display: block; }
  #workbench-topic {
    max-width: 137px;
    min-height: 44px;
    padding: 5px 8px;
    border: 1px solid #416353;
    border-radius: 7px;
    background: #10251fba;
    color: var(--ink);
    font: 1rem/1.3 "Segoe UI", sans-serif;
    color-scheme: dark;
  }
  #workbench-topic option { background: #10251f; color: var(--ink); }
  #projects :is(.case-navigation, .case-carousel) { grid-column: 1 / -1; min-width: 0; }
  #projects .case-navigation { margin-top: 5px; }
  #projects .case-carousel { gap: 8px; }
  #projects .case-carousel .project-card:not([hidden]) {
    flex-basis: 88%;
    background: rgb(13 32 26 / 51%);
  }
  #projects .case-carousel.case-single .project-card:not([hidden]) { flex-basis: 100%; }
  #projects .case-carousel .project-art {
    display: grid;
    align-content: start;
    gap: 5px;
    min-height: 74px;
    margin: 9px 9px 0;
    padding: 7px 9px;
    border-color: #29473c;
    background: rgb(5 16 13 / 45%);
  }
  #projects .case-carousel .terminal-bar {
    padding-bottom: 4px;
    border-bottom: 1px solid #29473c;
  }
  #projects .case-carousel .terminal-bar i { flex: 0 0 5px; height: 5px; }
  #projects .case-carousel .terminal-bar span { margin-left: 2px; overflow-wrap: anywhere; }
  #projects .case-carousel .project-art pre {
    max-height: 3.2em;
    overflow: hidden;
    color: #a6d4ba;
    line-height: 1.6;
  }
  #projects .case-carousel .project-copy { padding: 10px 12px 8px; gap: 4px; }
  #projects .case-carousel .project-copy .eyebrow { margin: 0 0 3px; letter-spacing: .06em; }
  #projects .case-carousel .project-copy h3 { font-size: 1.04rem; line-height: 1.3; margin: 0; }
  #projects .case-carousel .project-copy > p:not(.eyebrow) {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    overflow: hidden;
    margin: 0;
    font-size: .78rem;
  }
  #projects .case-carousel .project-copy .tags { display: none; }
  #projects .case-carousel .project-copy .text-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    margin: 0;
    padding: 0;
  }
  #projects .case-carousel .feature-select { margin: 0 12px 12px; }
  #workbench-back {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    margin: 8px 14px 0;
    color: #9be5be;
    font-size: .82rem;
  }
  #featured .feature-top { padding: 7px 14px 0; gap: 10px; }
  #featured .feature-tabs { flex-wrap: wrap; }
  #featured .feature-tabs button { min-height: 44px; }
  #featured .record-meta { padding-inline: 14px; }
  #featured .feature-body { padding: 14px; }

  @media (prefers-reduced-motion: reduce) {
    #professional-view #matrix-rain { opacity: .18; }
  }
}
