/* Editorial layout (preview). Loaded after base.css.
   The whole page is four full-height panels: the portrait, About, Book and
   Featured. The name is set vertically, in white, directly on the portrait. Each is separated by its own title set vertically. The panel
   under the pointer opens and the others fold down to their title.
   About is open by default. The portrait panel carries only the name, role
   and contact link; folded, it is a thin vertical cut of the photo. The four
   logos stay pinned to the bottom-right corner.                            */
:root {
  --rule: #dcd8cc;
  --pad: clamp(20px, 2.6vw, 40px);
  --tab: 84px;
  --cut: 88px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

body,
p {
  text-align: left;
}

/* ---- Role: set vertically in white at the top of the portrait ---- */
.p-name {
  display: contents;
}

.p-name .role {
  position: absolute;
  z-index: 1;
  top: var(--pad);
  left: 16px;
  margin: 0;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
  font-size: 0.6875rem;
  letter-spacing: 0.12em;
  line-height: 1;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.88);
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.5);
}

/* "Antonio Melé" as UTF-8 bytes in hex, running up the foot of the photo
   like an edge marking on film. */
.p-name .hex {
  position: absolute;
  z-index: 1;
  left: 17px;
  bottom: var(--pad);
  margin: 0;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 0.5625rem;
  letter-spacing: 0.16em;
  line-height: 1;
  color: rgba(255, 255, 255, 0.62);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5);
}

/* ---- Name: stacked layouts show it as a normal heading above About ---- */
.v-name {
  color: #4b483f;
  margin: 0 0 22px;
  font-size: 2.75rem;
  line-height: 1;
  letter-spacing: -0.02em;
}

/* The letters of the name are cut out of the portrait: the photo is the
   text's background, clipped to the glyphs. A dark wash keeps the pale
   parts of the photo (the shirt) from vanishing on paper. Browsers without
   background-clip:text keep the solid colour above. */
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .v-name {
    background-image:
      linear-gradient(rgba(24, 16, 10, 0.34), rgba(24, 16, 10, 0.34)),
      url(../img/portrait-fill.webp);
    background-size: auto, 135% auto;
    background-position: 0 0, 50% 76%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: saturate(0.85) contrast(1.12);
  }
}

/* ---- Portrait, with a vintage-photo treatment done entirely in CSS:
   filters on the image, then grain, a vignette and a warm tint layered on
   top. The image file itself is untouched. ---- */
.frame {
  position: relative;
  overflow: hidden;
}

.frame img.main-image {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
  border-radius: 0;
  object-fit: cover;
  object-position: 59% 13%;
  filter: blur(0.4px) saturate(0.72) contrast(1.14) brightness(0.72) sepia(0.14);
}

/* Layers, top to bottom: film grain, vignette, warm tint, then two soft
   shadows that keep the white text readable. */
.frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='1 0 0 0 0  1 0 0 0 0  1 0 0 0 0  0 0 0 0 0.11'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    radial-gradient(ellipse 130% 80% at 55% 38%, rgba(20, 12, 6, 0.08) 36%, rgba(20, 12, 6, 0.72) 100%),
    linear-gradient(rgba(214, 150, 70, 0.17), rgba(214, 150, 70, 0.17)),
    linear-gradient(to top right, rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0) 45%),
    linear-gradient(to right, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0) 110px);
}

.face {
  display: block;
  width: 230px;
  height: 230px;
  margin: 0 0 26px;
  border-radius: 8px;
}

/* Stacked layouts: the photo comes first, then the text. */
.about-cols {
  display: flex;
  flex-direction: column;
}

.about-cols .face {
  order: -1;
}

/* The Comillas crest sits a little low next to the wordmarks; nudge it up. */
.logos img[src="static/img/comillas.png"] {
  position: relative;
  top: -6px;
}

/* The Backbase and MIT marks are heavier than the other two, so they rest
   a little fainter. They still come to full strength on hover. */
.logos img[src="static/img/backbase.svg"],
.logos img[src="static/img/mitsloan.png"] {
  opacity: 0.58;
}

.p-about .logos {
  justify-content: flex-start;
  gap: 16px 30px;
  margin-top: 36px;
}

/* ---- Sections (stacked by default; see the accordion below) ---- */
.poster .section {
  margin: 0;
  padding: 0 var(--pad);
  border-radius: 0;
  background: none;
}

.panel + .panel {
  margin-top: 48px;
}

