/* Responsive refinements for the complete portfolio.
   Loaded after the component styles so existing desktop styling remains the source of truth. */

/* Keep every layout shrink-safe and prevent accidental page-level horizontal scrolling. */
html { scroll-padding-top: 84px; }
body { max-width: 100%; overflow-x: hidden; overflow-x: clip; }
main, section, header, footer, .section-shell, .opening-layout,
.work-grid, .project-grid, .contribution-overview, .closing-card {
  min-width: 0;
}
img, video, iframe, canvas, svg { max-width: 100%; }
button, input, select, textarea { max-width: 100%; }
.project-grid > *, .work-grid > *, .release-grid > *, .achievement-grid > * { min-width: 0; }
.project-card.product-showcase .project-copy,
.project-card.product-showcase .project-visual { min-width: 0; }

/* Small laptops and landscape tablets. */
@media (max-width: 980px) {
  .section-shell,
  .header-inner {
    width: min(calc(100% - 48px), var(--shell));
  }

  .header-inner { gap: 16px; }
  .desktop-nav { display: none; }
  .header-cta { display: none; }
  .header-actions { margin-left: auto; gap: 8px; }
  .mobile-menu-button {
    display: flex;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    border: 1px solid var(--line-strong);
    background: var(--panel);
    cursor: pointer;
  }
  .mobile-nav:not(.is-open) { display: none; }
  .mobile-nav.is-open {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    padding: 10px max(24px, calc((100% - var(--shell)) / 2)) 15px;
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg) 96%, transparent);
  }
  .mobile-nav a {
    min-width: 0;
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 9px;
    font-size: 11px;
  }
  .mobile-nav a:active { background: var(--panel); }

  .opening-kicker {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px 18px;
  }
  .opening-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: 34px;
    min-height: 0;
    padding: 50px 0 40px;
  }
  .opening-copy { max-width: 760px; }
  .opening h1 { max-width: 11ch; font-size: clamp(54px, 8.4vw, 82px); }
  .opening-description { max-width: 62ch; }
  #project-explorer {
    width: 100%;
    max-width: 760px;
    margin-inline: auto;
  }

  .proof-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px 12px;
  }
  .proof-caption {
    grid-column: 1 / -1;
    justify-self: start;
    max-width: 58ch;
    text-align: left;
  }

  .section-heading {
    align-items: start;
    gap: 20px;
  }
  .section-intro-copy { max-width: 55ch; }
  .contribution-overview { grid-template-columns: minmax(0, 1fr); }
  .contribution-number-panel { min-height: 175px; }
  .contribution-graph-panel { min-width: 0; }
  .contribution-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .contribution-filters .select-wrap:last-child { grid-column: 1 / -1; }
  .contribution-row {
    grid-template-columns: minmax(130px, .7fr) minmax(0, 1.5fr) auto 22px;
    gap: 11px;
  }
  .achievement-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .closing-card {
    grid-template-columns: 140px minmax(0, 1fr);
    gap: 26px;
    padding: 38px 34px 64px;
  }
}

