/* Homepage track grid (layout/_partial/track-grid.ejs): 8 tracks as /reel-style cards,
   4 across and full width. One click plays; the waveform seeks. Two looks, as on /reel:
   cyber (pink, grain) and hybrid (teal, aurora). */

.tg, .tg-chip {
  --ink: #E6E9EE;
  --ink-3: rgba(230, 233, 238, .40);
  --line: rgba(230, 233, 238, .12);
  --bg: #090D13;
  --bg-deep: #060910;
  --pink: #E8507F;
  --teal: #93D3C9;
  --mono: 'Courier New', Courier, ui-monospace, monospace;
  --sans: 'raleway-regular', 'Helvetica Neue', Arial, sans-serif;
}
.tg { position: relative; z-index: 5; width: 100%; color: var(--ink); font-family: var(--sans); text-align: left; }
.tg .fam-cyber, .tg-chip.fam-cyber { --fc: var(--pink); }
.tg .fam-hybrid, .tg-chip.fam-hybrid { --fc: var(--teal); }
.tg *, .tg *::before, .tg *::after, .tg-chip * { box-sizing: border-box; }
.tg button, .tg-chip button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; }
.tg :focus-visible, .tg-chip :focus-visible { outline: 1px dashed var(--fc, var(--pink)); outline-offset: -3px; }
.tg svg, .tg-chip svg { display: block; }
.tg .i-pause, .tg .is-playing .i-play, .tg-chip .i-pause, .tg-chip .is-playing .i-play { display: none; }
.tg .is-playing .i-pause, .tg-chip .is-playing .i-pause { display: block; }