.poster h2 {
  margin: 0 0 18px;
  font-family: var(--display);
  font-weight: 360;
  font-size: 1.75rem;
  line-height: 1;
  letter-spacing: -0.01em;
  text-transform: none;
  font-feature-settings: "calt", "liga";
  font-variation-settings: "opsz" 72;
  color: var(--ink);
}

.panel .body p {
  max-width: 60ch;
}

.p-hero .frame {
  aspect-ratio: 5 / 4;
  max-height: 70vh;
  margin: 0 calc(var(--pad) * -1) 32px;
}

.p-book .body,
.p-featured .body {
  font-size: 0.9375rem;
}

/* ---- Book: the latest edition large, the translations on a shelf ---- */
.shelf {
  display: flex;
  align-items: flex-start;
  gap: clamp(28px, 3vw, 52px);
}

.shelf-main {
  flex: none;
  display: block;
  border-radius: 6px;
}

.shelf-main img {
  display: block;
  width: clamp(170px, 17vw, 270px);
  border-radius: 6px;
  box-shadow: 12px 14px 28px rgba(0, 0, 0, 0.24);
  transition: transform 0.35s var(--ease);
}

.shelf-side p {
  margin-top: 2px;
}

.shelf-row {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 22px 14px;
  margin: 34px 0 0;
  padding: 0;
}

.shelf-row a {
  display: block;
  font-weight: 400;
  color: var(--muted);
}

.shelf-row img {
  display: block;
  width: auto;
  height: clamp(100px, 8.3vw, 136px);
  border-radius: 4px;
  box-shadow: 4px 6px 14px rgba(0, 0, 0, 0.2);
  transition: opacity 0.3s var(--ease), transform 0.35s var(--ease);
}

/* The label holds the language's English name and, stacked in the same
   cell, its own name. Sharing a cell keeps the label as wide as the longer
   of the two, so nothing shifts when they swap on hover. */
