body {
  display: flex;
  flex-direction: column;
}

header.home-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 1rem;
  padding: 1.4rem clamp(1.5rem, 4vw, 4rem) 0.6rem;
}

/* Sign in / sign out sits opposite the wordmark — the only way into edit mode. */
.auth-btn {
  margin-left: auto;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(36, 49, 78, 0.55);
  color: var(--text-muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: color 0.2s ease, border-color 0.2s ease;
}

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

header.home-header img {
  height: clamp(1.8rem, 3.2vh, 2.6rem);
}

main.home-layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: clamp(1.5rem, 4vw, 3.5rem);
  padding: 1rem clamp(1.5rem, 4vw, 4rem);
  position: relative;
}

.connector-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.connector-path {
  fill: none;
  stroke: url(#connGrad);
  stroke-width: 1.6;
  opacity: 0.9;
  filter: drop-shadow(0 0 5px rgba(34, 211, 238, 0.4));
}

.connector-path.flow {
  stroke-dasharray: 4 8;
  animation: connFlow 1s linear infinite;
}

@keyframes connFlow {
  to {
    stroke-dashoffset: -12;
  }
}

.connector-pulse {
  fill: var(--accent);
  filter: drop-shadow(0 0 6px rgba(34, 211, 238, 0.9));
}

@media (prefers-reduced-motion: reduce) {
  .connector-path.flow {
    animation: none;
  }
  .connector-pulse {
    display: none;
  }
}

.card {
  position: relative;
  z-index: 1;
  border-radius: 1.1rem;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: linear-gradient(160deg, rgba(36, 49, 78, 0.55), rgba(12, 20, 36, 0.55));
  backdrop-filter: blur(4px);
  padding: clamp(1rem, 2.4vh, 1.9rem) clamp(1.1rem, 2.2vw, 1.8rem);
  display: flex;
  flex-direction: column;
  min-height: 0;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
  transform: translateY(-4px) scale(1.008);
  border-color: var(--accent);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(34, 211, 238, 0.15);
}

.card:active {
  transform: translateY(-1px) scale(0.995);
}

.card-left {
  grid-column: 1;
  grid-row: 1 / span 3;
  justify-content: center;
  align-self: center;
  height: fit-content;
  max-height: 100%;
}

.card-left .card-headline {
  font-size: clamp(1.1rem, 2.4vh, 1.6rem);
}

/* Right column centers its three cards vertically so they line up with the
   (content-sized, centered) Overview card instead of hugging the top. */
.cards-right {
  grid-column: 2;
  grid-row: 1 / span 3;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(0.8rem, 2vh, 1.4rem);
  min-height: 0;
}

.card-right {
  flex: 0 1 auto;
  min-height: clamp(7.5rem, 22vh, 12rem);
}

.card-thumb {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center;
  opacity: 0.5;
  filter: saturate(1.1);
  transition: opacity 0.3s ease, transform 0.4s ease;
  transform: scale(1.02);
}

.card:hover .card-thumb {
  opacity: 0.65;
  transform: scale(1.06);
}

.card-scrim {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: linear-gradient(to top, rgba(10, 14, 26, 0.95) 12%, rgba(10, 14, 26, 0.72) 55%, rgba(10, 14, 26, 0.32) 100%);
}

.card-eyebrow {
  position: relative;
  z-index: 1;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-transform: uppercase;
  margin: 0 0 0.5rem;
}

.card-headline {
  position: relative;
  z-index: 1;
  font-size: clamp(1.05rem, 2.6vh, 1.5rem);
  font-weight: 600;
  margin: 0 0 0.6rem;
  line-height: 1.2;
}

.card-tagline {
  position: relative;
  z-index: 1;
  margin: 0;
  color: var(--text-muted);
  font-size: clamp(0.8rem, 1.9vh, 1rem);
  line-height: 1.4;
}

.card-icon-actions {
  position: absolute;
  top: clamp(0.7rem, 1.6vh, 1.1rem);
  right: clamp(0.7rem, 1.6vw, 1.1rem);
  z-index: 2;
  display: flex;
  gap: 0.4rem;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.card:hover .card-icon-actions,
.card:focus-within .card-icon-actions {
  opacity: 1;
  transform: translateY(0);
}

.card-icon-actions button {
  position: relative;
  width: 2.6rem;
  height: 2.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.6rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(10, 14, 26, 0.75);
  color: var(--text-muted);
  backdrop-filter: blur(4px);
  overflow: hidden;
  transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}

.card-icon-actions button svg {
  width: 1.25rem;
  height: 1.25rem;
}

.card-icon-actions button:hover {
  background: var(--accent);
  color: #06222b;
  border-color: var(--accent);
  transform: scale(1.12);
  box-shadow: 0 4px 16px rgba(34, 211, 238, 0.45);
}

footer.home-footer {
  z-index: 1;
  flex: 0 0 auto;
  text-align: center;
  padding: 0.6rem 0 1rem;
  font-size: 0.72rem;
  color: var(--text-dim);
  letter-spacing: 0.03em;
}

/* With a fourth deck the right column runs out of height, so the per-card
   floor drops rather than letting the stack overflow the viewport. */
.cards-right:has(> .card-right:nth-child(4)) .card-right {
  min-height: clamp(5rem, 15vh, 8.5rem);
}

/* Card actions only appear on hover, which never happens on a touch screen. */
@media (hover: none) {
  .card-icon-actions {
    opacity: 1;
    transform: none;
  }

  /* Permanently on screen now, so the text stops short of them — one button for
     a visitor (PDF), two for an admin (PDF + edit). */
  .card-eyebrow,
  .card-headline {
    padding-right: 3.4rem;
  }

  .card:has(.card-icon-actions button + button) .card-eyebrow,
  .card:has(.card-icon-actions button + button) .card-headline {
    padding-right: 6.2rem;
  }

  .card:hover {
    transform: none;
    box-shadow: none;
  }

  .card:hover .card-thumb {
    opacity: 0.5;
    transform: scale(1.02);
  }

  .card {
    backdrop-filter: none;
  }
}

/* ---- Phones and narrow/short windows: one column, and the page scrolls.
   The height clause is for a landscape phone: ~930px wide but only ~430 tall,
   where the two-column grid's vh-based sizing collapses. ---- */
@media (max-width: 820px), (max-height: 520px) {
  html,
  body {
    overflow-y: auto;
    height: auto;
  }

  body {
    min-height: 100dvh;
  }

  header.home-header {
    padding: 1rem 1rem 0.4rem;
  }

  main.home-layout {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    padding: 0.6rem 1rem 1.5rem;
  }

  /* Meaningless once the columns stack — there is no left-to-right to trace. */
  .connector-layer {
    display: none;
  }

  /* vh-based sizing collapses in landscape (2.4vh of 390px is 9px) — the phone
     layout uses fixed sizes instead. */
  .card {
    padding: 1rem 1.1rem;
    /* Blurring a full-bleed thumbnail is the most expensive paint on this page. */
    backdrop-filter: none;
  }

  .card-left,
  .cards-right {
    grid-column: auto;
    grid-row: auto;
    align-self: stretch;
    height: auto;
    max-height: none;
  }

  .card-right,
  .cards-right:has(> .card-right:nth-child(4)) .card-right {
    min-height: 8.5rem;
  }

  .card-left .card-headline,
  .card-headline {
    font-size: 1.2rem;
  }

  .card-tagline {
    font-size: 0.9rem;
  }

  .card-icon-actions {
    top: 0.7rem;
    right: 0.7rem;
  }
}
