/* Game detail is a deep-linkable overlay (#/game/:id) layered over the
   library. The panel is laid out so the essentials — capture, title, tagline,
   tags, builders, and the action bar — stay in view without scrolling on every
   viewport; only the description scrolls when a very small screen runs short. */

.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  align-items: safe center;
  justify-content: center;
  padding: clamp(16px, 4vh, 48px);
}

.detail-scrim {
  position: absolute;
  inset: 0;
  background: rgba(4, 5, 10, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 180ms ease;
}

.detail-overlay.is-open .detail-scrim {
  opacity: 1;
}

.detail-panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(760px, 100%);
  max-height: min(90vh, 760px);
  max-height: min(90dvh, 760px);
  overflow: hidden;
  border: 1px solid var(--border-hover);
  border-radius: 14px;
  background: linear-gradient(180deg, #14151f, #0c0d16);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  opacity: 0;
  transform: translateY(14px) scale(0.985);
  transition: opacity 200ms ease, transform 200ms ease;
}

.detail-overlay.is-open .detail-panel {
  opacity: 1;
  transform: none;
}

.detail-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  color: var(--text);
  cursor: pointer;
}

.detail-close span {
  grid-area: 1 / 1;
  width: 15px;
  height: 2px;
  border-radius: 4px;
  background: currentColor;
}

.detail-close span:first-child {
  transform: rotate(45deg);
}

.detail-close span:last-child {
  transform: rotate(-45deg);
}

.detail-media {
  position: relative;
  flex: 0 0 auto;
}

.detail-media .thumb.big {
  height: clamp(170px, 30vh, 300px);
  aspect-ratio: auto;
  border-radius: 0;
}

.detail-body {
  display: flex;
  min-height: 0;
  flex: 1 1 auto;
  flex-direction: column;
}

/* Essentials (eyebrow/title/tagline/tags/builders) sit above the description and
   never shrink, so they stay fully visible without scrolling. The description is
   the only flexible region (flex: 1 1 auto — it claims its content height, then
   shrinks/scrolls under the panel's max-height), and the action bar is pinned. */
.detail-header {
  flex: 0 0 auto;
  padding: clamp(18px, 2.4vw, 26px) clamp(20px, 3vw, 32px) 0;
}

.detail-scroll {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px clamp(20px, 3vw, 32px) 4px;
}

.detail-scroll:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Fade the bottom edge only while the description overflows and is not scrolled
   to the end, so clipped text reads as scrollable rather than truncated. */
.detail-scroll.show-fade {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 24px), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 24px), transparent);
}

/* Drop the mask while focused so the keyboard focus ring isn't clipped. */
.detail-scroll.show-fade:focus-visible {
  -webkit-mask-image: none;
  mask-image: none;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.eyebrow.is-wip {
  color: var(--warn);
}

.eyebrow.is-live {
  color: var(--accent-2);
}

.detail-title {
  margin: 8px 0 0;
  font-size: clamp(26px, 3.6vw, 38px);
  font-weight: 700;
  line-height: 1.05;
}

.detail-tagline {
  margin: 10px 0 0;
  color: var(--text-dim);
  font-size: clamp(15px, 1.7vw, 18px);
  line-height: 1.3;
}

.detail-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 11px;
  border: 1px solid var(--border-hover);
  border-radius: 999px;
  color: var(--text-mute);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.detail-credits {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.credit-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elev);
}

@media (hover: hover) {
  .credit-pill:hover {
    border-color: var(--accent);
  }
}

.credit-name {
  font-size: 13px;
}

