/* ==========================================================================
   Portfolio index: a bento grid of every website
   Bordered tiles in mixed sizes, each filled with the site's screenshot.
   Filters, tile sizes, "Show all" and the cursor spotlight are wired up in
   scripts/features/site-filter.js.
   ========================================================================== */

.portfolio {
  --bento-gap: clamp(10px, 1.2vw, 16px);
  --bento-border: 1.5px solid var(--color-ink);

  display: flex;
  flex-direction: column;
  gap: clamp(28px, 4vw, 48px);
  padding: var(--section-y) var(--gutter);
  background: var(--color-mist);
}

.portfolio__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px 40px;
}

.portfolio .section-title {
  font-size: var(--heading-md);
}

/* ---- Filter bar: a rounded pill tray ---- */
.portfolio__filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 5px;
  border: var(--bento-border);
  border-radius: var(--radius-pill);
  background: var(--color-paper);
}

.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-ink);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .24em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 200ms ease, color 200ms ease, transform 140ms var(--ease);
}

.filter-btn:active {
  transform: scale(.96);
}

.filter-btn[aria-pressed="true"] {
  background: var(--color-ink);
  color: var(--color-paper);
}

/* Number of sites behind each filter */
.filter-btn__count {
  font-variant-numeric: tabular-nums;
  letter-spacing: .08em;
  opacity: .6;
}

@media (hover: hover) and (pointer: fine) {
  .filter-btn:not([aria-pressed="true"]):hover { background: var(--color-mist); }
}

/* ==========================================================================
   Bento grid
   Every cell has the same 16:10 shape as the screenshots, so previews are
   never cropped or zoomed. Rows are sized from the column width: a column is
   (grid width − gaps) / columns, and a row is 10/16 of that. A large tile
   (.site--lg) spans 2 × 2 cells, which keeps it 16:10 as well (give or take
   one gap). site-filter.js chooses which tiles are large so every row fills.
   ========================================================================== */

/* The wrapper is the size container the row height is measured from */
.site-grid-wrap {
  container-type: inline-size;
}

.site-grid {
  --cols: 4;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-auto-rows: calc((100cqw - (var(--cols) - 1) * var(--bento-gap)) / var(--cols) * .625);
  grid-auto-flow: dense;
  gap: var(--bento-gap);
}

/* Browsers without container units fall back to a fixed row height */
@supports not (width: 1cqw) {
  .site-grid { grid-auto-rows: clamp(140px, 13vw, 200px); }
}

.site--lg { grid-column: span 2; grid-row: span 2; }

/* ---- One tile ---- */
.site__link {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: block;
  height: 100%;
  border: var(--bento-border);
  border-radius: var(--radius-box);
  background: var(--color-stone);
  color: var(--color-on-band);   /* caption sits on a dark fade in both themes */
  text-decoration: none;
  transition: transform 400ms var(--ease), box-shadow 400ms ease;
}

.site__link:focus-visible {
  outline-offset: 3px;
}

/* Screenshot fills the whole tile */
.site__shot {
  position: absolute;
  inset: 0;
  z-index: -2;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  transition: transform 900ms var(--ease);
}

/* Dark gradient behind the caption so it reads on any screenshot */
.site__link::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(to top, rgba(20, 20, 20, .88) 0%, rgba(20, 20, 20, .5) 26%, rgba(20, 20, 20, 0) 58%);
  transition: opacity 400ms ease;
}

/* Spotlight that follows the pointer (--x / --y are set by the script) */
.site__link::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(280px circle at var(--x, 50%) var(--y, 50%), rgba(255, 255, 255, .3), transparent 70%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 300ms ease;
}

.site__caption,
.site__arrow {
  z-index: 1;   /* stay above the spotlight */
}

.site__caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: clamp(12px, 1.4vw, 20px);
  transition: transform 400ms var(--ease);
}

.site__name {
  min-width: 0;
  font-size: clamp(13px, 1.05vw, 15px);
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: .01em;
  overflow-wrap: anywhere;
}

