:root {
  --hero-photo-size: 230px;
  --hero-name-size: 3.65rem;
  --hero-role-size: 1.05rem;
  --chip-size: 220px;
  --hero-sub-size: 1.15rem;
  --contact-size: 46px;
  --contact-icon-size: 1.24rem;
  --cream: #E6E1CF;
  --navy: #082660;
  --background-top: var(--cream);
  --background-bottom: var(--navy);
  --page-gradient: linear-gradient(180deg, var(--background-top) 0%, var(--background-bottom) 100%);
  --page-solid: var(--background-bottom);
  --text: #ffffff;

  /* Shared transparent-glass tokens */
  --glass-blur: 14px;
  --glass-shadow: 0 12px 30px rgba(0,0,0,0.12);
  --glass-card-radius: 20px;
  --glass-control-radius: 12px;
}

html.ios-safari-flat {
  --background-top: #778498;
  --background-bottom: #778498;
  --page-gradient: linear-gradient(180deg, #778498 0%, #778498 100%);
  --page-solid: #778498;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  color-scheme: light;
  background-color: var(--page-solid);
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--navy) var(--background-top);
}

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

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

a,
button {
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: "IBM Plex Mono", "Trebuchet MS", monospace;
  color: var(--text);
  min-height: 100vh;
  min-height: 100svh;
  position: relative;
  isolation: isolate;
  background-color: var(--page-solid);
}

/* Keep the background size stable while mobile browser toolbars move. */
.viewport-gradient {
  position: fixed;
  top: calc(0px - env(safe-area-inset-top, 0px));
  right: 0;
  left: 0;
  z-index: 0;
  pointer-events: none;
  height: calc(100vh + 72px + env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px));
  height: calc(100lvh + 72px + env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px));
  background: var(--page-gradient);
}

section {
  position: relative;
  z-index: 1;
  padding: 100px 6% 60px;
  max-width: 1100px;
  margin: 0 auto;
}

/* ── LOADER ── */
#site-loader {
  position: fixed;
  top: calc(0px - env(safe-area-inset-top, 0px));
  right: 0;
  bottom: calc(-72px - env(safe-area-inset-bottom, 0px));
  left: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page-gradient);
  transition: opacity .5s ease, visibility .5s ease;
}

#site-loader.hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.loader-text {
  display: inline-block;
  font-family: "Caveat", cursive;
  font-size: 2.2rem;
  line-height: 1.35;
  font-weight: 400;
  color: #ffffff;
  margin: 0;
  padding: .14em .42em .16em .26em;
  opacity: 0;
  overflow: visible;
  transition: opacity .18s ease;
}

#site-loader.font-ready .loader-text {
  opacity: 1;
}

.loader-bar-track {
  width: 140px;
  height: 3px;
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
  overflow: hidden;
}

.loader-bar-fill {
  height: 100%;
  width: 100%;
  background: #ffffff;
  border-radius: 999px;
  transform-origin: left;
  animation: loaderBar 2s ease-in-out infinite;
}

@keyframes loaderBar {
  0% {
    transform: scaleX(0);
  }
  100% {
    transform: scaleX(1);
  }
}

/* ── HERO ── */
.hero {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 40px;
  padding-top: 120px;
  padding-bottom: 60px;
}

.hero-text {
  flex: 1;
  min-width: 0;
}

.hero-photo {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeUp .75s .35s ease both;
}

.photo-wrap {
  position: relative;
  width: var(--hero-photo-size);
  height: var(--hero-photo-size);
}

.photo-wrap img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 100%;
  border: none;
  outline: none;
  box-shadow: none;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  transition: transform .4s cubic-bezier(.4,0,.2,1);
}

.hero-tag-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
  animation: fadeUp .7s ease both;
}

#chip3d {
  width: var(--chip-size);
  height: var(--chip-size);
  display: block;
  flex-shrink: 0;
  cursor: grab;
  transform: translateX(-30px);
  margin-top: 0;
  margin-bottom: 0;
  image-rendering: auto;
  touch-action: none;
  opacity: 0;
  transition: opacity .28s ease;
  will-change: opacity;
}