/* Tablets and phones. */
@media (max-width: 760px) {
  html { scroll-padding-top: 70px; }
  .section-shell,
  .header-inner {
    width: min(calc(100% - 36px), var(--shell));
  }

  .header-inner { min-height: 66px; gap: 8px; }
  .wordmark { min-width: 0; max-width: calc(100% - 104px); }
  .wordmark-copy { min-width: 0; }
  .wordmark-copy strong,
  .wordmark-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .header-actions { gap: 7px; }
  .theme-toggle,
  .mobile-menu-button { width: 42px; height: 42px; flex-basis: 42px; }
  .mobile-nav.is-open { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 8px 18px 14px; }
  .mobile-nav a { min-height: 44px; }

  .opening { padding-top: 22px; }
  .opening-kicker { align-items: flex-start; font-size: 7px; line-height: 1.55; }
  .opening-kicker > span:first-child { min-width: 0; }
  .opening-kicker > span:last-child { margin-left: auto; text-align: right; }
  .opening-layout { gap: 29px; padding: 36px 0 30px; }
  .opening h1 { max-width: 10ch; font-size: clamp(48px, 11vw, 72px); }
  .opening-description { margin: 18px 0 20px; font-size: 14px; line-height: 1.7; }
  .opening-note { align-items: flex-start; font-size: 9px; line-height: 1.55; }
  .opening-actions .button { min-height: 44px; }
  #project-explorer { max-width: 620px; }

  .proof-strip { gap: 13px 9px; }
  .proof-item { min-width: 0; }
  .proof-item strong { font-variant-numeric: tabular-nums; }
  .proof-item span { max-width: 13ch; line-height: 1.4; }
  .proof-caption { line-height: 1.6; }

  .work-section,
  .internship-section,
  .products-section,
  .contributions-section,
  .achievements-section,
  .release-section,
  .closing-section { min-width: 0; }
  .work-grid { grid-template-columns: minmax(0, 1fr); }
  .work-grid-single .work-card { width: 100%; }
  .work-card-copy { min-width: 0; }
  .work-card-actions { gap: 9px 14px; }
  .work-card-actions a,
  .work-card-actions button { min-height: 40px; }

  .project-card.product-showcase,
  .project-card.product-showcase:nth-child(even) {
    grid-template-columns: minmax(0, 1fr);
    gap: 22px;
    min-height: 0;
    padding: 34px 0;
  }
  .project-card.product-showcase:nth-child(even) .project-visual,
  .project-card.product-showcase:nth-child(even) .project-copy { order: initial; }
  .project-card.product-showcase.is-featured { min-height: 0; }
  .project-card.product-showcase .project-copy h3 {
    max-width: 14ch;
    font-size: clamp(35px, 9vw, 56px);
    overflow-wrap: anywhere;
  }
  .project-card.product-showcase .project-showcase-description {
    font-size: 12px;
    line-height: 1.7;
  }
  .project-card.product-showcase .project-browser { border-radius: 14px; }
  .project-browser-content { aspect-ratio: 16 / 10; }
  .project-grid { grid-template-columns: minmax(0, 1fr); }
  .project-grid > .project-showcase { grid-column: 1 / -1; }
  .project-visual { width: 100%; }

  .product-toolbar { min-width: 0; }
  .product-toolbar-note { min-width: 0; gap: 8px; flex-wrap: wrap; }
  .product-toolbar-note strong { white-space: normal; text-align: right; }
  .search-field { min-width: 0; }
  .search-field input { min-width: 0; width: 100%; font-size: 16px; }
  .category-browser { min-width: 0; }
  .category-browser-heading { gap: 7px; }
  .filter-row {
    display: flex;
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding: 2px 1px 8px;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }
  .filter-chip { flex: 0 0 auto; min-height: 40px; }
  .product-results-line { align-items: flex-start; gap: 8px; line-height: 1.5; }
  .product-results-line > * { min-width: 0; }
  .results-note { text-align: right; }

  .contribution-overview { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .contribution-number-panel { min-width: 0; }
  .contribution-graph-panel { padding: 16px 12px 13px; }
  .graph-heading { min-width: 0; }
  .graph-heading > div:first-child { min-width: 0; }
  .graph-heading strong { line-height: 1.35; }
  .graph-heading span { line-height: 1.55; }
  .graph-live-meta { min-width: 0; }
  .graph-source { overflow-wrap: anywhere; }
  .heatmap-wrap {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding-bottom: 5px;
    -webkit-overflow-scrolling: touch;
  }
  .heatmap-layout { width: max-content; min-width: 0; grid-template-columns: 20px max-content; gap: 6px; }
  .heatmap-months { width: max-content; min-width: 0; grid-auto-columns: 9px; }
  .heatmap-days { width: 20px; }
  .heatmap { width: max-content; }
  .heatmap-legend { gap: 5px; }
  .contribution-filter-panel { min-width: 0; }
  .contribution-filter-panel-top { align-items: center; flex-wrap: wrap; }
  .contribution-filters { grid-template-columns: minmax(0, 1fr); }
  .contribution-filters .select-wrap:last-child { grid-column: auto; }
  .contribution-filters .select-wrap { min-width: 0; }
  .custom-select-trigger { min-height: 46px; }
  .custom-select-menu { max-width: 100%; max-height: min(38dvh, 260px); }
  .activity-results-summary { line-height: 1.5; }
  .contribution-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 10px;
    min-width: 0;
    padding: 13px;
  }
  .contribution-repo { grid-column: 1 / -1; min-width: 0; }
  .contribution-detail { min-width: 0; overflow-wrap: anywhere; }
  .contribution-date { justify-self: end; white-space: nowrap; }
  .contribution-arrow { display: none; }

  .achievement-grid { grid-template-columns: minmax(0, 1fr); }
  .achievement-card { min-width: 0; }
  .release-grid { grid-template-columns: minmax(0, 1fr); }
  .closing-card {
    grid-template-columns: minmax(0, 1fr);
    gap: 22px;
    padding: 27px 22px 72px;
  }
  .closing-orbit { margin-inline: 4px; }
  .closing-copy { min-width: 0; }
  .closing-copy h2 { max-width: 15ch; font-size: clamp(32px, 8vw, 42px); }
  .closing-copy p { max-width: 58ch; line-height: 1.7; }
  .closing-links { display: flex; flex-wrap: wrap; gap: 10px 18px; }
  .closing-index { right: 18px; left: 18px; flex-wrap: wrap; font-size: 6px; line-height: 1.5; }

  .project-dialog {
    width: calc(100% - 20px);
    max-width: 720px;
    max-height: 92dvh;
    border-radius: 17px;
  }
  .dialog-shell { padding: 17px 16px 26px; }
  .dialog-topbar { gap: 12px; }
  .dialog-content { min-width: 0; }
  .dialog-hero { grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 24px 0 19px; }
  .dialog-hero h2 { max-width: 14ch; font-size: clamp(34px, 9vw, 46px); overflow-wrap: anywhere; }
  .dialog-hero p { font-size: 12px; }
  .dialog-columns { grid-template-columns: minmax(0, 1fr); }
  .dialog-columns > * { min-width: 0; }
  .dialog-status-line { align-items: flex-start; flex-direction: column; gap: 5px; }
  .dialog-content a,
  .dialog-content button { overflow-wrap: anywhere; }

  .site-footer { align-items: flex-start; gap: 12px 18px; line-height: 1.55; }
  .site-footer > * { min-width: 0; }
}

