/* ─────────────────────────────────────────────────────────────
   Adaptive responsive system
   Final cascade layer: stable from 320px phones to ultra-wide screens.
   Capability attributes are non-identifying and only tune layout/motion.
   ───────────────────────────────────────────────────────────── */

:root {
  --page-gutter: clamp(12px, 2.8vw, 32px);
  --section-space: clamp(76px, 8vw, 132px);
  --tap-size: 44px;
  --adaptive-vh: var(--viewport-height, 100dvh);
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
}

body {
  min-height: var(--adaptive-vh);
}

main,
footer {
  width: min(calc(100% - (var(--page-gutter) * 2)), var(--max));
}

main,
section,
article,
header,
footer,
nav,
form,
fieldset,
div {
  min-width: 0;
}

p,
h1,
h2,
h3,
h4,
small,
strong,
span,
a,
button,
dd,
dt {
  overflow-wrap: anywhere;
}

img,
svg,
canvas,
video,
iframe {
  max-width: 100%;
}

/* Fixed masthead: bounded at every viewport and never translated sideways. */
.site-header {
  left: max(var(--page-gutter), env(safe-area-inset-left));
  right: max(var(--page-gutter), env(safe-area-inset-right));
  width: auto;
  max-width: var(--max);
  margin-inline: auto;
  transform: none;
}

.site-header.is-hidden {
  transform: translateY(calc(-100% - 24px));
}

.brand-copy,
.header-actions,
.desktop-nav {
  min-width: 0;
}

.desktop-nav {
  justify-content: center;
  flex: 1 1 auto;
}

.desktop-nav a {
  white-space: nowrap;
}

/* Hero: fluid rather than breakpoint-dependent fixed geometry. */
.hero {
  min-height: min(100svh, 980px);
  grid-template-columns: minmax(0, 1.03fr) minmax(360px, .97fr);
  gap: clamp(34px, 5vw, 78px);
}

.hero-copy,
.hero-art {
  min-width: 0;
}

.hero h1 {
  max-width: 13ch;
  font-size: clamp(3.25rem, 6.1vw, 6.5rem);
  text-wrap: balance;
}

.hero-intro {
  max-width: 66ch;
}

.hero-art {
  width: 100%;
  min-height: clamp(470px, 54vw, 700px);
  height: min(72svh, 700px);
}

.hero-art-label {
  gap: 16px;
}

.hero-art-label span,
.hero-art-label small {
  min-width: 0;
}

.hero-proof > div,
.hero-fit-banner,
.hero-actions > * {
  min-width: 0;
}

/* Shared section rhythm and headings. */
.section {
  padding-block: var(--section-space);
}

.section-heading {
  width: min(100%, 940px);
  grid-template-columns: 64px minmax(0, 1fr);
}

.section-heading h2 {
  max-width: 18ch;
}

/* Work: explicit layout tiers and card-local responsiveness. */
.section.work-section {
  content-visibility: visible;
  contain-intrinsic-size: none;
}

.work-proof-legend {
  margin: -16px 0 30px 88px;
  gap: 10px 18px;
}

.work-section .project-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: clamp(18px, 2.1vw, 30px);
  align-items: stretch;
  perspective: none;
}

.work-section .project-card {
  --card-pad: clamp(24px, 2.7vw, 38px);
  min-height: 0;
  padding: var(--card-pad);
  display: flex;
  flex-direction: column;
  isolation: isolate;
  overflow: clip;
  transform: none;
  transform-style: flat;
  container: project-card / inline-size;
}

.work-section .project-card:nth-child(1) { grid-column: 1 / span 7; }
.work-section .project-card:nth-child(2) { grid-column: 8 / span 5; }
.work-section .project-card:nth-child(3) { grid-column: 1 / span 5; }
.work-section .project-card:nth-child(4) { grid-column: 6 / span 7; }
.work-section .project-card:nth-child(n) { margin-top: 0; }

.work-section .project-card:hover {
  transform: none;
}