/* play button (same shape as /reel) */
.tg-pbtn {
  width: 34px; height: 34px; flex: none; display: grid !important; place-items: center;
  border-radius: 50%; border: 1px solid color-mix(in srgb, var(--fc) 50%, transparent) !important;
  color: var(--fc) !important; transition: background .15s ease, color .15s ease;
}
.tg-pbtn svg { width: 12px; height: 12px; }
.tg-pbtn.is-playing { background: var(--fc) !important; color: #05070c !important; }
.fam-cyber .tg-pbtn, .fam-cyber.tg-chip .tg-pbtn { border-radius: 2px; }

/* the grid: flush, full width, 4 across (2 on tablets, 1 on phones), hairline gaps */
.tg-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); width: 100%;
  gap: 1px; background: var(--line); border-block: 1px solid var(--line);
}
@media (max-width: 1100px) { .tg-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* card */
.tg-card {
  -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none;
  position: relative; aspect-ratio: 1 / 1; overflow: hidden; isolation: isolate; cursor: pointer;
  display: flex; flex-direction: column; gap: 14px; padding: 18px 18px 16px;
  transition: background .2s ease;
}
.tg-card.fam-cyber { background: var(--bg-deep); }
.tg-card.fam-hybrid { background: var(--bg); }
.tg-card::after { /* playing card: family-colour frame */
  content: ''; position: absolute; inset: 0; z-index: 6; pointer-events: none;
  box-shadow: inset 0 0 0 0 var(--fc); transition: box-shadow .2s ease;
}
.tg-card.is-current::after { box-shadow: inset 0 0 0 2px var(--fc); }
.tg-card__bg { /* cover, blurred into the background */
  position: absolute; inset: -40px; z-index: -2; background-size: cover; background-position: center;
  filter: blur(30px) saturate(1.3); opacity: .28; transition: opacity .3s ease;
  /* stays on its own GPU layer: Safari otherwise promotes it only while the fade runs, then
     re-rasterises the blur at the end (a visible jump) and promotes it again on mouse-out (a replay) */
  will-change: opacity; -webkit-backface-visibility: hidden; backface-visibility: hidden;
}
.tg--preblur .tg-card__bg { filter: none; } /* already blurred by Cloudflare */
.tg-card.is-current .tg-card__bg { opacity: .42; }

.tg-card__top { display: flex; align-items: center; gap: 12px; }
.tg-thumb { width: 52px; height: 52px; flex: none; object-fit: cover; border-radius: 2px; box-shadow: 0 2px 10px rgba(0, 0, 0, .5); }
.tg-card__text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.tg-title { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tg .fam-cyber .tg-title { font-family: var(--mono); font-weight: bold; text-transform: uppercase; letter-spacing: .1em; font-size: 13px; }
.tg .fam-hybrid .tg-title { font-family: var(--sans); letter-spacing: .02em; font-size: 18px; }
.tg-card.is-current .tg-title { color: var(--fc); }
.tg-sub { font-family: var(--mono); font-size: 11px; color: var(--ink-3); letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

canvas.tg-wave { display: block; width: 100%; flex: 1 1 0; min-height: 0; cursor: pointer; }

/* one line: the old grid's git-log bar, tags as git-style decorations, then the time */
.tg-card__foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.tg-commit {
  display: flex; min-width: 0; padding: 4px 8px; border-radius: 3px; background: rgba(0, 0, 0, .88);
  font-family: var(--mono); font-size: 10px; line-height: 1.3; overflow: hidden;
}
/* when space runs out the tags shorten ("(boss battle, elec…)"); hash and year always show */
.tg-commit > span { flex: none; white-space: pre; }
.tg-commit > .tg-commit__t { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.tg-commit__h { color: #E8507F; }
.tg-commit__s { color: rgba(230, 233, 238, .25); }
.tg-commit__t { color: rgba(230, 233, 238, .6); }
.tg-commit__y { color: rgba(108, 182, 208, .65); }
.tg-time { flex: none; font-family: var(--mono); font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; }

.tg-link { /* ↗ to the project, on hover */
  position: absolute; z-index: 7; bottom: 52px; right: 14px; width: 30px; height: 30px;
  display: grid; place-items: center; border-radius: 2px;
  background: rgba(0, 0, 0, .7); color: var(--ink) !important; text-decoration: none; font-size: 15px;
  opacity: 0; transition: opacity .2s ease, background .15s ease, color .15s ease;
}
.tg-link:focus-visible { opacity: 1; }
/* hover looks only where there is a real pointer: on touch, Safari keeps :hover stuck after a tap */
@media (hover: hover) {
  .tg-pbtn:hover { background: var(--fc) !important; color: #05070c !important; }
  .tg-card:hover { background: #0c121b; }
  .tg-card:hover .tg-card__bg { opacity: .42; }
  .tg-link:hover { background: var(--fc); color: #05070c !important; }
  .tg-card:hover .tg-link { opacity: 1; }
}

/* cyber background: pink + mono grain (noise set in JS, as /reel); boils while playing.
   The boil moves the layer (transform), not the tiles (background-position), so it never repaints. */
.tg-grain { position: absolute; inset: -60px; z-index: -1; pointer-events: none; opacity: .16; animation: tg-boil .5s steps(1, end) infinite paused; }
.is-playing .tg-grain { animation-play-state: running; }
@keyframes tg-boil {
  0% { transform: translate(0, 0); } 20% { transform: translate(-37px, 21px); } 40% { transform: translate(18px, -44px); }
  60% { transform: translate(-52px, -9px); } 80% { transform: translate(29px, 38px); } 100% { transform: translate(0, 0); }
}
/* hybrid background: slow teal / blue light; drifts while playing, brighter when loud (JS sets --lvl) */
.tg-aurora { position: absolute; inset: -35%; z-index: -1; pointer-events: none; --lvl: 0; opacity: calc(.55 + var(--lvl) * .7); transition: opacity .4s ease; }
.tg-aurora::before, .tg-aurora::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  animation: tg-drift-a 26s ease-in-out infinite alternate paused;
}
.tg-aurora::before { background: radial-gradient(closest-side at 38% 70%, rgba(147, 211, 201, .30), transparent); }
.tg-aurora::after {
  background: radial-gradient(closest-side at 64% 40%, rgba(108, 182, 208, .22), transparent),
              radial-gradient(closest-side at 30% 30%, rgba(72, 84, 170, .18), transparent);
  animation-name: tg-drift-b; animation-duration: 34s;
}
.is-playing .tg-aurora::before, .is-playing .tg-aurora::after { animation-play-state: running; }
.is-playing .tg-aurora { transition: none; } /* JS eases --lvl every frame; a transition restarting each frame stutters in Safari */
@keyframes tg-drift-a { 0% { transform: translate(-8%, 4%) rotate(0deg) scale(1); } 100% { transform: translate(10%, -6%) rotate(25deg) scale(1.15); } }
@keyframes tg-drift-b { 0% { transform: translate(6%, -4%) rotate(0deg) scale(1.1); } 100% { transform: translate(-10%, 8%) rotate(-30deg) scale(.95); } }

/* now-playing chip, so the track can be paused after scrolling away */
.tg-chip {
  position: fixed; z-index: 190; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 12px; max-width: calc(100% - 32px);
  padding: 6px 16px 6px 6px; border-radius: 40px; color: var(--ink);
  background: rgba(0, 0, 0, .92); border: 1px solid color-mix(in srgb, var(--fc, #E6E9EE) 45%, transparent);
  font-family: var(--mono); font-size: 12px;
}
.tg-chip[hidden] { display: none; }
.tg-chip.fam-cyber { border-radius: 4px; padding-left: 5px; } /* square button, squared chip */
.tg-chip .tg-pbtn { width: 30px; height: 30px; }
.tg-chip__t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; color: var(--fc); }
.tg-chip__c { color: rgba(230, 233, 238, .4); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* phones: show the first 4; the rest open from the strip below */
.tg-more { display: none; }

/* phones: one per row, as a short strip */
@media (max-width: 499px) {
  .tg-grid { grid-template-columns: minmax(0, 1fr); }
  .tg-card { aspect-ratio: auto; height: 168px; padding: 14px 16px 12px; gap: 10px; }
  .tg-link { display: none; }
  .tg:not(.is-open) .tg-card:nth-child(n+5) { display: none; }
  .tg .tg-more { /* .tg prefix: outranks the .tg button reset */
    display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 48px;
    -webkit-tap-highlight-color: transparent;
    background: var(--bg-deep); border-bottom: 1px solid var(--line);
    font-family: var(--mono); font-size: 12px; letter-spacing: .06em; text-transform: none; color: var(--ink-3);
    transition: color .15s ease;
  }
  .tg .tg-more:active { color: var(--ink); }
  .tg.is-open .tg-more { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .tg *, .tg *::before, .tg *::after, .tg-chip { transition: none !important; animation: none !important; }
}