#chip3d.ready {
  opacity: 1;
  will-change: auto;
}

.hero-tag {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  font-family: "IBM Plex Mono", monospace;
  font-size: var(--hero-role-size);
  font-weight: 400;
  letter-spacing: .11em;
  text-transform: uppercase;
  text-align: left;
  color: var(--text);
  border: none;
  border-radius: var(--glass-control-radius);
  padding: 7px 16px;
  margin: 0;
  overflow: hidden;
  isolation: isolate;
}

.hero h1 {
  font-family: "Caveat", cursive;
  font-size: var(--hero-name-size);
  font-weight: 400;
  line-height: 1.3;
  display: inline-block;
  padding: 4px 8px 12px;
  margin: -4px -8px 14px;
  animation: fadeUp .75s .1s ease both;
}

.hero h1 span {
  display: inline-block;
  padding: 2px 8px 10px;
  margin: -2px -8px -10px;
  color: #ffffff;
}

.hero-sub {
  font-size: var(--hero-sub-size);
  color: #fff;
  max-width: 560px;
  line-height: 1.7;
  margin-top: 12px;
  margin-bottom: 28px;
  animation: fadeUp .75s .2s ease both;
}

/* ── CONTACT LINKS ── */
.fixed-contact {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
}

.fixed-contact a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--contact-size);
  height: var(--contact-size);
  color: #ffffff;
  font-size: var(--contact-icon-size);
  text-decoration: none;
  border-radius: var(--glass-control-radius);
  border: none;
  transition: transform .25s ease;
}

.fixed-contact .cv-icon {
  font-family: Arial, Helvetica, sans-serif;
  font-size: .85em;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.04em;
}

@media (hover: hover) and (pointer: fine) {
  .fixed-contact a:hover {
    transform: translateY(-3px);
  }
}

/* ── SECTION TITLES ── */
.slabel {
  font-family: "IBM Plex Mono", monospace;
  font-size: .75rem;
  font-weight: 400;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.slabel::before {
  content: "";
  display: block;
  width: 28px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

.stitle {
  font-size: clamp(2.2rem,4vw,3.2rem);
  font-weight: 400;
  line-height: 1.2;
  display: inline-block;
  padding-bottom: 6px;
  margin-bottom: 40px;
}

.stitle span {
  display: inline-block;
  padding: 0 5px 6px;
  margin: 0 -5px;
  color: #ffffff;
}

/* ── CARDS ── */
/* Shared glass surface: no tint/fill, only backdrop blur + depth. */
.card,
.hero-tag,
.fixed-contact a {
  background: transparent;
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  box-shadow: var(--glass-shadow);
}

.card {
  border: none;
  border-radius: var(--glass-card-radius);
  padding: 26px 28px;
}

/* Consistent typography for card titles throughout the site. */
.card h3 {
  font-size: 1.15rem;
  line-height: 1.35;
  font-weight: 400;
  color: var(--text);
}

/* Prevent long content from forcing horizontal overflow at high browser zoom. */
.card,
.acard > div,
.pc,
.scat,
.li {
  min-width: 0;
}

.pc h3,
.acard h3,
.acard p,
.scat h3,
.li h3,
.li p {
  overflow-wrap: break-word;
}

.reveal {
  opacity: 0;
  transform: translateY(22px);
  transition: opacity .55s ease, transform .55s cubic-bezier(.22,1,.36,1), box-shadow .18s ease;
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── ABOUT ── */
#about {
  max-width: 1560px;
}

.about-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 22px;
}

@media (min-width: 681px) {
  .about-grid > .acard:last-child {
    grid-column: 1 / -1;
    width: calc(50% - 11px);
    justify-self: center;
  }
}

.acard {
  display: flex;
  gap: 16px;
  align-items: center;
  grid-column: span 1;
}

.aico,
.pico {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  font-size: 1.1rem;
  transition: transform .35s cubic-bezier(.34,1.56,.64,1);
}

.aico {
  flex-shrink: 0;
}

.aico i,
.pico i {
  color: var(--text);
}

.acard h3 {
  margin-bottom: 5px;
}

.acard p {
  font-size: .84rem;
  color: var(--text);
  line-height: 1.6;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.cat-grid {
  display: grid;
  gap: 22px;
  margin-bottom: 4px;
}

/* ── RESEARCHES ── */
#researches {
  max-width: 1480px;
}

#researches .research-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
  align-items: stretch;
}