.site--lg .site__name {
  font-size: clamp(15px, 1.5vw, 21px);
}

/* Platform pill */
.site__tag {
  flex: none;
  padding: 6px 10px;
  border: 1px solid rgba(237, 232, 227, .55);
  border-radius: var(--radius-pill);
  font-size: 8px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: .22em;
  text-transform: uppercase;
}

/* Round arrow badge, top right */
.site__arrow {
  position: absolute;
  top: clamp(10px, 1.2vw, 16px);
  right: clamp(10px, 1.2vw, 16px);
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--color-paper);
  color: var(--color-ink);
  font-size: 16px;
  opacity: 0;
  transform: scale(.6) rotate(-45deg);
  transition: opacity 250ms ease, transform 450ms var(--ease);
}

/* ---- Hover and focus ---- */
@media (hover: hover) and (pointer: fine) {
  .site__link:hover { box-shadow: 0 28px 48px -26px rgba(30, 30, 30, .55); }
  .site__link:hover::after { opacity: 1; }
  .site__link:hover .site__arrow { opacity: 1; transform: none; }
}

@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  html:not(.motion-off):not(.is-keyboard) .site__link:hover { transform: translateY(-6px) scale(1.012); }
  html:not(.motion-off):not(.is-keyboard) .site__link:hover .site__shot { transform: scale(1.07); }
  html:not(.motion-off):not(.is-keyboard) .site__link:hover .site__caption { transform: translateY(-4px); }
}

.site__link:focus-visible .site__arrow {
  opacity: 1;
  transform: none;
}

/* ---- Footer bar: count on the left, "Show all" on the right ---- */
.portfolio__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  padding: 10px 10px 10px clamp(18px, 2vw, 28px);
  border-radius: var(--radius-box);
  background: var(--color-band);
  color: var(--color-on-band);
}

.portfolio__status {
  margin: 0;
  color: var(--color-on-dark);
}

.portfolio__more {
  border-color: var(--color-on-band);
  background: var(--color-on-band);
  color: var(--color-band);
  cursor: pointer;
}

.portfolio__more span {
  display: inline-block;
  transition: rotate 300ms var(--ease);
}

.portfolio__more[aria-expanded="true"] span {
  rotate: 180deg;
}

/* ---- Filter animation (View Transitions): tiles glide and resize ---- */
::view-transition-group(*) {
  animation-duration: 500ms;
  animation-timing-function: cubic-bezier(.23, 1, .32, 1);
}

/* ---- Smaller screens: two columns, same tile sizes ---- */
@media (max-width: 1000px) {
  .site-grid { --cols: 2; }
}

@media (max-width: 560px) {
  .site__tag { display: none; }
  .site--lg .site__tag { display: block; }
  .portfolio__filters {
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .portfolio__filters::-webkit-scrollbar { display: none; }
  .filter-btn { flex: none; padding: 0 14px; letter-spacing: .16em; white-space: nowrap; }
}

/* ==========================================================================
   "Custom code" filter: this portfolio on a laptop and a phone
   site-filter.js shows it in place of the grid. The device frames are drawn
   in CSS and stay dark in both themes. The card heading, tags and story list
   reuse .pub__* and .case__story from cases.css.
   ========================================================================== */

.showcase {
  display: flex;
  flex-direction: column;
  gap: clamp(24px, 3vw, 40px);
  padding: clamp(22px, 3vw, 40px);
  border: 1.5px solid var(--color-ink);
  border-radius: var(--radius-box);
}

.showcase__body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 20px;
}

/* ---- Devices ---- */
.showcase__devices {
  --frame: #161616;
  position: relative;
  padding: 2% 12% 7% 2%;      /* room for the phone to overlap the corner */
  border-radius: var(--radius-box);
  background: var(--color-mist);
  perspective: 1600px;
}

.device {
  margin: 0;
}

.device__screen {
  overflow: hidden;
  background: var(--color-paper);
}

.device__screen img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
}

.device--laptop {
  transition: transform 700ms var(--ease);
  transform-origin: 50% 100%;
}

