/* ==========================================================================
   Tilefolio
   A Windows Phone (Metro) style start screen: flat square tiles, light type,
   and full-screen pages instead of popups. No shadows, gradients or rounding.

   Tile colors (and each page's accent) come from content.js. The tile size
   and column count are computed in js/tilefolio.js so the grid fills the
   screen; the values below are the shared dark theme.
   ========================================================================== */

:root {
  --bg: #000;
  --text: #fff;
  --text-soft: #d4d4d4;
  --text-muted: #9a9a9a;
  --hover: rgb(255 255 255 / 0.08);
  --link: #33bbf5;
  --gap: 6px;
  --tile-radius: 3px;
  --margin: 1rem;
  /* The decelerate curve Windows uses for most of its motion. */
  --ease-out: cubic-bezier(0.1, 0.9, 0.2, 1);
  --font: "Segoe UI", "Open Sans", system-ui, -apple-system, Roboto, sans-serif;
}

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

html,
body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img,
iframe {
  display: block;
  max-width: 100%;
}

a {
  color: var(--link);
}

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

/* Round outlined icon button, the Windows Phone app bar style. */
.social-link,
.page-back {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  border: 2px solid var(--text);
  border-radius: 50%;
  background: none;
  color: var(--text);
  font-size: 1.05rem;
  text-decoration: none;
  cursor: pointer;
  transition:
    background 150ms ease,
    color 150ms ease;
}

.social-link:hover,
.page-back:hover,
.social-link:active,
.page-back:active {
  background: var(--text);
  color: var(--bg);
}

/* START SCREEN
   One grid holds the profile block and every tile. One cell is a "small"
   tile: medium = 2x2, wide = 4x2, large = 4x4, and the profile is 6x2.
   On desktop and tablets JS picks the column count (6-12) that gives the
   biggest tiles for the screen; phones use the --cols value below.
   --tile-unit, --grid-width and (when fitting) --cols are set by JS.
   ========================================================================== */

.home {
  --fit: 1; /* read by JS: size the grid to fill the screen */
  flex: 1;
  min-height: 0;
  display: flex;
  overflow-x: hidden;
  overflow-y: auto;
  padding: var(--margin);
  scrollbar-color: #444 transparent;
  scrollbar-width: thin;
}

.start {
  --cols: 6;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--tile-unit, minmax(0, 1fr)));
  grid-auto-rows: var(--tile-unit, 6rem);
  grid-auto-flow: row dense;
  gap: var(--gap);
  width: var(--grid-width, 100%);
  /* Centers the grid in any leftover space, but never pushes it off screen. */
  margin: auto;
}

/* The tiles are laid out directly in .start's grid. */
.tiles {
  display: contents;
}

/* Profile: a photo the size of a medium tile, with the name beside it. */
.profile {
  grid-column: span 6;
  grid-row: span 2;
  display: flex;
  min-width: 0;
}

.profile-avatar {
  flex: none;
  width: calc(2 * var(--tile-unit, 6rem) + var(--gap));
  height: 100%;
  border-radius: var(--tile-radius);
  object-fit: cover;
}

.profile-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding-left: clamp(0.75rem, calc(var(--tile-unit, 6rem) * 0.15), 1.5rem);
  overflow: hidden;
}

/* Without a photo, the text starts at the grid edge. */
.profile-text:first-child {
  padding-left: 0;
}