#researches .research-grid > .pc {
  min-height: 100%;
}

/* ── PROJECTS ── */
#projects,
#websites {
  max-width: 1380px;
}

.pgrid {
  display: grid;
  gap: 20px;
}

#projects .project-grid-engineering {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}

#projects .project-grid-engineering > .project-centered {
  grid-column: 1 / -1;
  width: calc(50% - 10px);
  justify-self: center;
}

#websites .project-grid-web {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  max-width: 980px;
  margin: 0 auto;
}

#websites .project-grid-web > .pc {
  grid-column: span 1;
  min-height: 100%;
}

#projects .pc {
  min-height: 100%;
}

.project-private {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 400;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
}

.project-private i {
  color: var(--text);
  font-size: .72rem;
}

.pc {
  display: flex;
  flex-direction: column;
  gap: 11px;
  position: relative;
}

.pc:has(.pl) {
  cursor: pointer;
}

.pctop {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pl {
  color: var(--text);
  font-size: .92rem;
  text-decoration: none;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  line-height: 1;
  padding: 3px;
  overflow: visible;
  flex-shrink: 0;
}

.pl i {
  display: block;
  line-height: 1;
}

.pc .pl {
  position: absolute;
  top: 26px;
  right: 28px;
  z-index: 2;
}

.thesis-note {
  font-size: .7em;
  opacity: .7;
}

.pc p {
  font-size: .82rem;
  color: var(--text);
  line-height: 1.6;
  flex: 1;
}

/* ── SKILLS ── */
#skills {
  max-width: 1400px;
}

.sgrid {
  display: grid;
  gap: 20px;
}

#skills .skills-grid {
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-auto-flow: dense;
  align-items: stretch;
}

#skills .skills-grid > .scat {
  grid-column: span 4;
  min-height: 100%;
}

#skills .skills-grid > .scat:first-child {
  grid-column: span 6;
}

#skills .skills-grid > .scat:nth-child(2),
#skills .skills-grid > .scat:nth-child(3) {
  grid-column: span 3;
}

#skills .skills-grid > .scat:nth-last-child(-n+2) {
  grid-column: span 6;
}

.scat .pills {
  justify-content: center;
}

.scat h3 {
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}

.scat h3 i {
  color: var(--text);
}

.pill {
  font-size: .77rem;
  font-weight: 400;
  padding: 5px 12px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  cursor: default;
}