.shelf-row .lang {
  display: grid;
  margin-top: 10px;
  font-size: 0.6875rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.shelf-row .lang span {
  grid-area: 1 / 1;
  transition: opacity 0.3s var(--ease);
}

.shelf-row .lang .native {
  opacity: 0;
}

.shelf-row a:hover .lang span,
.shelf-row a:focus-visible .lang span {
  opacity: 0;
}

.shelf-row a:hover .lang .native,
.shelf-row a:focus-visible .lang .native {
  opacity: 1;
}

/* Translations rest at reduced strength; the one under the pointer comes
   to full and lifts slightly. The others never change. */
@media (hover: hover) {
  .shelf-row img {
    opacity: 0.78;
  }

  .shelf-row a:hover img,
  .shelf-row a:focus-visible img {
    opacity: 1;
    transform: translateY(-4px);
  }

  /* Only the image moves; the link it sits in stays put, so the pointer
     never falls off the cover as it lifts. */
  .shelf-main:hover img {
    transform: translateY(-5px);
  }
}

.featured li + li {
  margin-top: 1.6rem;
}

/* Dates share the monospace of the hex marking. This replaces the serif
   dates set in base.css. */
.featured time {
  font-family: var(--mono);
  font-size: 0.84em;
}

/* A block cursor after the "hacker since he was a kid" paragraph. */
.cursor {
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  margin-left: 5px;
  vertical-align: -0.16em;
  background: var(--link);
  animation: blink 1.2s steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* ---- Featured: the whole section sits on terracotta ---- */
.poster .p-featured {
  background: var(--link);
  color: #fff;
  padding-top: 36px;
  padding-bottom: 40px;
}

.poster .p-featured h2 {
  color: #fff;
}

.p-featured a {
  color: #fff;
}

.p-featured a:hover {
  color: #fff;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.p-featured .featured span {
  color: rgba(255, 255, 255, 0.72);
}

.p-hero .body {
  padding: 4px 0 8px;
}

/* The copy of the LinkedIn link at the foot of Featured is for the stacked
   layout only. */
.social-foot {
  display: none;
}

.social {
  display: inline-block;
  line-height: 0;
}

.social .inline-icon {
  width: 26px;
  height: 26px;
  margin: 0;
}




/* ---- Wide screens with a pointer: the page becomes an accordion ---- */
@media (hover: hover) and (min-width: 62em) {
  .poster {
    display: flex;
    height: 100vh;
    min-height: 620px;
  }

  /* The row's own background is Featured's terracotta, so if a sliver of
     the row is ever uncovered at the right edge it reads as Featured. */
  .panels {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: stretch;
    background: var(--link);
  }

  .poster .panel:not(.p-featured) {
    background: var(--paper);
  }

  .poster .panel,
  .poster .panel + .panel {
    display: flex;
    flex: 0 1 var(--tab);
    min-width: var(--tab);
    margin: 0;
    padding: 0;
    overflow: hidden;
    transition: flex-grow 0.7s var(--ease), flex-basis 0.7s var(--ease);
  }

  /* The portrait panel. Folded it is only a thin cut; open, the photo
     fills it. It carries the name, the role and the contact link. */
  .poster .p-hero {
    position: relative;
    flex-basis: var(--cut);
    min-width: var(--cut);
    color: #fff;
  }

  .p-hero .frame {
    position: absolute;
    inset: 0;
    aspect-ratio: auto;
    max-height: none;
    margin: 0;
  }

  .poster .p-hero .body {
    position: absolute;
    z-index: 1;
    left: auto;
    right: var(--pad);
    bottom: var(--pad);
    flex: none;
    width: auto;
    padding: 0;
    overflow: visible;
  }

  .p-hero .body p {
    margin: 0;
  }

  /* The folded strip shows a two-tone ordered-dither copy of the portrait,
     drawn with hard pixels over the photo. As the panel opens it fades to
     a faint texture over the real photo. */
  .p-hero .dither {
    position: absolute;
    inset: 0;
    background: url(../img/portrait-dither.png) 59% 13% / cover no-repeat;
    image-rendering: pixelated;
    filter: brightness(0.82);
    opacity: 0.8;
    transition: opacity 0.7s var(--ease);
  }

  .poster .panels .p-hero:hover .dither,
  .poster .panels:not(:has(.panel:hover)) .p-hero:focus-within .dither {
    opacity: 0;
  }

  /* Slight darkening behind the white text; only while the photo is open. */
  .p-hero .frame::before {
    content: "";
    position: absolute;
    z-index: 1;
    inset: 0;
    pointer-events: none;
    background: rgba(14, 11, 9, 0.4);
    opacity: 0;
    transition: opacity 0.6s var(--ease);
  }

  .poster .panels .p-hero:hover .frame::before,
  .poster .panels:not(:has(.panel:hover)) .p-hero:focus-within .frame::before {
    opacity: 1;
  }



  .p-hero .body a {
    color: #fff;
    font-size: 1.125rem;
    text-decoration: underline;
    text-decoration-color: rgba(255, 255, 255, 0.5);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
  }

  .p-hero .body a:hover {
    text-decoration-color: #fff;
  }


  .poster .p-featured,
  .poster .panel + .p-featured {
    padding: 0;
  }

  /* On terracotta the folded title is a soft white, the open one full. */
  .poster .p-featured > h2,
  .panels:hover .p-featured:not(:hover) > h2,
  .panels:not(:has(.panel:hover)):focus-within .p-featured:not(:focus-within) > h2 {
    color: rgba(255, 255, 255, 0.72);
  }

  .panels .p-featured:hover > h2,
  .panels:not(:has(.panel:hover)) .p-featured:focus-within > h2 {
    color: #fff;
  }

  /* The name runs up the foot of About's title strip, in the same place
     and at the same size it had on the photo, so it stays visible whether
     About is open or folded. The strip is widened to hold it. */
  .poster .p-about {
    position: relative;
    flex-basis: var(--name-strip);
    min-width: var(--name-strip);
    --name-strip: calc(clamp(2.25rem, min(3.8vw, 5.2vh), 4rem) + 44px);
  }

  .poster .p-about > h2 {
    width: var(--name-strip);
  }

  .v-name {
    position: absolute;
    z-index: 1;
    left: 22px;
    bottom: var(--pad);
    margin: 0;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    white-space: nowrap;
    font-size: clamp(2.25rem, min(3.8vw, 5.2vh), 4rem);
    line-height: 1;
    /* A true cut-out: the letters show the same photo as the strip on the
       left, at the same scale and in register with it, as if the photo ran
       on behind the paper. The photo is drawn at full viewport height (it
       is 2:3, so 66.667vh wide) and offset exactly as the strip crops it
       (object-position 59%). The element is turned 180deg, so it uses a
       pre-turned copy and the offsets are worked out in its turned space. */
    background-image:
      linear-gradient(rgba(22, 15, 9, 0.42), rgba(22, 15, 9, 0.42)),
      url(../img/portrait-fill-rotated.webp);
    background-size: auto, 66.667vh 100vh;
    background-position:
      0 0,
      calc(100% + 39.333vh + 0.41 * var(--cut) + 22px) calc(0px - var(--pad));
    transition: background-position 0.7s var(--ease);
    filter: saturate(1.05) contrast(1.08) brightness(1.2);
  }

  /* The title, turned to run up the page, is the separator. */
  .panel > h2 {
    flex: none;
    width: var(--tab);
    margin: 0;
    padding: 0 26px var(--pad) 0;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    text-align: right;
    white-space: nowrap;
    color: var(--title);
    cursor: default;
    transition: color 0.4s;
  }

  /* A fixed minimum width keeps the text from re-wrapping as panels move. */
  .panel .body {
    flex: 1 0 auto;
    width: min(560px, 38vw);
    padding: var(--pad) 32px 24px 0;
    overflow-y: auto;
    scrollbar-width: none;
    opacity: 0;
    transition: opacity 0.35s;
  }

  /* Panels can still scroll if a screen is short, but show no scrollbar. */
  .panel .body::-webkit-scrollbar {
    display: none;
  }

  /* About is a single column sized to fit one screen: a wider measure
     keeps the text short, and the face photo scales with the height. */
  .poster .p-about .body {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    padding-top: clamp(48px, 9vh, 96px);
  }

  /* Text on the left, the face photo on the right, centred as a pair. */
  .about-cols {
    display: grid;
    grid-template-columns: minmax(0, 470px) auto;
    column-gap: clamp(36px, 4vw, 64px);
    align-items: start;
    justify-content: center;
    font-size: 0.9375rem;
  }

  .about-main,
  .about-side {
    grid-column: 1;
  }

  .about-cols .face {
    grid-column: 2;
    grid-row: 1 / span 2;
    order: 0;
  }

  .about-cols p {
    margin-bottom: 0.8rem;
    line-height: 1.55;
  }

  /* While the photo panel is open there is less room, so About shows only
     its text. */
  .poster .panels:has(.p-hero:hover) .about-cols,
  .poster .panels:not(:has(.panel:hover)):has(.p-hero:focus-within) .about-cols {
    grid-template-columns: minmax(0, 470px);
  }

  .poster .panels:has(.p-hero:hover) .about-cols .face,
  .poster .panels:not(:has(.panel:hover)):has(.p-hero:focus-within) .about-cols .face {
    display: none;
  }

  /* The logo row spans the full width of the text column. */
  .p-about .logos {
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 16px;
    margin-top: 72px;
  }

  /* Optical nudge: Backbase sits a little left of its even-spaced slot. */
  .p-about .logos img[src="static/img/backbase.svg"] {
    position: relative;
    left: -4px;
  }

  .p-about .body p {
    max-width: none;
  }

  .p-about .face {
    width: clamp(180px, 18vw, 310px);
    height: clamp(180px, 18vw, 310px);
    margin: 4px 0 0;
  }

  /* The Book panel uses the width it gets: the latest cover large with the
     text beside it, and the translations in a row underneath. */
  .poster .p-book .body {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    padding-top: clamp(48px, 9vh, 96px);
  }

  /* The cover-and-text pair is centred in the panel, as in About. */
  .p-book .shelf {
    display: grid;
    grid-template-columns: auto minmax(260px, 30em);
    justify-content: center;
    column-gap: clamp(32px, 3.4vw, 60px);
    row-gap: clamp(30px, 5vh, 52px);
    align-items: start;
  }

  .p-book .shelf-side {
    display: contents;
  }

  .p-book .shelf-main img {
    width: clamp(240px, min(26vw, 42vh), 430px);
  }

  .p-book .shelf-text {
    max-width: 34em;
    margin-top: 6px;
  }

  .p-book .shelf-row {
    /* One line across the full width of the cover-and-text pair, with the
       spare room shared out between the covers. */
    grid-column: 1 / -1;
    margin: 0;
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 14px;
  }

  .p-book .shelf-row img {
    height: clamp(96px, min(8.6vw, 15vh), 150px);
  }

  /* Featured takes the panel's width too, with the list centred in it as a
     block, as in About and Book. The list keeps a fixed width so its lines
     do not re-wrap while the panel opens. */
  .poster .p-featured .body {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    padding-top: clamp(48px, 9vh, 96px);
  }

  .p-featured .featured {
    --w: min(560px, 38vw);
    width: var(--w);
    /* Left of centre: a quarter of the spare room on the left, the rest on
       the right. */
    margin: 0 0 0 max(0px, (100% - var(--w)) * 0.25);
  }

  /* The hex marking lies flat along the foot of the photo and shows only
     while the photo is open; on the folded strip it is hidden. */
  .p-name .hex {
    left: var(--pad);
    writing-mode: horizontal-tb;
    transform: none;
    opacity: 0;
    transition: opacity 0.25s var(--ease);
  }

  .poster .panels .p-hero:hover .hex,
  .poster .panels:not(:has(.panel:hover)) .p-hero:focus-within .hex {
    opacity: 1;
    transition: opacity 0.45s var(--ease) 0.3s;
  }

  .panel .copyright {
    margin-bottom: 0;
  }

  /* ---- Open / folded states. About is open by default; hovering Book or
     Featured (or moving keyboard focus into one) opens that panel instead.
     Hovering the photo only widens it part-way, with About still open
     beside it. "No panel hovered" is tested on the panels themselves, not
     the row, so the pointer resting on the row's edge keeps About open
     instead of folding everything. ---- */
  .poster .panels:not(:has(.panel:hover)):not(:focus-within) .p-about,
  .poster .panels:has(.p-hero:hover) .p-about,
  .poster .panels .panel:hover,
  .poster .panels:not(:has(.panel:hover)) .panel:focus-within {
    flex-grow: 1;
  }

  /* While the photo is open the name slides right with About, and its
     fill slides too, so the letters pass across the photo like a window
     rather than carrying a fixed picture. The whole photo is on show in
     that state, so nothing is truly "behind" the name; the fill settles on
     the right-hand edge of the photo (the table and chair), which keeps
     the letters dark enough to read. */
  .poster .panels:has(.p-hero:hover) .v-name,
  .poster .panels:not(:has(.panel:hover)):has(.p-hero:focus-within) .v-name {
    background-position: 0 0, calc(100% + 59vh) calc(0px - var(--pad));
  }

  .poster .panels .panel.p-hero:hover,
  .poster .panels:not(:has(.panel:hover)) .panel.p-hero:focus-within {
    flex-grow: 0;
    flex-basis: clamp(360px, 36vw, 620px);
  }

  .poster .panels:not(:has(.panel:hover)):not(:focus-within) .p-about .body,
  .poster .panels:has(.p-hero:hover) .p-about .body,
  .poster .panels .panel:hover .body,
  .poster .panels:not(:has(.panel:hover)) .panel:focus-within .body {
    opacity: 1;
    transition-delay: 0.25s;
  }

  .poster .panels:not(:has(.panel:hover)):not(:focus-within) .p-about > h2,
  .poster .panels:has(.p-hero:hover) .p-about > h2,
  .poster .panels .p-about:hover > h2,
  .poster .panels .p-book:hover > h2,
  .poster .panels:not(:has(.panel:hover)) .p-about:focus-within > h2,
  .poster .panels:not(:has(.panel:hover)) .p-book:focus-within > h2 {
    color: var(--ink);
  }
}

@media (prefers-reduced-motion: reduce) {
  .panel,
  .panel .body,
  .panel > h2,
  .p-hero .dither,
  .v-name {
    transition: none;
  }

  .p-name .hex {
    transition: none !important;
  }

  .cursor {
    animation: none;
  }
}

/* ---- Phones and touch screens: a plain single column. No vertical photo:
   the name centred, the face photo large and centred, then the text and
   logos, Book, and Featured. ---- */
@media screen and (max-width: 62em), (hover: none) {
  .panels {
    display: flex;
    flex-direction: column;
  }

  .p-about { order: 0; }
  .p-hero { order: 1; }
  .p-book { order: 2; }
  .p-featured { order: 3; }

  .p-hero .frame {
    display: none;
  }

  /* The photo panel is not shown at all here; its LinkedIn link moves to
     the foot of Featured, in white. */
  .poster .p-hero {
    display: none;
  }

  .panel .body .social-foot {
    display: block;
    max-width: none;
    margin: 40px 0 0;
    text-align: center;
  }

  .poster .p-about {
    margin-top: 0;
  }

  .v-name {
    margin: 52px 0 30px;
    text-align: center;
  }

  .p-about > h2 {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .about-cols .face {
    width: min(78vw, 340px);
    height: auto;
    aspect-ratio: 1;
    margin: 0 auto 34px;
  }

  .p-about .logos {
    justify-content: center;
    margin-top: 32px;
  }

  /* Section titles and the book cover are centred. */
  .poster h2 {
    text-align: center;
    margin-bottom: 26px;
  }

  .shelf {
    display: block;
  }

  .shelf-main img {
    width: 210px;
    margin: 0;
  }

  .shelf-main {
    width: fit-content;
    margin: 0 auto 30px;
  }

  .shelf-row {
    justify-content: center;
  }
}
