:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --border: #d8dee4;
  --dots: #d0d7de;
  --text: #16202a;
  --muted: #57636f;
  --accent: #0f766e;
  --on-accent: #ffffff;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --dot-off: #c3cbd3;
  --button-gap: 1.25rem;
  --dots-bottom: 0.5rem;
  --card-bottom-space: 2.75rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.25rem 1.25rem calc(3rem + 2 * var(--button-gap) + env(safe-area-inset-bottom));
  background-color: var(--bg);
  background-image: radial-gradient(var(--dots) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.5;
}

main {
  position: relative;
  perspective: 1400px;
  width: 100%;
  max-width: 26rem;
}

.flipper {
  display: grid;
  touch-action: pan-y;
  transform-style: preserve-3d;
  transition: transform 600ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Both faces share one grid cell, so the card is as tall as the taller face. */
.card {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.banner {
  position: relative;
  flex: none;
  width: 100%;
  aspect-ratio: 2 / 1;
  overflow: hidden;
  /* Matches the top edge of the photo, so the headroom above it looks continuous. */
  background: #0a0a0a;
  container-type: size;
}

/* Face centre sits 25% down the photo. Short banners centre the face in the area
   above the sheet; taller ones stop at a small downward shift to add headroom. */
.banner img {
  --shift: min(3cqw, 50cqh - 0.625rem - 25cqw);
  position: absolute;
  top: var(--shift);
  left: 0;
  width: 100%;
  height: calc(100% - var(--shift));
  object-fit: cover;
  object-position: center top;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 3cqw);
  mask-image: linear-gradient(to bottom, transparent, #000 3cqw);
}

/* Fades the photo into the accent colour of the sheet's top border. */
.banner::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 70%, rgb(15 118 110 / 0.3));
}

/* A rounded sheet that overlaps the bottom of the banner. */
.details {
  position: relative;
  margin-top: -1.25rem;
  padding: 1.5rem 1.5rem var(--card-bottom-space);
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 0 0 1.5px var(--accent);
}

h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.title {
  margin: 0.25rem 0 0;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.9rem;
}

.org {
  margin: 0.125rem 0 0;
  font-size: 0.9rem;
}

.bio {
  margin: 0.875rem 0 0;
  color: var(--muted);
}

h2 {
  margin: 1.75rem 0 0.5rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.04em;
}

h2::before {
  content: "// ";
  color: var(--accent);
}

.rows {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--border);
}

.rows li {
  border-bottom: 1px solid var(--border);
}

.rows a {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0 1rem;
  min-height: 3rem;
  padding: 0.625rem 0;
  color: var(--text);
  text-decoration: none;
  transition: color 150ms ease;
}

.rows a:hover {
  color: var(--accent);
}

.label {
  flex: none;
  font-size: 0.95rem;
}

.value {
  min-width: 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.8rem;
  text-align: right;
  overflow-wrap: anywhere;
}

.icons {
  display: flex;
  gap: 0.625rem;
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
}

.icons a {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  transition: border-color 150ms ease, color 150ms ease;
}

.icons a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.icons svg {
  width: 1.375rem;
  height: 1.375rem;
}

.qr {
  transform: rotateY(180deg);
  padding: 1.75rem 1.5rem var(--card-bottom-space);
  align-items: center;
  justify-content: center;
  text-align: center;
}

.qr img {
  display: block;
  width: 100%;
  max-width: 20rem;
  height: auto;
}

.qr p {
  margin: 1rem 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.8rem;
}

.dots {
  position: absolute;
  bottom: var(--dots-bottom);
  left: 50%;
  z-index: 1;
  display: flex;
  transform: translateX(-50%);
}

/* The button is a larger tap target around the visible dot. */
[role="tab"] {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 1.5rem;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

[role="tab"]::before {
  content: "";
  width: 0.5625rem;
  height: 0.5625rem;
  background: var(--dot-off);
  border-radius: 50%;
  transition: background-color 150ms ease;
}

[role="tab"][aria-selected="true"]::before {
  background: var(--text);
}

.actions {
  position: fixed;
  right: 1.25rem;
  bottom: calc(var(--button-gap) + env(safe-area-inset-bottom));
  left: 1.25rem;
  z-index: 1;
  display: flex;
  gap: 0.625rem;
  max-width: 26rem;
  margin: 0 auto;
}

.button {
  flex: 1;
  min-height: 3rem;
  padding: 0.75rem 1rem;
  background: var(--accent);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgb(22 32 42 / 0.28);
  color: var(--on-accent);
  font: 600 0.95rem/1.4 var(--sans);
  text-align: center;
  text-decoration: none;
  transition: opacity 150ms ease;
}

.share {
  display: grid;
  place-items: center;
  flex: none;
  width: 3rem;
  height: 3rem;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgb(22 32 42 / 0.28);
  color: var(--text);
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease;
}

.share:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.share svg {
  width: 1.25rem;
  height: 1.25rem;
}

.toast {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 50%;
  margin: 0;
  padding: 0.375rem 0.75rem;
  background: var(--text);
  border-radius: 6px;
  color: var(--surface);
  font-family: var(--mono);
  font-size: 0.75rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 150ms ease;
}

.toast.visible {
  opacity: 1;
}

.button:hover {
  opacity: 0.88;
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Phones: the card fills the screen edge to edge, with the button floating over it. */
@media (max-width: 600px) {
  :root {
    --button-gap: 1rem;
    --dots-bottom: calc(4.5rem + env(safe-area-inset-bottom));
    --card-bottom-space: calc(6.5rem + env(safe-area-inset-bottom));
  }

  body {
    display: block;
    padding: 0;
    background: var(--bg);
  }

  /* Keeps the card's near edge from widening the page mid-flip. */
  main {
    max-width: none;
    overflow: hidden;
  }

  .flipper {
    min-height: 100vh;
    min-height: 100dvh;
  }

  .card {
    border: 0;
    border-radius: 0;
  }

  /* Takes whatever height the details leave free, whatever the photo's shape. */
  .banner {
    flex: 1 1 0;
    min-height: 10rem;
    aspect-ratio: auto;
  }

  .details {
    padding-inline: 1.25rem;
  }

  h2 {
    margin-top: 1.25rem;
  }

  .icons {
    margin-top: 0.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