.device--laptop .device__screen {
  aspect-ratio: 16 / 10;
  border: clamp(6px, .9vw, 12px) solid var(--frame);
  border-bottom-width: clamp(10px, 1.4vw, 18px);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, .45);
}

/* Keyboard deck: a little wider than the screen, with a thumb notch */
.device__base {
  position: relative;
  width: 112%;
  height: clamp(8px, 1.1vw, 14px);
  margin-left: -6%;
  border-radius: 0 0 14px 14px;
  background: linear-gradient(#cfc9c3, #9d948c);
  box-shadow: 0 14px 24px -14px rgba(0, 0, 0, .5);
}

.device__base::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 16%;
  height: 45%;
  border-radius: 0 0 8px 8px;
  background: #8a8179;
  transform: translateX(-50%);
}

.device--phone {
  position: absolute;
  right: 3%;
  bottom: 3%;
  width: 22%;
  transition: transform 700ms var(--ease);
}

.device--phone .device__screen {
  aspect-ratio: 390 / 844;
  border: clamp(4px, .5vw, 7px) solid var(--frame);
  border-radius: clamp(16px, 2.2vw, 28px);
  box-shadow: 0 30px 50px -20px rgba(0, 0, 0, .55);
}

/* The phone floats gently; hovering tilts the laptop and lifts the phone */
@media (prefers-reduced-motion: no-preference) {
  html:not(.motion-off) .device--phone {
    animation: phone-float 6s ease-in-out infinite;
  }
}

@keyframes phone-float {
  50% { translate: 0 -8px; }
}

@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  html:not(.motion-off) .showcase__devices:hover .device--laptop { transform: rotateX(6deg) scale(.98); }
  html:not(.motion-off) .showcase__devices:hover .device--phone { transform: translate(-6%, -6%) rotate(-3deg); }
}

@media (max-width: 560px) {
  .showcase__devices { padding: 4% 16% 10% 3%; }
  .device--phone { width: 28%; }
}

/* Filter panels (Custom code, Publications) fade up when a filter opens them */
.portfolio__panel:not([hidden]) {
  animation: panel-in 500ms var(--ease) both;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(12px); }
}

html.motion-off .portfolio__panel { animation: none; }

/* ==========================================================================
   "Publications" filter: publication card
   ========================================================================== */

.pub {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 18px;
  padding: clamp(22px, 3vw, 40px);
  border: 1.5px solid var(--color-ink);
  border-radius: var(--radius-box);
  transition: background-color 350ms ease, color 350ms ease;
}

.pub__top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 20px;
  width: 100%;
  padding-bottom: 16px;
  border-bottom: 1px solid rgb(var(--ink-rgb) / .2);
}

.pub__venue {
  font-family: var(--font-display);
  font-stretch: var(--stretch-display);
  font-weight: var(--weight-display);
  font-size: var(--text-num);
  letter-spacing: .12em;
  text-transform: uppercase;
}

.pub__title {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: 400;
  line-height: 1.25;
}

.pub__meta {
  margin: -6px 0 0;
  font-size: var(--text-sm);
  color: var(--color-muted);
}

.pub__text {
  max-width: 640px;
  margin: 0;
}

.pub__authors {
  margin: -6px 0 0;
  font-size: var(--text-sm);
  line-height: 1.6;
}

.pub__authors strong {
  font-weight: 500;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

/* System features: a simple list with short dashes */
.pub__features {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
  gap: 8px 24px;
  width: 100%;
  padding: 16px 0;
  border-block: 1px solid rgb(var(--ink-rgb) / .2);
  font-size: var(--text-sm);
}

.pub__features li {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pub__features li::before {
  content: '';
  flex: none;
  width: 14px;
  height: 1px;
  background: currentColor;
}

.pub__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pub__tags li {
  padding: 9px 14px;
  border: 1px solid var(--color-ink);
  border-radius: var(--radius-pill);
  font-size: 9px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: .22em;
  text-transform: uppercase;
}

.pub__link {
  margin-top: 6px;
}