.credit-role {
  color: var(--text-mute);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.credit-ext {
  color: var(--text-faint);
  font-size: 11px;
}

.detail-desc {
  margin: 0;
  color: var(--text-dim);
  font-size: 14.5px;
  line-height: 1.6;
}

.detail-actions {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  flex: 0 0 auto;
  padding: 14px clamp(20px, 3vw, 32px);
  border-top: 1px solid var(--border);
  background: rgba(8, 9, 16, 0.6);
}

/* WIP games have only two actions (Follow on GitHub + Copy link). */
.detail-actions.is-duo {
  grid-template-columns: 1fr auto;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border: 1px solid var(--play);
  border-radius: 6px;
  background: var(--play);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  box-shadow: 0 12px 28px color-mix(in srgb, var(--play) 28%, transparent);
  color: #0a0b14;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 0 18px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

@media (hover: hover) {
  .button:hover:not(:disabled) {
    transform: translateY(-1px);
  }
}

/* The dialogs receive focus on open; give them a visible ring like other
   focusable targets (the global focus-visible only covers form controls). */
.detail-panel:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.button-secondary,
.button.is-disabled {
  border-color: var(--border-hover);
  background: transparent;
  box-shadow: none;
  color: var(--text);
}

.button-secondary.is-copied {
  border-color: var(--accent-2);
  color: var(--accent-2);
}

/* Stable width so a label change ("Copy link" -> "Copied"/"Copy failed") can't
   reflow the auto-sized action columns. */
.detail-actions [data-action="copy-link"] {
  min-width: 11ch;
}

.button:disabled,
.button.is-disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

@media (max-width: 840px) {
  .detail-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .detail-panel {
    width: 100%;
    max-width: none;
    max-height: 90vh;
    max-height: 94dvh;
    border-width: 1px 0 0;
    border-radius: 18px 18px 0 0;
    transform: translateY(100%);
  }

  .detail-overlay.is-open .detail-panel {
    transform: translateY(0);
  }

  .detail-media .thumb.big {
    height: clamp(140px, 24vh, 220px);
  }

  .detail-actions {
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 520px) {
  /* Reclaim vertical overhead so the credits row and the description keep a
     usable, scrollable area above the fold on the smallest phones. */
  .detail-media .thumb.big {
    height: clamp(96px, 18vh, 140px);
  }

  .detail-scroll {
    padding-top: 10px;
  }

  .detail-header {
    padding-top: 14px;
  }

  .detail-tags {
    margin-top: 12px;
  }

  .detail-credits {
    margin-top: 10px;
  }

  .detail-actions {
    grid-template-columns: 1fr 1fr;
  }

  .detail-actions > :first-child {
    grid-column: 1 / -1;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .detail-overlay {
    align-items: center;
    align-items: safe center;
    padding: 12px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .detail-panel {
    width: min(820px, 100%);
    /* Subtract the overlay's own padding + safe-area so the panel cannot exceed
       the visible viewport and force the overlay itself to scroll. */
    max-height: calc(94vh - 24px);
    max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    flex-direction: row;
    border-width: 1px;
    border-radius: 14px;
    transform: translateY(8px) scale(0.985);
  }

  .detail-overlay.is-open .detail-panel {
    transform: none;
  }

  .detail-media {
    flex: 0 0 40%;
    align-self: stretch;
  }

  .detail-media .thumb.big {
    height: 100%;
    min-height: 160px;
  }

  /* The action bar lives at the bottom of the body; on the very shortest
     landscape heights (or a many-builder game) the body scrolls so Play stays
     reachable. On the required landscape sizes (844x390, 932x430) everything
     fits without scrolling. */
  .detail-body {
    flex: 1 1 auto;
    min-width: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  /* Reserve clearance for the floating close button. */
  .detail-header {
    padding-right: 60px;
  }

  .detail-title {
    overflow-wrap: anywhere;
  }

  /* Keep the compact one-row action bar in landscape even when width <= 520,
     where the portrait two-row rule would otherwise win on source order. */
  .detail-actions {
    grid-template-columns: 1fr auto auto;
    padding-top: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .detail-actions > :first-child {
    grid-column: auto;
  }
}

/* Very short landscape (e.g. 568x320): narrow the media column and tighten
   spacing so the builders row stays above the fold beside the description. */
@media (orientation: landscape) and (max-height: 360px) {
  .detail-media {
    flex: 0 0 36%;
  }

  .detail-media .thumb.big {
    min-height: 120px;
  }

  .detail-header {
    padding-top: 14px;
  }

  .detail-title {
    font-size: 22px;
  }

  .detail-tagline {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 6px;
  }

  .detail-tags,
  .detail-credits {
    margin-top: 8px;
  }
}