/* ── LANGUAGES ── */
.lgrid {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

.lcard {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex: 0 0 auto;
  min-width: 186px;
  min-height: 60px;
  padding: 15px 30px;
  background: transparent;
  border: none;
  backdrop-filter: none;
  box-shadow: none;
}

.lflag {
  width: 34px;
  line-height: 0;
  transition: transform .35s cubic-bezier(.34,1.56,.64,1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.lflag svg {
  display: block;
  width: 34px;
  height: auto;
  border-radius: 6px;
}

.li p {
  font-size: .82rem;
  color: var(--text);
}

/* ── FOOTER ── */
footer {
  text-align: center;
  padding: 36px 6% calc(36px + env(safe-area-inset-bottom, 0px));
  color: var(--text);
  font-size: .82rem;
  position: relative;
  z-index: 1;
}

.footer-build-link span {
  font-family: "Caveat", cursive;
  font-size: 1.15rem;
  font-weight: 400;
  display: inline-block;
  padding: 0;
  margin: 0;
  color: #ffffff;
}

/* ── ANIMATIONS ── */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(28px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar {
  width: 10px;
}
::-webkit-scrollbar-track {
  background: var(--background-top);
}
::-webkit-scrollbar-thumb {
  background: var(--navy);
  border-radius: 999px;
  border: 2px solid var(--background-top);
}
::-webkit-scrollbar-corner {
  background: var(--background-top);
}

/* ── SECTION ENTRY ANIMATIONS ── */
.section-anim {
  opacity: 0;
  transition: opacity .55s ease, transform .55s cubic-bezier(.22,1,.36,1);
  will-change: opacity, transform;
}

.section-anim.in-view {
  opacity: 1;
  transform: none;
}

.anim-left {
  transform: translateX(-40px);
}

.anim-up {
  transform: translateY(40px);
}

.anim-zoom {
  transform: scale(.98);
}

/* ── FOOTER TOP BUTTON ── */
.footer-top-btn {
  position: relative;
  display: inline-flex;
  border: 0;
  -webkit-appearance: none;
  appearance: none;
  font: inherit;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 14px 22px 13px;
  color: var(--text);
  background: transparent;
  font-size: .88rem;
  font-weight: 400;
  transition: transform .25s ease;
  border-radius: 10px;
  white-space: nowrap;
}

/* ── DESKTOP / REAL HOVER ── */
@media (hover: hover) and (pointer: fine) {
  .photo-wrap:hover img {
    transform: scale(1.04);
  }

  .card.reveal.visible:not(.lcard):hover {
    transform: translateY(-6px) scale(1.01);
    box-shadow: 0 14px 36px rgba(0,0,0,0.18);
  }

  .acard:hover .aico {
    transform: scale(1.15);
  }

  .pc:hover .pico {
    transform: scale(1.18);
  }

  .pl:hover {
    transform: scale(1.15);
  }

  .pc:hover .pl {
    transform: scale(1.15);
  }

  .lcard:hover .lflag {
    transform: scale(1.25);
  }

  .footer-top-btn:hover {
    transform: translateY(-2px);
  }
}

/* ── TOUCH / MOBILE ── */
@media (hover: none) and (pointer: coarse) {
  html {
    scrollbar-width: none;
  }

  ::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
  }

  .pl:active {
    transform: scale(1.18);
  }

  .footer-top-btn:active {
    transform: translateY(-2px);
  }
}

/* ── ACCESSIBILITY ── */

#main-content:focus {
  outline: none;
}
.fixed-contact a:focus-visible,
.pl:focus-visible,
.footer-top-btn:focus-visible,
#chip3d:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 4px;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }

  .section-anim,
  .reveal {
    opacity: 1 !important;
    transform: none !important;
  }
}

/* ── FIXED INTRO / DESKTOP ──
   Wide mouse-driven viewports keep the intro fixed beside the content.
   Breakpoints use the CSS viewport width, including browser zoom. */
@media (min-width: 1500px) and (hover: hover) and (pointer: fine) {
  .hero {
    width: 0;
    height: 0;
    min-height: 0;
    padding: 0;
    margin: 0;
    gap: 0;
    overflow: visible;
  }

  .hero-text {
    position: fixed;
    top: clamp(58px, 7.5vh, 92px);
    bottom: 18px;
    left: clamp(42px, 5vw, 86px);
    z-index: 20;

    width: min(35vw, 520px);
    min-height: 0;

    display: flex;
    flex-direction: column;
    align-items: flex-start;

    overflow: visible;
    transform: none;
  }

  .hero-text .hero-photo,
  .hero h1 {
    transform: none;
  }

  .hero-text .hero-photo {
    order: initial;
    flex: 0 0 auto;
    margin: 0 0 12px;
    animation: fadeUp .75s .05s ease both;
  }

  .hero h1 {
    flex: 0 0 auto;
    margin-top: 0;
    margin-bottom: 10px;
  }

  .hero-tag-row {
    flex: 0 0 auto;
    margin-bottom: 8px;
  }

  .hero-tag {
    transform: none;
  }

  .hero h1,
  .hero-tag-row,
  #chip3d,
  .hero-sub,
  .fixed-contact {
    position: relative;
    z-index: 1;
  }

  #chip3d {
    flex: 0 0 auto;
    transform: translateX(-10px);
    align-self: flex-start;
  }

  /* Subtitle belongs to the chip, so it always remains directly below it. */
  .hero-sub {
    flex: 0 0 auto;
    margin-top: 8px;
    margin-bottom: 0;
    text-align: left;
  }

  /* Keep contacts at the bottom of the fixed intro. */
  .fixed-contact {
    flex: 0 0 auto;
    margin-top: auto;
    justify-content: flex-start;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  #main-content > section:not(.hero) {
    width: auto;
    max-width: none;
    margin-left: 43vw;
    margin-right: 3.5vw;
    padding-left: 0;
    padding-right: 0;
  }

  #about {
    padding-top: 92px;
  }

  footer {
    margin-left: 43vw;
    padding-left: 0;
    padding-right: 3.5vw;
  }

  #websites .project-grid-web {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: none;
  }

  #skills .skills-grid > .scat,
  #skills .skills-grid > .scat:first-child,
  #skills .skills-grid > .scat:nth-child(2),
  #skills .skills-grid > .scat:nth-child(3),
  #skills .skills-grid > .scat:nth-last-child(-n+2) {
    grid-column: span 6;
  }

  .about-grid > .acard:last-child {
    width: 72%;
  }

  #websites .project-grid-web > .pc:last-child {
    grid-column: 1 / -1;
    width: auto;
    justify-self: stretch;
    margin-left: calc(25% + 5px);
    margin-right: calc(25% + 5px);
  }

  #skills .skills-grid > .scat:last-child {
    grid-column: 1 / -1;
    width: calc(50% - 10px);
    justify-self: center;
  }
}

