:root {
  --fondo: #f2f2f2;
  --carta: #ffffff;
  --inchiostro: #111113;
  --grigio: #8a8a90;
  --riga: #ececee;
  --linea: rgba(17, 17, 19, 0.08);
  --accento: #4f46e5;
  --video: #16161c;
}

* { box-sizing: border-box; margin: 0; }

html, body { height: 100%; }

body {
  background: var(--fondo);
  color: var(--inchiostro);
  font-family: "Mona Sans Variable", "Mona Sans", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.stage {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: hidden;
}

/* the app window: measured on the width and the height, so it fits the phone box too */
.app {
  position: relative;
  width: min(900px, calc(100vw - 32px), calc((100vh - 32px) * 1.6));
  height: min(560px, calc(100vh - 32px), calc((100vw - 32px) / 1.2));
  background: var(--carta);
  border: 1px solid var(--linea);
  border-radius: 18px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 30px 60px -28px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.app__bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 clamp(10px, 2.2vw, 16px);
  height: clamp(34px, 7.5vh, 44px);
  border-bottom: 1px solid var(--linea);
  font-size: clamp(10.5px, 1.6vh, 12.5px);
  flex: none;
}
.app__brand { display: flex; align-items: center; gap: 6px; font-weight: 640; }
.app__brand svg { width: 15px; height: 15px; fill: none; stroke: var(--inchiostro); stroke-width: 1.7; stroke-linejoin: round; }
.app__crumb { color: var(--grigio); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.app__crumb b { color: var(--inchiostro); font-weight: 560; }
.app__sep { margin: 0 4px; opacity: 0.6; }
.app__share { padding: 5px 11px; border-radius: 999px; background: var(--inchiostro); color: #fff; font-weight: 560; }

.doc { position: relative; flex: 1; overflow: hidden; }
.doc__page { width: min(430px, 76%); margin: clamp(14px, 5vh, 34px) auto 0; }
.doc__kicker { font-size: clamp(9.5px, 1.5vh, 11px); color: var(--grigio); letter-spacing: 0.02em; }
.doc__title { font-size: clamp(17px, 4vh, 26px); font-weight: 680; font-stretch: 104%; letter-spacing: -0.02em; margin: 4px 0 clamp(10px, 2.6vh, 18px); }
.doc__lines { display: grid; gap: clamp(6px, 1.5vh, 10px); }
.doc__lines i { display: block; height: clamp(6px, 1.25vh, 8px); border-radius: 4px; background: var(--riga); }
.doc__lines i.gap { background: transparent; height: 2px; }

/* the snap zones: a faint wash of the accent in each corner, brighter on the one the throw will land in */
.zone {
  position: absolute;
  left: 0; top: 0;
  border-radius: 14px;
  background: color-mix(in srgb, var(--accento) 6%, transparent);
  outline: 1px dashed color-mix(in srgb, var(--accento) 22%, transparent);
  outline-offset: -1px;
  opacity: 0;
  pointer-events: none;
}

.pip {
  position: absolute;
  left: 0; top: 0;
  touch-action: none;
  cursor: grab;
  will-change: transform;
}
.pip.is-held { cursor: grabbing; }

/* the visible window: a child of the element GSAP moves, so its own scale and shadow live on it */
.pip__body {
  position: relative;
  width: 100%; height: 100%;
  border-radius: 13px;
  overflow: hidden;
  background: var(--video);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), 0 14px 30px -12px rgba(0, 0, 0, 0.45);
}
.pip__video { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.pip__top {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: center; gap: 6px;
  padding: 7px 9px;
  font-size: clamp(9px, 1.45vh, 10.5px);
  color: rgba(255, 255, 255, 0.92);
  background: linear-gradient(rgba(0, 0, 0, 0.38), transparent);
}
.pip__live { padding: 1px 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); font-weight: 600; letter-spacing: 0.01em; }
.pip__name { font-weight: 520; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pip__controls {
  position: absolute; left: 50%; top: 50%;
  display: flex; gap: 8px;
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
}
.pip__btn {
  width: clamp(24px, 4.6vh, 30px); height: clamp(24px, 4.6vh, 30px);
  border-radius: 50%; border: 0; padding: 0;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
}
.pip__btn svg { width: 55%; height: 55%; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.pip__foot {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 7px;
  padding: 7px 9px;
  font-size: clamp(8.5px, 1.35vh, 10px);
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.85);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.42));
}
.pip__track { flex: 1; height: 3px; border-radius: 3px; background: rgba(255, 255, 255, 0.22); overflow: hidden; }
.pip__fill { height: 100%; width: 31%; border-radius: 3px; background: #fff; }

/* the tab: a slim handle on the side the window was tucked into */
.pip__tab {
  position: absolute;
  top: 50%;
  width: 22px; height: 46px;
  margin-top: -23px;
  border: 0; padding: 0;
  border-radius: 10px;
  background: var(--inchiostro);
  display: grid; place-items: center;
  opacity: 0;
  pointer-events: none;
  cursor: pointer;
  box-shadow: 0 8px 18px -8px rgba(0, 0, 0, 0.5);
}
.pip__tab svg { width: 16px; height: 16px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pip.is-tucked .pip__tab { pointer-events: auto; }

@media (hover: hover) {
  .pip:not(.is-tucked):hover .pip__controls { opacity: 1; pointer-events: auto; transition: opacity 0.2s; }
}
.pip.show-controls .pip__controls { opacity: 1; transition: opacity 0.2s; }
.pip__controls { transition: opacity 0.25s; }

.ghost {
  position: absolute; left: 0; top: 0;
  width: 26px; height: 26px;
  fill: #111; stroke: #fff; stroke-width: 1.4; stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25));
  pointer-events: none;
  opacity: 0;
  z-index: 5;
}