.work-section .project-card-top {
  align-items: flex-start;
}

.work-section .project-card-top small {
  max-width: min(58%, 240px);
}

.work-section .project-symbol {
  display: none;
}

.work-section .project-card h3,
.work-section .project-card:nth-child(2) h3,
.work-section .project-card:nth-child(3) h3 {
  max-width: 14ch;
  margin: 22px 0 12px;
  font-size: clamp(2.25rem, 4cqi, 4.25rem);
  line-height: .98;
  text-wrap: balance;
}

.work-section .project-card > p {
  max-width: 68ch;
}

.work-section .project-card .project-evidence.is-compact {
  margin: 22px calc(var(--card-pad) * -1) 22px;
}

.work-section .project-card .project-evidence.is-compact figcaption {
  min-height: 58px;
  padding: 13px var(--card-pad) 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 3px;
  align-items: start;
  line-height: 1.35;
}

.work-section .project-card .project-evidence.is-compact figcaption > span {
  grid-column: 1;
  grid-row: 1 / span 2;
  padding: 3px 0 0;
  writing-mode: horizontal-tb;
  line-height: 1.25;
  white-space: nowrap;
}

.work-section .project-card .project-evidence.is-compact figcaption > strong {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  line-height: 1.28;
  overflow-wrap: anywhere;
}