/* Compact spacing near the desktop breakpoint. */
@media (min-width: 1500px) and (max-width: 1599px) and (hover: hover) and (pointer: fine) {
  .hero-text {
    top: 20px;
    bottom: 14px;
  }

  .hero-text .hero-photo {
    margin-bottom: 7px;
  }

  .hero h1 {
    margin-bottom: 7px;
  }

  .hero-tag-row {
    margin-bottom: 4px;
  }

  .hero-sub {
    margin-top: 6px;
  }

  .fixed-contact {
    gap: 12px;
  }
}

/* ── STACKED INTRO ──
   Narrow viewports and touch devices place the intro above the content. */
@media (max-width: 1499px),
       (hover: none) and (pointer: coarse) {
  .hero {
    width: auto;
    height: auto;
    min-height: 100vh;
    /* Toolbar visibility must not move the sections below the intro. */
    min-height: 100svh;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    gap: 0;
    padding:
      calc(clamp(54px, 8vh, 90px) + env(safe-area-inset-top, 0px))
      6%
      calc(clamp(46px, 7vh, 76px) + env(safe-area-inset-bottom, 0px));
    margin: 0 auto;

    overflow: visible;
    text-align: center;
  }

  .hero-text {
    position: static;
    width: min(100%, 680px);
    min-width: 0;

    display: flex;
    flex-direction: column;
    align-items: center;

    overflow: visible;
    transform: none;
  }

  .hero-text .hero-photo {
    order: -1;
    margin: 0 0 18px;
    transform: none;
  }

  .hero h1 {
    margin: -4px -8px 12px;
    transform: none;
    text-align: center;
  }

  .hero-tag-row {
    justify-content: center;
    margin-bottom: 10px;
  }

  .hero-tag {
    transform: none;
    margin-left: 0;
    margin-right: 0;
    text-align: center;
  }

  #chip3d {
    margin: 0;
    align-self: center;
    transform: translateY(6px);
  }

  .hero-sub {
    margin-top: 10px;
    margin-bottom: 0;
    text-align: center;
  }

  .fixed-contact {
    justify-content: center;
    margin-top: 20px;
    padding-bottom: 0;
  }

  #main-content > section:not(.hero),
  footer {
    width: auto;
    margin-left: auto;
    margin-right: auto;
  }

  #websites .project-grid-web,
  #skills .skills-grid {
    max-width: none;
    margin-left: 0;
    margin-right: 0;
  }

  #websites .project-grid-web > .pc,
  #skills .skills-grid > .scat {
    width: auto;
    justify-self: stretch;
    margin-left: 0;
    margin-right: 0;
  }
}