/* Compact phones and narrow split-screen windows. */
@media (max-width: 560px) {
  .section-shell,
  .header-inner { width: min(calc(100% - 30px), var(--shell)); }
  .wordmark { gap: 8px; }
  .wordmark-avatar { flex: 0 0 auto; }
  .wordmark-copy strong { font-size: 9px; letter-spacing: .07em; }
  .wordmark-copy small { font-size: 6px; letter-spacing: .1em; }
  .header-actions { gap: 5px; }
  .theme-toggle,
  .mobile-menu-button { width: 40px; height: 40px; flex-basis: 40px; }
  .mobile-nav.is-open { padding-inline: 15px; }

  .opening-kicker { flex-direction: column; gap: 5px; }
  .opening-kicker > span:last-child { margin-left: 0; text-align: left; }
  .opening-layout { padding-top: 31px; gap: 25px; }
  .opening h1 { max-width: 10ch; font-size: clamp(43px, 12vw, 62px); }
  .opening-description { font-size: 13px; }
  .opening-actions { display: grid; grid-template-columns: minmax(0, 1fr); }
  .opening-actions .button { width: 100%; justify-content: space-between; }
  .opening-note { margin-top: 19px; }

  .proof-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 10px; }
  .proof-caption { grid-column: 1 / -1; }
  .proof-item strong { font-size: 23px; }
  .proof-item span { max-width: 16ch; font-size: 7px; }

  .section-heading h2,
  .method-lead h2 { font-size: clamp(34px, 10vw, 46px); }
  .section-intro-copy { font-size: 11px; }
  .work-card-copy { padding: 18px 16px 19px; }
  .work-card-meta { align-items: flex-start; }
  .work-card-copy h3 { font-size: clamp(24px, 7vw, 32px); overflow-wrap: anywhere; }
  .work-card-actions { gap: 8px 13px; }

  .project-card.product-showcase { gap: 17px; padding: 28px 0; }
  .project-card.product-showcase .project-copy h3 { font-size: clamp(32px, 10vw, 48px); }
  .project-browser-content { aspect-ratio: 4 / 3; }
  .product-toolbar-note { align-items: flex-start; }
  .product-toolbar-note strong { text-align: left; }
  .product-results-line { flex-direction: column; }
  .results-note { text-align: left; }

  .contribution-number-panel { padding: 18px; }
  .contribution-number-panel strong { font-size: clamp(50px, 16vw, 68px); }
  .contribution-graph-panel { padding: 14px 10px 12px; }
  .graph-live-meta { grid-template-columns: minmax(0, 1fr); justify-items: start; }
  .heatmap-layout { grid-template-columns: 17px max-content; gap: 5px; }
  .heatmap-months { grid-auto-columns: 7px; gap: 2px; height: 12px; }
  .heatmap-months span { font-size: 7px; }
  .heatmap-days { width: 17px; grid-template-rows: repeat(7, 8px); gap: 2px; line-height: 8px; font-size: 6px; }
  .heatmap { grid-auto-columns: 7px; grid-template-rows: repeat(7, 8px); gap: 2px; }
  .heatmap-legend { font-size: 7px; }
  .heatmap-legend i { width: 8px; height: 8px; }

  .contribution-filter-panel { padding: 13px 11px 11px; }
  .contribution-filter-panel-top { align-items: flex-start; }
  .filter-reset-button { min-height: 38px; }
  .contribution-row { grid-template-columns: minmax(0, 1fr); gap: 6px; padding: 12px; }
  .contribution-date { justify-self: start; }
  .contribution-detail strong { display: block; overflow-wrap: anywhere; }
  .contribution-repo { font-size: 9px; }
  .closing-card { padding: 23px 17px 76px; }
  .closing-copy h2 { font-size: clamp(30px, 9vw, 38px); }
  .closing-index { right: 14px; left: 14px; }
  .project-dialog { width: calc(100% - 14px); max-height: 94dvh; border-radius: 14px; }
  .dialog-shell { padding: 17px 13px calc(26px + env(safe-area-inset-bottom)); }
  .dialog-hero h2 { font-size: clamp(31px, 10vw, 40px); }
  .site-footer { flex-direction: column; gap: 8px; padding: 18px 0 22px; }
  .site-footer span:nth-child(2) { order: initial; width: auto; }
}