.work-section .project-card .project-evidence.is-compact figcaption > small {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.work-section .project-card .project-evidence.is-compact .project-evidence-visual,
.work-section .project-card:nth-child(2) .project-evidence.is-compact .project-evidence-visual,
.work-section .project-card:nth-child(3) .project-evidence.is-compact .project-evidence-visual {
  width: 100%;
  height: clamp(245px, 55cqi, 410px);
  min-height: 0;
  max-height: 410px;
  border-inline: 0;
  border-radius: 0;
}

.work-section .project-verification-row {
  margin-top: 0;
  gap: 8px 12px;
  align-items: center;
}

.work-section .project-verification-row > span,
.work-section .project-verification-row > a {
  min-width: 0;
  line-height: 1.4;
}

.work-section .project-decision-signals {
  margin-top: 18px;
}

.work-section .tag-row {
  margin-block: 18px;
}

.work-section .evidence-card-status {
  margin-bottom: 18px;
}

.work-section .text-button {
  margin-top: auto;
  min-height: var(--tap-size);
}

.work-section .conversion-strip {
  align-items: center;
  gap: 24px;
}

/* Component-local fallbacks for narrower cards, including two-column laptops. */
@container project-card (max-width: 620px) {
  .work-section .project-card h3,
  .work-section .project-card:nth-child(2) h3,
  .work-section .project-card:nth-child(3) h3 {
    font-size: clamp(2.15rem, 9cqi, 3.15rem);
  }

  .work-section .project-decision-signals {
    grid-template-columns: 1fr;
  }

  .work-section .project-card .project-evidence.is-compact figcaption {
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    gap: 4px;
  }

  .work-section .project-card .project-evidence.is-compact figcaption > span,
  .work-section .project-card .project-evidence.is-compact figcaption > strong,
  .work-section .project-card .project-evidence.is-compact figcaption > small {
    grid-column: 1;
    grid-row: auto;
  }

  .work-section .project-card .project-evidence.is-compact figcaption > span {
    padding: 0;
    white-space: normal;
  }
}

@container project-card (max-width: 440px) {
  .work-section .project-card .project-evidence.is-compact .project-evidence-visual,
  .work-section .project-card:nth-child(2) .project-evidence.is-compact .project-evidence-visual,
  .work-section .project-card:nth-child(3) .project-evidence.is-compact .project-evidence-visual {
    height: clamp(230px, 82cqi, 310px);
  }

  .evidence-app-shell,
  .evidence-repo-grid {
    grid-template-columns: 1fr;
  }

  .evidence-app-shell > aside,
  .evidence-repo-grid > aside {
    display: none;
  }

  .evidence-warehouse-ui {
    padding: 14px;
    grid-template-columns: 1fr;
  }

  .evidence-warehouse-side {
    display: none;
  }

  .evidence-phone {
    width: min(190px, 84%);
    min-height: 292px;
    margin-inline: auto;
  }

  .evidence-window-bar small {
    max-width: 68%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Services, decision, credibility and about sections. */
.principles-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.principle-card,
.decision-path,
.credibility-record,
.about-panel {
  min-width: 0;
}

.decision-path-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.decision-proof-strip {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.credibility-heading {
  grid-template-columns: minmax(0, 1fr) minmax(170px, auto);
}

.credibility-records,
.claim-policy {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.about-grid {
  grid-template-columns: minmax(0, 1.05fr) minmax(340px, .95fr);
  gap: clamp(44px, 6vw, 80px);
}

/* Contact and footer. */
.contact-section {
  min-height: 0;
  padding-block: var(--section-space);
}

.contact-grid {
  width: min(1180px, 100%);
  grid-template-columns: minmax(300px, .82fr) minmax(480px, 1.18fr);
  align-items: start;
}

.contact-copy,
.contact-form {
  min-width: 0;
}

.contact-copy h2 {
  max-width: 12ch;
}

footer {
  gap: 18px 32px;
  flex-wrap: wrap;
}

/* Overlays are viewport-safe and keyboard-safe. */
.modal-backdrop,
.command-backdrop {
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}

.project-modal,
.command-panel,
.project-modal {
  max-height: min(88dvh, 900px);
}

/* Capability-based tuning; no tracking or persistent identifier. */
html[data-performance='constrained'] .grain,
html[data-connection='save-data'] .grain {
  display: none;
}

html[data-performance='constrained'] .reveal-on-view,
html[data-motion='reduced'] .reveal-on-view,
html[data-motion='reduced'] .hero-enter,
html[data-motion='reduced'] .hero-art-enter {
  opacity: 1;
  transform: none;
  animation: none;
  transition: none;
}

html[data-performance='constrained'] .hero-art {
  box-shadow: 0 16px 38px rgba(0,0,0,.17);
}

html[data-transparency='reduced'] .site-header,
html[data-performance='constrained'] .site-header {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  background: var(--panel-solid);
}

/* Laptop tier. */
@media (max-width: 1279px) {
  .brand-copy small {
    display: none;
  }

  .header-actions [data-action='command-palette'] {
    display: none;
  }

  .hero {
    grid-template-columns: minmax(0, 1fr) minmax(340px, .78fr);
  }

  .work-section .project-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .work-section .project-card:nth-child(n) {
    grid-column: auto;
  }

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

  .credibility-records,
  .claim-policy {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .contact-grid {
    grid-template-columns: 1fr;
    width: min(900px, 100%);
  }
}

/* Tablet tier. */
@media (max-width: 979px) {
  .hero {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .hero-copy {
    max-width: 760px;
  }

  .hero-art {
    width: min(100%, 760px);
    margin-inline: auto;
  }

  .work-proof-legend {
    margin-left: 0;
  }

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

  .decision-path-grid,
  .about-grid {
    grid-template-columns: 1fr;
  }

  .decision-proof-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .review-route {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* Mobile composition. */
@media (max-width: 820px) {
  :root {
    --page-gutter: 12px;
    --section-space: clamp(66px, 16vw, 86px);
    --mobile-dock-space: calc(80px + env(safe-area-inset-bottom));
  }

  html {
    scroll-padding-top: 74px;
  }

  body {
    padding-bottom: var(--mobile-dock-space);
  }

  .site-header {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    min-height: 58px;
    padding: 7px 8px 7px 10px;
  }

  .site-header.is-hidden {
    transform: translateY(calc(-100% - 18px));
  }

  .brand {
    flex: 1 1 auto;
  }

  .brand-copy strong {
    font-size: .94rem;
  }

  .header-actions {
    flex: none;
  }

  .header-actions [data-action='command-palette'] {
    display: none;
  }

  .hero {
    padding-top: calc(94px + env(safe-area-inset-top));
    padding-bottom: 38px;
    gap: 30px;
  }

  .hero h1 {
    max-width: 12ch;
    font-size: clamp(3rem, 11.6vw, 5rem);
    line-height: .95;
  }

  .hero-intro {
    font-size: 1rem;
    line-height: 1.66;
  }

  .hero-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hero-actions > a {
    width: 100%;
    min-height: 50px;
  }

  .hero-fit-banner {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .hero-fit-banner a {
    grid-column: 2;
    justify-self: start;
  }

  .hero-art {
    min-height: 390px;
    height: min(58svh, 540px);
    max-height: none;
  }

  .hero-art-label {
    left: 18px;
    right: 18px;
    bottom: 16px;
  }

  .section-heading {
    grid-template-columns: 46px minmax(0, 1fr);
    gap: 12px;
    margin-bottom: 34px;
  }

  .section-heading > div:last-child {
    padding-left: 10px;
  }

  .section-heading h2,
  .contact-section h2 {
    font-size: clamp(2.45rem, 9.8vw, 4.1rem);
    line-height: 1.02;
  }

  .work-section .project-card {
    --card-pad: 20px;
  }

  .work-section .project-card h3,
  .work-section .project-card:nth-child(2) h3,
  .work-section .project-card:nth-child(3) h3 {
    margin-top: 20px;
    font-size: clamp(2.35rem, 9.6vw, 3.65rem);
  }

  .work-section .conversion-strip {
    align-items: stretch;
    flex-direction: column;
  }

  .work-section .conversion-strip .primary-button {
    width: 100%;
  }

  .credibility-heading {
    grid-template-columns: 1fr;
  }

  .credibility-records,
  .claim-policy {
    grid-template-columns: 1fr;
  }

  .credibility-record {
    min-height: 0;
  }

  .claim-policy > div {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .claim-policy > div:first-child {
    border-top: 0;
  }

  .principles-grid,
  .decision-path-grid {
    grid-template-columns: 1fr;
  }

  .decision-path dl > div {
    grid-template-columns: minmax(100px, .34fr) minmax(0, 1fr);
  }

  .review-route nav {
    width: 100%;
  }

  .review-route nav a {
    flex: 1 1 130px;
    justify-content: center;
  }

  .contact-section::before {
    inset: 22px 0;
  }

  .contact-grid {
    padding: 24px 18px;
    gap: 28px;
  }

  .contact-copy h2 {
    max-width: 14ch;
  }

  .contact-form {
    padding: 18px 14px;
  }

  footer {
    flex-direction: column;
    padding-bottom: 24px;
  }

  .project-modal {
    width: 100%;
    max-height: min(90dvh, var(--adaptive-vh));
  }

  html[data-keyboard='open'] .mobile-dock {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, calc(100% + 24px));
  }

  html[data-keyboard='open'] body {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Phones. */
@media (max-width: 560px) {
  .brand-seal {
    width: 36px;
    height: 36px;
  }

  .icon-button {
    width: 40px;
    height: 40px;
  }

  .hero-kicker {
    font-size: .61rem;
    letter-spacing: .09em;
  }

  .hero h1 {
    max-width: none;
    font-size: clamp(2.75rem, 13.2vw, 4.2rem);
  }

  .hero-actions {
    grid-template-columns: 1fr;
  }

  .hero-proof {
    margin-inline: 0;
    padding-inline: 0;
    display: grid;
    grid-template-columns: 1fr;
    overflow: visible;
    scroll-snap-type: none;
  }

  .hero-proof > div {
    width: 100%;
    min-width: 0;
    min-height: 58px;
  }

  .hero-art {
    min-height: 370px;
    height: min(55svh, 500px);
  }

  .hero-art-label {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .section-heading {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .section-heading > div:last-child {
    padding-left: 0;
  }

  .section-number {
    width: fit-content;
    height: auto;
    margin: 0;
    padding: 0 0 8px;
    border: 0;
    border-bottom: 1px solid var(--kintsugi, var(--brass));
    border-radius: 0;
    font-size: .72rem;
  }

  .section-heading h2,
  .contact-section h2 {
    max-width: none;
    font-size: clamp(2.35rem, 11.2vw, 3.45rem);
  }

  .work-proof-legend {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px 12px;
    font-size: .61rem;
  }

  .work-section .project-card {
    --card-pad: 17px;
  }

  .work-section .project-card h3,
  .work-section .project-card:nth-child(2) h3,
  .work-section .project-card:nth-child(3) h3 {
    max-width: none;
    margin-top: 18px;
    font-size: clamp(2.2rem, 10.7vw, 3.1rem);
  }

  .work-section .project-card-top {
    gap: 10px;
  }

  .work-section .project-card-top small {
    max-width: 62%;
    font-size: .57rem;
  }

  .work-section .project-verification-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .work-section .project-verification-row > a {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }

  .decision-proof-strip {
    grid-template-columns: 1fr;
  }

  .decision-proof-strip > div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .decision-proof-strip > div:last-child {
    border-bottom: 0;
  }

  .decision-path {
    padding: 22px 17px;
  }

  .decision-path dl > div,
  .about-line {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .decision-actions,
  .verification-actions,
  .contact-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .decision-actions > *,
  .verification-actions > *,
  .contact-actions > * {
    width: 100%;
  }

  .review-route nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .contact-form-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .contact-form-footer > div {
    display: grid;
  }

  .mobile-dock {
    width: calc(100% - 12px);
    bottom: max(6px, env(safe-area-inset-bottom));
    padding: 5px;
  }

  .mobile-dock a {
    font-size: .54rem;
  }
}

/* Narrow phones, including 320px CSS width. */
@media (max-width: 379px) {
  :root {
    --page-gutter: 10px;
  }

  .site-header {
    left: max(6px, env(safe-area-inset-left));
    right: max(6px, env(safe-area-inset-right));
  }

  .brand {
    gap: 7px;
  }

  .brand-copy strong {
    font-size: .86rem;
  }

  .header-actions {
    gap: 3px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .hero h1 {
    font-size: clamp(2.55rem, 13.8vw, 3.45rem);
    letter-spacing: -.045em;
  }

  .hero-art {
    min-height: 340px;
  }

  .work-proof-legend {
    grid-template-columns: 1fr;
  }

  .work-section .project-card {
    --card-pad: 15px;
  }

  .tag-row span,
  .evidence-card-status span {
    font-size: .53rem;
  }

  .mobile-dock a span {
    font-size: .5rem;
  }
}

/* Short landscape phones: preserve content height and safe controls. */
@media (max-width: 920px) and (max-height: 560px) and (orientation: landscape) {
  body {
    padding-bottom: calc(66px + env(safe-area-inset-bottom));
  }

  .site-header {
    min-height: 50px;
  }

  .hero {
    padding-top: calc(72px + env(safe-area-inset-top));
    grid-template-columns: minmax(0, 1.05fr) minmax(300px, .95fr);
    align-items: start;
  }

  .hero h1 {
    font-size: clamp(2.55rem, 6.6vw, 4rem);
  }

  .hero-art {
    min-height: 320px;
    height: calc(var(--adaptive-vh) - 92px);
  }

  .mobile-dock {
    min-height: 56px;
  }

  .mobile-dock a {
    min-height: 44px;
    grid-template-columns: auto auto;
    gap: 5px;
  }
}

@media (hover: none), (pointer: coarse) {
  .project-card:hover,
  .principle-card:hover,
  .primary-button:hover,
  .secondary-button:hover,
  .icon-button:hover {
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .site-header,
  .mobile-dock,
  .project-card,
  .principle-card,
  .primary-button,
  .secondary-button {
    transition: none !important;
  }
}