/* Only mouse-driven layouts use a height breakpoint; mobile toolbar changes
   must not switch the intro spacing during a scroll. */
@media (max-width: 1499px) and (max-height: 679px) and (hover: hover) and (pointer: fine),
       (max-width: 680px) {
  .hero {
    justify-content: flex-start;
    padding-top: calc(32px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(36px + env(safe-area-inset-bottom, 0px));
  }

  .hero-text .hero-photo {
    margin-bottom: 8px;
  }

  .hero h1 {
    margin-bottom: 7px;
  }

  .hero-tag-row {
    margin-bottom: 6px;
  }

  #chip3d {
    transform: none;
  }

  .hero-sub {
    margin-top: 6px;
  }

  .fixed-contact {
    margin-top: 12px;
    gap: 12px;
  }
}

/* ── NARROW / MOBILE CONTENT ───────────────────────────────────────────── */

/* Collapse content grids and remove desktop skill-card spans. */
@media (max-width: 820px) {
  .pctop {
    justify-content: flex-start;
    gap: 12px;
  }

  .about-grid,
  #researches .research-grid,
  #projects .project-grid-engineering,
  #websites .project-grid-web,
  #skills .skills-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  #skills .skills-grid {
    grid-auto-flow: row;
  }

  #skills .skills-grid > .scat,
  #skills .skills-grid > .scat:first-child,
  #skills .skills-grid > .scat:nth-child(2),
  #skills .skills-grid > .scat:nth-child(3),
  #skills .skills-grid > .scat:nth-last-child(-n+2),
  #skills .skills-grid > .scat:last-child {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    justify-self: stretch;
    margin-left: 0;
    margin-right: 0;
  }

  .about-grid > .acard,
  .about-grid > .acard:last-child,
  #projects .project-grid-engineering > .project-centered,
  #websites .project-grid-web > .pc:last-child {
    grid-column: auto;
    width: 100%;
    justify-self: stretch;
    margin-left: 0;
    margin-right: 0;
  }
}

/* Language cards stack cleanly on small screens. */
@media (max-width: 680px) {
  .lgrid {
    flex-direction: column;
    gap: 14px;
    align-items: flex-start;
    padding-left: 10px;
  }

  .lgrid .lcard {
    width: 100%;
    min-width: 0;
    min-height: 54px;
    padding: 8px 0;
    justify-content: flex-start;
  }

  .lflag,
  .lflag svg {
    width: 36px;
  }
}

/* Scale hero elements to fit phone widths. */
@media (max-width: 599px) {
  .hero-text .photo-wrap {
    width: min(var(--hero-photo-size), 56vw);
    height: min(var(--hero-photo-size), 56vw);
  }

  .hero h1 {
    font-size: min(var(--hero-name-size), 12vw);
  }

  .hero-tag {
    font-size: min(var(--hero-role-size), 3.6vw);
    padding: 6px 12px;
  }

  #chip3d {
    width: min(var(--chip-size), 53vw);
    height: min(var(--chip-size), 53vw);
  }

  .hero-sub {
    font-size: min(var(--hero-sub-size), 4.4vw);
  }

  .fixed-contact a {
    width: 40px;
    height: 40px;
    font-size: 1.10rem;
  }
}

@media (max-width: 560px) {
  section {
    padding: 60px 16px 40px;
  }

  .hero {
    padding-left: 16px;
    padding-right: 16px;
  }

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

@media (max-width: 420px) {
  .hero-tag {
    letter-spacing: .075em;
    line-height: 1.45;
    padding: 6px 10px;
  }

  .card {
    padding: 22px 20px;
  }

  .pc .pl {
    top: 22px;
    right: 20px;
  }

  .fixed-contact {
    gap: 10px;
  }

  .fixed-contact a {
    width: 38px;
    height: 38px;
  }
}