/* Very narrow devices. */
@media (max-width: 390px) {
  .section-shell,
  .header-inner { width: calc(100% - 26px); }
  .header-inner { gap: 6px; }
  .wordmark { max-width: calc(100% - 91px); }
  .wordmark-avatar { width: 34px; height: 34px; }
  .wordmark-avatar img { width: 28px; height: 28px; }
  .wordmark-copy strong { font-size: 8px; }
  .theme-toggle,
  .mobile-menu-button { width: 44px; height: 44px; flex-basis: 44px; }
  .opening h1 { font-size: 44px; }
  .opening-kicker { font-size: 6.5px; }
  #project-explorer.project-showcase-card { padding: 14px 12px 13px; }
  #project-explorer .showcase-topline { gap: 6px; }
  #project-explorer .showcase-eyebrow { font-size: 6px; letter-spacing: .1em; }
  #project-explorer .showcase-counter { font-size: 7px; }
  #project-explorer .showcase-image-caption { right: 9px; bottom: 9px; left: 10px; }
  #project-explorer .showcase-image-caption strong { font-size: 19px; }
  #project-explorer .showcase-description { font-size: 8px; }
  #project-explorer .showcase-tech-groups { grid-template-columns: minmax(0, 1fr); }
  #project-explorer .showcase-tech-group--tools { grid-column: auto; }
  #project-explorer .showcase-tech-chip { min-height: 22px; font-size: 7px; }
  #project-explorer .showcase-control-row { align-items: center; }
  #project-explorer .showcase-arrow { width: 44px; height: 44px; }
  #project-explorer .showcase-timer-label { gap: 5px; padding-inline: 6px; font-size: 6px; }
  #project-explorer .showcase-foot { gap: 6px; font-size: 6px; }
  #project-explorer .showcase-indicators { grid-template-columns: repeat(10, minmax(0, 1fr)); }
  .proof-item strong { font-size: 21px; }
  .filter-chip { padding-inline: 9px; }
}

/* Short landscape viewports: retain the compact navigation and avoid a cramped side-by-side hero. */
@media (max-height: 560px) and (min-width: 600px) {
  .site-header .header-inner { min-height: 58px; }
  .opening { padding-top: 18px; }
  .opening-layout { min-height: 0; padding-top: 28px; padding-bottom: 24px; }
  .project-dialog { max-height: 94dvh; }
}

/* Touchscreens should not depend on hover to discover interactive elements. */
@media (hover: none) {
  .project-card:hover,
  .work-card:hover,
  .contribution-row:hover,
  .contribution-filters .select-wrap:hover {
    transform: none;
  }
  .project-card.product-showcase:hover .project-browser,
  .work-card:hover { box-shadow: none; }
}

/* Keep the responsive layouts accessible when motion reduction is requested. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .filter-row { scroll-behavior: auto; }
}
