/*
 * The time machine, as a standalone widget.
 *
 * The apex serves the current portfolio's own HTML, so there is no React tree
 * of ours on those pages. This is a plain-CSS port of the overlay in
 * src/_components/, injected by the proxy. Everything is prefixed tm- so it
 * cannot collide with whatever the portfolio itself styles.
 *
 * Never use 100vw here: it includes the scrollbar gutter and would overflow
 * the page sideways.
 */

#tm-root {
  --tm-size: 120px;
}

/* ---------- trigger ---------- */

/*
 * The emoji cannot live inside the button: the button is clipped to the morph
 * shape and would clip the glyph with it. So both sit in a box of the blob's
 * size and each fills it, which centres the emoji without depending on the
 * glyph's own metrics.
 */
.tm-trigger-wrap {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 2147483000;
  width: var(--tm-size);
  height: var(--tm-size);
}

.tm-trigger {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  clip-path: url(#tm-clip);
  transition: filter 0.3s;
}

.tm-trigger:hover {
  filter: brightness(1.5);
}

.tm-trigger-icon {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  line-height: 1;
  pointer-events: none;
  user-select: none;
  transition: transform 0.3s, filter 0.3s;
}

.tm-trigger:hover + .tm-trigger-icon {
  transform: rotate(12deg) scale(1.25);
  filter: brightness(1.1);
}

.tm-defs {
  position: absolute;
  width: 0;
  height: 0;
}

/* ---------- overlay ---------- */

.tm-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483002;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 40px 24px;
  overflow-y: auto;
}

#tm-root.tm-open .tm-overlay {
  display: flex;
}

.tm-close {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2147483003;
  padding: 8px 16px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: rgba(255, 255, 255, 0.85);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.tm-close:hover {
  color: #fff;
}

/* ---------- starfield (ported from globals.css) ---------- */

.tm-sky {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #1b2735 0%, #27272a 100%);
}

.tm-stars1,
.tm-stars2,
.tm-stars3 {
  position: absolute;
  top: 0;
  left: 0;
  width: 200%;
  height: 200%;
  background-repeat: repeat;
  background-size: contain;
  animation: tm-move-stars 50s linear infinite;
}

.tm-stars1 {
  background-image: url("/_tm/stardust.png");
  opacity: 0.25;
  animation-duration: 50s;
}

.tm-stars2 {
  background-image: url("/_tm/stardust.png");
  opacity: 0.5;
  background-position: 75% 50%;
  animation-duration: 100s;
  animation-delay: -10s;
}

.tm-stars3 {
  background-image: url("/_tm/stardust.png");
  background-position: 25% 0%;
  animation-duration: 300s;
  animation-delay: -20s;
}

@keyframes tm-move-stars {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-50%, -50%, 0); }
}

/* Content sits above the starfield. */
.tm-title,
.tm-grid {
  position: relative;
  z-index: 1;
}

/* ---------- title ---------- */

.tm-title {
  margin: 0 0 8px;
  padding-left: 10px;
  color: #fff;
  text-align: center;
  font-family: "Lato", system-ui, sans-serif;
  font-weight: 300;
  font-size: clamp(28px, 6vw, 50px);
  letter-spacing: 10px;
}

.tm-title span {
  background: linear-gradient(#fff, #38495a);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ---------- version grid ---------- */

.tm-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  width: 100%;
  max-width: 1100px;
}

@media (min-width: 700px) {
  .tm-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.tm-entry {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 8px;
  text-decoration: none;
  border-radius: 12px;
}

.tm-entry:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 2px;
}

.tm-name {
  font-family: "Lato", system-ui, sans-serif;
  font-size: clamp(18px, 3vw, 30px);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.3);
  transition: color 0.3s;
}

.tm-date {
  font-size: 15px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.1);
  transition: color 0.3s;
}

.tm-entry:hover .tm-name,
.tm-entry:focus-visible .tm-name { color: rgba(255, 255, 255, 0.8); }
.tm-entry:hover .tm-date,
.tm-entry:focus-visible .tm-date { color: rgba(255, 255, 255, 0.5); }

.tm-current .tm-name { color: rgba(255, 255, 255, 0.55); }

/* ---------- wormhole (ported from globals.css) ---------- */

.tm-wormhole {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 140px;
  height: 140px;
  max-width: 100%;
  background: radial-gradient(circle, black, #1a1a2e, #16213e, transparent, transparent);
}

.tm-wormhole i {
  position: absolute;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  box-shadow: inset 0 0 20px 5px rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.25);
  background-image: url("/_tm/stardust.png");
  animation: tm-spin 3s linear infinite;
}

.tm-wormhole i:nth-child(2) {
  opacity: 0.5;
  background-position: 75% 50%;
  animation: tm-spin 3s linear infinite, tm-resize 2s ease-in-out infinite -0.4s;
}

.tm-wormhole i:nth-child(3) {
  opacity: 0.75;
  background-position: 25% 0%;
  animation: tm-spin 3s linear infinite, tm-resize 2s ease-in-out infinite -1.1s;
}

.tm-wormhole i:nth-child(4) {
  opacity: 0.25;
  background-position: 50% 33%;
  animation: tm-spin 3s linear infinite, tm-resize 2s ease-in-out infinite -1.7s;
}

@keyframes tm-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes tm-resize {
  0% { width: 140px; height: 140px; opacity: 1; }
  99% { width: 0; height: 0; opacity: 1; }
  99.5% { width: 0; height: 0; opacity: 0; }
  100% { width: 140px; height: 140px; opacity: 0; }
}

/* ---------- always-present link out ---------- */

.tm-link {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 2147483000;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  color: rgba(255, 255, 255, 0.85);
  font-family: system-ui, sans-serif;
  font-size: 12px;
  text-decoration: none;
  backdrop-filter: blur(4px);
}

.tm-link:hover {
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
}

@media (prefers-reduced-motion: reduce) {
  .tm-stars1, .tm-stars2, .tm-stars3, .tm-wormhole i { animation: none; }
}