.profile-name {
  margin: -0.12em 0 0 -0.04em; /* align the light type's cap height and stem */
  font-size: clamp(1.75rem, calc(var(--tile-unit, 6rem) * 0.42), 4rem);
  font-weight: 300;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.profile-tagline {
  margin-top: 0.3rem;
  color: var(--text-muted);
  font-size: clamp(0.9rem, calc(var(--tile-unit, 6rem) * 0.14), 1.25rem);
  line-height: 1.3;
}

.socials {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.85rem;
}

.profile-footer {
  margin-top: auto;
  padding-top: 0.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.tile {
  --span-cols: 2;
  --span-rows: 2;
  grid-column: span var(--span-cols);
  grid-row: span var(--span-rows);
  position: relative;
  overflow: hidden;
  border-radius: var(--tile-radius);
  background-color: var(--tile-color, #0078d7);
  /* Soft top-to-bottom shading, light enough to keep the color flat. */
  background-image: linear-gradient(rgb(255 255 255 / 0.1), rgb(0 0 0 / 0.14));
  color: #fff;
  text-decoration: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 200ms var(--ease-out);
}

.tile--small {
  --span-cols: 1;
  --span-rows: 1;
}

.tile--wide {
  --span-cols: 4;
}

.tile--large {
  --span-cols: 4;
  --span-rows: 4;
}

/* Live tile: the front (icon) and back (subtitle) faces are stacked
   vertically and slide up, like a Windows Phone "peek" tile. */
.tile-faces {
  position: absolute;
  inset: 0;
  transition: transform 700ms var(--ease-out);
}

.tile-face {
  position: absolute;
  left: 0;
  right: 0;
  height: 100%;
  display: flex;
}

.tile-face--front {
  top: 0;
  align-items: center;
  justify-content: center;
}

.tile-face--back {
  top: 100%;
  align-items: flex-start;
  padding: 0.7rem 0.85rem 2.5rem;
}

.tile.is-flipped .tile-faces {
  transform: translateY(-100%);
}

.tile-icon {
  font-size: calc(var(--tile-unit, 6rem) * 0.55);
  line-height: 1;
}

.tile--small .tile-icon {
  font-size: calc(var(--tile-unit, 6rem) * 0.4);
}

.tile--large .tile-icon {
  font-size: calc(var(--tile-unit, 6rem) * 1.05);
}

.tile-subtitle {
  font-size: clamp(1rem, calc(var(--tile-unit, 6rem) * 0.19), 1.6rem);
  font-weight: 300;
  line-height: 1.25;
}

.tile-label {
  position: absolute;
  z-index: 1;
  right: 0.75rem;
  bottom: 0.55rem;
  left: 0.75rem;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: clamp(0.82rem, calc(var(--tile-unit, 6rem) * 0.13), 1rem);
  line-height: 1.2;
}

.tile-title {
  overflow: hidden;
  font-size: inherit;
  font-weight: 400;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tile-external {
  opacity: 0.8;
}

/* Small tiles are icon-only; the label stays available to screen readers. */
.tile--small .tile-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.noscript {
  padding: 2rem 0;
  color: var(--text-muted);
}

/* PAGE (the overlay)
   Opens full screen, like an app launched from a tile.
   ========================================================================== */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
}

.overlay[hidden] {
  display: none;
}

.overlay-panel {
  --accent: var(--link);
  /* Accent lightened for use as text on black. */
  --accent-text: color-mix(in srgb, var(--accent) 65%, #fff);

  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--margin) 2.5rem;
  scrollbar-color: #444 transparent;
  scrollbar-width: thin;
}

.overlay-panel:focus {
  outline: none;
}

/* Pages line up with the edges of the tile grid (at least 48rem wide). */
.page-bar,
.overlay-content {
  width: min(100%, max(var(--grid-width, 0px), 48rem));
  margin: 0 auto;
}

.page-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: var(--margin) 0 0.5rem;
  background: var(--bg);
}

.page-app-title {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.overlay-title {
  margin: 0 0 1.25rem -0.05em;
  font-size: clamp(2.5rem, 1.5rem + 3vw, 4.5rem);
  font-weight: 300;
  line-height: 1.05;
  letter-spacing: -0.02em;
  text-transform: lowercase;
  overflow-wrap: break-word;
}

.block + .block {
  margin-top: 2.25rem;
}

/* Block: text
   ========================================================================== */

.block-text.has-image {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 2rem;
  align-items: start;
}

.block-text-body p {
  max-width: 38em;
  color: var(--text-soft);
  font-size: 1.05rem;
  line-height: 1.7;
}

.block-text-body p:first-child {
  color: var(--text);
  font-size: 1.4rem;
  font-weight: 300;
  line-height: 1.45;
}

.block-text-body p + p {
  margin-top: 1.1rem;
}

.block-text-figure img {
  width: 100%;
}

.block-text-figure figcaption {
  margin-top: 0.75rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  white-space: pre-line;
}

/* Block: cards (rendered as a Windows Phone style list)
   ========================================================================== */

.block-cards {
  --col-gap: 2rem;
  display: grid;
  gap: 0.5rem var(--col-gap);
  /* Up to --columns per row, wrapping to fewer on narrow screens. */
  grid-template-columns: repeat(
    auto-fill,
    minmax(max(16rem, calc((100% - (var(--columns) - 1) * var(--col-gap)) / var(--columns))), 1fr)
  );
  /* Items have padding for their hover area; pull them back into line. */
  margin-inline: -0.75rem;
}

.card {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 0.75rem;
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background 150ms ease,
    transform 200ms var(--ease-out);
}

.card-icon {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 3.5rem;
  height: 3.5rem;
  background: var(--accent);
  color: #fff;
  font-size: 1.35rem;
}

.card-body {
  min-width: 0;
}

.card-title {
  font-size: 1.35rem;
  font-weight: 400;
  line-height: 1.25;
}

.card-text,
.card-link {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.95rem;
}

.card-text {
  color: var(--text-muted);
  white-space: pre-line;
}

.card-link {
  color: var(--accent-text);
  overflow-wrap: anywhere;
}

/* Block: badges
   ========================================================================== */

.block-badges {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 2.5rem 3rem;
}

.badge-group-title {
  margin-bottom: 1rem;
  font-size: 1.75rem;
  font-weight: 300;
  line-height: 1.2;
  text-transform: lowercase;
}

.badge-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.badge {
  padding: 0.35rem 0.8rem;
  background: var(--accent);
  font-size: 0.95rem;
}

/* Block: projects
   ========================================================================== */

.project {
  color: inherit;
  text-decoration: none;
}

.project-media {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border: 0;
  background: #1a1a1a;
}

.project-title {
  font-size: 1.75rem;
  font-weight: 300;
  line-height: 1.2;
}

.project-description {
  max-width: 40em;
  margin-top: 0.5rem;
  color: var(--text-soft);
}

.project-tech {
  margin-top: 0.75rem;
  color: var(--accent-text);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.project-link {
  display: inline-block;
  margin-top: 1rem;
  color: var(--accent-text);
  font-weight: 600;
  text-decoration: none;
}

a.project-link:hover {
  text-decoration: underline;
}

.block-projects--rows {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.block-projects--rows .project.has-media {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  gap: 1.75rem;
  align-items: center;
}

.block-projects--grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 0.5rem 1rem;
  margin-inline: -0.75rem;
}

.block-projects--grid .project {
  display: block;
  padding: 0.75rem;
  -webkit-tap-highlight-color: transparent;
  transition:
    background 150ms ease,
    transform 200ms var(--ease-out);
}

.block-projects--grid .project-body {
  margin-top: 0.75rem;
}

.block-projects--grid .project-title {
  font-size: 1.2rem;
  font-weight: 400;
}

.block-projects--grid .project-description {
  font-size: 0.95rem;
}

.block-projects--grid .project-link {
  margin-top: 0.15rem;
  font-size: 0.9rem;
  font-weight: 400;
}

/* HOVER (mouse / trackpad only, so it doesn't stick on touch screens)
   ========================================================================== */

@media (hover: hover) {
  .tile:hover {
    outline: 2px solid rgb(255 255 255 / 0.45);
    outline-offset: -2px;
  }

  /* Peek at the back of a tile; the delay keeps quick sweeps calm. */
  .tile.has-back:hover .tile-faces {
    transform: translateY(-100%);
    transition-delay: 120ms;
  }

  a.card:hover,
  a.project:hover {
    background: var(--hover);
  }
}

.tile:focus-visible {
  z-index: 1;
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.tile.has-back:focus-visible .tile-faces {
  transform: translateY(-100%);
}

/* MOTION
   Tiles swing in on load (turnstile), pages swing open, and page content
   slides in a beat later. All of it is skipped with reduced motion.
   ========================================================================== */

@media (prefers-reduced-motion: no-preference) {
  .tile,
  .profile {
    animation: tile-in 650ms var(--ease-out) backwards;
    animation-delay: calc(var(--i, 0) * 40ms + 60ms);
  }

  .overlay:not([hidden]) .overlay-panel {
    transform-origin: 0 50%;
    animation: page-in 450ms var(--ease-out) both;
  }

  .overlay-content > * {
    animation: content-in 600ms var(--ease-out) backwards;
    animation-delay: calc(var(--i, 0) * 60ms + 100ms);
  }
}

@keyframes tile-in {
  from {
    opacity: 0;
    transform: perspective(900px) rotateY(80deg);
    transform-origin: 0 50%;
  }
  to {
    transform-origin: 0 50%;
  }
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: perspective(1600px) rotateY(30deg);
  }
}

@keyframes content-in {
  from {
    opacity: 0;
    transform: translateX(3rem);
  }
}

/* TABLET
   ========================================================================== */

@media (max-width: 1023px) {
  .block-text.has-image,
  .block-projects--rows .project.has-media {
    grid-template-columns: minmax(0, 1fr);
  }

  .block-projects--rows .project.has-media {
    gap: 1rem;
  }
}

/* SCROLLING LAYOUT
   On phones and short screens the page scrolls instead of fitting the grid
   to the viewport, like the Windows Phone start screen.
   ========================================================================== */

@media (max-width: 599px), (max-height: 599px) {
  body {
    height: auto;
    min-height: 100%;
    overflow: visible;
  }

  body.overlay-open {
    overflow: hidden;
  }

  .home {
    --fit: 0;
    display: block;
    flex: none;
    overflow: visible;
  }
}

/* Short but wide (phones in landscape): more, smaller tiles per row. */
@media (min-width: 600px) and (max-height: 599px) {
  .start {
    --cols: 10;
  }
}

/* PHONE
   ========================================================================== */

@media (max-width: 599px) {
  :root {
    --margin: 0.625rem;
    --gap: 5px;
  }

  .social-link,
  .page-back {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 0.95rem;
  }

  .tile-label {
    right: 0.6rem;
    bottom: 0.45rem;
    left: 0.6rem;
  }

  .tile-face--back {
    padding: 0.6rem 0.7rem 2.25rem;
  }

  .overlay-panel {
    padding-inline: 1rem;
  }

  .overlay-title {
    margin-bottom: 1rem;
  }

  .block + .block {
    margin-top: 2rem;
  }

  .block-text-body p:first-child {
    font-size: 1.25rem;
  }

  .block-text-body p {
    font-size: 1rem;
  }

  .card-icon {
    width: 3rem;
    height: 3rem;
    font-size: 1.15rem;
  }

  .card-title {
    font-size: 1.2rem;
  }

  .project-title {
    font-size: 1.5rem;
  }

  .block-projects--grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.25rem 0.5rem;
  }

  .block-projects--grid .project-title {
    font-size: 1.05rem;
  }
}

/* REDUCED MOTION
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
